2024-03-24 13:54:33 -04:00
|
|
|
const { Box, Entry, Label, Window } = Widget;
|
2024-04-21 14:57:38 -04:00
|
|
|
const { idle, readFileAsync } = Utils;
|
2024-03-24 13:54:33 -04:00
|
|
|
|
|
|
|
const greetd = await Service.import('greetd');
|
|
|
|
|
|
|
|
const { Gtk } = imports.gi;
|
|
|
|
|
|
|
|
const DEFAULT_NAME = 'matt';
|
|
|
|
|
|
|
|
|
|
|
|
const parsePasswd = (fileContent: string) => {
|
|
|
|
const splitUsers = fileContent.split('\n');
|
|
|
|
const parsedUsers = splitUsers.map((u) => {
|
|
|
|
const user = u.split(':');
|
|
|
|
|
|
|
|
return {
|
|
|
|
name: user[0],
|
|
|
|
uid: Number(user[2]),
|
|
|
|
gid: Number(user[3]),
|
|
|
|
desc: user[4],
|
|
|
|
home: user[5],
|
|
|
|
shell: user[6],
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
// 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(await readFileAsync('/etc/passwd'));
|
|
|
|
|
2024-07-25 23:24:19 -04:00
|
|
|
const dropdown = new Gtk.ComboBoxText();
|
|
|
|
|
|
|
|
users.forEach((u) => {
|
|
|
|
dropdown.append(null, u.name);
|
|
|
|
});
|
2024-03-24 13:54:33 -04:00
|
|
|
|
|
|
|
const password = Entry({
|
|
|
|
placeholderText: 'Password',
|
|
|
|
visibility: false,
|
|
|
|
|
|
|
|
setup: (self) => idle(() => {
|
|
|
|
self.grab_focus();
|
|
|
|
}),
|
|
|
|
|
|
|
|
on_accept: () => {
|
|
|
|
greetd.login(
|
2024-07-25 23:24:19 -04:00
|
|
|
dropdown.get_active_text() ?? '',
|
2024-03-24 13:54:33 -04:00
|
|
|
password.text || '',
|
|
|
|
'Hyprland',
|
|
|
|
|
|
|
|
).catch((error) => {
|
|
|
|
response.label = JSON.stringify(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
const response = Label();
|
|
|
|
|
|
|
|
export default () => Window({
|
|
|
|
name: 'greeter',
|
|
|
|
keymode: 'on-demand',
|
|
|
|
|
|
|
|
child: Box({
|
|
|
|
vertical: true,
|
|
|
|
hpack: 'center',
|
|
|
|
vpack: 'center',
|
|
|
|
hexpand: true,
|
|
|
|
vexpand: true,
|
2024-07-25 23:24:19 -04:00
|
|
|
class_names: ['base'],
|
2024-03-24 13:54:33 -04:00
|
|
|
|
|
|
|
children: [
|
|
|
|
Box({
|
|
|
|
vertical: true,
|
|
|
|
hpack: 'center',
|
|
|
|
vpack: 'center',
|
|
|
|
hexpand: true,
|
|
|
|
vexpand: true,
|
2024-07-25 23:24:19 -04:00
|
|
|
class_names: ['linked'],
|
2024-03-24 13:54:33 -04:00
|
|
|
|
2024-07-25 23:24:19 -04:00
|
|
|
setup: () => {
|
2024-03-24 13:54:33 -04:00
|
|
|
idle(() => {
|
2024-07-25 23:24:19 -04:00
|
|
|
const usernames = users.map((u) => u.name);
|
2024-03-24 13:54:33 -04:00
|
|
|
|
|
|
|
if (usernames.includes(DEFAULT_NAME)) {
|
2024-07-25 23:24:19 -04:00
|
|
|
dropdown.set_active(usernames.indexOf(DEFAULT_NAME));
|
2024-03-24 13:54:33 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
children: [
|
|
|
|
dropdown,
|
|
|
|
password,
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
response,
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
});
|