Skip to content

Commit

Permalink
feat: JSR support
Browse files Browse the repository at this point in the history
  • Loading branch information
eliassjogreen committed Mar 3, 2024
1 parent 83c5ff0 commit 03725e7
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 22 deletions.
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",
"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
2 changes: 1 addition & 1 deletion src/ffi.ts
Original file line number Diff line number Diff line change
@@ -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";
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
2 changes: 1 addition & 1 deletion webview

0 comments on commit 03725e7

Please sign in to comment.