Skip to content

Commit 39204b4

Browse files
committed
Updated mod.ts
1 parent 0bc471c commit 39204b4

File tree

1 file changed

+20
-61
lines changed

1 file changed

+20
-61
lines changed

mod.ts

Lines changed: 20 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,28 @@
1-
function open(): Deno.Plugin {
2-
let filename = "bins/";
1+
import { prepare } from "https://deno.land/x/plugin_prepare/mod.ts";
32

4-
switch (Deno.build.os) {
5-
case "linux":
6-
filename += "libdeno_webview.so";
7-
break;
8-
case "mac":
9-
filename += "libdeno_webview.dylib";
10-
break;
11-
case "win":
12-
filename += "deno_webview.dll";
13-
break;
14-
}
15-
16-
return Deno.openPlugin(filename);
17-
}
18-
19-
const plugin = open();
20-
21-
const { testSync, testAsync } = plugin.ops;
22-
23-
const textDecoder = new TextDecoder();
24-
25-
function runTestSync() {
26-
const response = testSync.dispatch(
27-
new Uint8Array([116, 101, 115, 116]),
28-
new Uint8Array([116, 101, 115, 116])
29-
);
30-
31-
console.log(`Plugin Sync Response: ${textDecoder.decode(response)}`);
32-
}
3+
const releaseUrl =
4+
"https://github.com/eliassjogreen/deno_webview/releases/latest/download";
335

34-
testAsync.setAsyncHandler((response) => {
35-
console.log(`Plugin Async Response: ${textDecoder.decode(response)}`);
6+
const deno_webview = await prepare({
7+
name: "deno_webview",
8+
urls: {
9+
mac: `${releaseUrl}/libdeno_webview.dylib`,
10+
win: `${releaseUrl}/deno_webview.dll`,
11+
linux: `${releaseUrl}/libdeno_webview.so`
12+
}
3613
});
3714

38-
function runTestAsync() {
39-
const response = testAsync.dispatch(
40-
new Uint8Array([116, 101, 115, 116]),
41-
new Uint8Array([116, 101, 115, 116])
42-
);
43-
44-
if (response != null || response != undefined) {
45-
throw new Error("Expected null response!");
46-
}
15+
export interface Options {
16+
title: string;
17+
width: number;
18+
height: number;
19+
resizable: boolean;
20+
debug: boolean;
21+
content: string;
4722
}
4823

49-
function runTestOpCount() {
50-
const start = Deno.metrics();
51-
52-
testSync.dispatch(new Uint8Array([116, 101, 115, 116]));
53-
54-
const end = Deno.metrics();
24+
export function run(options: Options) {
25+
const { webview_run } = deno_webview.ops;
5526

56-
if (end.opsCompleted - start.opsCompleted !== 2) {
57-
// one op for the plugin and one for Deno.metrics
58-
throw new Error("The opsCompleted metric is not correct!");
59-
}
60-
if (end.opsDispatched - start.opsDispatched !== 2) {
61-
// one op for the plugin and one for Deno.metrics
62-
throw new Error("The opsDispatched metric is not correct!");
63-
}
27+
webview_run(new TextEncoder().encode(JSON.stringify(options)));
6428
}
65-
66-
runTestSync();
67-
runTestAsync();
68-
69-
runTestOpCount();

0 commit comments

Comments
 (0)