🔧 chore(app, windows): create app scope disposed on app ::shutdown, delete WindowInstance object from WindowData instead of defining as undefined
This commit is contained in:
+13
-4
@@ -14,12 +14,15 @@ import { Stylesheet } from "./scripts/stylesheet";
|
|||||||
import { Clipboard } from "./scripts/clipboard";
|
import { Clipboard } from "./scripts/clipboard";
|
||||||
import { PluginClipboard } from "./runner/plugins/clipboard";
|
import { PluginClipboard } from "./runner/plugins/clipboard";
|
||||||
import { Config } from "./scripts/config";
|
import { Config } from "./scripts/config";
|
||||||
|
import { onCleanup, Scope } from "/usr/share/ags/js/gnim/src/jsx/scope";
|
||||||
|
|
||||||
import App from "ags/gtk4/app"
|
import App from "ags/gtk4/app"
|
||||||
import GObject from "ags/gobject";
|
import GObject from "ags/gobject";
|
||||||
import AstalNotifd from "gi://AstalNotifd";
|
import AstalNotifd from "gi://AstalNotifd";
|
||||||
|
|
||||||
|
|
||||||
|
export const appScope: Scope = new Scope(null);
|
||||||
|
|
||||||
let osdTimer: (Time|undefined), osdTimeout = 3500;
|
let osdTimer: (Time|undefined), osdTimeout = 3500;
|
||||||
let connections = new Map<GObject.Object, (Array<number> | number)>();
|
let connections = new Map<GObject.Object, (Array<number> | number)>();
|
||||||
|
|
||||||
@@ -40,8 +43,10 @@ App.start({
|
|||||||
requestHandler: (request: string, response: (result: any) => void): void => {
|
requestHandler: (request: string, response: (result: any) => void): void => {
|
||||||
response(handleArguments(request));
|
response(handleArguments(request));
|
||||||
},
|
},
|
||||||
main: (..._args: Array<string>) => {
|
main: (..._args: Array<string>) => appScope.run(() => {
|
||||||
console.log(`Initialized astal instance as: ${ App.instanceName || "astal" }`);
|
console.log(`Initialized astal instance as: ${ App.instanceName || "astal" }`);
|
||||||
|
App.connect("shutdown", () => appScope.dispose());
|
||||||
|
|
||||||
console.log("Config: initializing configuration file");
|
console.log("Config: initializing configuration file");
|
||||||
Config.getDefault();
|
Config.getDefault();
|
||||||
|
|
||||||
@@ -63,10 +68,10 @@ App.start({
|
|||||||
console.log("Adding runner plugins");
|
console.log("Adding runner plugins");
|
||||||
runnerPlugins.map(plugin => Runner.addPlugin(plugin));
|
runnerPlugins.map(plugin => Runner.addPlugin(plugin));
|
||||||
|
|
||||||
connections.set(Wireplumber.getDefault(), [
|
connections.set(Wireplumber.getDefault(),
|
||||||
Wireplumber.getDefault().getDefaultSink().connect("notify::volume", () =>
|
Wireplumber.getDefault().getDefaultSink().connect("notify::volume", () =>
|
||||||
triggerOSD())
|
triggerOSD())
|
||||||
]);
|
);
|
||||||
|
|
||||||
connections.set(Notifications.getDefault(), [
|
connections.set(Notifications.getDefault(), [
|
||||||
Notifications.getDefault().connect("notification-added", (_, _notif: AstalNotifd.Notification) => {
|
Notifications.getDefault().connect("notification-added", (_, _notif: AstalNotifd.Notification) => {
|
||||||
@@ -78,7 +83,11 @@ App.start({
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
defaultWindows.forEach(w => Windows.getDefault().open(w));
|
defaultWindows.forEach(w => Windows.getDefault().open(w));
|
||||||
}
|
|
||||||
|
onCleanup(() => connections.forEach((ids, obj) => Array.isArray(ids) ?
|
||||||
|
ids.forEach(id => obj.disconnect(id))
|
||||||
|
: obj.disconnect(ids)));
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
function triggerOSD() {
|
function triggerOSD() {
|
||||||
|
|||||||
+13
-12
@@ -12,6 +12,7 @@ import GObject, { getter, register, signal } from "ags/gobject";
|
|||||||
|
|
||||||
import AstalHyprland from "gi://AstalHyprland";
|
import AstalHyprland from "gi://AstalHyprland";
|
||||||
import { Scope } from "../../../../usr/share/ags/js/gnim/src/jsx/scope";
|
import { Scope } from "../../../../usr/share/ags/js/gnim/src/jsx/scope";
|
||||||
|
import { appScope } from "./app";
|
||||||
|
|
||||||
|
|
||||||
export { Windows };
|
export { Windows };
|
||||||
@@ -60,7 +61,6 @@ class Windows extends GObject.Object {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
createRoot((_) => {
|
|
||||||
// Listen to monitor events
|
// Listen to monitor events
|
||||||
const hyprConnections = [
|
const hyprConnections = [
|
||||||
AstalHyprland.get_default().connect("monitor-added", () =>
|
AstalHyprland.get_default().connect("monitor-added", () =>
|
||||||
@@ -70,15 +70,7 @@ class Windows extends GObject.Object {
|
|||||||
this.reopen())
|
this.reopen())
|
||||||
];
|
];
|
||||||
|
|
||||||
onCleanup(() => {
|
appScope.run(() => {
|
||||||
hyprConnections.forEach(id =>
|
|
||||||
GObject.signal_handler_is_connected(AstalHyprland.get_default(), id) &&
|
|
||||||
AstalHyprland.get_default().disconnect(id)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.openWindows.forEach(name => this.disconnectWindow(name));
|
|
||||||
});
|
|
||||||
|
|
||||||
// open windows with the "open" status on startup
|
// open windows with the "open" status on startup
|
||||||
Object.keys(this.#windows).filter((key) =>
|
Object.keys(this.#windows).filter((key) =>
|
||||||
this.#windows[key].status === "open"
|
this.#windows[key].status === "open"
|
||||||
@@ -87,6 +79,15 @@ class Windows extends GObject.Object {
|
|||||||
console.log(`Windows: opening window \`${name}\` on startup`);
|
console.log(`Windows: opening window \`${name}\` on startup`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private disconnectWindow(name: string) {
|
private disconnectWindow(name: string) {
|
||||||
@@ -157,7 +158,7 @@ class Windows extends GObject.Object {
|
|||||||
window.instance.forEach(inst => inst.connections = [
|
window.instance.forEach(inst => inst.connections = [
|
||||||
inst.instance!.connect("close-request", () => {
|
inst.instance!.connect("close-request", () => {
|
||||||
this.disconnectWindow(name);
|
this.disconnectWindow(name);
|
||||||
inst.instance = undefined;
|
delete window.instance;
|
||||||
window.status = "closed";
|
window.status = "closed";
|
||||||
this.notify("open-windows");
|
this.notify("open-windows");
|
||||||
})
|
})
|
||||||
@@ -169,7 +170,7 @@ class Windows extends GObject.Object {
|
|||||||
window.instance.connections = [
|
window.instance.connections = [
|
||||||
window.instance.instance!.connect("close-request", () => {
|
window.instance.instance!.connect("close-request", () => {
|
||||||
this.disconnectWindow(name);
|
this.disconnectWindow(name);
|
||||||
(window.instance as WindowInstance).instance = undefined;
|
delete window.instance;
|
||||||
window.status = "closed";
|
window.status = "closed";
|
||||||
this.notify("open-windows");
|
this.notify("open-windows");
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user