@gjsify/node-gi 0.13.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,60 @@
1
+ // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
2
+ // SPDX-FileCopyrightText: 2012 Giovanni Campagna <scampa.giovanni@gmail.com>
3
+ //
4
+ // Adapted from GJS (refs/gjs/modules/script/mainloop.js). Copyright (c) 2012
5
+ // Giovanni Campagna. MIT OR LGPL-2.0-or-later.
6
+ // Modifications: the legacy `imports.mainloop` — a thin convenience layer over
7
+ // GLib.MainLoop — ported to @gjsify/node-gi. GJS builds the idle/timeout sources
8
+ // via GObject.source_set_closure; this port routes through GLib.idle_add /
9
+ // GLib.timeout_add directly instead (equivalent behavior, one less indirection —
10
+ // the engine marshals JS functions both as GI callbacks and as GClosures, see
11
+ // test/gclosure-in-args.test.mjs), keeping the same `imports.mainloop.*` surface.
12
+
13
+ const DEFAULT_IDLE_PRIORITY = 200; // GLib.PRIORITY_DEFAULT_IDLE
14
+
15
+ /**
16
+ * Build the `imports.mainloop` object bound to the L1 GLib namespace.
17
+ * @param {Record<string, any>} GLib
18
+ * @returns {{ run(name?: string): void, quit(name?: string): void, idle_add: Function, timeout_add: Function, timeout_add_seconds: Function, source_remove: Function }}
19
+ */
20
+ export function createMainloop(GLib) {
21
+ const _mainLoops = Object.create(null);
22
+
23
+ function run(name = '') {
24
+ if (!_mainLoops[name]) _mainLoops[name] = GLib.MainLoop.new(null, false);
25
+ _mainLoops[name].run();
26
+ }
27
+
28
+ function quit(name = '') {
29
+ if (!_mainLoops[name]) throw new Error('No main loop with this id');
30
+
31
+ const loop = _mainLoops[name];
32
+ _mainLoops[name] = null;
33
+
34
+ if (!loop.is_running()) throw new Error('Main loop was stopped already');
35
+
36
+ loop.quit();
37
+ }
38
+
39
+ // GJS signature is `idle_add(handler, priority)` — handler first — whereas the
40
+ // introspected GLib.idle_add is `(priority, handler)`; bridge the argument order.
41
+ function idle_add(handler, priority = DEFAULT_IDLE_PRIORITY) {
42
+ return GLib.idle_add(priority, handler);
43
+ }
44
+
45
+ function timeout_add(timeout, handler, priority = GLib.PRIORITY_DEFAULT) {
46
+ return GLib.timeout_add(priority, timeout, handler);
47
+ }
48
+
49
+ function timeout_add_seconds(timeout, handler, priority = GLib.PRIORITY_DEFAULT) {
50
+ return GLib.timeout_add_seconds(priority, timeout, handler);
51
+ }
52
+
53
+ function source_remove(id) {
54
+ return GLib.source_remove(id);
55
+ }
56
+
57
+ return { run, quit, idle_add, timeout_add, timeout_add_seconds, source_remove };
58
+ }
59
+
60
+ export default createMainloop;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/node-gi",
3
- "version": "0.13.0",
3
+ "version": "0.20.0",
4
4
  "description": "GObject-Introspection runtime for Node.js — load gi:// namespaces (GLib/GObject/Gio/…) with GJS-compatible semantics. Vendored + rewritten from node-gtk under MIT.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -19,6 +19,22 @@
19
19
  "./globals": {
20
20
  "types": "./globals.d.ts",
21
21
  "default": "./globals.js"
22
+ },
23
+ "./system": {
24
+ "types": "./system.d.ts",
25
+ "default": "./system.js"
26
+ },
27
+ "./gettext": {
28
+ "types": "./gettext.d.ts",
29
+ "default": "./gettext.js"
30
+ },
31
+ "./cairo": {
32
+ "types": "./cairo.d.ts",
33
+ "default": "./cairo.js"
34
+ },
35
+ "./gtk-runtime": {
36
+ "types": "./gtk-runtime.d.ts",
37
+ "default": "./gtk-runtime.js"
22
38
  }
23
39
  },
24
40
  "files": [
@@ -26,8 +42,17 @@
26
42
  "index.d.ts",
27
43
  "gi.js",
28
44
  "gi.d.ts",
45
+ "gtk-runtime.js",
46
+ "gtk-runtime.d.ts",
29
47
  "globals.js",
30
48
  "globals.d.ts",
49
+ "system.js",
50
+ "system.d.ts",
51
+ "gettext.js",
52
+ "gettext.d.ts",
53
+ "cairo.js",
54
+ "cairo.d.ts",
55
+ "overrides",
31
56
  "src",
32
57
  "binding.gyp",
33
58
  "prebuilds"
@@ -38,16 +63,32 @@
38
63
  "node": "polyfill",
39
64
  "browser": "none",
40
65
  "nativescript": "none"
41
- }
66
+ },
67
+ "tier": 2
42
68
  },
43
69
  "scripts": {
44
70
  "install": "node-gyp rebuild",
45
71
  "build": "node-gyp rebuild",
46
72
  "build:native": "node-gyp rebuild",
73
+ "build:prebuild": "node-gyp rebuild && node scripts/stage-prebuild.mjs",
47
74
  "rebuild": "node-gyp rebuild",
48
75
  "clean": "node-gyp clean",
49
- "test": "node --test",
50
- "test:node": "node --test"
76
+ "test": "NODE_GI_NATIVE=build node --test",
77
+ "test:node": "NODE_GI_NATIVE=build node --test",
78
+ "test:gc": "NODE_GI_NATIVE=build node --test --expose-gc",
79
+ "test:dbus": "dbus-run-session -- env NODE_GI_NATIVE=build node --test --expose-gc test/dbus.test.mjs test/dbus-async.test.mjs",
80
+ "test:bun": "node scripts/cross-runtime.mjs bun",
81
+ "test:conformance": "node scripts/conformance.mjs",
82
+ "test:gimarshalling": "node scripts/gimarshalling.mjs",
83
+ "test:deno": "node scripts/cross-runtime.mjs deno",
84
+ "test:cairo": "NODE_GI_NATIVE=build node --test test/cairo.test.mjs",
85
+ "test:cairo-canvas2d": "NODE_GI_NATIVE=build node --test test/cairo-canvas2d.test.mjs",
86
+ "test:gtk": "NODE_GI_NATIVE=build node --test test/gtk-smoke.test.mjs",
87
+ "test:gtk-cairo": "NODE_GI_NATIVE=build node --test test/cairo-drawfunc.test.mjs",
88
+ "test:adw": "NODE_GI_NATIVE=build node --test test/adw-smoke.test.mjs",
89
+ "test:gtk-template": "NODE_GI_NATIVE=build node --test test/gtk-template.test.mjs",
90
+ "test:gtk-template-callbacks": "NODE_GI_NATIVE=build node --test test/gtk-template-callbacks.test.mjs",
91
+ "test:gtk-template-signals": "NODE_GI_NATIVE=build node --test test/gtk-template-signals.test.mjs"
51
92
  },
52
93
  "dependencies": {
53
94
  "node-addon-api": "^8.0.0"