-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0bc471c
commit 39204b4
Showing
1 changed file
with
20 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,28 @@ | ||
function open(): Deno.Plugin { | ||
let filename = "bins/"; | ||
import { prepare } from "https://deno.land/x/plugin_prepare/mod.ts"; | ||
|
||
switch (Deno.build.os) { | ||
case "linux": | ||
filename += "libdeno_webview.so"; | ||
break; | ||
case "mac": | ||
filename += "libdeno_webview.dylib"; | ||
break; | ||
case "win": | ||
filename += "deno_webview.dll"; | ||
break; | ||
} | ||
|
||
return Deno.openPlugin(filename); | ||
} | ||
|
||
const plugin = open(); | ||
|
||
const { testSync, testAsync } = plugin.ops; | ||
|
||
const textDecoder = new TextDecoder(); | ||
|
||
function runTestSync() { | ||
const response = testSync.dispatch( | ||
new Uint8Array([116, 101, 115, 116]), | ||
new Uint8Array([116, 101, 115, 116]) | ||
); | ||
|
||
console.log(`Plugin Sync Response: ${textDecoder.decode(response)}`); | ||
} | ||
const releaseUrl = | ||
"https://github.com/eliassjogreen/deno_webview/releases/latest/download"; | ||
|
||
testAsync.setAsyncHandler((response) => { | ||
console.log(`Plugin Async Response: ${textDecoder.decode(response)}`); | ||
const deno_webview = await prepare({ | ||
name: "deno_webview", | ||
urls: { | ||
mac: `${releaseUrl}/libdeno_webview.dylib`, | ||
win: `${releaseUrl}/deno_webview.dll`, | ||
linux: `${releaseUrl}/libdeno_webview.so` | ||
} | ||
}); | ||
|
||
function runTestAsync() { | ||
const response = testAsync.dispatch( | ||
new Uint8Array([116, 101, 115, 116]), | ||
new Uint8Array([116, 101, 115, 116]) | ||
); | ||
|
||
if (response != null || response != undefined) { | ||
throw new Error("Expected null response!"); | ||
} | ||
export interface Options { | ||
title: string; | ||
width: number; | ||
height: number; | ||
resizable: boolean; | ||
debug: boolean; | ||
content: string; | ||
} | ||
|
||
function runTestOpCount() { | ||
const start = Deno.metrics(); | ||
|
||
testSync.dispatch(new Uint8Array([116, 101, 115, 116])); | ||
|
||
const end = Deno.metrics(); | ||
export function run(options: Options) { | ||
const { webview_run } = deno_webview.ops; | ||
|
||
if (end.opsCompleted - start.opsCompleted !== 2) { | ||
// one op for the plugin and one for Deno.metrics | ||
throw new Error("The opsCompleted metric is not correct!"); | ||
} | ||
if (end.opsDispatched - start.opsDispatched !== 2) { | ||
// one op for the plugin and one for Deno.metrics | ||
throw new Error("The opsDispatched metric is not correct!"); | ||
} | ||
webview_run(new TextEncoder().encode(JSON.stringify(options))); | ||
} | ||
|
||
runTestSync(); | ||
runTestAsync(); | ||
|
||
runTestOpCount(); |