Skip to content

Set last focused Window as Default Profile #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/lib/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
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);
}
}
}