Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
drive4ik committed Apr 28, 2023
1 parent b7cb6b9 commit 6131a56
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
6 changes: 3 additions & 3 deletions addon/src/js/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export function applyTabSession(tab) {
return applySession(tab, tabs[tab.id] || {});
}

export function removeTabSession(tabId) {
export async function removeTabSession(tabId) {
return Promise.all([
removeTabGroup(tabId),
removeTabFavIcon(tabId),
Expand All @@ -231,7 +231,7 @@ export function getTabsSessionAndRemove(tabIds) {
}

// WINDOWS
export function setWindowGroup(windowId, groupId) {
export async function setWindowGroup(windowId, groupId) {
windows[windowId] ??= {};
windows[windowId].groupId = groupId;

Expand All @@ -254,7 +254,7 @@ export function removeWindow(windowId) {
delete windows[windowId];
}

export function removeWindowGroup(windowId) {
export async function removeWindowGroup(windowId) {
delete windows[windowId].groupId;
return browser.sessions.removeWindowValue(windowId, 'groupId').catch(() => {});
}
Expand Down
32 changes: 21 additions & 11 deletions addon/src/stg-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ async function GrandRestoreWindows({ id }, needRestoreMissedTabsMap) {
return;
}

const log = logger.start('GrandRestoreWindows restore windows:', Array.from(windowIdsForRestoring));

let [
windows,
{ groups },
Expand Down Expand Up @@ -884,9 +886,11 @@ async function GrandRestoreWindows({ id }, needRestoreMissedTabsMap) {
}
}

await Promise.all(windows.map(win => loadingBrowserAction(false, win.id)));
await Promise.all(windows.map(win => loadingBrowserAction(false, win.id).catch(() => {})));

windowIdsForRestoring.clear();

log.stop();
}

const onCreatedWindow = catchFunc(async function (win) {
Expand Down Expand Up @@ -3966,6 +3970,8 @@ browser.runtime.onInstalled.addListener(function ({ reason, previousVersion, tem
});

async function initializeGroupWindows(windows, currentGroupIds) {
const log = logger.start('initializeGroupWindows windows count:', windows.length);

let tabsToShow = [],
tabsToHide = [],
moveTabsToWin = {};
Expand All @@ -3979,14 +3985,14 @@ async function initializeGroupWindows(windows, currentGroupIds) {

duplicateGroupWindows.forEach(function (w) {
delete w.groupId;
Cache.removeWindowSession(w.id);
Cache.removeWindowSession(w.id).catch(log.onCatch(['cant removeWindowSession', w.id], false));
});
}

win.tabs.forEach(function (tab) {
if (tab.groupId && !currentGroupIds.includes(tab.groupId)) {
delete tab.groupId;
Cache.removeTabGroup(tab.id);
Cache.removeTabGroup(tab.id).catch(log.onCatch(['cant removeTabGroup', tab.id], false));
}

if (tab.groupId) {
Expand Down Expand Up @@ -4018,7 +4024,7 @@ async function initializeGroupWindows(windows, currentGroupIds) {
if (!tab.hidden) {
if (Utils.isTabLoading(tab) || tab.url.startsWith('file:') || tab.lastAccessed > self.localStorage.START_TIME) {
tab.groupId = win.groupId;
Cache.setTabGroup(tab.id, win.groupId);
Cache.setTabGroup(tab.id, win.groupId).catch(log.onCatch(['cant setTabGroup', tab.id, 'group', win.groupId], false));
} else {
tabsToHide.push(tab);
}
Expand All @@ -4039,15 +4045,15 @@ async function initializeGroupWindows(windows, currentGroupIds) {
windowId: windowId,
});

logger.log('[initializeGroupWindows] moveTabsToWin length', moveTabsToWin[windowId].length);
log.log('moveTabsToWin length', moveTabsToWin[windowId].length);
}

if (tabsToShow.length) {
await Tabs.show(tabsToShow);

tabsToShow.forEach(tab => tab.hidden = false);

logger.log('[initializeGroupWindows] tabsToShow length', tabsToShow.length);
log.log('tabsToShow length', tabsToShow.length);
}

if (tabsToHide.length) {
Expand All @@ -4069,8 +4075,10 @@ async function initializeGroupWindows(windows, currentGroupIds) {

await Tabs.hide(tabsToHide);

logger.log('[initializeGroupWindows] tabsToHide length', tabsToHide.length);
log.log('tabsToHide length', tabsToHide.length);
}

log.stop();
}

async function init() {
Expand Down Expand Up @@ -4147,11 +4155,13 @@ async function init() {
await initializeGroupWindows(windows, data.groups.map(g => g.id));

await Promise.all(windows.map(async win => {
await updateBrowserActionData(null, win.id);
try {
await updateBrowserActionData(null, win.id);

if (win.groupId) {
groupsHistory.add(win.groupId);
}
if (win.groupId) {
groupsHistory.add(win.groupId);
}
} catch (e) {}
}));

let tabs = Utils.concatTabs(windows);
Expand Down

0 comments on commit 6131a56

Please sign in to comment.