Skip to content

Commit

Permalink
Restore sidebar from cache correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jan 24, 2024
1 parent 504cd51 commit 6a77105
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion webextensions/background/background-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ Tab.onHidden.addListener(tab => {
browser.runtime.onMessage.addListener((message, _sender) => {
switch (message && message.type) {
case Constants.kCOMMAND_GET_ON_MEMORY_CACHE:
return sessionStorage.getItem(message.key);
return Promise.resolve(sessionStorage.getItem(message.key));

case Constants.kCOMMAND_SET_ON_MEMORY_CACHE:
if (message.value)
Expand Down
19 changes: 7 additions & 12 deletions webextensions/sidebar/sidebar-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,13 @@ export async function tryPreload(tab = null) {
}

async function preload(tab) {
const cache = await Promise.all([
browser.sessions.getWindowValue(tab.windowId, Constants.kWINDOW_STATE_CACHED_SIDEBAR),
browser.sessions.getWindowValue(tab.windowId, Constants.kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY),
browser.sessions.getWindowValue(tab.windowId, Constants.kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY),
browser.sessions.getTabValue(tab.id, Constants.kWINDOW_STATE_CACHED_SIDEBAR),
browser.sessions.getTabValue(tab.id, Constants.kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY),
browser.sessions.getTabValue(tab.id, Constants.kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY)
]).catch(ApiTabs.createErrorSuppressor());
if (!cache)
return;
mPreloadedCaches.set(`window${tab.windowId}`, cache.slice(0, 2));
mPreloadedCaches.set(`tab${tab.id}`, cache.slice(3, 5));
mTargetWindow = tab.windowId;
const cache = await MetricsData.addAsync('preload: reading window cache', Promise.all([
getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR),
getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_TABS_DIRTY),
getWindowCache(Constants.kWINDOW_STATE_CACHED_SIDEBAR_COLLAPSED_DIRTY),
]).catch(ApiTabs.createErrorSuppressor()));
mPreloadedCaches.set(`window${mTargetWindow}`, cache);
}

export async function getEffectiveWindowCache(options = {}) {
Expand Down

0 comments on commit 6a77105

Please sign in to comment.