🔧 chore: implement gresource in application + global variables
This commit is contained in:
+20
-6
@@ -43,7 +43,9 @@ const runnerPlugins: Array<Runner.Plugin> = [
|
|||||||
|
|
||||||
const defaultWindows: Array<string> = [];
|
const defaultWindows: Array<string> = [];
|
||||||
|
|
||||||
|
Gtk.init();
|
||||||
Adw.init();
|
Adw.init();
|
||||||
|
GLib.unsetenv("LD_PRELOAD");
|
||||||
|
|
||||||
@register({ GTypeName: "Shell" })
|
@register({ GTypeName: "Shell" })
|
||||||
export class Shell extends Gtk.Application {
|
export class Shell extends Gtk.Application {
|
||||||
@@ -51,8 +53,10 @@ export class Shell extends Gtk.Application {
|
|||||||
|
|
||||||
#loop!: GLib.MainLoop;
|
#loop!: GLib.MainLoop;
|
||||||
#scope!: ReturnType<typeof getScope>;
|
#scope!: ReturnType<typeof getScope>;
|
||||||
|
#connections = new Map<GObject.Object, Array<number> | number>();
|
||||||
#stylesheet: Uint8Array|undefined;
|
#stylesheet: Uint8Array|undefined;
|
||||||
#styleProvider: Gtk.CssProvider;
|
#styleProvider: Gtk.CssProvider;
|
||||||
|
#gresource: Gio.Resource|null = null;
|
||||||
|
|
||||||
get scope() { return this.#scope; }
|
get scope() { return this.#scope; }
|
||||||
|
|
||||||
@@ -64,6 +68,12 @@ export class Shell extends Gtk.Application {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.#styleProvider = Gtk.CssProvider.new();
|
this.#styleProvider = Gtk.CssProvider.new();
|
||||||
|
try {
|
||||||
|
this.#gresource = Gio.Resource.load(GRESOURCES_FILE);
|
||||||
|
} catch(_e) {
|
||||||
|
const e = _e as Error;
|
||||||
|
console.error(`Error: couldn't load gresource! Stderr: ${e.message}\n${e.stack}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getDefault(): Shell {
|
public static getDefault(): Shell {
|
||||||
@@ -122,17 +132,21 @@ export class Shell extends Gtk.Application {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.main();
|
this.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vfunc_activate(): void {
|
||||||
|
super.vfunc_activate();
|
||||||
|
this.main();
|
||||||
|
}
|
||||||
|
|
||||||
private main(): void {
|
private main(): void {
|
||||||
this.#loop = GLib.MainLoop.new(null, false);
|
this.#loop = GLib.MainLoop.new(null, false);
|
||||||
const connections = new Map<GObject.Object, Array<number> | number>();
|
|
||||||
|
|
||||||
connections.set(this, this.connect("shutdown", () => this.#scope.dispose()));
|
this.#connections.set(this, this.connect("shutdown", () => this.#scope.dispose()));
|
||||||
createRoot(() => {
|
createRoot(() => {
|
||||||
console.log(`Colorshell: initializing`);
|
console.log(`Colorshell: initializing`);
|
||||||
this.#scope = getScope();
|
this.#scope = getScope();
|
||||||
@@ -148,12 +162,12 @@ export class Shell extends Gtk.Application {
|
|||||||
console.log("Adding runner plugins");
|
console.log("Adding runner plugins");
|
||||||
runnerPlugins.forEach(plugin => Runner.addPlugin(plugin));
|
runnerPlugins.forEach(plugin => Runner.addPlugin(plugin));
|
||||||
|
|
||||||
connections.set(Wireplumber.getDefault(),
|
this.#connections.set(Wireplumber.getDefault(),
|
||||||
Wireplumber.getDefault().getDefaultSink().connect("notify::volume", () =>
|
Wireplumber.getDefault().getDefaultSink().connect("notify::volume", () =>
|
||||||
triggerOSD())
|
triggerOSD())
|
||||||
);
|
);
|
||||||
|
|
||||||
connections.set(Notifications.getDefault(), [
|
this.#connections.set(Notifications.getDefault(), [
|
||||||
Notifications.getDefault().connect("notification-added", (_, _notif: AstalNotifd.Notification) => {
|
Notifications.getDefault().connect("notification-added", (_, _notif: AstalNotifd.Notification) => {
|
||||||
Windows.getDefault().open("floating-notifications");
|
Windows.getDefault().open("floating-notifications");
|
||||||
}),
|
}),
|
||||||
@@ -167,7 +181,7 @@ export class Shell extends Gtk.Application {
|
|||||||
|
|
||||||
this.#scope.onCleanup(() => {
|
this.#scope.onCleanup(() => {
|
||||||
console.log("Colorshell: disposing connections and quitting because of ::shutdown");
|
console.log("Colorshell: disposing connections and quitting because of ::shutdown");
|
||||||
connections.forEach((ids, obj) => Array.isArray(ids) ?
|
this.#connections.forEach((ids, obj) => Array.isArray(ids) ?
|
||||||
ids.forEach(id => obj.disconnect(id))
|
ids.forEach(id => obj.disconnect(id))
|
||||||
: obj.disconnect(ids));
|
: obj.disconnect(ids));
|
||||||
});
|
});
|
||||||
|
|||||||
Vendored
+2
@@ -1,4 +1,6 @@
|
|||||||
declare const SRC: string
|
declare const SRC: string
|
||||||
|
declare const DEVEL: boolean;
|
||||||
|
declare const GRESOURCES_FILE: string;
|
||||||
|
|
||||||
declare module "inline:*" {
|
declare module "inline:*" {
|
||||||
const content: string
|
const content: string
|
||||||
|
|||||||
+18
-23
@@ -7,7 +7,7 @@ import { FloatingNotifications } from "./window/FloatingNotifications";
|
|||||||
import { CenterWindow } from "./window/CenterWindow";
|
import { CenterWindow } from "./window/CenterWindow";
|
||||||
import { LogoutMenu } from "./window/LogoutMenu";
|
import { LogoutMenu } from "./window/LogoutMenu";
|
||||||
import { AppsWindow } from "./window/AppsWindow";
|
import { AppsWindow } from "./window/AppsWindow";
|
||||||
import { Scope } from "/usr/share/ags/js/gnim/src/jsx/scope";
|
import { createRoot, getScope, onCleanup, Scope } from "/usr/share/ags/js/gnim/src/jsx/scope";
|
||||||
import { Shell } from "./app";
|
import { Shell } from "./app";
|
||||||
import GObject, { getter, register, signal } from "ags/gobject";
|
import GObject, { getter, register, signal } from "ags/gobject";
|
||||||
|
|
||||||
@@ -35,6 +35,7 @@ export type WindowData = {
|
|||||||
class Windows extends GObject.Object {
|
class Windows extends GObject.Object {
|
||||||
private static instance: (Windows | null);
|
private static instance: (Windows | null);
|
||||||
|
|
||||||
|
#scope!: ReturnType<typeof getScope>;
|
||||||
#windows: Record<string, WindowData> = {
|
#windows: Record<string, WindowData> = {
|
||||||
"bar": { create: this.createWindowForMonitors(Bar) },
|
"bar": { create: this.createWindowForMonitors(Bar) },
|
||||||
"osd": { create: this.createWindowForFocusedMonitor(OSD), },
|
"osd": { create: this.createWindowForFocusedMonitor(OSD), },
|
||||||
@@ -60,6 +61,10 @@ class Windows extends GObject.Object {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
createRoot((dispose) => {
|
||||||
|
this.#scope = getScope();
|
||||||
|
Shell.getDefault().scope.onMount(dispose);
|
||||||
|
|
||||||
// Listen to monitor events
|
// Listen to monitor events
|
||||||
const hyprConnections = [
|
const hyprConnections = [
|
||||||
AstalHyprland.get_default().connect("monitor-added", () =>
|
AstalHyprland.get_default().connect("monitor-added", () =>
|
||||||
@@ -69,24 +74,12 @@ class Windows extends GObject.Object {
|
|||||||
this.reopen())
|
this.reopen())
|
||||||
];
|
];
|
||||||
|
|
||||||
Shell.getDefault().scope.run(() => {
|
onCleanup(() => {
|
||||||
// open windows with the "open" status on startup
|
hyprConnections.forEach(id => AstalHyprland.get_default().disconnect(id));
|
||||||
Object.keys(this.#windows).filter((key) =>
|
|
||||||
this.#windows[key].status === "open"
|
|
||||||
).forEach(name => {
|
|
||||||
this.open(name, true);
|
|
||||||
console.log(`Windows: opening window \`${name}\` on startup`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
Shell.getDefault().scope.onCleanup(() => {
|
|
||||||
hyprConnections.forEach(id =>
|
|
||||||
GObject.signal_handler_is_connected(AstalHyprland.get_default(), id) &&
|
|
||||||
AstalHyprland.get_default().disconnect(id)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.openWindows.forEach(name => this.disconnectWindow(name));
|
this.openWindows.forEach(name => this.disconnectWindow(name));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private disconnectWindow(name: string) {
|
private disconnectWindow(name: string) {
|
||||||
@@ -199,12 +192,14 @@ class Windows extends GObject.Object {
|
|||||||
|
|
||||||
// create a scope for every window generator function and dispose on ::close-request
|
// create a scope for every window generator function and dispose on ::close-request
|
||||||
return () => monitors.map(mon => {
|
return () => monitors.map(mon => {
|
||||||
const scope = new Scope(null);
|
return createRoot(() => {
|
||||||
return scope.run(() => {
|
const scope = getScope();
|
||||||
const instance = create(mon.id, scope) as Astal.Window;
|
const instance = create(mon.id, scope) as Astal.Window;
|
||||||
const connection: number = instance.connect("close-request", () =>
|
const connection: number = instance.connect("close-request", () =>
|
||||||
scope.dispose());
|
scope.dispose());
|
||||||
|
|
||||||
|
this.#scope.onMount(scope.dispose);
|
||||||
|
|
||||||
scope.onCleanup(() => instance.disconnect(connection));
|
scope.onCleanup(() => instance.disconnect(connection));
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
@@ -227,12 +222,12 @@ class Windows extends GObject.Object {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
const scope = new Scope(null);
|
return createRoot((dispose) => {
|
||||||
return scope.run(() => {
|
const scope = getScope();
|
||||||
const instance = create(focusedMonitor, scope) as Astal.Window;
|
const instance = create(focusedMonitor, scope) as Astal.Window;
|
||||||
const connection: number = instance.connect("close-request", () =>
|
const connection = instance.connect("close-request", () => dispose());
|
||||||
scope.dispose());
|
|
||||||
|
|
||||||
|
this.#scope.onMount(dispose)
|
||||||
scope.onCleanup(() => instance.disconnect(connection));
|
scope.onCleanup(() => instance.disconnect(connection));
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
|
|||||||
Reference in New Issue
Block a user