From 7374bf6425a8ec80ff281583781540da652762db Mon Sep 17 00:00:00 2001 From: mastef Date: Mon, 23 Sep 2024 00:01:34 +0700 Subject: [PATCH] Move tabs to window in the background --- lib/TabManager.jsx | 8 +++----- lib/background.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/TabManager.jsx b/lib/TabManager.jsx index 90ee34e3..45329c31 100644 --- a/lib/TabManager.jsx +++ b/lib/TabManager.jsx @@ -1427,11 +1427,9 @@ class TabManager extends React.Component { var tabs = Object.keys(this.state.selection).map(function(id) { return _this6.state.tabsbyid[id]; }); - for (var i = 0; i < tabs.length; i++) { - var t = tabs[i]; - await browser.tabs.move(t.id, { windowId: windowId, index: -1 }); - await browser.tabs.update(t.id, { pinned: t.pinned }); - } + + browser.runtime.sendMessage({command: "move_tabs_to_window", window_id: windowId, tabs: tabs}); + this.setState({ selection: {} }); diff --git a/lib/background.js b/lib/background.js index 8ee3087e..ab05aa53 100644 --- a/lib/background.js +++ b/lib/background.js @@ -15,6 +15,14 @@ browser.runtime.onStartup.addListener( } ); +async function moveTabsToWindow(windowId, tabs) { + for (var i = 0; i < tabs.length; i++) { + var t = tabs[i]; + await browser.tabs.move(t.id, {windowId: windowId, index: -1}); + await browser.tabs.update(t.id, {pinned: t.pinned}); + } +} + async function createWindowWithTabs(tabs, isIncognito) { var pinnedIndex = 0; @@ -715,6 +723,9 @@ browser.runtime.onMessage.addListener(function(request, sender, sendResponse) { case "update_tab_count": updateTabCount(); break; + case "move_tabs_to_window": + moveTabsToWindow(request.window_id, request.tabs); + break; case "focus_on_tab_and_window": focusOnTabAndWindow(request.tab); break;