diff options
author | Aylur <[email protected]> | 2025-03-01 20:59:09 +0100 |
---|---|---|
committer | Aylur <[email protected]> | 2025-03-01 21:02:29 +0100 |
commit | 23cdbc8088b5c308a068b432a6b03213ede68f07 (patch) | |
tree | 1e8bd6ffde5273fcd80aca0d30cbb38dbe5f9461 /examples/gtk4/simple-bar/js/src/ts/App.ts | |
parent | dfd1f23c7562694e571d44c45aa74fcea9b1ba01 (diff) |
add gtk4 examples
Diffstat (limited to 'examples/gtk4/simple-bar/js/src/ts/App.ts')
-rw-r--r-- | examples/gtk4/simple-bar/js/src/ts/App.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/examples/gtk4/simple-bar/js/src/ts/App.ts b/examples/gtk4/simple-bar/js/src/ts/App.ts new file mode 100644 index 0000000..012fafa --- /dev/null +++ b/examples/gtk4/simple-bar/js/src/ts/App.ts @@ -0,0 +1,52 @@ +import GObject from "gi://GObject" +import Astal from "gi://Astal?version=4.0" +import Gio from "gi://Gio" +import GLib from "gi://GLib" +import AstalIO from "gi://AstalIO" +import Bar from "./Bar" + +export default class App extends Astal.Application { + static { + GObject.registerClass(this) + } + + static instance: App + static instanceName = "simple-bar" + + // this is where request handlers can be implemented + // that will be used to handle `astal` cli invocations + vfunc_request(request: string, conn: Gio.SocketConnection): void { + print("incoming request", request) + AstalIO.write_sock(conn, "response", null) + } + + // this is the method that will be invoked on `app.runAsync()` + // this is where everything should be initialized and instantiated + vfunc_activate(): void { + this.apply_css("resource:///main.css", false) + this.add_window(new Bar()) + } + + // entry point of our app + static async main(argv: string[]): Promise<number> { + GLib.set_prgname(App.instanceName) + App.instance = new App({ instanceName: App.instanceName }) + + try { + // `app.acquire_socket()` needed for the request API to work + App.instance.acquire_socket() + + // if it succeeds we can run the app + return await App.instance.runAsync([]) + } catch (error) { + // if it throws an error it means there is already an instance + // with `instanceName` running, so we just send a request instead + const response = AstalIO.send_request( + App.instanceName, + argv.join(" "), + ) + print(response) + return 0 + } + } +} |