Skip to content

Commit

Permalink
feat: JSR support (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliassjogreen committed Mar 3, 2024
1 parent 83c5ff0 commit f60700d
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
open_collective: denosaurs
github: denosaurs
7 changes: 0 additions & 7 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
<html>
Expand Down
30 changes: 16 additions & 14 deletions deno.json
Original file line number Diff line number Diff line change
@@ -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" }
}
1 change: 0 additions & 1 deletion deps.ts

This file was deleted.

25 changes: 25 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -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 = `
* <html>
* <body>
* <h1>Hello from deno v${Deno.version.deno}</h1>
* </body>
* </html>
* `;
*
* 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";
2 changes: 1 addition & 1 deletion script/build.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/ffi.ts
Original file line number Diff line number Diff line change
@@ -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}/`;
Expand Down
6 changes: 3 additions & 3 deletions src/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface Size {
* ```
*/
export class Webview {
#handle: Deno.PointerValue | null = null;
#handle: Deno.PointerValue = null;
#callbacks: Map<
string,
Deno.UnsafeCallback<{
Expand All @@ -74,7 +74,7 @@ export class Webview {
*
* An unsafe pointer to the webview
*/
get unsafeHandle() {
get unsafeHandle(): Deno.PointerValue {
return this.#handle;
}

Expand All @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions test_import_map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"imports": {
"@webview/webview": "./mod.ts",
"@denosaurs/plug": "jsr:@denosaurs/plug@^1.0.5"
}
}

0 comments on commit f60700d

Please sign in to comment.