2017-11-12 22:00:40 +01:00
// Copyright (c) 2017 kroppy. All rights reserved.
// Use of this source code is governed by a Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) license
// that can be found at https://creativecommons.org/licenses/by-nc-nd/4.0/
2017-11-20 18:14:07 +01:00
if ( browserId == "F" ) {
2018-01-01 19:50:56 +01:00
FirefoxStart ( 0 ) ;
2017-11-12 22:00:40 +01:00
FirefoxMessageListeners ( ) ;
}
2018-01-01 19:50:56 +01:00
function FirefoxStart ( retry ) {
chrome . windows . getAll ( { windowTypes : [ "normal" ] , populate : true } , function ( w ) {
FirefoxLoadTabs ( 0 ) ;
if ( w [ 0 ] . tabs . length == 1 && ( w [ 0 ] . tabs [ 0 ] . url == "about:blank" || w [ 0 ] . tabs [ 0 ] . url == "about:sessionrestore" ) ) {
setTimeout ( function ( ) {
FirefoxStart ( retry + 1 ) ;
} , 2000 ) ;
} else {
if ( retry > 0 ) {
chrome . runtime . sendMessage ( { command : "reload_sidebar" } ) ;
2017-11-12 22:00:40 +01:00
}
2018-01-01 19:50:56 +01:00
setTimeout ( function ( ) {
schedule _save = 0 ;
} , 2000 ) ;
2017-11-12 22:00:40 +01:00
}
2018-01-01 19:50:56 +01:00
} ) ;
2017-11-12 22:00:40 +01:00
}
function FirefoxLoadTabs ( retry ) {
chrome . windows . getAll ( { windowTypes : [ "normal" ] , populate : true } , function ( w ) {
2018-03-13 14:39:34 +01:00
chrome . storage . local . get ( null , function ( storage ) {
// LOAD PREFERENCES
opt = Object . assign ( { } , DefaultPreferences ) ;
if ( storage [ "preferences" ] ) {
for ( var parameter in storage [ "preferences" ] ) {
if ( opt [ parameter ] != undefined ) {
opt [ parameter ] = storage [ "preferences" ] [ parameter ] ;
}
2017-11-12 22:00:40 +01:00
}
2018-03-13 14:39:34 +01:00
}
// LOAD THEME
if ( storage [ "current_theme" ] && storage [ "themes" ] && storage [ "themes" ] [ storage [ "current_theme" ] ] ) {
theme = storage [ "themes" ] [ storage [ "current_theme" ] ] ;
} else {
theme = Object . assign ( { } , DefaultTheme ) ;
}
// CACHED COUNTS AND STUFF
// var tt_ids = {};
var tabs _matched = 0 ;
var tabs _count = 0 ;
for ( var wIndex = 0 ; wIndex < w . length ; wIndex ++ ) {
tabs _count += w [ wIndex ] . tabs . length ;
}
var lastWinId = w [ w . length - 1 ] . id ;
var lastTabId = w [ w . length - 1 ] . tabs [ w [ w . length - 1 ] . tabs . length - 1 ] . id ;
var WinCount = w . length ;
for ( var wIndex = 0 ; wIndex < WinCount ; wIndex ++ ) {
let winIndex = wIndex ;
let winId = w [ winIndex ] . id ;
let tabsCount = w [ winIndex ] . tabs . length ;
// LOAD TTID FROM FIREFOX GET WINDOW VALUE
let win = Promise . resolve ( browser . sessions . getWindowValue ( winId , "TTdata" ) ) . then ( function ( WindowData ) {
if ( opt . skip _load == false && WindowData != undefined ) {
windows [ winId ] = Object . assign ( { } , WindowData ) ;
} else {
windows [ winId ] = { ttid : "" , group _bar : opt . groups _toolbar _default , search _filter : "url" , active _shelf : "" , active _group : "tab_list" , groups : { tab _list : { id : "tab_list" , index : 0 , active _tab : 0 , active _tab _ttid : "" , prev _active _tab : 0 , prev _active _tab _ttid : "" , name : caption _ungrouped _group , font : "" } } , folders : { } } ;
}
for ( var tIndex = 0 ; tIndex < tabsCount ; tIndex ++ ) {
let tabIndex = tIndex ;
let tabId = w [ winIndex ] . tabs [ tabIndex ] . id ;
let tabPinned = w [ winIndex ] . tabs [ tabIndex ] . pinned ;
// LOAD TTID FROM FIREFOX GET TAB VALUE
let tab = Promise . resolve ( browser . sessions . getTabValue ( tabId , "TTdata" ) ) . then ( function ( TabData ) {
if ( opt . skip _load == false && TabData != undefined ) {
tabs [ tabId ] = Object . assign ( { } , TabData ) ;
tt _ids [ tabs [ tabId ] . ttid ] = tabId ;
tabs _matched ++ ;
} else {
tabs [ tabId ] = { ttid : "" , parent _ttid : "" , parent : tabPinned ? "pin_list" : "tab_list" , index : tabIndex , expand : "" } ;
2017-11-12 22:00:40 +01:00
}
2018-03-13 14:39:34 +01:00
// IF ON LAST TAB AND LAST WINDOW, START MATCHING LOADED DATA
if ( tabId == lastTabId && winId == lastWinId ) {
for ( var ThisSessonWinId in windows ) {
if ( windows [ ThisSessonWinId ] . ttid == "" ) {
AppendWinTTId ( parseInt ( ThisSessonWinId ) ) ;
}
2017-11-12 22:00:40 +01:00
}
2018-03-13 14:39:34 +01:00
// OK, DONE WITH WINDOWS, START TABS LOOP
for ( var ThisSessonTabId in tabs ) {
if ( tabs [ ThisSessonTabId ] . ttid == "" ) {
AppendTabTTId ( parseInt ( ThisSessonTabId ) ) ;
}
2017-11-12 22:00:40 +01:00
}
2018-03-13 14:39:34 +01:00
// OK, DONE, NOW REPLACE OLD PARENTS IDS WITH THIS SESSION IDS
for ( var ThisSessonTabId in tabs ) {
if ( tt _ids [ tabs [ ThisSessonTabId ] . parent _ttid ] != undefined ) {
tabs [ ThisSessonTabId ] . parent = tt _ids [ tabs [ ThisSessonTabId ] . parent _ttid ] ;
2017-11-12 22:00:40 +01:00
}
}
2018-03-13 14:39:34 +01:00
// OK, SAME THING FOR ACTIVE TABS IN GROUPS
for ( var ThisSessonWinId in windows ) {
for ( var group in windows [ ThisSessonWinId ] . groups ) {
if ( tt _ids [ windows [ ThisSessonWinId ] . groups [ group ] . active _tab _ttid ] != undefined ) {
windows [ ThisSessonWinId ] . groups [ group ] . active _tab = tt _ids [ windows [ ThisSessonWinId ] . groups [ group ] . active _tab _ttid ] ;
}
if ( tt _ids [ windows [ ThisSessonWinId ] . groups [ group ] . prev _active _tab _ttid ] != undefined ) {
windows [ ThisSessonWinId ] . groups [ group ] . prev _active _tab = tt _ids [ windows [ ThisSessonWinId ] . groups [ group ] . prev _active _tab _ttid ] ;
}
}
}
// will try to find tabs for 3 times
if ( opt . skip _load == true || retry > 2 || ( tabs _matched > tabs _count * 0.5 ) ) {
running = true ;
// setInterval(function() {
FirefoxAutoSaveData ( ) ;
// }, 10000);
FirefoxListeners ( ) ;
} else {
setTimeout ( function ( ) {
FirefoxLoadTabs ( retry + 1 ) ;
} , 2000 ) ;
}
2017-11-12 22:00:40 +01:00
}
2018-03-13 14:39:34 +01:00
} ) ;
}
} ) ;
}
} ) ;
2017-11-12 22:00:40 +01:00
} ) ;
}
// save every second if there is anything to save obviously
2017-11-20 18:14:07 +01:00
async function FirefoxAutoSaveData ( ) {
setInterval ( function ( ) {
2018-01-01 19:50:56 +01:00
if ( schedule _save > 1 ) {
schedule _save = 1 ;
}
2017-11-20 18:14:07 +01:00
if ( running && schedule _save > 0 && Object . keys ( tabs ) . length > 1 ) {
2017-11-12 22:00:40 +01:00
chrome . windows . getAll ( { windowTypes : [ 'normal' ] , populate : true } , function ( w ) {
var WinCount = w . length ;
for ( var wIndex = 0 ; wIndex < WinCount ; wIndex ++ ) {
let winId = w [ wIndex ] . id ;
2017-11-20 18:14:07 +01:00
if ( windows [ winId ] != undefined && windows [ winId ] . ttid != undefined && windows [ winId ] . group _bar != undefined && windows [ winId ] . search _filter != undefined && windows [ winId ] . active _shelf != undefined && windows [ winId ] . active _group != undefined && windows [ winId ] . groups != undefined && windows [ winId ] . folders != undefined ) {
browser . sessions . setWindowValue ( winId , "TTdata" , windows [ winId ] ) ;
2017-11-12 22:00:40 +01:00
}
let TabsCount = w [ wIndex ] . tabs . length ;
for ( var tabIndex = 0 ; tabIndex < TabsCount ; tabIndex ++ ) {
let tabId = w [ wIndex ] . tabs [ tabIndex ] . id ;
if ( tabs [ tabId ] != undefined && tabs [ tabId ] . ttid != undefined && tabs [ tabId ] . parent != undefined && tabs [ tabId ] . index != undefined && tabs [ tabId ] . expand != undefined ) {
2017-11-20 18:14:07 +01:00
browser . sessions . setTabValue ( tabId , "TTdata" , tabs [ tabId ] ) ;
2017-11-12 22:00:40 +01:00
}
}
}
schedule _save -- ;
} ) ;
}
2017-11-20 18:14:07 +01:00
} , 1000 ) ;
2017-11-12 22:00:40 +01:00
}
2018-01-01 19:50:56 +01:00
function GenerateNewWindowID ( ) {
2017-11-20 18:14:07 +01:00
var newID = "w_" + GenerateRandomID ( ) ;
2017-11-12 22:00:40 +01:00
var newIdAvailable = true ;
for ( var windowId in windows ) {
if ( windows [ windowId ] . ttid == newID ) {
newIdAvailable = false ;
}
}
if ( newIdAvailable ) {
return newID ;
} else {
GenerateNewWindowID ( ) ;
}
}
2018-01-01 19:50:56 +01:00
function GenerateNewTabID ( ) {
2017-11-20 18:14:07 +01:00
var newID = "t_" + GenerateRandomID ( ) ;
2017-11-12 22:00:40 +01:00
var newIdAvailable = true ;
2018-03-13 14:39:34 +01:00
// for (var tabId in tabs) {
// if (tabs[tabId].ttid == newID) {
// newIdAvailable = false;
// }
// }
if ( tt _ids [ newID ] != undefined ) {
newIdAvailable = false ;
2017-11-12 22:00:40 +01:00
}
if ( newIdAvailable ) {
return newID ;
} else {
GenerateNewTabID ( ) ;
}
}
2018-01-01 19:50:56 +01:00
function AppendTabTTId ( tabId ) {
2017-11-12 22:00:40 +01:00
let NewTTTabId = GenerateNewTabID ( ) ;
if ( tabs [ tabId ] != undefined ) {
tabs [ tabId ] . ttid = NewTTTabId ;
} else {
2018-03-13 14:39:34 +01:00
tabs [ tabId ] = { ttid : NewTTTabId , parent : "tab_list" , parent _ttid : "" , index : 0 , expand : "" } ;
2017-11-12 22:00:40 +01:00
}
2018-03-13 14:39:34 +01:00
tt _ids [ NewTTTabId ] = tabId ;
return NewTTTabId ;
2018-01-01 19:50:56 +01:00
// if (schedule_save > 0) browser.sessions.setTabValue( tabId, "TTdata", tabs[tabId] );
2017-11-12 22:00:40 +01:00
}
2018-01-01 19:50:56 +01:00
function AppendWinTTId ( windowId ) {
2017-11-12 22:00:40 +01:00
let NewTTWindowId = GenerateNewWindowID ( ) ;
if ( windows [ windowId ] != undefined ) {
windows [ windowId ] . ttid = NewTTWindowId ;
} else {
2018-03-13 14:39:34 +01:00
windows [ windowId ] = { ttid : NewTTWindowId , group _bar : opt . groups _toolbar _default , search _filter : "url" , active _shelf : "" , active _group : "tab_list" , groups : { tab _list : { id : "tab_list" , index : 0 , active _tab : 0 , active _tab _ttid : "" , prev _active _tab : 0 , prev _active _tab _ttid : "" , name : caption _ungrouped _group , font : "" } } , folders : { } } ;
2017-11-12 22:00:40 +01:00
}
2018-01-01 19:50:56 +01:00
// if (schedule_save > 0) browser.sessions.setWindowValue( windowId, "TTdata", windows[windowId] );
2017-11-12 22:00:40 +01:00
}
function ReplaceParents ( oldTabId , newTabId ) {
for ( var tabId in tabs ) {
if ( tabs [ tabId ] . parent == oldTabId ) {
tabs [ tabId ] . parent = newTabId ;
}
}
}
2018-03-13 14:39:34 +01:00
var DETACHED _TABS _ _ _Bug1398272 _ _ _WTF _ARE _YOU _DOING _MOZILLA = { } ; // MOZILLA BUG 1398272
2017-11-12 22:00:40 +01:00
// start all listeners
function FirefoxListeners ( ) {
browser . browserAction . onClicked . addListener ( function ( ) {
browser . sidebarAction . setPanel ( { panel : ( browser . extension . getURL ( "/sidebar.html" ) ) } ) ;
browser . sidebarAction . open ( ) ;
} ) ;
chrome . tabs . onCreated . addListener ( function ( tab ) {
2018-03-13 14:39:34 +01:00
chrome . tabs . get ( tab . id , function ( NewTab ) { // for some reason firefox sends tab with "active == false" even if tab is active (THIS IS POSSIBLY A NEW BUG IN FF 60.01!)
let t = Promise . resolve ( browser . sessions . getTabValue ( NewTab . id , "TTdata" ) ) . then ( function ( TabData ) {
if ( TabData != undefined ) {
tabs [ NewTab . id ] = Object . assign ( { } , TabData ) ;
let originalParent = TabData . parent _ttid == "" ? undefined : ( tt _ids [ TabData . parent _ttid ] ? tt _ids [ TabData . parent _ttid ] : TabData . parent _ttid ) ;
chrome . runtime . sendMessage ( { command : "tab_created" , windowId : NewTab . windowId , tab : NewTab , tabId : NewTab . id , parentTabId : originalParent , index : TabData . index } ) ;
} else {
AppendTabTTId ( NewTab . id ) ;
chrome . runtime . sendMessage ( { command : "tab_created" , windowId : NewTab . windowId , tab : NewTab , tabId : NewTab . id } ) ;
}
schedule _save ++ ;
} ) ;
2018-01-01 19:50:56 +01:00
} ) ;
2017-11-12 22:00:40 +01:00
} ) ;
chrome . tabs . onAttached . addListener ( function ( tabId , attachInfo ) {
2018-01-01 19:50:56 +01:00
let oldId = tabId ;
chrome . tabs . get ( oldId , function ( tab ) {
ReplaceParents ( oldId , tab . id ) ;
2018-03-13 14:39:34 +01:00
tt _ids [ tabs [ oldId ] . ttid ] = tab . id ; // MOZILLA BUG 1398272
tabs [ tab . id ] = tabs [ oldId ] ; // MOZILLA BUG 1398272
DETACHED _TABS _ _ _Bug1398272 _ _ _WTF _ARE _YOU _DOING _MOZILLA [ oldId ] = tab . id ; // MOZILLA BUG 1398272
DETACHED _TABS _ _ _Bug1398272 _ _ _WTF _ARE _YOU _DOING _MOZILLA [ tab . id ] = oldId ; // MOZILLA BUG 1398272
browser . sessions . setTabValue ( tab . id , "TTdata" , tabs [ oldId ] ) ; // MOZILLA BUG 1398272
2018-01-01 19:50:56 +01:00
chrome . runtime . sendMessage ( { command : "tab_attached" , windowId : attachInfo . newWindowId , tab : tab , tabId : tab . id , ParentId : tabs [ tab . id ] . parent } ) ;
2017-11-12 22:00:40 +01:00
schedule _save ++ ;
} ) ;
} ) ;
chrome . tabs . onDetached . addListener ( function ( tabId , detachInfo ) {
2018-01-01 19:50:56 +01:00
chrome . runtime . sendMessage ( { command : "tab_detached" , windowId : detachInfo . oldWindowId , tabId : tabId } ) ;
let detachTabId = tabId ;
2018-03-13 14:39:34 +01:00
if ( DETACHED _TABS _ _ _Bug1398272 _ _ _WTF _ARE _YOU _DOING _MOZILLA [ tabId ] != undefined ) { // MOZILLA BUG 1398272
detachTabId = DETACHED _TABS _ _ _Bug1398272 _ _ _WTF _ARE _YOU _DOING _MOZILLA [ tabId ] ; // MOZILLA BUG 1398272
chrome . runtime . sendMessage ( { command : "tab_detached" , windowId : detachInfo . oldWindowId , tabId : DETACHED _TABS _ _ _Bug1398272 _ _ _WTF _ARE _YOU _DOING _MOZILLA [ tabId ] } ) ; // MOZILLA BUG 1398272
} // MOZILLA BUG 1398272
2017-11-12 22:00:40 +01:00
} ) ;
chrome . tabs . onRemoved . addListener ( function ( tabId , removeInfo ) {
2018-01-01 19:50:56 +01:00
setTimeout ( function ( ) {
2018-03-13 14:39:34 +01:00
if ( DETACHED _TABS _ _ _Bug1398272 _ _ _WTF _ARE _YOU _DOING _MOZILLA [ tabId ] != undefined ) { // MOZILLA BUG 1398272
chrome . runtime . sendMessage ( { command : "tab_removed" , windowId : removeInfo . windowId , tabId : DETACHED _TABS _ _ _Bug1398272 _ _ _WTF _ARE _YOU _DOING _MOZILLA [ tabId ] } ) ; // MOZILLA BUG 1398272
} // MOZILLA BUG 1398272
2018-01-01 19:50:56 +01:00
chrome . runtime . sendMessage ( { command : "tab_removed" , windowId : removeInfo . windowId , tabId : tabId } ) ;
} , 5 ) ;
// setTimeout(function() {
// delete tabs[tabId];
// },60000);
2017-11-12 22:00:40 +01:00
schedule _save ++ ;
} ) ;
chrome . tabs . onUpdated . addListener ( function ( tabId , changeInfo , tab ) {
2018-03-13 14:39:34 +01:00
if ( changeInfo . pinned == true && tabs [ tabId ] ) {
2017-11-12 22:00:40 +01:00
tabs [ tabId ] . parent = "pin_list" ;
2017-11-20 18:14:07 +01:00
tabs [ tabId ] . parent _ttid = "" ;
schedule _save ++ ;
2018-03-13 14:39:34 +01:00
} else {
AppendTabTTId ( tabId ) ;
2017-11-12 22:00:40 +01:00
}
if ( changeInfo . title != undefined && ! tab . active ) {
chrome . runtime . sendMessage ( { command : "tab_attention" , windowId : tab . windowId , tabId : tabId } ) ;
}
chrome . runtime . sendMessage ( { command : "tab_updated" , windowId : tab . windowId , tab : tab , tabId : tabId , changeInfo : changeInfo } ) ;
} ) ;
chrome . tabs . onReplaced . addListener ( function ( addedTabId , removedTabId ) {
chrome . tabs . get ( addedTabId , function ( tab ) {
if ( addedTabId == removedTabId ) {
chrome . runtime . sendMessage ( { command : "tab_updated" , windowId : tab . windowId , tab : tab , tabId : tab . id , changeInfo : { status : tab . status , url : tab . url , title : tab . title , audible : tab . audible , mutedInfo : tab . mutedInfo } } ) ;
} else {
if ( tabs [ removedTabId ] ) {
tabs [ addedTabId ] = tabs [ removedTabId ] ;
}
ReplaceParents ( tabId , tab . id ) ;
chrome . runtime . sendMessage ( { command : "tab_removed" , windowId : tab . windowId , tabId : removedTabId } ) ;
chrome . runtime . sendMessage ( { command : "tab_attached" , windowId : tab . windowId , tab : tab , tabId : addedTabId , ParentId : tabs [ addedTabId ] . parent } ) ;
2018-03-13 14:39:34 +01:00
// delete ttid[tabs[removedTabId].ttid];
2018-01-01 19:50:56 +01:00
// delete tabs[removedTabId];
2017-11-12 22:00:40 +01:00
}
setTimeout ( function ( ) {
AppendTabTTId ( addedTabId ) ;
schedule _save ++ ;
} , 100 ) ;
} ) ;
} ) ;
chrome . tabs . onActivated . addListener ( function ( activeInfo ) {
chrome . runtime . sendMessage ( { command : "tab_activated" , windowId : activeInfo . windowId , tabId : activeInfo . tabId } ) ;
} ) ;
chrome . windows . onCreated . addListener ( function ( window ) {
2018-01-01 19:50:56 +01:00
let win = Promise . resolve ( browser . sessions . getWindowValue ( window . id , "TTdata" ) ) . then ( function ( WindowData ) {
if ( WindowData != undefined ) {
2018-03-13 14:39:34 +01:00
windows [ window . id ] = Object . assign ( { } , WindowData ) ;
2018-01-01 19:50:56 +01:00
} else {
AppendWinTTId ( window . id ) ;
}
schedule _save ++ ;
} ) ;
2017-11-12 22:00:40 +01:00
} ) ;
chrome . windows . onRemoved . addListener ( function ( windowId ) {
2018-01-01 19:50:56 +01:00
// delete windows[windowId];
2017-11-12 22:00:40 +01:00
schedule _save ++ ;
} ) ;
}
function FirefoxMessageListeners ( ) {
chrome . runtime . onMessage . addListener ( function ( message , sender , sendResponse ) {
2018-03-13 14:39:34 +01:00
if ( opt . debug ) console . log ( "message to background:" ) ;
if ( opt . debug ) console . log ( message ) ;
if ( message . command == "reload" ) {
window . location . reload ( ) ;
return ;
}
if ( message . command == "get_preferences" ) {
sendResponse ( opt ) ;
return ;
}
if ( message . command == "save_preferences" ) {
opt = Object . assign ( { } , message . opt ) ;
chrome . storage . local . set ( { preferences : message . opt } ) ;
return ;
}
if ( message . command == "get_windows" ) {
sendResponse ( windows ) ;
return ;
}
if ( message . command == "get_folders" ) {
if ( windows [ message . windowId ] ) {
sendResponse ( windows [ message . windowId ] . folders ) ;
}
return ;
}
if ( message . command == "save_folders" ) {
if ( windows [ message . windowId ] ) {
2018-01-01 19:50:56 +01:00
windows [ message . windowId ] . folders = Object . assign ( { } , message . folders ) ;
schedule _save ++ ;
2018-03-13 14:39:34 +01:00
}
return ;
}
if ( message . command == "get_groups" ) {
if ( windows [ message . windowId ] ) {
sendResponse ( windows [ message . windowId ] . groups ) ;
}
return ;
}
if ( message . command == "save_groups" ) {
if ( windows [ message . windowId ] ) {
2017-11-12 22:00:40 +01:00
windows [ message . windowId ] . groups = Object . assign ( { } , message . groups ) ;
2017-11-20 18:14:07 +01:00
for ( var group in windows [ message . windowId ] . groups ) {
2018-01-01 19:50:56 +01:00
if ( tabs [ windows [ message . windowId ] . groups [ group ] . active _tab ] ) {
windows [ message . windowId ] . groups [ group ] . active _tab _ttid = tabs [ windows [ message . windowId ] . groups [ group ] . active _tab ] . ttid ;
2017-11-20 18:14:07 +01:00
}
2018-03-13 14:39:34 +01:00
if ( tabs [ windows [ message . windowId ] . groups [ group ] . prev _active _tab ] ) {
windows [ message . windowId ] . groups [ group ] . prev _active _tab _ttid = tabs [ windows [ message . windowId ] . groups [ group ] . prev _active _tab ] . ttid ;
}
2017-11-20 18:14:07 +01:00
}
2017-11-12 22:00:40 +01:00
schedule _save ++ ;
2018-03-13 14:39:34 +01:00
}
return ;
}
if ( message . command == "set_active_group" ) {
if ( windows [ message . windowId ] ) {
2017-11-12 22:00:40 +01:00
windows [ message . windowId ] . active _group = message . active _group ;
schedule _save ++ ;
2018-03-13 14:39:34 +01:00
}
return ;
}
if ( message . command == "get_active_group" ) {
if ( windows [ message . windowId ] ) {
sendResponse ( windows [ message . windowId ] . active _group ) ;
}
return ;
}
if ( message . command == "set_search_filter" ) {
if ( windows [ message . windowId ] ) {
2017-11-20 18:14:07 +01:00
windows [ message . windowId ] . search _filter = message . search _filter ;
schedule _save ++ ;
2018-03-13 14:39:34 +01:00
}
return ;
}
if ( message . command == "get_search_filter" ) {
if ( windows [ message . windowId ] ) {
sendResponse ( windows [ message . windowId ] . search _filter ) ;
}
return ;
}
if ( message . command == "set_active_shelf" ) {
if ( windows [ message . windowId ] ) {
2017-11-12 22:00:40 +01:00
windows [ message . windowId ] . active _shelf = message . active _shelf ;
schedule _save ++ ;
2018-03-13 14:39:34 +01:00
}
return ;
}
if ( message . command == "get_active_shelf" ) {
if ( windows [ message . windowId ] ) {
sendResponse ( windows [ message . windowId ] . active _shelf ) ;
}
return ;
}
if ( message . command == "set_group_bar" ) {
if ( windows [ message . windowId ] ) {
2017-11-12 22:00:40 +01:00
windows [ message . windowId ] . group _bar = message . group _bar ;
schedule _save ++ ;
2018-03-13 14:39:34 +01:00
}
return ;
}
if ( message . command == "get_group_bar" ) {
if ( windows [ message . windowId ] ) {
sendResponse ( windows [ message . windowId ] . group _bar ) ;
}
return ;
}
if ( message . command == "get_browser_tabs" ) {
sendResponse ( tabs ) ;
return ;
}
if ( message . command == "is_bg_ready" ) {
sendResponse ( running ) ;
return ;
}
if ( message . command == "update_tab" ) {
if ( tabs [ message . tabId ] ) {
if ( message . tab . index ) {
tabs [ message . tabId ] . index = message . tab . index ;
2017-11-12 22:00:40 +01:00
}
2018-03-13 14:39:34 +01:00
if ( message . tab . expand ) {
tabs [ message . tabId ] . expand = message . tab . expand ;
}
if ( message . tab . parent ) {
tabs [ message . tabId ] . parent = message . tab . parent ;
if ( tabs [ message . tab . parent ] ) {
tabs [ message . tabId ] . parent _ttid = tabs [ message . tab . parent ] . ttid ;
} else {
tabs [ message . tabId ] . parent _ttid = "" ;
2017-11-20 18:14:07 +01:00
}
2018-03-13 14:39:34 +01:00
}
schedule _save ++ ;
}
return ;
}
if ( message . command == "update_all_tabs" ) {
for ( let i = 0 ; i < message . pins . length ; i ++ ) {
if ( tabs [ message . pins [ i ] . id ] ) {
tabs [ message . pins [ i ] . id ] . parent = "pin_list" ;
tabs [ message . pins [ i ] . id ] . parent _ttid = "" ;
tabs [ message . pins [ i ] . id ] . expand = "" ;
tabs [ message . pins [ i ] . id ] . index = message . pins [ i ] . index ;
}
}
for ( let j = 0 ; j < message . tabs . length ; j ++ ) {
if ( tabs [ message . tabs [ j ] . id ] ) {
tabs [ message . tabs [ j ] . id ] . parent = message . tabs [ j ] . parent ;
tabs [ message . tabs [ j ] . id ] . expand = message . tabs [ j ] . expand ;
tabs [ message . tabs [ j ] . id ] . index = message . tabs [ j ] . index ;
if ( tabs [ message . tabs [ j ] . parent ] ) {
tabs [ message . tabs [ j ] . id ] . parent _ttid = tabs [ message . tabs [ j ] . parent ] . ttid ;
} else {
tabs [ message . tabs [ j ] . id ] . parent _ttid = AppendTabTTId ( message . tabs [ j ] . parent ) ;
2017-11-12 22:00:40 +01:00
}
}
2018-03-13 14:39:34 +01:00
}
schedule _save ++ ;
return ;
}
if ( message . command == "get_theme" ) {
sendResponse ( theme ) ;
return ;
}
if ( message . command == "reload_theme" ) {
GetCurrentTheme ( ) ;
return ;
2017-11-12 22:00:40 +01:00
}
} ) ;
2018-01-01 19:50:56 +01:00
}