Skip to content

Commit b95667a

Browse files
feat: unload all instances when unload is called (#120)
1 parent a1293a6 commit b95667a

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ jobs:
4242
- name: Upload Artifacts
4343
uses: actions/upload-artifact@v3
4444
with:
45-
path: build/
45+
name: build
46+
path: |
47+
build/*.dll
48+
build/*.dylib
49+
build/*.so
4650
4751
# - name: Release Plugin
4852
# uses: softprops/action-gh-release@master

src/ffi.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CachePolicy, download, join, prepare } from "../deps.ts";
2+
import { Webview } from "./webview.ts";
23

34
const version = "0.7.2";
45
const policy = Deno.env.get("PLUGIN_URL") === undefined
@@ -22,6 +23,12 @@ async function checkForWebView2Loader(): Promise<boolean> {
2223
// make sure we don't preload twice
2324
let preloaded = false;
2425

26+
/**
27+
* All active webview instances. This is internally used for automatically
28+
* destroying all instances once {@link unload} is called.
29+
*/
30+
export const instances: Webview[] = [];
31+
2532
/**
2633
* Loads the `./WebView2Loader.dll` for running on Windows. Removes old version
2734
* if it already existed, and only runs once. Should be run on the main thread
@@ -55,6 +62,9 @@ export async function preload() {
5562
* otherwise, you may have to call this manually.
5663
*/
5764
export function unload() {
65+
for (const instance of instances) {
66+
instance.destroy();
67+
}
5868
lib.close();
5969
if (Deno.build.os === "windows") {
6070
Deno.removeSync("./WebView2Loader.dll");

src/webview.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import sys from "./ffi.ts";
1+
import sys, { instances } from "./ffi.ts";
22

33
const encoder = new TextEncoder();
44
const encode = (value: string) => encoder.encode(value + "\0");
@@ -174,6 +174,9 @@ export class Webview {
174174
if (size !== undefined) {
175175
this.size = size;
176176
}
177+
178+
// Push this instance to the global instances list to automatically destroy
179+
instances.push(this);
177180
}
178181

179182
/**

0 commit comments

Comments
 (0)