From 423b7924b73c62309e443b98ac9899fa439ee1f9 Mon Sep 17 00:00:00 2001 From: Invertex Date: Wed, 24 Jan 2024 18:13:01 -0800 Subject: [PATCH 1/3] Set last focused Window as Default Profile Whenever window focus changes, the Default Profile will be set to whatever the new window is. This will then ensure external links that are opened will open in your last focused window instead of the pre-set Default Profile. --- src/lib/native.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/lib/native.ts b/src/lib/native.ts index ba7525e..7f15ab9 100644 --- a/src/lib/native.ts +++ b/src/lib/native.ts @@ -75,6 +75,9 @@ async function initNativePort(eventCallback) { curProfileId = profileListData.current_profile_id; } } + + browser.windows.onFocusChanged.addListener(onWindowFocusChange); + nativeRequestInternal(nativePort, "Initialize", { extension_id: EXTENSION_ID, extension_version: APP_VERSION, @@ -236,3 +239,20 @@ export async function nativeDeleteAvatar(id) { export async function nativeUpdateProfileOrder(order) { return await nativeRequest("UpdateProfileOrder", { order }); } + +//Make the last focused window be the current "Default Profile" so that external links open in whatever was the last window you focused. +export async function onWindowFocusChange(windowID) { + //We're not in the currently active Profile or no main window has been focused again yet + if(windowID < 0) { return; } + + const profileList = await browser.storage.local.get(STORAGE_CACHE_PROFILE_LIST_KEY); + if(profileList != null) { + const profileListData = profileList[STORAGE_CACHE_PROFILE_LIST_KEY]; + if(profileListData != null) { + let curProfile = profileListData.profiles.find((profile) => profile.id == profileListData.current_profile_id); + if(curProfile.default == true) { return; } //Don't waste time setting default again + + await nativeUpdateProfile(curProfile.id, curProfile.name, curProfile.avatar, true, curProfile.options); + } + } +} \ No newline at end of file From 5e8c79f945b44daa956d05b95dde429ee7a8187c Mon Sep 17 00:00:00 2001 From: Dabbles in too many things Date: Thu, 25 Jan 2024 10:29:10 -0800 Subject: [PATCH 2/3] Change variable to const Co-authored-by: Jesse Kawell --- src/lib/native.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/native.ts b/src/lib/native.ts index 7f15ab9..579807c 100644 --- a/src/lib/native.ts +++ b/src/lib/native.ts @@ -249,7 +249,7 @@ export async function onWindowFocusChange(windowID) { if(profileList != null) { const profileListData = profileList[STORAGE_CACHE_PROFILE_LIST_KEY]; if(profileListData != null) { - let curProfile = profileListData.profiles.find((profile) => profile.id == profileListData.current_profile_id); + const curProfile = profileListData.profiles.find((profile) => profile.id == profileListData.current_profile_id); if(curProfile.default == true) { return; } //Don't waste time setting default again await nativeUpdateProfile(curProfile.id, curProfile.name, curProfile.avatar, true, curProfile.options); From e2686a08970662e36f00ece134235aa89d41a42f Mon Sep 17 00:00:00 2001 From: Dabbles in too many things Date: Thu, 25 Jan 2024 10:30:34 -0800 Subject: [PATCH 3/3] Remove tab based spacing --- src/lib/native.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib/native.ts b/src/lib/native.ts index 579807c..d7a12b8 100644 --- a/src/lib/native.ts +++ b/src/lib/native.ts @@ -75,9 +75,9 @@ async function initNativePort(eventCallback) { curProfileId = profileListData.current_profile_id; } } - - browser.windows.onFocusChanged.addListener(onWindowFocusChange); - + + browser.windows.onFocusChanged.addListener(onWindowFocusChange); + nativeRequestInternal(nativePort, "Initialize", { extension_id: EXTENSION_ID, extension_version: APP_VERSION, @@ -242,17 +242,17 @@ export async function nativeUpdateProfileOrder(order) { //Make the last focused window be the current "Default Profile" so that external links open in whatever was the last window you focused. export async function onWindowFocusChange(windowID) { - //We're not in the currently active Profile or no main window has been focused again yet - if(windowID < 0) { return; } + //We're not in the currently active Profile or no main window has been focused again yet + if(windowID < 0) { return; } - const profileList = await browser.storage.local.get(STORAGE_CACHE_PROFILE_LIST_KEY); + const profileList = await browser.storage.local.get(STORAGE_CACHE_PROFILE_LIST_KEY); if(profileList != null) { const profileListData = profileList[STORAGE_CACHE_PROFILE_LIST_KEY]; if(profileListData != null) { const curProfile = profileListData.profiles.find((profile) => profile.id == profileListData.current_profile_id); - if(curProfile.default == true) { return; } //Don't waste time setting default again - - await nativeUpdateProfile(curProfile.id, curProfile.name, curProfile.avatar, true, curProfile.options); + if(curProfile.default == true) { return; } //Don't waste time setting default again + + await nativeUpdateProfile(curProfile.id, curProfile.name, curProfile.avatar, true, curProfile.options); } } -} \ No newline at end of file +}