Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: two-way deno bindings with support for external.invoke
- Loading branch information
1 parent
0a9b842
commit 050332f
Showing
6 changed files
with
175 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { Plug } from "https://deno.land/x/plug@0.2.6/mod.ts"; | ||
export { deferred } from "https://deno.land/std@0.79.0/async/mod.ts"; | ||
export type { Deferred } from "https://deno.land/std@0.79.0/async/mod.ts"; | ||
export { Plug } from "https://deno.land/x/plug@0.2.6/mod.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Webview } from "../mod.ts"; | ||
|
||
const html = ` | ||
<html> | ||
<body> | ||
<button onclick="external.invoke('A')">A</button> | ||
<button onclick="external.invoke('B')">B</button> | ||
<button onclick="external.invoke('C')">C</button> | ||
</body> | ||
</html> | ||
`; | ||
|
||
const webview = new Webview( | ||
{ url: `data:text/html,${encodeURIComponent(html)}` }, | ||
); | ||
|
||
const interval = setInterval(() => { | ||
const success = webview.loop(); | ||
const events = webview.step(); | ||
|
||
if (events.length > 0) { | ||
console.log(events); | ||
} | ||
|
||
if (!success) { | ||
clearInterval(interval); | ||
} | ||
}, 1000 / 60); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { serve } from "https://deno.land/std@0.79.0/http/mod.ts"; | ||
import { Webview } from "../mod.ts"; | ||
|
||
const webview = new Webview( | ||
{ url: `http://localhost:8080` }, | ||
); | ||
const promise = webview.run(); | ||
|
||
const server = serve({ port: 8080 }); | ||
for await (const req of server) { | ||
req.respond({ body: "Hello World" }); | ||
} | ||
|
||
await promise; |
Oops, something went wrong.