Skip to content

Commit 54265f0

Browse files
committed
Add "reload" command for internal operations.
It is imported from #2239 and https://github.com/piroor/treestyletab/tree/PowerAccess-master
1 parent ba77ac3 commit 54265f0

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

webextensions/background/background.js

+14
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,20 @@ async function rebuildAll(windows) {
269269
return restoredFromCache;
270270
}
271271

272+
export async function reload(options = {}) {
273+
mPreloadedCaches.clear();
274+
await MetricsData.addAsync('reload: rebuildAll', rebuildAll());
275+
if (!options.all)
276+
return;
277+
for (const window of TabsStore.windows.values()) {
278+
if (!SidebarConnection.isOpen(window.id))
279+
continue;
280+
browser.runtime.sendMessage({
281+
type: Constants.kCOMMAND_RELOAD_SIDEBARS
282+
}).catch(ApiTabs.createErrorSuppressor());
283+
}
284+
}
285+
272286
export async function tryStartHandleAccelKeyOnTab(tab) {
273287
if (!TabsStore.ensureLivingTab(tab))
274288
return;

webextensions/background/handle-misc.js

+3
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ function onMessage(message, sender) {
264264

265265
//log('onMessage: ', message, sender);
266266
switch (message.type) {
267+
case Constants.kCOMMAND_RELOAD:
268+
return Background.reload({ all: message.all });
269+
267270
case Constants.kCOMMAND_REQUEST_UNIQUE_ID:
268271
return (async () => {
269272
if (!Tab.get(message.tabId))

webextensions/common/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
export const kBACKGROUND_CONTENTS_VERSION = 5;
99
export const kSIDEBAR_CONTENTS_VERSION = 8;
1010

11+
export const kCOMMAND_RELOAD = 'treestyletab:reload';
1112
export const kCOMMAND_PING_TO_BACKGROUND = 'treestyletab:ping-to-background';
1213
export const kCOMMAND_PING_TO_SIDEBAR = 'treestyletab:ping-to-sidebar';
1314
export const kCOMMAND_REQUEST_CONNECT_PREFIX = 'treestyletab:request-connect-from:';

webextensions/sidebar/sidebar.js

+4
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,10 @@ function onMessage(message, _sender, _respond) {
854854
case Constants.kCOMMAND_CONFIRM_TO_AUTO_GROUP_NEW_TABS:
855855
log('kCOMMAND_CONFIRM_TO_AUTO_GROUP_NEW_TABS: ', { message, mTargetWindow });
856856
return confirmToAutoGroupNewTabs(message.tabIds);
857+
858+
case Constants.kCOMMAND_RELOAD:
859+
location.reload();
860+
return;
857861
}
858862
}
859863

0 commit comments

Comments
 (0)