From b3d7d11ae32e0970184f53be26e2c5530f78cdf0 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Tue, 6 Jun 2023 04:50:05 -0700 Subject: [PATCH] fix(stronghold): remove constructor, add static load function (#416) --- .changes/stronghold-constructor.md | 5 +++++ plugins/stronghold/guest-js/index.ts | 11 +++++------ 2 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 .changes/stronghold-constructor.md diff --git a/.changes/stronghold-constructor.md b/.changes/stronghold-constructor.md new file mode 100644 index 00000000..99966095 --- /dev/null +++ b/.changes/stronghold-constructor.md @@ -0,0 +1,5 @@ +--- +"stronghold-js": minor +--- + +Added `Stronghold.load` and removed its constructor. diff --git a/plugins/stronghold/guest-js/index.ts b/plugins/stronghold/guest-js/index.ts index 3339f87f..071eabf1 100644 --- a/plugins/stronghold/guest-js/index.ts +++ b/plugins/stronghold/guest-js/index.ts @@ -395,21 +395,20 @@ export class Stronghold { * @param path * @param password */ - constructor(path: string, password: string) { + private constructor(path: string) { this.path = path; - void this.reload(password); } /** - * Force a reload of the snapshot. The password must match. + * Load the snapshot if it exists (password must match), or start a fresh stronghold instance otherwise. * @param password * @returns */ - private async reload(password: string): Promise { + static async load(path: string, password: string): Promise { return await invoke("plugin:stronghold|initialize", { - snapshotPath: this.path, + snapshotPath: path, password, - }); + }).then(() => new Stronghold(path)); } /**