feat(agsV2): separate configs using async imports
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-11-01 18:16:43 -04:00
parent 07474f1209
commit 2082a2aeb4
7 changed files with 292 additions and 290 deletions

View file

@ -1,89 +1,4 @@
import { execAsync } from 'astal';
import { App } from 'astal/gtk3';
import GLib from 'gi://GLib';
import style from './style/main.scss';
import AppLauncher from './widgets/applauncher/main';
import Bar from './widgets/bar/wim';
import BgFade from './widgets/bg-fade/main';
import Calendar from './widgets/date/main';
import Clipboard from './widgets/clipboard/main';
import Corners from './widgets/corners/main';
import IconBrowser from './widgets/icon-browser/main';
import { NotifPopups, NotifCenter } from './widgets/notifs/main';
import OSD from './widgets/osd/main';
import PowerMenu from './widgets/powermenu/main';
import Screenshot from './widgets/screenshot/main';
import { closeAll as closeAllFunc } from './lib';
import BrightnessService from './services/brightness';
import MonitorClicks from './services/monitor-clicks';
import Lockscreen from './widgets/lockscreen/main';
declare global {
function closeAll(): void;
// eslint-disable-next-line
var Brightness: typeof BrightnessService;
}
globalThis.closeAll = closeAllFunc;
globalThis.Brightness = BrightnessService;
const CONF = GLib.getenv('CONF');
switch (CONF) {
case 'lock': {
App.start({
css: style,
instanceName: CONF,
main: () => {
Lockscreen();
},
});
break;
}
case 'wim': {
App.start({
css: style,
requestHandler(js, res) {
App.eval(js).then(res).catch(res);
},
main: () => {
execAsync('hyprpaper').catch(print);
AppLauncher();
Bar();
BgFade();
Calendar();
Clipboard();
Corners();
IconBrowser();
NotifPopups();
NotifCenter();
OSD();
PowerMenu();
Screenshot();
Brightness.initService({
kbd: 'tpacpi::kbd_backlight',
caps: 'input1::capslock',
});
new MonitorClicks();
setTimeout(() => {
App.get_window('win-applauncher')?.set_visible(true);
}, 3 * 1000);
},
});
break;
}
}
(await import(`./configurations/${GLib.getenv('CONF')}.ts`)).default();

View file

@ -0,0 +1,17 @@
export default async() => {
const { App } = await import('astal/gtk3');
const Lockscreen = (await import('../widgets/lockscreen/main')).default;
const style = (await import('../style/lock.scss')).default;
App.start({
css: style,
instanceName: 'lock',
main: () => {
Lockscreen();
},
});
};

View file

@ -0,0 +1,61 @@
export default async() => {
const { execAsync } = await import('astal');
const { App } = await import('astal/gtk3');
const style = (await import('../style/main.scss')).default;
const AppLauncher = (await import('../widgets/applauncher/main')).default;
const Bar = (await import('../widgets/bar/wim')).default;
const BgFade = (await import('../widgets/bg-fade/main')).default;
const Calendar = (await import('../widgets/date/main')).default;
const Clipboard = (await import('../widgets/clipboard/main')).default;
const Corners = (await import('../widgets/corners/main')).default;
const IconBrowser = (await import('../widgets/icon-browser/main')).default;
const { NotifPopups, NotifCenter } = await import('../widgets/notifs/main');
const OSD = (await import('../widgets/osd/main')).default;
const PowerMenu = (await import('../widgets/powermenu/main')).default;
const Screenshot = (await import('../widgets/screenshot/main')).default;
const { closeAll } = await import('../lib');
const Brightness = (await import('../services/brightness')).default;
const MonitorClicks = (await import('../services/monitor-clicks')).default;
globalThis.closeAll = closeAll;
globalThis.Brightness = Brightness;
App.start({
css: style,
requestHandler(js, res) {
App.eval(js).then(res).catch(res);
},
main: () => {
execAsync('hyprpaper').catch(print);
AppLauncher();
Bar();
BgFade();
Calendar();
Clipboard();
Corners();
IconBrowser();
NotifPopups();
NotifCenter();
OSD();
PowerMenu();
Screenshot();
Brightness.initService({
kbd: 'tpacpi::kbd_backlight',
caps: 'input1::capslock',
});
new MonitorClicks();
setTimeout(() => {
App.get_window('win-applauncher')?.set_visible(true);
}, 3 * 1000);
},
});
};

View file

