Skip to content

Commit

Permalink
Hide tab preview panel when the sidebar is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Nov 28, 2024
1 parent c826d85 commit c6c64e0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions webextensions/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const kCOMMAND_CONFIRM_TO_CLOSE_TABS = 'treestyletab:confirm-to-
export const kCOMMAND_SHOW_DIALOG = 'treestyletab:show-dialog';
export const kCOMMAND_NOTIFY_BACKGROUND_READY = 'treestyletab:notify-background-ready';
export const kCOMMAND_NOTIFY_CONNECTION_READY = 'treestyletab:notify-connection-ready';
export const kCOMMAND_NOTIFY_SIDEBAR_CLOSED = 'treestyletab:notify-sidebar-closed';
export const kCOMMAND_NOTIFY_TAB_CREATING = 'treestyletab:notify-tab-creating';
export const kCOMMAND_NOTIFY_TAB_CREATED = 'treestyletab:notify-tab-created';
export const kCOMMAND_NOTIFY_TAB_UPDATED = 'treestyletab:notify-tab-updated';
Expand Down
29 changes: 28 additions & 1 deletion webextensions/common/sidebar-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import EventListenerManager from '/extlib/EventListenerManager.js';
import {
log as internalLogger,
mapAndFilterUniq,
configs
configs,
wait,
} from './common.js';
import * as Constants from './constants.js';
import * as TabsStore from './tabs-store.js';
Expand Down Expand Up @@ -223,6 +224,32 @@ if (Constants.IS_BACKGROUND) {
mReceivers.delete(windowId);
mFocusState.delete(windowId);
onDisconnected.dispatch(windowId, connections.size);

// We need to notify this to some conetnt scripts, to destroy themselves.
/*
browser.runtime.sendMessage({
type: Constants.kCOMMAND_NOTIFY_SIDEBAR_CLOSED,
windowId,
});
*/
browser.windows.get(windowId, { populate: true }).then(async win => {
let count = 0;
for (const tab of win.tabs) {
count++;
if (count >= 20) {
// We should not block too long seconds on too much tabs case.
await wait(10);
count = 0;
}
try {
browser.tabs.sendMessage(tab.id, {
type: Constants.kCOMMAND_NOTIFY_SIDEBAR_CLOSED,
});
}
catch (_error) {
}
}
});
};
const receiver = message => {
if (Array.isArray(message))
Expand Down
6 changes: 6 additions & 0 deletions webextensions/resources/tab-preview-frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ try{
panel.classList.add('hidden');
}
break;

case 'treestyletab:notify-sidebar-closed':
if (panel) {
panel.classList.add('hidden');
}
break;
}
});

Expand Down

0 comments on commit c6c64e0

Please sign in to comment.