@corelauncher/rod 1.0.7 → 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.7",
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
@@ -65,6 +65,10 @@ const {
65
65
  // window actions
66
66
  rod_window_start_drag,
67
67
 
68
+ // webcontext
69
+ rod_webcontext_create,
70
+ rod_webcontext_destroy,
71
+
68
72
  // webview
69
73
  rod_webview_create,
70
74
  rod_webview_destroy,
@@ -259,9 +263,19 @@ const {
259
263
  returns: FFIType.void,
260
264
  },
261
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
+
262
276
  // webview
263
277
  rod_webview_create: {
264
- args: [FFIType.ptr, FFIType.cstring],
278
+ args: [FFIType.ptr, FFIType.ptr, FFIType.cstring],
265
279
  returns: FFIType.ptr,
266
280
  },
267
281
  rod_webview_destroy: {
@@ -354,6 +368,9 @@ export {
354
368
  rod_window_set_visible_on_all_workspaces,
355
369
  // window actions
356
370
  rod_window_start_drag,
371
+ // webcontext
372
+ rod_webcontext_create,
373
+ rod_webcontext_destroy,
357
374
  // webview
358
375
  rod_webview_create,
359
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