feat(greetd): add list of all normal users as dropdown
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-02-06 15:50:56 -05:00
parent 51e4988599
commit 3ae192b3c1
3 changed files with 73 additions and 13 deletions

View file

@ -22,9 +22,6 @@
"block-scoped-var": ["error"], "block-scoped-var": ["error"],
"capitalized-comments": ["warn", "always", {
"ignoreConsecutiveComments": true
}],
"class-methods-use-this": ["error"], "class-methods-use-this": ["error"],
"curly": ["warn"], "curly": ["warn"],
"default-case-last": ["warn"], "default-case-last": ["warn"],

View file

@ -1,17 +1,76 @@
const { idle } = Utils; const { Box, Button, Entry, Label, Menu, MenuItem, Window } = Widget;
const { idle, readFileAsync } = Utils;
const greetd = await Service.import('greetd'); const greetd = await Service.import('greetd');
const name = Widget.Entry({ const { Gdk } = imports.gi;
placeholder_text: 'Username',
on_accept: () => password.grab_focus(), const DEFAULT_NAME = 'matt';
const name = Label(DEFAULT_NAME);
let menu;
const dropdown = Button({
child: name,
setup: () => {
idle(() => {
readFileAsync('/etc/passwd').then((out) => {
const users = out.split('\n')
.map((u) => {
const user = u.split(':');
let i = 2;
return {
name: user[0],
uid: Number(user[i++]),
gid: Number(user[i++]),
desc: user[i++],
home: user[i++],
shell: user[i],
};
})
.filter((u) => {
return u.uid >= 1000 &&
!u.name.includes('nixbld') &&
u.name !== 'nobody';
});
// FIXME: make menu scrollable
menu = Menu({
attach_widget: dropdown,
children: users.map((u) => MenuItem({
on_activate: () => {
name.label = u.name;
},
child: Label({
label: u.name,
justification: 'center',
css: `
min-width: ${dropdown.get_allocated_width() / 2}px;
`,
}),
})),
});
}).catch(print);
});
},
on_primary_click_release: (_, event) => {
menu.popup_at_widget(
dropdown,
Gdk.Gravity.SOUTH,
Gdk.Gravity.NORTH,
event,
);
},
}); });
const password = Widget.Entry({ const password = Entry({
placeholder_text: 'Password', placeholder_text: 'Password',
visibility: false, visibility: false,
on_accept: () => { on_accept: () => {
greetd.login( greetd.login(
name.text || '', name.label || '',
password.text || '', password.text || '',
'Hyprland', 'Hyprland',
@ -21,9 +80,9 @@ const password = Widget.Entry({
}, },
}); });
const response = Widget.Label(); const response = Label();
const win = Widget.Window({ const win = Window({
name: 'greeter', name: 'greeter',
css: 'background-color: transparent;', css: 'background-color: transparent;',
anchor: ['top', 'left', 'right', 'bottom'], anchor: ['top', 'left', 'right', 'bottom'],
@ -35,14 +94,14 @@ const win = Widget.Window({
}); });
}, },
child: Widget.Box({ child: Box({
vertical: true, vertical: true,
hpack: 'center', hpack: 'center',
vpack: 'center', vpack: 'center',
hexpand: true, hexpand: true,
vexpand: true, vexpand: true,
children: [ children: [
name, dropdown,
password, password,
response, response,
], ],

View file

@ -0,0 +1,4 @@
// Delete /tmp/ags-greeter before and after using this
import { transpileTypeScript } from './js/utils.js';
export default (await transpileTypeScript('greeter')).default;