@ -1,6 +1,11 @@
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars, no-var */
const SRC: string;
var Brightness: import('./services/brightness').default;
function closeAll(): void;
declare module 'inline:*' {
const content: string;

View file

@ -0,0 +1,3 @@
@use 'common';
@use '../widgets/lockscreen';

View file

@ -5,7 +5,6 @@
@use '../widgets/clipboard';
@use '../widgets/date';
@use '../widgets/icon-browser';
@use '../widgets/lockscreen';
@use '../widgets/misc';
@use '../widgets/notifs';
@use '../widgets/osd';

View file

@ -8,30 +8,28 @@ import Lock from 'gi://GtkSessionLock';
import Separator from '../misc/separator';
import { get_hyprland_monitor_desc } from '../../lib';
declare global {
function authFinger(): void;
}
// This file is generated by Nix
import Vars from './vars';
export default () => {
const lock = Lock.prepare_lock();
const windows = new Map<Gdk.Monitor, Gtk.Window>();
@register()
class BlurredBox extends Widget.Box {
/* Types */
declare global {
function authFinger(): void;
}
@register()
class BlurredBox extends Widget.Box {
geometry = {} as { w: number, h: number };
}
const blurBGs: BlurredBox[] = [];
}
const transition_duration = 1000;
const WINDOW_MARGINS = -2;
const ENTRY_SPACING = 20;
const CLOCK_SPACING = 60;
const bgCSS = ({ w = 1, h = 1 } = {}) => `
const windows = new Map<Gdk.Monitor, Gtk.Window>();
const blurBGs: BlurredBox[] = [];
const transition_duration = 1000;
const WINDOW_MARGINS = -2;
const ENTRY_SPACING = 20;
const CLOCK_SPACING = 60;
const bgCSS = ({ w = 1, h = 1 } = {}) => `
border: 2px solid rgba(189, 147, 249, 0.8);
background: rgba(0, 0, 0, 0.2);
min-height: ${h}px;
@ -40,7 +38,9 @@ export default () => {
min-width ${transition_duration / 2}ms;
`;
const unlock = () => {
const lock = Lock.prepare_lock();
const unlock = () => {
blurBGs.forEach((b) => {
b.css = bgCSS({
w: b.geometry.w,
@ -59,9 +59,9 @@ export default () => {
Gdk.Display.get_default()?.sync();
App.quit();
});
};
};
const Clock = () => {
const Clock = () => {
const time = Variable<string>('').poll(1000, () => {
return (new Date().toLocaleString([], {
hour: 'numeric',
@ -78,9 +78,9 @@ export default () => {
label={bind(time)}
/>
);
};
};
const PasswordPrompt = (monitor: Gdk.Monitor, visible: boolean) => {
const PasswordPrompt = (monitor: Gdk.Monitor, visible: boolean) => {
const rev = new BlurredBox({ css: bgCSS() });
idle(() => {
@ -102,8 +102,6 @@ export default () => {
});
});
blurBGs.push(rev);
<window
@ -185,17 +183,17 @@ export default () => {
) :
<box />,
});
};
};
const createWindow = (monitor: Gdk.Monitor) => {
const createWindow = (monitor: Gdk.Monitor) => {
const hyprDesc = get_hyprland_monitor_desc(monitor);
const entryVisible = Vars.mainMonitor === hyprDesc || Vars.dupeLockscreen;
const win = PasswordPrompt(monitor, entryVisible);
windows.set(monitor, win);
};
};
const lock_screen = () => {
const lock_screen = () => {
const display = Gdk.Display.get_default();
for (let m = 0; m < (display?.get_n_monitors() ?? 0); m++) {
@ -205,25 +203,28 @@ export default () => {
createWindow(monitor);
}
}
display?.connect('monitor-added', (_, monitor) => {
createWindow(monitor);
});
lock.lock_lock();
windows.forEach((win, monitor) => {
lock.new_surface(win, monitor);
win.show();
});
};
};
const on_finished = () => {
const on_finished = () => {
lock.destroy();
Gdk.Display.get_default()?.sync();
App.quit();
};
};
lock.connect('finished', on_finished);
lock.connect('finished', on_finished);
if (Vars.hasFprintd) {
if (Vars.hasFprintd) {
globalThis.authFinger = () => AstalAuth.Pam.authenticate('', (_, task) => {
try {
AstalAuth.Pam.authenticate_finish(task);
@ -234,7 +235,8 @@ export default () => {
}
});
globalThis.authFinger();
}
}
export default () => {
lock_screen();
};