@corelauncher/rod 1.0.6 → 1.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corelauncher/rod",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Webview for bun based on tauri's tao and wry.",
5
5
  "keywords": [
6
6
  "corelauncher",
@@ -0,0 +1,21 @@
1
+ import type { Pointer } from "bun:ffi";
2
+ import { resolve } from "node:path";
3
+ import { rod_webcontext_create, rod_webcontext_destroy } from "../ffi";
4
+ import { encodeString } from "../utilities/strings";
5
+
6
+ export default class WebContext {
7
+ readonly path: string;
8
+ readonly ptr: Pointer;
9
+
10
+ constructor(path: string) {
11
+ this.path = resolve(path);
12
+
13
+ const ptr = rod_webcontext_create(encodeString(this.path));
14
+ if (!ptr) throw new Error("Failed to create WebContext");
15
+ this.ptr = ptr;
16
+ }
17
+
18
+ destroy() {
19
+ rod_webcontext_destroy(this.ptr);
20
+ }
21
+ }
@@ -16,9 +16,11 @@ import type { WebViewOptions, WindowOptions } from "../types";
16
16
  import { transformWebViewOptions } from "../utilities/options";
17
17
  import { encodeString } from "../utilities/strings";
18
18
  import type EventLoop from "./eventloop";
19
+ import WebContext from "./webcontext";
19
20
  import Window from "./window";
20
21
 
21
22
  export default class WebView extends Window {
23
+ private webcontext: WebContext;
22
24
  protected webviewPtr: Pointer;
23
25
  constructor(
24
26
  eventLoop: EventLoop,
@@ -27,8 +29,11 @@ export default class WebView extends Window {
27
29
  ) {
28
30
  super(eventLoop.eventloopPtr, id, options);
29
31
 
32
+ this.webcontext = new WebContext(options.dataDirectory || "./rod_data");
33
+
30
34
  const webviewPtr = rod_webview_create(
31
35
  this.windowPtr,
36
+ this.webcontext.ptr,
32
37
  encodeString(JSON.stringify(transformWebViewOptions(options))),
33
38
  );
34
39
  if (!webviewPtr) throw new Error("Failed to create WebView");
@@ -78,6 +83,7 @@ export default class WebView extends Window {
78
83
  rod_webview_destroy(this.webviewPtr);
79
84
  this.webviewPtr = null as unknown as Pointer;
80
85
 
86
+ this.webcontext.destroy();
81
87
  super.destroy();
82
88
  }
83
89
  }
package/src-ts/ffi.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { dlopen, FFIType } from "bun:ffi";
2
+ import { join } from "node:path";
2
3
 
3
4
  let library: { default: string };
4
5
  if (process.env.WEBVIEW_PATH) {
5
- library = { default: process.env.WEBVIEW_PATH };
6
+ library = { default: join(".", process.env.WEBVIEW_PATH) };
6
7
  } else if (process.platform === "win32") {
7
8
  library = await import("../target/release/rod.dll");
8
9
  } else {
@@ -64,6 +65,10 @@ const {
64
65
  // window actions
65
66
  rod_window_start_drag,
66
67
 
68
+ // webcontext
69
+ rod_webcontext_create,
70
+ rod_webcontext_destroy,
71
+
67
72
  // webview
68
73
  rod_webview_create,
69
74
  rod_webview_destroy,
@@ -258,9 +263,19 @@ const {
258
263
  returns: FFIType.void,
259
264
  },
260
265
 
266
+ // webcontext
267
+ rod_webcontext_create: {
268
+ args: [FFIType.ptr, FFIType.cstring],
269
+ returns: FFIType.ptr,
270
+ },
271
+ rod_webcontext_destroy: {
272
+ args: [FFIType.ptr],
273
+ returns: FFIType.void,
274
+ },
275
+
261
276
  // webview
262
277
  rod_webview_create: {
263
- args: [FFIType.ptr, FFIType.cstring],
278
+ args: [FFIType.ptr, FFIType.ptr, FFIType.cstring],
264
279
  returns: FFIType.ptr,
265
280
  },
266
281
  rod_webview_destroy: {
@@ -353,6 +368,9 @@ export {
353
368
  rod_window_set_visible_on_all_workspaces,
354
369
  // window actions
355
370
  rod_window_start_drag,
371
+ // webcontext
372
+ rod_webcontext_create,
373
+ rod_webcontext_destroy,
356
374
  // webview
357
375
  rod_webview_create,
358
376
  rod_webview_destroy,
package/src-ts/types.ts CHANGED
@@ -7,6 +7,7 @@ export type WebViewOptions = {
7
7
  html?: string;
8
8
  url?: string;
9
9
  incognito?: boolean;
10
+ dataDirectory?: string;
10
11
  };
11
12
 
12
13
  export type WindowOptions = {
Binary file