forked from sonnyp/Tangram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
re.sonny.Tangram
executable file
·67 lines (56 loc) · 1.65 KB
/
re.sonny.Tangram
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env -S gjs -m
// -*- mode: js; -*-
import { exit } from "system";
import GLib from "gi://GLib";
import Gio from "gi://Gio";
import Gtk from "gi://Gtk?version=4.0";
import Adw from "gi://Adw";
import { build as gjspack } from "./troll/gjspack/src/gjspack.js";
globalThis.__DEV__ = true;
Gtk.init();
Adw.init();
const { gresource_path, prefix } = gjspack({
appid: "re.sonny.Tangram",
entry: Gio.File.new_for_path("./src/main.js"),
output: Gio.File.new_for_path("./src"),
potfiles: Gio.File.new_for_path("./po/POTFILES"),
});
const resource = Gio.resource_load(gresource_path);
Gio.resources_register(resource);
const [filename] = GLib.filename_from_uri(import.meta.url);
const dirname = GLib.path_get_dirname(filename);
const [, , stderr, status] = GLib.spawn_command_line_sync(
`glib-compile-schemas --strict ${GLib.canonicalize_filename(
"./data",
dirname,
)}`,
);
if (status !== 0) {
throw new Error(new TextDecoder().decode(stderr));
}
GLib.setenv(
"GSETTINGS_SCHEMA_DIR",
GLib.canonicalize_filename("./data", dirname),
true,
);
// https://gitlab.gnome.org/GNOME/gjs/blob/master/doc/Package/Specification.md
// https://gitlab.gnome.org/GNOME/gjs/-/blob/master/modules/script/package.js
imports.package.init({
name: "re.sonny.Tangram",
version: "dev",
prefix: "var",
libdir: "",
datadir: "data",
});
const loop = GLib.MainLoop.new(null, false);
import(`resource://${prefix}/src/main.js`)
.then((main) => {
GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
loop.quit();
const exit_code = imports.package.run(main);
exit(exit_code);
return GLib.SOURCE_REMOVE;
});
})
.catch(logError);
loop.run();