Skip to content

Commit

Permalink
Update Sidebar to 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlex94 committed Jun 11, 2024
1 parent f65eae0 commit 1a0668a
Show file tree
Hide file tree
Showing 16 changed files with 572 additions and 117 deletions.
2 changes: 1 addition & 1 deletion waterfox/browser/components/WaterfoxGlue.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export const WaterfoxGlue = {
addon =
(await lazy.AddonManager.maybeInstallBuiltinAddon(
ID,
"1.0.1",
"1.0.2",
"resource://builtin-addons/sidebar/"
)) || addon;

Expand Down
64 changes: 35 additions & 29 deletions waterfox/browser/components/sidebar/_locales/en/messages.json

Large diffs are not rendered by default.

60 changes: 33 additions & 27 deletions waterfox/browser/components/sidebar/_locales/ja/messages.json

Large diffs are not rendered by default.

186 changes: 172 additions & 14 deletions waterfox/browser/components/sidebar/background/handle-misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,27 +224,29 @@ async function onShortcutCommand(command) {
return;

case 'focusPrevious':
case 'focusPreviousSilently': {
const nextActive = activeTab.$TST.nearestVisiblePrecedingTab ||
Tab.getLastVisibleTab(activeTab.windowId);
TabsInternalOperation.activateTab(nextActive, {
silently: /Silently/.test(command)
});
}; return;
focusPrevious(activeTab);
return;
case 'focusPreviousSilently':
focusPreviousSilently(activeTab);
return;
case 'focusNext':
case 'focusNextSilently': {
const nextActive = activeTab.$TST.nearestVisibleFollowingTab ||
Tab.getFirstVisibleTab(activeTab.windowId);
TabsInternalOperation.activateTab(nextActive, {
silently: /Silently/.test(command)
});
}; return;
focusNext(activeTab);
return;
case 'focusNextSilently':
focusNextSilently(activeTab);
return;
case 'focusParent':
TabsInternalOperation.activateTab(activeTab.$TST.parent);
return;
case 'focusParentOrCollapse':
collapseOrFocusToParent(activeTab);
return;
case 'focusFirstChild':
TabsInternalOperation.activateTab(activeTab.$TST.firstChild);
return;
case 'focusFirstChildOrExpand':
expandOrFocusToFirstChild(activeTab);
return;
case 'focusLastChild':
TabsInternalOperation.activateTab(activeTab.$TST.lastChild);
return;
Expand All @@ -261,6 +263,110 @@ async function onShortcutCommand(command) {
);
return;

case 'simulateUpOnTree':
if (SidebarConnection.isSidebarOpen(activeTab.windowId)) {
if (configs.faviconizePinnedTabs &&
(activeTab.pinned ||
activeTab == Tab.getFirstNormalTab(activeTab.windowId))) {
const nextActiveId = await browser.runtime.sendMessage({
type: Constants.kCOMMAND_GET_ABOVE_TAB,
windowId: activeTab.windowId,
tabId: activeTab.id,
});
log(`simulateUpOnTree: nextActiveId = ${nextActiveId}`);
const nextActive = (
nextActiveId && Tab.get(nextActiveId) ||
Tab.getLastVisibleTab(activeTab.windowId)
);
TabsInternalOperation.activateTab(nextActive, {
silently: true,
});
}
else {
focusPreviousSilently(activeTab);
}
}
else {
focusPrevious(activeTab);
}
return;
case 'simulateDownOnTree':
if (SidebarConnection.isSidebarOpen(activeTab.windowId)) {
if (configs.faviconizePinnedTabs &&
activeTab.pinned) {
const nextActiveId = await browser.runtime.sendMessage({
type: Constants.kCOMMAND_GET_BELOW_TAB,
windowId: activeTab.windowId,
tabId: activeTab.id,
});
log(`simulateDownOnTree: nextActiveId = ${nextActiveId}`);
const nextActive = (
nextActiveId && Tab.get(nextActiveId) ||
Tab.getFirstNormalTab(activeTab.windowId)
);
TabsInternalOperation.activateTab(nextActive, {
silently: true,
});
}
else {
focusNextSilently(activeTab);
}
}
else {
focusNext(activeTab);
}
return;
case 'simulateLeftOnTree':
if (SidebarConnection.isSidebarOpen(activeTab.windowId)) {
if (configs.faviconizePinnedTabs &&
activeTab.pinned) {
const nextActiveId = await browser.runtime.sendMessage({
type: Constants.kCOMMAND_GET_LEFT_TAB,
windowId: activeTab.windowId,
tabId: activeTab.id,
});
log(`simulateLeftOnTree: nextActiveId = ${nextActiveId}`);
TabsInternalOperation.activateTab(Tab.get(nextActiveId), {
silently: true,
});
}
else if (await isSidebarRightSide(activeTab.windowId)) {
expandOrFocusToFirstChild(activeTab);
}
else {
collapseOrFocusToParent(activeTab);
}
}
else {
focusPrevious(activeTab);
}
return;
case 'simulateRightOnTree':
if (SidebarConnection.isSidebarOpen(activeTab.windowId)) {
if (configs.faviconizePinnedTabs &&
activeTab.pinned) {
const nextActiveId = await browser.runtime.sendMessage({
type: Constants.kCOMMAND_GET_RIGHT_TAB,
windowId: activeTab.windowId,
tabId: activeTab.id,
});
log(`simulateRightOnTree: nextActiveId = ${nextActiveId}`);
TabsInternalOperation.activateTab(Tab.get(nextActiveId), {
silently: true,
});
}
else if (await isSidebarRightSide(activeTab.windowId)) {
collapseOrFocusToParent(activeTab);
}
else {
expandOrFocusToFirstChild(activeTab);
}
}
else {
focusNext(activeTab);
}
return;

case 'tabbarUp':
SidebarConnection.sendMessage({
type: Constants.kCOMMAND_SCROLL_TABBAR,
Expand Down Expand Up @@ -345,6 +451,58 @@ async function onShortcutCommand(command) {
}
}

function focusPrevious(activeTab) {
const nextActive = activeTab.$TST.nearestVisiblePrecedingTab ||
Tab.getLastVisibleTab(activeTab.windowId);
TabsInternalOperation.activateTab(nextActive);
}

function focusPreviousSilently(activeTab) {
const nextActive = activeTab.$TST.nearestVisiblePrecedingTab ||
Tab.getLastVisibleTab(activeTab.windowId);
TabsInternalOperation.activateTab(nextActive, {
silently: true,
});
}

function focusNext(activeTab) {
const nextActive = activeTab.$TST.nextVisibleTab ||
Tab.getFirstVisibleTab(activeTab.windowId);
TabsInternalOperation.activateTab(nextActive);
}

function focusNextSilently(activeTab) {
const nextActive = activeTab.$TST.nearestVisibleFollowingTab ||
Tab.getFirstVisibleTab(activeTab.windowId);
TabsInternalOperation.activateTab(nextActive, {
silently: true,
});
}

async function isSidebarRightSide(windowId) {
const position = await browser.runtime.sendMessage({
type: Constants.kCOMMAND_GET_SIDEBAR_POSITION,
windowId,
});
return position == Constants.kTABBAR_POSITION_RIGHT;
}

function collapseOrFocusToParent(activeTab) {
if (!activeTab.$TST.subtreeCollapsed && activeTab.$TST.hasChild)
Commands.collapseTree(activeTab);
else
TabsInternalOperation.activateTab(activeTab.$TST.parent);
}

function expandOrFocusToFirstChild(activeTab) {
if (activeTab.$TST.subtreeCollapsed && activeTab.$TST.hasChild)
Commands.expandTree(activeTab);
else
TabsInternalOperation.activateTab(activeTab.$TST.firstChild, {
silently: true,
});
}

// This must be synchronous and return Promise on demando, to avoid
// blocking to other listeners.
function onMessage(message, sender) {
Expand Down
3 changes: 3 additions & 0 deletions waterfox/browser/components/sidebar/background/tabs-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ function cleanupNeedlssGroupTab(tabs) {
log('trying to clanup needless temporary group tabs from ', () => tabs.map(dumpTab));
const tabsToBeRemoved = [];
for (const tab of tabs) {
if (tab.$TST.temporaryMetadata.has('movingAcrossWindows'))
continue;

if (tab.$TST.isTemporaryGroupTab) {
if (tab.$TST.childIds.length > 1)
break;
Expand Down
42 changes: 38 additions & 4 deletions waterfox/browser/components/sidebar/background/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,15 @@ export async function moveTabs(tabs, options = {}) {
const structure = TreeBehavior.getTreeStructureFromTabs(tabs);
log('original tree structure: ', structure);

let hasActive = false;
for (const tab of movedTabs) {
if (tab.active)
hasActive = true;
if (isAcrossWindows &&
!options.duplicate)
tab.$TST.temporaryMetadata.set('movingAcrossWindows', true);
}

if (!options.duplicate)
await detachTabsFromTree(tabs, options);

Expand Down Expand Up @@ -1504,9 +1513,11 @@ export async function moveTabs(tabs, options = {}) {
movedTabIds = movedTabs.map(tab => tab.id);
}
else {
const movedTabIdsSet = new Set(movedTabIds);
for (const tab of movedTabs) {
if (tab.$TST.parent &&
!movedTabs.includes(tab.$TST.parent))
tab.$TST.temporaryMetadata.set('movingAcrossWindows', true);
if (tab.$TST.parentId &&
!movedTabIdsSet.has(tab.$TST.parentId))
detachTab(tab, {
broadcast: true,
toBeDetached: true
Expand Down Expand Up @@ -1543,13 +1554,38 @@ export async function moveTabs(tabs, options = {}) {
toIndex--;
log(' => ', toIndex);
if (isAcrossWindows) {
let temporaryFocusHolderTab = null;
if (hasActive) {
// Blur to-be-moved tab, otherwise tabs.move() will activate them for each
// while the moving process and all dicarded tabs are unexpectedly restored.
const nextActiveTab = await TabsInternalOperation.blurTab(movedTabs, {
silently: true,
});
if (!nextActiveTab) {
// There is no focusible left tab, so we move focus to a tmeporary tab.
// It will be removed automatically after tabs are moved.
temporaryFocusHolderTab = await browser.tabs.create({
url: 'about:blank',
active: true,
windowId
});
}
}
movedTabs = await browser.tabs.move(movedTabIds, {
windowId: destinationWindowId,
index: toIndex
});
if (temporaryFocusHolderTab) {
const leftTabsInSourceWindow = await browser.tabs.query({ windowId });
if (leftTabsInSourceWindow.length == 1)
browser.windows.remove(windowId);
else
browser.tabs.remove(temporaryFocusHolderTab.id);
}
movedTabs = movedTabs.map(tab => Tab.get(tab.id));
movedTabIds = movedTabs.map(tab => tab.id);
for (const tab of movedTabs) {
tab.$TST.temporaryMetadata.delete('movingAcrossWindows');
tab.windowId = destinationWindowId;
}
log('moved across windows: ', movedTabIds);
Expand Down Expand Up @@ -2132,8 +2168,6 @@ SidebarConnection.onMessage.addListener(async (windowId, message) => {
log('new window requested: ', message);
await Tab.waitUntilTracked(message.tabIds);
const tabs = message.tabIds.map(id => TabsStore.tabs.get(id));
if (!message.duplicate)
await detachTabsFromTree(tabs);
openNewWindowFromTabs(tabs, message);
}; break;
}
Expand Down
16 changes: 13 additions & 3 deletions waterfox/browser/components/sidebar/common/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -2261,7 +2261,10 @@ function destroyWaitingTabTask(task) {
}

function onWaitingTabTracked(tab) {
const tasks = mWaitingTasks.get(tab?.id);
if (!tab)
return;

const tasks = mWaitingTasks.get(tab.id);
if (!tasks)
return;

Expand All @@ -2279,7 +2282,10 @@ Tab.onElementBound.addListener(onWaitingTabTracked);
Tab.onTracked.addListener(onWaitingTabTracked);

function onWaitingTabDestroyed(tab) {
const tasks = mWaitingTasks.get(tab?.id);
if (!tab)
return;

const tasks = mWaitingTasks.get(tab.id);
if (!tasks)
return;

Expand Down Expand Up @@ -2322,6 +2328,7 @@ async function waitUntilTracked(tabId, options = {}) {
const stack = configs.debug && new Error().stack;
const tab = Tab.get(tabId);
if (tab) {
onWaitingTabTracked(tab);
if (options.element)
return tab.$TST.promisedElement;
return tab;
Expand All @@ -2343,8 +2350,11 @@ async function waitUntilTracked(tabId, options = {}) {
}
}, configs.maximumDelayUntilTabIsTracked); // Tabs.moveTabs() between windows may take much time
browser.tabs.get(tabId).catch(_error => null).then(tab => {
if (tab)
if (tab) {
if (Tab.get(tabId))
onWaitingTabTracked(tab);
return;
}
const { resolve } = destroyWaitingTabTask(task);
if (resolve) {
log('waitUntilTracked was called for unexisting tab');
Expand Down
5 changes: 5 additions & 0 deletions waterfox/browser/components/sidebar/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ export const kCOMMAND_NOTIFY_CONTEXT_OVERRIDDEN = 'ws:notify-context-overri
export const kCOMMAND_AUTODETECT_DUPLICATED_TAB_DETECTION_DELAY = 'ws:autodetect-duplicated-tab-detection-delay';
export const kCOMMAND_TEST_DUPLICATED_TAB_DETECTION = 'ws:test-duplicated-tab-detection';
export const kCOMMAND_WAIT_UNTIL_SUCCESSORS_UPDATED = 'ws:wait-until-successors-updated';
export const kCOMMAND_GET_SIDEBAR_POSITION = 'ws:get-sidebar-position';
export const kCOMMAND_GET_ABOVE_TAB = 'ws:get-above-tab';
export const kCOMMAND_GET_BELOW_TAB = 'ws:get-below-tab';
export const kCOMMAND_GET_LEFT_TAB = 'ws:get-left-tab';
export const kCOMMAND_GET_RIGHT_TAB = 'ws:get-right-tab';
export const kCOMMAND_GET_BOUNDING_CLIENT_RECT = 'ws:get-bounding-client-rect';

export const kCOMMAND_ACTIVATE_TAB = 'ws:activate-tab';
Expand Down
Loading

0 comments on commit 1a0668a

Please sign in to comment.