From 03725e7f89fc951fcb88688a9499a0a098a7e73b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Sj=C3=B6green?= Date: Sun, 3 Mar 2024 14:58:52 +0100 Subject: [PATCH 1/6] feat: JSR support --- README.md | 18 +++++++++++++++++- deno.json | 30 ++++++++++++++++-------------- deps.ts | 1 - mod.ts | 25 +++++++++++++++++++++++++ script/build.ts | 2 +- src/ffi.ts | 2 +- src/webview.ts | 6 +++--- webview | 2 +- 8 files changed, 64 insertions(+), 22 deletions(-) delete mode 100644 deps.ts diff --git a/README.md b/README.md index 7a60fd2..b996897 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,26 @@ applications**. ![Example Image](images/webview_deno.png) +## Installation + +Webview is published to [jsr.io](https://jsr.io/@webview/webview) and +[deno.land](https://deno.land/x/webview). The recommended way to use it is to use +JSR: + +```bash +deno add @webview/webview +``` + +or without the CLI: + +```typescript +import { Webview } from "jsr:@webview/webview"; +``` + ## Example ```typescript -import { Webview } from "https://deno.land/x/webview/mod.ts"; +import { Webview } from "@webview/webview"; const html = ` diff --git a/deno.json b/deno.json index 26ef65c..e57e989 100644 --- a/deno.json +++ b/deno.json @@ -1,19 +1,21 @@ { + "name": "@webview/webview", + "version": "0.8.0", + "exports": "./mod.ts", + "lock": false, "tasks": { - "check": "deno check --unstable mod.ts", - "fmt": "deno fmt --unstable", - "fmt:check": "deno fmt --unstable --check", - "lint": "deno lint --unstable", - "test:doc": "deno test -A --unstable --doc", - "build": "deno run -A --unstable script/build.ts", - "run": "deno task build && export PLUGIN_URL=\"./build/\" && deno run -A --unstable", - "run:fast": "export PLUGIN_URL=\"./build/\" && deno run -A --unstable" + "check": "deno check mod.ts", + "fmt": "deno fmt", + "fmt:check": "deno fmt --check", + "lint": "deno lint", + "test:doc": "deno test -A --unstable-ffi --doc", + "build": "deno run -A script/build.ts", + "run": "deno task build && export PLUGIN_URL=\"./build/\" && deno run -A --unstable-ffi", + "run:fast": "export PLUGIN_URL=\"./build/\" && deno run -A --unstable-ffi" }, + "unstable": ["ffi"], "fmt": { - "files": { - "exclude": [ - "webview/" - ] - } - } + "exclude": ["webview/"] + }, + "imports": { "@denosaurs/plug": "jsr:@denosaurs/plug@^1.0.5" } } diff --git a/deps.ts b/deps.ts deleted file mode 100644 index 9534fd9..0000000 --- a/deps.ts +++ /dev/null @@ -1 +0,0 @@ -export { dlopen, download } from "https://deno.land/x/plug@1.0.2/mod.ts"; diff --git a/mod.ts b/mod.ts index 54b55d0..3436b1a 100644 --- a/mod.ts +++ b/mod.ts @@ -1,2 +1,27 @@ +/** + * Webview is a tiny cross-platform library to make web-based GUIs for desktop + * applications. + * + * @example + * ``` + * import { Webview } from "@webview/webview"; + * + * const html = ` + * + * + *

Hello from deno v${Deno.version.deno}

