refactor: make the whole thing more generic

This commit is contained in:
2024-04-02 16:28:57 +02:00
parent 7b648e1955
commit 651f3ad808
193 changed files with 763 additions and 521 deletions

View File

@@ -0,0 +1,31 @@
import Widget from "resource:///com/github/Aylur/ags/widget.js";
import icons from "../icons.js";
import PowerMenu from "../services/powermenu.js";
import ShadedPopup from "./ShadedPopup.js";
/**
* @param {'sleep' | 'reboot' | 'logout' | 'shutdown'} action
* @param {string} label
*/
const SysButton = (action, label) =>
Widget.Button({
on_clicked: () => PowerMenu.action(action),
child: Widget.Box({
vertical: true,
children: [Widget.Icon(icons.powermenu[action]), Widget.Label(label)],
}),
});
export default () =>
ShadedPopup({
name: "powermenu",
expand: true,
child: Widget.Box({
children: [
SysButton("sleep", "Sleep"),
SysButton("reboot", "Reboot"),
SysButton("logout", "Log Out"),
SysButton("shutdown", "Shutdown"),
],
}),
});

View File

@@ -0,0 +1,44 @@
import App from "resource:///com/github/Aylur/ags/app.js";
import Widget from "resource:///com/github/Aylur/ags/widget.js";
/** @param {string} windowName */
const Padding = (windowName) =>
Widget.EventBox({
class_name: "padding",
hexpand: true,
vexpand: true,
setup: (w) =>
w.on("button-press-event", () => App.toggleWindow(windowName)),
});
/**
* @template {import('gi://Gtk?version=3.0').default.Widget} T
* @param {import('types/widgets/window').WindowProps<T> & {
* name: string
* child: import('types/widgets/box').default
* }} o
*/
export default ({ name, child, ...rest }) =>
Widget.Window({
...rest,
class_names: ["popup-window", name],
name,
visible: false,
popup: true,
keymode: "on-demand",
setup() {
child.toggleClassName("window-content");
},
child: Widget.CenterBox({
class_name: "shader",
css: "min-width: 5000px; min-height: 3000px;",
start_widget: Padding(name),
end_widget: Padding(name),
center_widget: Widget.CenterBox({
vertical: true,
start_widget: Padding(name),
end_widget: Padding(name),
center_widget: child,
}),
}),
});

View File

@@ -0,0 +1,46 @@
import Widget from "resource:///com/github/Aylur/ags/widget.js";
import App from "resource:///com/github/Aylur/ags/app.js";
import * as Utils from "resource:///com/github/Aylur/ags/utils.js";
import PowerMenu from "../services/powermenu.js";
import ShadedPopup from "./ShadedPopup.js";
export default () =>
ShadedPopup({
name: "verification",
expand: true,
child: Widget.Box({
vertical: true,
children: [
Widget.Box({
class_name: "text-box",
vertical: true,
children: [
Widget.Label({
class_name: "title",
label: PowerMenu.bind("title"),
}),
Widget.Label({
class_name: "desc",
label: "Are you sure?",
}),
],
}),
Widget.Box({
class_name: "buttons horizontal",
vexpand: true,
vpack: "end",
homogeneous: true,
children: [
Widget.Button({
child: Widget.Label("No"),
on_clicked: () => App.toggleWindow("verification"),
}),
Widget.Button({
child: Widget.Label("Yes"),
on_clicked: () => Utils.exec(PowerMenu.cmd),
}),
],
}),
],
}),
});