Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed build.ts and added <Webview>.setHTML() and updated deps. #159

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ build/

# MacOS
.DS_Store

#lockfile
deno.lock
2 changes: 1 addition & 1 deletion examples/bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const html = `

const webview = new Webview();

webview.navigate(`data:text/html,${encodeURIComponent(html)}`);
webview.setHTML(html);

let counter = 0;
webview.bind("press", (a, b, c) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ const html = `

const webview = new Webview();

webview.navigate(`data:text/html,${encodeURIComponent(html)}`);
webview.setHTML(html);
webview.run();
2 changes: 1 addition & 1 deletion examples/ssr/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dirname, join } from "https://deno.land/std@0.157.0/path/mod.ts";
import { dirname, join } from "https://deno.land/std@0.197.0/path/mod.ts";
import { Webview } from "../../mod.ts";

const worker = new Worker(
Expand Down
6 changes: 2 additions & 4 deletions examples/ssr/worker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />

import { serve } from "https://deno.land/[email protected]/http/server.ts";
import { h, ssr, tw } from "https://crux.land/[email protected]";

const Hello = (props: { name: string }) => (
Expand All @@ -15,12 +14,11 @@ const Hello = (props: { name: string }) => (
</div>
);

const server = serve((req) => {
Deno.serve({ port: 8000 }, (req) => {
console.log(req);
const url = new URL(req.url);
const name = url.searchParams.get("name") ?? "world";
return ssr(() => <Hello name={name} />);
}, { port: 8000 });
});

console.log("[runner] Listening on http://localhost:8000");
await server;
2 changes: 1 addition & 1 deletion examples/user_agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ const html = `

const webview = new Webview();

webview.navigate(`data:text/html,${encodeURIComponent(html)}`);
webview.setHTML(html);
webview.run();
8 changes: 4 additions & 4 deletions 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.157.0/fs/ensure_dir.ts";
import { ensureDir } from "https://deno.land/std@0.197.0/fs/ensure_dir.ts";

const decoder = new TextDecoder();
const architectures = [["x86_64", "x86_64"], ["aarch64", "arm64"]] as const;
Expand All @@ -23,11 +23,11 @@ function indent(source: string, spaces = 2): string {
.join("");
}

async function spawn<T extends Deno.SpawnOptions>(
async function spawn<T extends Deno.CommandOptions>(
cmd: string,
{ opts, exit, log }: { opts?: T; exit?: ExitType; log?: LogType } = {},
): Promise<{
status: Deno.ChildStatus;
status: Deno.CommandStatus;
stdout: string;
stderr: string;
}> {
Expand All @@ -39,7 +39,7 @@ async function spawn<T extends Deno.SpawnOptions>(
exit ??= ExitType.Never;
log ??= LogType.Always;

const result = await Deno.spawn(cmd, opts);
const result = await new Deno.Command(cmd, opts).output();

const stdout = decoder.decode(result.stdout!);
const stderr = decoder.decode(result.stderr!);
Expand Down
2 changes: 1 addition & 1 deletion src/ffi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const lib = await dlopen(
result: "void",
},
"webview_set_html": {
parameters: ["pointer", "pointer"],
parameters: ["pointer", "buffer"],
result: "void",
},
"webview_init": {
Expand Down
10 changes: 10 additions & 0 deletions src/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ export class Webview {
);
}

/**
* Sets the current HTML of the webview to the given `html` string.
*/
setHTML(html: string) {
lib.symbols.webview_set_html(
this.#handle,
encodeCString(html),
);
}

/**
* Runs the main event loop until it's terminated. After this function exits
* the webview is automatically destroyed.
Expand Down
2 changes: 1 addition & 1 deletion webview