From 8f5f1f2d6cffbb6f4a255498d2a4631f57b90ed1 Mon Sep 17 00:00:00 2001 From: "YUKI \"Piro\" Hiroshi" Date: Thu, 25 Jan 2024 03:51:34 +0900 Subject: [PATCH] Restore sidebar from cahce correctly --- webextensions/background/background-cache.js | 2 +- webextensions/sidebar/sidebar-cache.js | 19 +++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/webextensions/background/background-cache.js b/webextensions/background/background-cache.js index 279b8c5a7..f3ce4ac00 100644 --- a/webextensions/background/background-cache.js +++ b/webextensions/background/background-cache.js @@ -520,7 +520,7 @@ Tab.onHidden.addListener(tab => { browser.runtime.onMessage.addListener((message, _sender) => { switch (message && message.type) { case Constants.kCOMMAND_GET_ON_MEMORY_CACHE: - return mCaches[message.key]; + return Promise.resolve(mCaches[message.key]); case Constants.kCOMMAND_SET_ON_MEMORY_CACHE: if (message.value) diff --git a/webextensions/sidebar/sidebar-cache.js b/webextensions/sidebar/sidebar-cache.js index 53cea5488..ca18794e8 100644 --- a/webextensions/sidebar/sidebar-cache.js +++ b/webextensions/sidebar/sidebar-cache.js @@ -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 = {}) {