@gtkx/ffi 0.1.33 → 0.1.35

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.
package/README.md CHANGED
@@ -119,10 +119,12 @@ import { AccessibleRole } from "@gtkx/ffi/gtk";
119
119
  import { App } from "./app.js";
120
120
 
121
121
  // Clean up after each test
122
- afterEach(() => cleanup());
122
+ afterEach(async () => {
123
+ await cleanup();
124
+ });
123
125
 
124
126
  test("increments count when clicking button", async () => {
125
- render(<App />);
127
+ await render(<App />);
126
128
 
127
129
  const button = await screen.findByRole(AccessibleRole.BUTTON, {
128
130
  name: "Increment",
@@ -132,8 +134,8 @@ test("increments count when clicking button", async () => {
132
134
  await screen.findByText("Count: 1");
133
135
  });
134
136
 
135
- test("can also use fireEvent for synchronous events", async () => {
136
- render(<App />);
137
+ test("can also use fireEvent for low-level events", async () => {
138
+ await render(<App />);
137
139
 
138
140
  const button = await screen.findByRole(AccessibleRole.BUTTON, {
139
141
  name: "Increment",
@@ -146,10 +148,8 @@ test("can also use fireEvent for synchronous events", async () => {
146
148
 
147
149
  ### Available APIs
148
150
 
149
- **Queries** - Find elements in the rendered tree:
150
- - `getBy*` / `getAllBy*` - Throws if not found
151
- - `queryBy*` / `queryAllBy*` - Returns null/empty array if not found
152
- - `findBy*` / `findAllBy*` - Async, waits for element
151
+ **Queries** - Find elements in the rendered tree (all async):
152
+ - `findBy*` / `findAllBy*` - Waits for element to appear
153
153
 
154
154
  Query types: `ByRole`, `ByText`, `ByLabelText`, `ByTestId`
155
155
 
package/dist/native.d.ts CHANGED
@@ -12,4 +12,5 @@ export declare const wrapPtr: <T extends object>(ptr: unknown, cls: {
12
12
  prototype: T;
13
13
  }) => T;
14
14
  export declare const start: (appId: string, flags?: ApplicationFlags) => Application;
15
+ export declare const getCurrentApp: () => Application;
15
16
  export declare const stop: () => void;
package/dist/native.js CHANGED
@@ -2,6 +2,7 @@ import { EventEmitter } from "node:events";
2
2
  import { createRef, start as nativeStart, stop as nativeStop } from "@gtkx/native";
3
3
  export { createRef };
4
4
  import { Application } from "./generated/gtk/application.js";
5
+ let currentApp = null;
5
6
  let keepAliveTimeout = null;
6
7
  export const events = new EventEmitter();
7
8
  export const wrapPtr = (ptr, cls) => {
@@ -13,16 +14,30 @@ const keepAlive = () => {
13
14
  keepAliveTimeout = setTimeout(() => keepAlive(), 2147483647);
14
15
  };
15
16
  export const start = (appId, flags) => {
17
+ if (currentApp) {
18
+ return currentApp;
19
+ }
16
20
  const app = nativeStart(appId, flags);
21
+ currentApp = wrapPtr(app, Application);
17
22
  events.emit("start");
18
23
  keepAlive();
19
- return wrapPtr(app, Application);
24
+ return currentApp;
25
+ };
26
+ export const getCurrentApp = () => {
27
+ if (!currentApp) {
28
+ throw new Error("GTK application not initialized. Call start() first.");
29
+ }
30
+ return currentApp;
20
31
  };
21
32
  export const stop = () => {
33
+ if (!currentApp) {
34
+ return;
35
+ }
22
36
  if (keepAliveTimeout) {
23
37
  clearTimeout(keepAliveTimeout);
24
38
  keepAliveTimeout = null;
25
39
  }
26
40
  events.emit("stop");
27
41
  nativeStop();
42
+ currentApp = null;
28
43
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gtkx/ffi",
3
- "version": "0.1.33",
3
+ "version": "0.1.35",
4
4
  "description": "Generated TypeScript FFI bindings for GTK4 libraries",
5
5
  "keywords": [
6
6
  "gtk",
@@ -46,10 +46,10 @@
46
46
  "dist"
47
47
  ],
48
48
  "dependencies": {
49
- "@gtkx/native": "0.1.33"
49
+ "@gtkx/native": "0.1.35"
50
50
  },
51
51
  "devDependencies": {
52
- "@gtkx/gir": "0.1.33"
52
+ "@gtkx/gir": "0.1.35"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "tsc -b && cp ../../README.md .",