+ * + * + * `; + * + * const webview = new Webview(); + * + * webview.navigate(`data:text/html,${encodeURIComponent(html)}`); + * webview.run(); + * ``` + * + * @module + */ + export * from "./src/webview.ts"; export { preload, unload } from "./src/ffi.ts"; diff --git a/script/build.ts b/script/build.ts index 91601f2..85b8205 100644 --- a/script/build.ts +++ b/script/build.ts @@ -1,4 +1,4 @@ -import { ensureDir } from "https://deno.land/std@0.197.0/fs/ensure_dir.ts"; +import { ensureDir } from "jsr:@std/fs@0.218/ensure_dir"; const decoder = new TextDecoder(); const architectures = [["x86_64", "x86_64"], ["aarch64", "arm64"]] as const; diff --git a/src/ffi.ts b/src/ffi.ts index ea7799b..4cf4d5d 100644 --- a/src/ffi.ts +++ b/src/ffi.ts @@ -1,4 +1,4 @@ -import { dlopen, download } from "../deps.ts"; +import { dlopen, download } from "@denosaurs/plug"; import { Webview } from "./webview.ts"; const version = "0.7.3"; diff --git a/src/webview.ts b/src/webview.ts index d20f091..9ebc2a1 100644 --- a/src/webview.ts +++ b/src/webview.ts @@ -61,7 +61,7 @@ export interface Size { * ``` */ export class Webview { - #handle: Deno.PointerValue | null = null; + #handle: Deno.PointerValue = null; #callbacks: Map< string, Deno.UnsafeCallback<{ @@ -74,7 +74,7 @@ export class Webview { * * An unsafe pointer to the webview */ - get unsafeHandle() { + get unsafeHandle(): Deno.PointerValue { return this.#handle; } @@ -85,7 +85,7 @@ export class Webview { * backend the pointer is `NSWindow` pointer, when using Win32 backend the * pointer is `HWND` pointer. */ - get unsafeWindowHandle() { + get unsafeWindowHandle(): Deno.PointerValue { return lib.symbols.webview_get_window(this.#handle); } diff --git a/webview b/webview index 2ee04cc..adbb85d 160000 --- a/webview +++ b/webview @@ -1 +1 @@ -Subproject commit 2ee04ccd0530e3928a872f5d508c114403803e61 +Subproject commit adbb85d0f54537b8034ece0bab67c7d1438e3cda From db6c998dfbf23480b557d0a3a2ca89e896c5b34c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Sj=C3=B6green?= Date: Sun, 3 Mar 2024 15:04:49 +0100 Subject: [PATCH 2/6] fix: workflows and tests --- .github/FUNDING.yml | 2 ++ .github/workflows/checks.yml | 7 ------- .github/workflows/publish.yml | 17 +++++++++++++++++ deno.json | 2 +- test_import_map.json | 5 +++++ 5 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/publish.yml create mode 100644 test_import_map.json diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..8f7e379 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +open_collective: denosaurs +github: denosaurs diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 8307edc..e09b1c5 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -10,13 +10,6 @@ jobs: - name: Checkout sources uses: actions/checkout@v2 - - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - name: Install stable deno uses: denoland/setup-deno@v1 with: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..ebf40ee --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,17 @@ +name: Publish + +on: + push: + branches: + - main + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v4 + - uses: denoland/setup-deno@v1 + - run: deno publish diff --git a/deno.json b/deno.json index e57e989..084c862 100644 --- a/deno.json +++ b/deno.json @@ -8,7 +8,7 @@ "fmt": "deno fmt", "fmt:check": "deno fmt --check", "lint": "deno lint", - "test:doc": "deno test -A --unstable-ffi --doc", + "test:doc": "deno test -A --unstable-ffi --doc --import-map test_import_map.json", "build": "deno run -A script/build.ts", "run": "deno task build && export PLUGIN_URL=\"./build/\" && deno run -A --unstable-ffi", "run:fast": "export PLUGIN_URL=\"./build/\" && deno run -A --unstable-ffi" diff --git a/test_import_map.json b/test_import_map.json new file mode 100644 index 0000000..cdefc30 --- /dev/null +++ b/test_import_map.json @@ -0,0 +1,5 @@ +{ + "imports": { + "@webview/webview": "./mod.ts" + } +} From cbd126f3389df65b181fcbd3c55d701e2514f706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Sj=C3=B6green?= Date: Sun, 3 Mar 2024 15:05:02 +0100 Subject: [PATCH 3/6] chore: fmt --- README.md | 4 ++-- mod.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b996897..34d3366 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ applications**. ## Installation Webview is published to [jsr.io](https://jsr.io/@webview/webview) and -[deno.land](https://deno.land/x/webview). The recommended way to use it is to use -JSR: +[deno.land](https://deno.land/x/webview). The recommended way to use it is to +use JSR: ```bash deno add @webview/webview diff --git a/mod.ts b/mod.ts index 3436b1a..28f309d 100644 --- a/mod.ts +++ b/mod.ts @@ -1,11 +1,11 @@ /** * Webview is a tiny cross-platform library to make web-based GUIs for desktop * applications. - * + * * @example * ``` * import { Webview } from "@webview/webview"; - * + * * const html = ` * * @@ -13,13 +13,13 @@ * * * `; - * + * * const webview = new Webview(); - * + * * webview.navigate(`data:text/html,${encodeURIComponent(html)}`); * webview.run(); * ``` - * + * * @module */ From c3f67b8f66d7bc2d67c86f85bca8d4f59e6098b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Sj=C3=B6green?= Date: Sun, 3 Mar 2024 15:14:20 +0100 Subject: [PATCH 4/6] fix: test import map --- test_import_map.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test_import_map.json b/test_import_map.json index cdefc30..09bcc53 100644 --- a/test_import_map.json +++ b/test_import_map.json @@ -1,5 +1,6 @@ { "imports": { - "@webview/webview": "./mod.ts" + "@webview/webview": "./mod.ts", + "@denosaurs/plug": "jsr:@denosaurs/plug@^1.0.5" } } From 0170174ce036091db093dbaae9ba52f18c6838bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Sj=C3=B6green?= Date: Sun, 3 Mar 2024 15:30:48 +0100 Subject: [PATCH 5/6] fix: use version from deno.json --- src/ffi.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ffi.ts b/src/ffi.ts index 4cf4d5d..93e6055 100644 --- a/src/ffi.ts +++ b/src/ffi.ts @@ -1,7 +1,9 @@ +import { version } from "../deno.json" with { type: "json" }; + import { dlopen, download } from "@denosaurs/plug"; import { Webview } from "./webview.ts"; -const version = "0.7.3"; + const cache = Deno.env.get("PLUGIN_URL") === undefined ? "use" : "reloadAll"; const url = Deno.env.get("PLUGIN_URL") ?? `https://github.com/webview/webview_deno/releases/download/${version}/`; From 420c0be401e0658669c468fca7dbbcd86ad83fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Sj=C3=B6green?= Date: Sun, 3 Mar 2024 15:35:30 +0100 Subject: [PATCH 6/6] fix: use old version of submodule --- webview | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webview b/webview index adbb85d..2ee04cc 160000 --- a/webview +++ b/webview @@ -1 +1 @@ -Subproject commit adbb85d0f54537b8034ece0bab67c7d1438e3cda +Subproject commit 2ee04ccd0530e3928a872f5d508c114403803e61