Skip to content

Commit

Permalink
fix(example): launch webview from main thread (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy authored Feb 11, 2022
1 parent 19c1e77 commit d19defc
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 27 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ crate-type = ["cdylib"]
[dependencies]
webview-official-sys = "0.1.2"
once_cell = "1.9.0"

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ example:
--unstable \
--no-check \
--config examples/ssr/tsconfig.json \
examples/ssr/ssr.jsx
examples/ssr/main.ts

fmt:
cargo fmt
Expand Down
3 changes: 2 additions & 1 deletion examples/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ const html = `
`;

const webview = new Webview();

webview.navigate(`data:text/html,${encodeURIComponent(html)}`);
webview.run();
webview.run();
13 changes: 13 additions & 0 deletions examples/ssr/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { dirname, join } from "https://deno.land/[email protected]/path/mod.ts";
import { Webview } from "../../mod.ts";

new Worker(
join(dirname(import.meta.url), "worker.tsx"),
{ type: "module", deno: true },
)

const webview = new Webview();
webview.navigate("http://localhost:8000/");

console.log("[runner] worker started");
webview.run();
12 changes: 0 additions & 12 deletions examples/ssr/worker.ts

This file was deleted.

11 changes: 1 addition & 10 deletions examples/ssr/ssr.jsx → examples/ssr/worker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { dirname, join } from "https://deno.land/[email protected]/path/mod.ts";
import { serve } from "https://deno.land/[email protected]/http/server.ts";
import { h, ssr, tw } from "https://crux.land/[email protected]";

Expand All @@ -18,12 +17,4 @@ const server = serve((req) => {
}, { port: 8000 });

console.log("[runner] Listening on http://localhost:8000");
console.log("[runner] worker started");

setTimeout(() =>
new Worker(
join(dirname(import.meta.url), "worker.ts"),
{ type: "module", deno: true },
), 1000);

await server;
await server;
4 changes: 2 additions & 2 deletions src/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export class Webview {
this.#url = url;
}

async run() {
run() {
if (this.#url == null) throw new TypeError("URL not initialized");
sys.symbols.deno_webview_navigate(this.#handle, encode(this.#url));
await sys.symbols.deno_webview_run(this.#handle);
sys.symbols.deno_webview_run(this.#handle);
}

set title(title: string) {
Expand Down

0 comments on commit d19defc

Please sign in to comment.