Skip to content

Commit

Permalink
fix: add support for deno 1.25.0 (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-runge authored Aug 26, 2022
1 parent 9ea4a3d commit 5fcde3c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
14 changes: 7 additions & 7 deletions src/ffi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,39 +131,39 @@ export const lib = await prepare(
result: "pointer",
},
"webview_set_title": {
parameters: ["pointer", "pointer"],
parameters: ["pointer", "buffer"],
result: "void",
},
"webview_set_size": {
parameters: ["pointer", "i32", "i32", "i32"],
result: "void",
},
"webview_navigate": {
parameters: ["pointer", "pointer"],
parameters: ["pointer", "buffer"],
result: "void",
},
"webview_set_html": {
parameters: ["pointer", "pointer"],
result: "void",
},
"webview_init": {
parameters: ["pointer", "pointer"],
parameters: ["pointer", "buffer"],
result: "void",
},
"webview_eval": {
parameters: ["pointer", "pointer"],
parameters: ["pointer", "buffer"],
result: "void",
},
"webview_bind": {
parameters: ["pointer", "pointer", "function", "pointer"],
parameters: ["pointer", "buffer", "function", "pointer"],
result: "void",
},
"webview_unbind": {
parameters: ["pointer", "pointer"],
parameters: ["pointer", "buffer"],
result: "void",
},
"webview_return": {
parameters: ["pointer", "pointer", "i32", "pointer"],
parameters: ["pointer", "buffer", "i32", "buffer"],
result: "void",
},
} as const,
Expand Down
37 changes: 19 additions & 18 deletions src/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface Size {
* ```
*/
export class Webview {
#handle: bigint | null = null;
#handle: Deno.PointerValue | null = null;
#callbacks: Map<
string,
Deno.UnsafeCallback<{
Expand Down Expand Up @@ -142,7 +142,7 @@ export class Webview {
*
* @param handle A previously created webview instances handle
*/
constructor(handle: bigint);
constructor(handle: Deno.PointerValue);
/**
* Creates a new webview instance.
*
Expand Down Expand Up @@ -178,19 +178,20 @@ export class Webview {
constructor(
debug?: boolean,
size?: Size,
window?: bigint | null,
window?: Deno.PointerValue | null,
);
constructor(
debugOrHandle: boolean | bigint = false,
debugOrHandle: boolean | Deno.PointerValue = false,
size: Size | undefined = { width: 1024, height: 768, hint: SizeHint.NONE },
window: bigint | null = null,
window: Deno.PointerValue | null = null,
) {
this.#handle = typeof debugOrHandle === "bigint"
? debugOrHandle
: lib.symbols.webview_create(
Number(debugOrHandle),
window,
);
this.#handle =
typeof debugOrHandle === "bigint" || typeof debugOrHandle === "number"
? debugOrHandle
: lib.symbols.webview_create(
Number(debugOrHandle),
window,
);

if (size !== undefined) {
this.size = size;
Expand Down Expand Up @@ -251,22 +252,22 @@ export class Webview {
callback: (
seq: string,
req: string,
arg: bigint | null,
arg: Deno.PointerValue | null,
) => void,
arg: bigint | null = null,
arg: Deno.PointerValue | null = null,
) {
const callbackResource = new Deno.UnsafeCallback(
{
parameters: ["pointer", "pointer", "pointer"],
result: "void",
},
(
seqPtr: bigint,
reqPtr: bigint,
arg: bigint | null,
seqPtr: Deno.PointerValue,
reqPtr: Deno.PointerValue,
arg: Deno.PointerValue | null,
) => {
const seq = new Deno.UnsafePointerView(seqPtr).getCString();
const req = new Deno.UnsafePointerView(reqPtr).getCString();
const seq = new Deno.UnsafePointerView(BigInt(seqPtr)).getCString();
const req = new Deno.UnsafePointerView(BigInt(reqPtr)).getCString();
callback(seq, req, arg);
},
);
Expand Down

0 comments on commit 5fcde3c

Please sign in to comment.