From 56098a382ea105412f60d42b1a07d5ece34b40c4 Mon Sep 17 00:00:00 2001 From: Nils Maier Date: Tue, 3 Sep 2019 13:14:46 +0200 Subject: [PATCH] Actually get most recent window --- lib/windowutils.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/windowutils.ts b/lib/windowutils.ts index b5caf2a..44833ea 100644 --- a/lib/windowutils.ts +++ b/lib/windowutils.ts @@ -9,8 +9,25 @@ const DONATE_URL = "https://www.downthemall.org/howto/donate/"; const MANAGER_URL = "/windows/manager.html"; export async function mostRecentBrowser(): Promise { - let window = Array.from(await windows.getAll({windowTypes: ["normal"]})). - filter((w: any) => w.type === "normal").pop(); + let window; + try { + window = await windows.getCurrent({windowTypes: ["normal"]}); + if (window.type !== "normal") { + throw new Error("not a normal window"); + } + } + catch { + try { + window = await windows.getlastFocused({windowTypes: ["normal"]}); + if (window.type !== "normal") { + throw new Error("not a normal window"); + } + } + catch { + window = Array.from(await windows.getAll({windowTypes: ["normal"]})). + filter((w: any) => w.type === "normal").pop(); + } + } if (!window) { window = await windows.create({ url: DONATE_URL,