From f60700d78e2aa8e53c5975501658a5c33def39de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Sj=C3=B6green?= Date: Sun, 3 Mar 2024 15:35:52 +0100 Subject: [PATCH] feat: JSR support (#166) --- .github/FUNDING.yml | 2 ++ .github/workflows/checks.yml | 7 ------- .github/workflows/publish.yml | 17 +++++++++++++++++ README.md | 18 +++++++++++++++++- deno.json | 30 ++++++++++++++++-------------- deps.ts | 1 - mod.ts | 25 +++++++++++++++++++++++++ script/build.ts | 2 +- src/ffi.ts | 6 ++++-- src/webview.ts | 6 +++--- test_import_map.json | 6 ++++++ 11 files changed, 91 insertions(+), 29 deletions(-) create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/publish.yml delete mode 100644 deps.ts 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/README.md b/README.md index 7a60fd2..34d3366 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..084c862 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 --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" }, + "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..28f309d 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..93e6055 100644 --- a/src/ffi.ts +++ b/src/ffi.ts @@ -1,7 +1,9 @@ -import { dlopen, download } from "../deps.ts"; +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}/`; 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/test_import_map.json b/test_import_map.json new file mode 100644 index 0000000..09bcc53 --- /dev/null +++ b/test_import_map.json @@ -0,0 +1,6 @@ +{ + "imports": { + "@webview/webview": "./mod.ts", + "@denosaurs/plug": "jsr:@denosaurs/plug@^1.0.5" + } +}