fix(ags): revert async imports to work with latest
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-11-19 23:55:17 -05:00
parent c688707d49
commit ef23df4bb2
10 changed files with 373 additions and 360 deletions

View file

@ -2,8 +2,23 @@
// TODO: quick-settings // TODO: quick-settings
// TODO: music player stuff // TODO: music player stuff
// TODO: on-screen-keyboard // TODO: on-screen-keyboard
// TODO: see if I can bundle each config separately with nix
import GLib from 'gi://GLib'; import { programArgs } from 'system';
import binto from './configurations/binto';
import wim from './configurations/wim';
import greeter from './configurations/greeter';
import lock from './configurations/lock';
(await import(`./configurations/${GLib.getenv('CONF')}.ts`)).default(); switch (programArgs[0]) {
case 'binto': binto(); break;
case 'wim': wim(); break;
case 'greeter': greeter(); break;
case 'lock': lock(); break;
}

View file

@ -1,25 +1,25 @@
export default async() => { import { execAsync } from 'astal';
const { execAsync } = await import('astal'); import { App } from 'astal/gtk3';
const { App } = await import('astal/gtk3');
const style = (await import('../style/main.scss')).default; import style from '../style/main.scss';
const AppLauncher = (await import('../widgets/applauncher/main')).default; import AppLauncher from '../widgets/applauncher/main';
const Bar = (await import('../widgets/bar/binto')).default; import Bar from '../widgets/bar/binto';
const BgLayer = (await import('../widgets/bg-layer/main')).default; import BgLayer from '../widgets/bg-layer/main';
const Calendar = (await import('../widgets/date/binto')).default; import Calendar from '../widgets/date/binto';
const Clipboard = (await import('../widgets/clipboard/main')).default; import Clipboard from '../widgets/clipboard/main';
const { NotifPopups, NotifCenter } = await import('../widgets/notifs/binto'); import { NotifPopups, NotifCenter } from '../widgets/notifs/binto';
const OSD = (await import('../widgets/osd/main')).default; import OSD from '../widgets/osd/main';
const PowerMenu = (await import('../widgets/powermenu/main')).default; import PowerMenu from '../widgets/powermenu/main';
const Screenshot = (await import('../widgets/screenshot/main')).default; import Screenshot from '../widgets/screenshot/main';
const { closeAll, perMonitor } = await import('../lib'); import { closeAll, perMonitor } from '../lib';
const Brightness = (await import('../services/brightness')).default; import Brightness from '../services/brightness';
const GSR = (await import('../services/gpu-screen-recorder')).default; import GSR from '../services/gpu-screen-recorder';
const MonitorClicks = (await import('../services/monitor-clicks')).default; import MonitorClicks from '../services/monitor-clicks';
export default () => {
App.start({ App.start({
css: style, css: style,
@ -61,9 +61,8 @@ export default async() => {
PowerMenu(); PowerMenu();
Screenshot(); Screenshot();
Brightness.initService({ Brightness.initService({ caps: 'input2::capslock' });
caps: 'input2::capslock', GSR.initService();
});
new MonitorClicks(); new MonitorClicks();
}, },
}); });

View file

@ -1,12 +1,12 @@
export default async() => { import { execAsync } from 'astal';
const { execAsync } = await import('astal'); import { App } from 'astal/gtk3';
const { App } = await import('astal/gtk3');
const Greeter = (await import('../widgets/greeter/main')).default; import Greeter from '../widgets/greeter/main';
const style = (await import('../style/greeter.scss')).default; import style from '../style/greeter.scss';
export default () => {
App.start({ App.start({
css: style, css: style,
instanceName: 'greeter', instanceName: 'greeter',

View file

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

View file

@ -1,26 +1,26 @@
export default async() => { import { execAsync } from 'astal';
const { execAsync } = await import('astal'); import { App } from 'astal/gtk3';
const { App } = await import('astal/gtk3');
const style = (await import('../style/main.scss')).default; import style from '../style/main.scss';
const AppLauncher = (await import('../widgets/applauncher/main')).default; import AppLauncher from '../widgets/applauncher/main';
const Bar = (await import('../widgets/bar/wim')).default; import Bar from '../widgets/bar/wim';
const BgLayer = (await import('../widgets/bg-layer/main')).default; import BgLayer from '../widgets/bg-layer/main';
const Calendar = (await import('../widgets/date/wim')).default; import Calendar from '../widgets/date/wim';
const Clipboard = (await import('../widgets/clipboard/main')).default; import Clipboard from '../widgets/clipboard/main';
const Corners = (await import('../widgets/corners/main')).default; import Corners from '../widgets/corners/main';
const IconBrowser = (await import('../widgets/icon-browser/main')).default; import IconBrowser from '../widgets/icon-browser/main';
const { NotifPopups, NotifCenter } = await import('../widgets/notifs/wim'); import { NotifPopups, NotifCenter } from '../widgets/notifs/wim';
const OSD = (await import('../widgets/osd/main')).default; import OSD from '../widgets/osd/main';
const PowerMenu = (await import('../widgets/powermenu/main')).default; import PowerMenu from '../widgets/powermenu/main';
const Screenshot = (await import('../widgets/screenshot/main')).default; import Screenshot from '../widgets/screenshot/main';
const { closeAll, perMonitor } = await import('../lib'); import { closeAll, perMonitor } from '../lib';
const Brightness = (await import('../services/brightness')).default; import Brightness from '../services/brightness';
const MonitorClicks = (await import('../services/monitor-clicks')).default; import MonitorClicks from '../services/monitor-clicks';
export default () => {
App.start({ App.start({
css: style, css: style,

View file

@ -75,25 +75,28 @@ const notifySend = ({
class GSR extends GObject.Object { class GSR extends GObject.Object {
private _lastNotifID: number | undefined; private _lastNotifID: number | undefined;
constructor() { public initService() {
super(); try {
subprocess(
['gsr-start'],
(path) => {
if (!this._lastNotifID) {
console.error('[GSR] ID of warning notif not found');
subprocess( setTimeout(() => {
['gsr-start'], this._onSaved(path);
(path) => { }, 1000);
if (!this._lastNotifID) { }
console.error('[GSR] ID of warning notif not found'); else {
setTimeout(() => {
this._onSaved(path); this._onSaved(path);
}, 1000); }
} },
else { () => { /**/ },
this._onSaved(path); );
} }
}, catch (_e) {
() => { /**/ }, console.error('Missing dependency for gpu-screen-recorder');
); }
} }
public saveReplay() { public saveReplay() {

View file

@ -4,92 +4,84 @@ import { App, Astal, Gtk, Widget } from 'astal/gtk3';
import AstalGreet from 'gi://AstalGreet'; import AstalGreet from 'gi://AstalGreet';
const DEFAULT_NAME = 'matt'; export default () => {
const PARSED_INDEX = { const DEFAULT_NAME = 'matt';
name: 0, const PARSED_INDEX = {
uid: 2, name: 0,
gid: 3, uid: 2,
desc: 4, gid: 3,
home: 5, desc: 4,
shell: 6, home: 5,
}; shell: 6,
};
const parsePasswd = (fileContent: string) => { const parsePasswd = (fileContent: string) => {
const splitUsers = fileContent.split('\n'); const splitUsers = fileContent.split('\n');
const parsedUsers = splitUsers.map((u) => { const parsedUsers = splitUsers.map((u) => {
const user = u.split(':'); const user = u.split(':');
return { return {
name: user[PARSED_INDEX.name], name: user[PARSED_INDEX.name],
uid: Number(user[PARSED_INDEX.uid]), uid: Number(user[PARSED_INDEX.uid]),
gid: Number(user[PARSED_INDEX.gid]), gid: Number(user[PARSED_INDEX.gid]),
desc: user[PARSED_INDEX.desc], desc: user[PARSED_INDEX.desc],
home: user[PARSED_INDEX.home], home: user[PARSED_INDEX.home],
shell: user[PARSED_INDEX.shell], shell: user[PARSED_INDEX.shell],
}; };
});
// Filter out system users, nixbld users and nobody
return parsedUsers.filter((u) => {
return u.uid >= 1000 &&
!u.name.includes('nixbld') &&
u.name !== 'nobody';
});
};
const users = parsePasswd(readFile('/etc/passwd'));
const dropdown = new Gtk.ComboBoxText();
dropdown.show_all();
users.forEach((u) => {
dropdown.append(null, u.name);
}); });
// Filter out system users, nixbld users and nobody const response = <label /> as Widget.Label;
return parsedUsers.filter((u) => {
return u.uid >= 1000 &&
!u.name.includes('nixbld') &&
u.name !== 'nobody';
});
};
const users = parsePasswd(readFile('/etc/passwd')); const password = (
<entry
placeholderText="Password"
visibility={false}
const dropdown = new Gtk.ComboBoxText(); setup={(self) => idle(() => {
self.grab_focus();
})}
dropdown.show_all(); onActivate={(self) => {
AstalGreet.login(
dropdown.get_active_text() ?? '',
self.text || '',
'Hyprland',
(_, res) => {
try {
AstalGreet.login_finish(res);
App.quit();
}
catch (error) {
response.label = JSON.stringify(error);
}
},
);
}}
/>
);
users.forEach((u) => { return (
dropdown.append(null, u.name); <window
}); name="greeter"
keymode={Astal.Keymode.ON_DEMAND}
const response = <label /> as Widget.Label;
const password = (
<entry
placeholderText="Password"
visibility={false}
setup={(self) => idle(() => {
self.grab_focus();
})}
onActivate={(self) => {
AstalGreet.login(
dropdown.get_active_text() ?? '',
self.text || '',
'Hyprland',
(_, res) => {
try {
AstalGreet.login_finish(res);
App.quit();
}
catch (error) {
response.label = JSON.stringify(error);
}
},
);
}}
/>
);
export default () => (
<window
name="greeter"
keymode={Astal.Keymode.ON_DEMAND}
>
<box
vertical
halign={Gtk.Align.CENTER}
valign={Gtk.Align.CENTER}
hexpand
vexpand
className="base"
> >
<box <box
vertical vertical
@ -97,23 +89,32 @@ export default () => (
valign={Gtk.Align.CENTER} valign={Gtk.Align.CENTER}
hexpand hexpand
vexpand vexpand
className="linked" className="base"
setup={() => {
idle(() => {
const usernames = users.map((u) => u.name);
if (usernames.includes(DEFAULT_NAME)) {
dropdown.set_active(usernames.indexOf(DEFAULT_NAME));
}
});
}}
> >
{dropdown} <box
{password} vertical
</box> halign={Gtk.Align.CENTER}
valign={Gtk.Align.CENTER}
hexpand
vexpand
className="linked"
{response} setup={() => {
</box> idle(() => {
</window> const usernames = users.map((u) => u.name);
);
if (usernames.includes(DEFAULT_NAME)) {
dropdown.set_active(usernames.indexOf(DEFAULT_NAME));
}
});
}}
>
{dropdown}
{password}
</box>
{response}
</box>
</window>
);
};

View file

@ -21,222 +21,221 @@ class BlurredBox extends Widget.Box {
} }
const windows = new Map<Gdk.Monitor, Gtk.Window>(); export default () => {
const blurBGs: BlurredBox[] = []; const windows = new Map<Gdk.Monitor, Gtk.Window>();
const blurBGs: BlurredBox[] = [];
const transition_duration = 1000; const transition_duration = 1000;
const WINDOW_MARGINS = -2; const WINDOW_MARGINS = -2;
const ENTRY_SPACING = 20; const ENTRY_SPACING = 20;
const CLOCK_SPACING = 60; const CLOCK_SPACING = 60;
const bgCSS = ({ w = 1, h = 1 } = {}) => ` const bgCSS = ({ w = 1, h = 1 } = {}) => `
border: 2px solid rgba(189, 147, 249, 0.8); border: 2px solid rgba(189, 147, 249, 0.8);
background: rgba(0, 0, 0, 0.2); background: rgba(0, 0, 0, 0.2);
min-height: ${h}px; min-height: ${h}px;
min-width: ${w}px; min-width: ${w}px;
transition: min-height ${transition_duration / 2}ms, transition: min-height ${transition_duration / 2}ms,
min-width ${transition_duration / 2}ms; min-width ${transition_duration / 2}ms;
`; `;
const lock = Lock.prepare_lock(); const lock = Lock.prepare_lock();
const unlock = () => { const unlock = () => {
blurBGs.forEach((b) => { blurBGs.forEach((b) => {
b.css = bgCSS({
w: b.geometry.w,
h: 1,
});
timeout(transition_duration / 2, () => {
b.css = bgCSS({ b.css = bgCSS({
w: 1, w: b.geometry.w,
h: 1, h: 1,
}); });
});
});
timeout(transition_duration, () => {
lock.unlock_and_destroy();
Gdk.Display.get_default()?.sync();
App.quit();
});
};
const Clock = () => { timeout(transition_duration / 2, () => {
const time = Variable<string>('').poll(1000, () => { b.css = bgCSS({
return (new Date().toLocaleString([], { w: 1,
hour: 'numeric', h: 1,
minute: 'numeric', });
hour12: true,
}) ?? '')
.replace('a.m.', 'AM')
.replace('p.m.', 'PM');
});
return (
<label
className="lock-clock"
label={bind(time)}
/>
);
};
const PasswordPrompt = (monitor: Gdk.Monitor, visible: boolean) => {
const rev = new BlurredBox({ css: bgCSS() });
idle(() => {
rev.geometry = {
w: monitor.geometry.width,
h: monitor.geometry.height,
};
rev.css = bgCSS({
w: rev.geometry.w,
h: 1,
});
timeout(transition_duration / 2, () => {
rev.css = bgCSS({
w: rev.geometry.w,
h: rev.geometry.h,
}); });
}); });
}); timeout(transition_duration, () => {
lock.unlock_and_destroy();
Gdk.Display.get_default()?.sync();
App.quit();
});
};
blurBGs.push(rev); const Clock = () => {
const time = Variable<string>('').poll(1000, () => {
return (new Date().toLocaleString([], {
hour: 'numeric',
minute: 'numeric',
hour12: true,
}) ?? '')
.replace('a.m.', 'AM')
.replace('p.m.', 'PM');
});
<window return (
name={`blur-bg-${monitor.get_model()}`} <label
namespace={`blur-bg-${monitor.get_model()}`} className="lock-clock"
gdkmonitor={monitor} label={bind(time)}
layer={Astal.Layer.OVERLAY} />
anchor={ );
Astal.WindowAnchor.TOP | };
Astal.WindowAnchor.LEFT |
Astal.WindowAnchor.RIGHT | const PasswordPrompt = (monitor: Gdk.Monitor, visible: boolean) => {
Astal.WindowAnchor.BOTTOM const rev = new BlurredBox({ css: bgCSS() });
}
margin={WINDOW_MARGINS} idle(() => {
exclusivity={Astal.Exclusivity.IGNORE} rev.geometry = {
> w: monitor.geometry.width,
<box h: monitor.geometry.height,
halign={Gtk.Align.CENTER} };
valign={Gtk.Align.CENTER}
rev.css = bgCSS({
w: rev.geometry.w,
h: 1,
});
timeout(transition_duration / 2, () => {
rev.css = bgCSS({
w: rev.geometry.w,
h: rev.geometry.h,
});
});
});
blurBGs.push(rev);
<window
name={`blur-bg-${monitor.get_model()}`}
namespace={`blur-bg-${monitor.get_model()}`}
gdkmonitor={monitor}
layer={Astal.Layer.OVERLAY}
anchor={
Astal.WindowAnchor.TOP |
Astal.WindowAnchor.LEFT |
Astal.WindowAnchor.RIGHT |
Astal.WindowAnchor.BOTTOM
}
margin={WINDOW_MARGINS}
exclusivity={Astal.Exclusivity.IGNORE}
> >
{rev} <box
</box> halign={Gtk.Align.CENTER}
</window>; valign={Gtk.Align.CENTER}
>
{rev}
</box>
</window>;
const label = <label label="Enter password:" /> as Widget.Label; const label = <label label="Enter password:" /> as Widget.Label;
return new Gtk.Window({
child: visible ?
(
<box
vertical
halign={Gtk.Align.CENTER}
valign={Gtk.Align.CENTER}
spacing={16}
>
<Clock />
<Separator size={CLOCK_SPACING} vertical />
return new Gtk.Window({
child: visible ?
(
<box <box
halign={Gtk.Align.CENTER}
className="avatar"
/>
<box
className="entry-box"
vertical vertical
halign={Gtk.Align.CENTER}
valign={Gtk.Align.CENTER}
spacing={16}
> >
{label} <Clock />
<Separator size={ENTRY_SPACING} vertical /> <Separator size={CLOCK_SPACING} vertical />
<entry <box
halign={Gtk.Align.CENTER} halign={Gtk.Align.CENTER}
xalign={0.5} className="avatar"
visibility={false}
placeholder_text="password"
onRealize={(self) => self.grab_focus()}
onActivate={(self) => {
self.sensitive = false;
AstalAuth.Pam.authenticate(self.text ?? '', (_, task) => {
try {
AstalAuth.Pam.authenticate_finish(task);
unlock();
}
catch (e) {
self.text = '';
label.label = (e as Error).message;
self.sensitive = true;
}
});
}}
/> />
<box
className="entry-box"
vertical
>
{label}
<Separator size={ENTRY_SPACING} vertical />
<entry
halign={Gtk.Align.CENTER}
xalign={0.5}
visibility={false}
placeholder_text="password"
onRealize={(self) => self.grab_focus()}
onActivate={(self) => {
self.sensitive = false;
AstalAuth.Pam.authenticate(self.text ?? '', (_, task) => {
try {
AstalAuth.Pam.authenticate_finish(task);
unlock();
}
catch (e) {
self.text = '';
label.label = (e as Error).message;
self.sensitive = true;
}
});
}}
/>
</box>
</box> </box>
</box> ) :
) : <box />,
<box />, });
}); };
};
const createWindow = (monitor: Gdk.Monitor) => { const createWindow = (monitor: Gdk.Monitor) => {
const hyprDesc = get_hyprland_monitor_desc(monitor); const hyprDesc = get_hyprland_monitor_desc(monitor);
const entryVisible = Vars.mainMonitor === hyprDesc || Vars.dupeLockscreen; const entryVisible = Vars.mainMonitor === hyprDesc || Vars.dupeLockscreen;
const win = PasswordPrompt(monitor, entryVisible); const win = PasswordPrompt(monitor, entryVisible);
windows.set(monitor, win); windows.set(monitor, win);
}; };
const lock_screen = () => { const lock_screen = () => {
const display = Gdk.Display.get_default(); const display = Gdk.Display.get_default();
for (let m = 0; m < (display?.get_n_monitors() ?? 0); m++) { for (let m = 0; m < (display?.get_n_monitors() ?? 0); m++) {
const monitor = display?.get_monitor(m); const monitor = display?.get_monitor(m);
if (monitor) { if (monitor) {
createWindow(monitor);
}
}
display?.connect('monitor-added', (_, monitor) => {
createWindow(monitor); createWindow(monitor);
} });
lock.lock_lock();
windows.forEach((win, monitor) => {
lock.new_surface(win, monitor);
win.show();
});
};
const on_finished = () => {
lock.destroy();
Gdk.Display.get_default()?.sync();
App.quit();
};
lock.connect('finished', on_finished);
if (Vars.hasFprintd) {
globalThis.authFinger = () => AstalAuth.Pam.authenticate('', (_, task) => {
try {
AstalAuth.Pam.authenticate_finish(task);
unlock();
}
catch (e) {
console.error((e as Error).message);
}
});
globalThis.authFinger();
} }
display?.connect('monitor-added', (_, monitor) => {
createWindow(monitor);
});
lock.lock_lock();
windows.forEach((win, monitor) => {
lock.new_surface(win, monitor);
win.show();
});
};
const on_finished = () => {
lock.destroy();
Gdk.Display.get_default()?.sync();
App.quit();
};
lock.connect('finished', on_finished);
if (Vars.hasFprintd) {
globalThis.authFinger = () => AstalAuth.Pam.authenticate('', (_, task) => {
try {
AstalAuth.Pam.authenticate_finish(task);
unlock();
}
catch (e) {
console.error((e as Error).message);
}
});
globalThis.authFinger();
}
export default () => {
lock_screen(); lock_screen();
}; };

View file

@ -26,8 +26,10 @@ in {
"cava" "cava"
"powerprofiles" "powerprofiles"
"river" "river"
"docs" # not a lib
"gjs" # not a lib # Not libraries
"docs"
"gjs"
] ]
) )
++ [gtk-session-lock.packages.${pkgs.system}.default]; ++ [gtk-session-lock.packages.${pkgs.system}.default];
@ -36,10 +38,8 @@ in {
name = "lock"; name = "lock";
runtimeInputs = [cfg.package]; runtimeInputs = [cfg.package];
text = '' text = ''
export CONF="lock"
if [ "$#" == 0 ]; then if [ "$#" == 0 ]; then
exec ags run ~/${cfg.configDir} exec ags run ~/${cfg.configDir} -a lock
else else
exec ags "$@" -i lock exec ags "$@" -i lock
fi fi
@ -54,10 +54,8 @@ in {
name = "ags"; name = "ags";
runtimeInputs = [cfg.package]; runtimeInputs = [cfg.package];
text = '' text = ''
export CONF="${hostName}"
if [ "$#" == 0 ]; then if [ "$#" == 0 ]; then
exec ags run ~/${cfg.configDir} exec ags run ~/${cfg.configDir} -a ${hostName}
else else
exec ags "$@" exec ags "$@"
fi fi
@ -67,8 +65,7 @@ in {
name = "agsConf"; name = "agsConf";
runtimeInputs = [cfg.package]; runtimeInputs = [cfg.package];
text = '' text = ''
export CONF="$1" exec ags run ~/${cfg.configDir} -a "$1"
exec ${cfg.package}/bin/ags run ~/${cfg.configDir}
''; '';
}) })
] ]

View file

@ -54,8 +54,7 @@ self: {
]; ];
text = '' text = ''
export CONF="greeter" exec ags run ${agsConfig} -a greeter
exec ags run ${agsConfig}
''; '';
}) })
]; ];