diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9b6c2b1..1fae1f5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/Cargo.lock b/Cargo.lock
index c70b571..4e1cde5 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -278,7 +278,7 @@ dependencies = [
[[package]]
name = "deno-webview"
-version = "0.1.10"
+version = "0.1.11"
dependencies = [
"schemars",
"serde",
diff --git a/Cargo.toml b/Cargo.toml
index fa5bd04..048135f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "deno-webview"
-version = "0.1.10"
+version = "0.1.11"
edition = "2021"
[profile.release]
diff --git a/deno.json b/deno.json
index 5aa6d13..3030043 100644
--- a/deno.json
+++ b/deno.json
@@ -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",
diff --git a/examples/load-html.ts b/examples/load-html.ts
new file mode 100644
index 0000000..98afe1e
--- /dev/null
+++ b/examples/load-html.ts
@@ -0,0 +1,12 @@
+import { createWebView } from "../src/lib.ts";
+
+using webview = await createWebView({
+ title: "Load Html Example",
+ html: "
Initial html
",
+});
+
+webview.on("started", async () => {
+ await webview.loadHtml("Updated html!
");
+});
+
+await webview.waitUntilClosed();
diff --git a/schemas/WebViewRequest.json b/schemas/WebViewRequest.json
index 340dd61..265c0af 100644
--- a/schemas/WebViewRequest.json
+++ b/schemas/WebViewRequest.json
@@ -259,6 +259,28 @@
]
}
}
+ },
+ {
+ "type": "object",
+ "required": [
+ "$type",
+ "html",
+ "id"
+ ],
+ "properties": {
+ "$type": {
+ "type": "string",
+ "enum": [
+ "loadHtml"
+ ]
+ },
+ "html": {
+ "type": "string"
+ },
+ "id": {
+ "type": "string"
+ }
+ }
}
],
"definitions": {
diff --git a/src/lib.ts b/src/lib.ts
index 140d18b..227924e 100644
--- a/src/lib.ts
+++ b/src/lib.ts
@@ -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
@@ -463,6 +463,14 @@ export class WebView implements Disposable {
return returnAck(result);
}
+ /**
+ * Reloads the webview with the provided html.
+ */
+ async loadHtml(html: string): Promise {
+ const result = await this.#send({ $type: "loadHtml", html });
+ return returnAck(result);
+ }
+
/**
* Destroys the webview and cleans up resources.
*
diff --git a/src/main.rs b/src/main.rs
index 6f89f65..bc606f9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -164,6 +164,10 @@ enum Request {
id: String,
minimized: Option,
},
+ LoadHtml {
+ id: String,
+ html: String,
+ },
}
/// Responses from the webview to the client.
@@ -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 });
+ }
}
}
}
diff --git a/src/schemas.ts b/src/schemas.ts
index b06df53..b25707e 100644
--- a/src/schemas.ts
+++ b/src/schemas.ts
@@ -136,6 +136,11 @@ export type WebViewRequest =
$type: "minimize";
id: string;
minimized?: boolean;
+ }
+ | {
+ $type: "loadHtml";
+ html: string;
+ id: string;
};
export const WebViewRequest: z.ZodType = z.discriminatedUnion(
"$type",
@@ -180,6 +185,11 @@ export const WebViewRequest: z.ZodType = z.discriminatedUnion(
id: z.string(),
minimized: z.boolean().optional(),
}),
+ z.object({
+ $type: z.literal("loadHtml"),
+ html: z.string(),
+ id: z.string(),
+ }),
],
);