Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.0.13 (binary 0.1.11) -- 2024-09-26

- added `webview.loadHtml(...)`

## 0.0.12 (binary 0.1.10) -- 2024-09-26

BREAKING CHANGES
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "deno-webview"
version = "0.1.10"
version = "0.1.11"
edition = "2021"

[profile.release]
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@justbe/webview",
"exports": "./src/lib.ts",
"version": "0.0.12",
"version": "0.0.13",
"tasks": {
"dev": "deno run --watch main.ts",
"gen": "deno task gen:rust && deno task gen:deno",
Expand Down
12 changes: 12 additions & 0 deletions examples/load-html.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createWebView } from "../src/lib.ts";

using webview = await createWebView({
title: "Load Html Example",
html: "<h1>Initial html</h1>",
});

webview.on("started", async () => {
await webview.loadHtml("<h1>Updated html!</h1>");
});

await webview.waitUntilClosed();
22 changes: 22 additions & 0 deletions schemas/WebViewRequest.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type { WebViewOptions } from "./schemas.ts";

// Should match the cargo package version
/** The version of the webview binary that's expected */
export const BIN_VERSION = "0.1.10";
export const BIN_VERSION = "0.1.11";

type JSON =
| string
Expand Down Expand Up @@ -463,6 +463,14 @@ export class WebView implements Disposable {
return returnAck(result);
}

/**
* Reloads the webview with the provided html.
*/
async loadHtml(html: string): Promise<void> {
const result = await this.#send({ $type: "loadHtml", html });
return returnAck(result);
}

/**
* Destroys the webview and cleans up resources.
*
Expand Down
8 changes: 8 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ enum Request {
id: String,
minimized: Option<bool>,
},
LoadHtml {
id: String,
html: String,
},
}

/// Responses from the webview to the client.
Expand Down Expand Up @@ -426,6 +430,10 @@ fn main() -> wry::Result<()> {
window.set_minimized(minimized);
res(Response::Ack { id });
}
Request::LoadHtml { id, html } => {
webview.load_html(&html).unwrap();
res(Response::Ack { id });
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ export type WebViewRequest =
$type: "minimize";
id: string;
minimized?: boolean;
}
| {
$type: "loadHtml";
html: string;
id: string;
};
export const WebViewRequest: z.ZodType<WebViewRequest> = z.discriminatedUnion(
"$type",
Expand Down Expand Up @@ -180,6 +185,11 @@ export const WebViewRequest: z.ZodType<WebViewRequest> = z.discriminatedUnion(
id: z.string(),
minimized: z.boolean().optional(),
}),
z.object({
$type: z.literal("loadHtml"),
html: z.string(),
id: z.string(),
}),
],
);

Expand Down