1+ /* global MAC_CONSTANTS */
12/* This Source Code Form is subject to the terms of the Mozilla Public
23 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
34 * You can obtain one at http://mozilla.org/MPL/2.0/. */
@@ -11,33 +12,35 @@ const backgroundLogic = {
1112 "about:home" ,
1213 "about:blank"
1314 ] ) ,
14- NUMBER_OF_KEYBOARD_SHORTCUTS : 10 ,
15+ // Use shared constants for counts
16+ // NOTE: Keep in sync with MAC_CONSTANTS.NUMBER_OF_KEYBOARD_SHORTCUTS
1517 unhideQueue : [ ] ,
1618
1719 init ( ) {
1820 browser . commands . onCommand . addListener ( async function ( command ) {
1921 if ( command === "sort_tabs" ) {
2022 backgroundLogic . sortTabs ( ) ;
21- return ;
22- }
23-
24- for ( let i = 0 ; i < backgroundLogic . NUMBER_OF_KEYBOARD_SHORTCUTS ; i ++ ) {
25- const key = "open_container_" + i ;
26- const reopenKey = "reopen_in_container_" + i ;
27- const cookieStoreId = identityState . keyboardShortcut [ key ] ;
28-
29- if ( cookieStoreId === "none" ) {
30- continue ;
23+ } else if ( command . startsWith ( MAC_CONSTANTS . OPEN_CONTAINER_PREFIX ) ) {
24+ for ( let i = 0 ; i < MAC_CONSTANTS . NUMBER_OF_KEYBOARD_SHORTCUTS ; i ++ ) {
25+ const key = MAC_CONSTANTS . OPEN_CONTAINER_PREFIX + i ;
26+ const cookieStoreId = identityState . keyboardShortcut [ key ] ;
27+ if ( command === key ) {
28+ if ( cookieStoreId !== "none" ) {
29+ browser . tabs . create ( { cookieStoreId } ) ;
30+ }
31+ break ;
32+ }
3133 }
32-
33- if ( command === key ) {
34- browser . tabs . create ( { cookieStoreId} ) ;
35- return ;
36- }
37-
38- if ( command === reopenKey ) {
39- backgroundLogic . reopenInContainer ( cookieStoreId ) ;
40- return ;
34+ } else if ( command . startsWith ( MAC_CONSTANTS . REOPEN_IN_CONTAINER_PREFIX ) ) {
35+ for ( let i = 0 ; i < MAC_CONSTANTS . NUMBER_OF_KEYBOARD_SHORTCUTS ; i ++ ) {
36+ const key = MAC_CONSTANTS . REOPEN_IN_CONTAINER_PREFIX + i ;
37+ const cookieStoreId = identityState . keyboardShortcut [ key ] ;
38+ if ( command === key ) {
39+ if ( cookieStoreId !== "none" ) {
40+ backgroundLogic . reopenInContainer ( cookieStoreId ) ;
41+ }
42+ break ;
43+ }
4144 }
4245 }
4346 } ) ;
@@ -80,7 +83,7 @@ const backgroundLogic = {
8083 } ,
8184
8285 async reopenInContainer ( cookieStoreId ) {
83- const currentTab = await browser . tabs . query ( { active : true , currentWindow : true } )
86+ const currentTab = await browser . tabs . query ( { active : true , currentWindow : true } ) ;
8487
8588 if ( currentTab . length > 0 ) {
8689 const tab = currentTab [ 0 ] ;
@@ -97,14 +100,14 @@ const backgroundLogic = {
97100 } ,
98101
99102 updateTranslationInManifest ( ) {
100- for ( let index = 0 ; index < 10 ; index ++ ) {
103+ for ( let index = 0 ; index < MAC_CONSTANTS . NUMBER_OF_KEYBOARD_SHORTCUTS ; index ++ ) {
101104 const adjustedIndex = index + 1 ; // We want to start from 1 instead of 0 in the UI.
102105 browser . commands . update ( {
103- name : `open_container_ ${ index } ` ,
106+ name : `${ MAC_CONSTANTS . OPEN_CONTAINER_PREFIX } ${ index } ` ,
104107 description : browser . i18n . getMessage ( "containerShortcut" , `${ adjustedIndex } ` )
105108 } ) ;
106109 browser . commands . update ( {
107- name : `reopen_in_container_ ${ index } ` ,
110+ name : `${ MAC_CONSTANTS . REOPEN_IN_CONTAINER_PREFIX } ${ index } ` ,
108111 description : browser . i18n . getMessage ( "reopenInContainerShortcut" , `${ adjustedIndex } ` )
109112 } ) ;
110113 }
@@ -216,9 +219,9 @@ const backgroundLogic = {
216219 const protocol = new URL ( url ) . protocol ;
217220 // We can't open these we just have to throw them away
218221 if ( protocol === "about:"
219- || protocol === "chrome:"
220- || protocol === "moz-extension:"
221- || protocol === "file:" ) {
222+ || protocol === "chrome:"
223+ || protocol === "moz-extension:"
224+ || protocol === "file:" ) {
222225 return false ;
223226 }
224227 return true ;
@@ -235,7 +238,7 @@ const backgroundLogic = {
235238 async getTabs ( options ) {
236239 const requiredArguments = [ "cookieStoreId" , "windowId" ] ;
237240 this . checkArgs ( requiredArguments , options , "getTabs" ) ;
238- const { cookieStoreId, windowId } = options ;
241+ const { cookieStoreId, windowId} = options ;
239242
240243 const list = [ ] ;
241244 const tabs = await browser . tabs . query ( {
@@ -279,7 +282,7 @@ const backgroundLogic = {
279282 async moveTabsToWindow ( options ) {
280283 const requiredArguments = [ "cookieStoreId" , "windowId" ] ;
281284 this . checkArgs ( requiredArguments , options , "moveTabsToWindow" ) ;
282- const { cookieStoreId, windowId } = options ;
285+ const { cookieStoreId, windowId} = options ;
283286
284287 const list = await browser . tabs . query ( {
285288 cookieStoreId,
@@ -290,7 +293,7 @@ const backgroundLogic = {
290293
291294 // Nothing to do
292295 if ( list . length === 0 &&
293- containerState . hiddenTabs . length === 0 ) {
296+ containerState . hiddenTabs . length === 0 ) {
294297 return ;
295298 }
296299 let newWindowObj ;
@@ -301,16 +304,15 @@ const backgroundLogic = {
301304 // Pin the default tab in the new window so existing pinned tabs can be moved after it.
302305 // From the docs (https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/move):
303306 // Note that you can't move pinned tabs to a position after any unpinned tabs in a window, or move any unpinned tabs to a position before any pinned tabs.
304- await browser . tabs . update ( newWindowObj . tabs [ 0 ] . id , { pinned : true } ) ;
307+ await browser . tabs . update ( newWindowObj . tabs [ 0 ] . id , { pinned : true } ) ;
305308
306309 browser . tabs . move ( list . map ( ( tab ) => tab . id ) , {
307310 windowId : newWindowObj . id ,
308311 index : - 1
309312 } ) ;
310313 } else {
311314 // As we get a blank tab here we will need to await the tabs creation
312- newWindowObj = await browser . windows . create ( {
313- } ) ;
315+ newWindowObj = await browser . windows . create ( { } ) ;
314316 hiddenDefaultTabToClose = true ;
315317 }
316318
@@ -371,7 +373,7 @@ const backgroundLogic = {
371373 const identities = await browser . contextualIdentities . query ( { } ) ;
372374 const identitiesOutput = { } ;
373375 const identitiesPromise = identities . map ( async ( identity ) => {
374- const { cookieStoreId } = identity ;
376+ const { cookieStoreId} = identity ;
375377 const containerState = await identityState . storageArea . get ( cookieStoreId ) ;
376378 const openTabs = await browser . tabs . query ( {
377379 cookieStoreId,
@@ -430,7 +432,7 @@ const backgroundLogic = {
430432
431433 if ( ! map . has ( tab . cookieStoreId ) ) {
432434 const userContextId = backgroundLogic . getUserContextIdFromCookieStoreId ( tab . cookieStoreId ) ;
433- map . set ( tab . cookieStoreId , { order : userContextId , tabs : [ ] } ) ;
435+ map . set ( tab . cookieStoreId , { order : userContextId , tabs : [ ] } ) ;
434436 }
435437 map . get ( tab . cookieStoreId ) . tabs . push ( tab ) ;
436438 }
@@ -449,7 +451,7 @@ const backgroundLogic = {
449451 const sortMap = new Map ( [ ...map . entries ( ) ] . sort ( ( a , b ) => a [ 1 ] . order > b [ 1 ] . order ) ) ;
450452
451453 // Let's move tabs.
452- for ( const { tabs } of sortMap . values ( ) ) {
454+ for ( const { tabs} of sortMap . values ( ) ) {
453455 for ( const tab of tabs ) {
454456 ++ pos ;
455457 browser . tabs . move ( tab . id , {
@@ -473,7 +475,7 @@ const backgroundLogic = {
473475 async hideTabs ( options ) {
474476 const requiredArguments = [ "cookieStoreId" , "windowId" ] ;
475477 this . checkArgs ( requiredArguments , options , "hideTabs" ) ;
476- const { cookieStoreId, windowId } = options ;
478+ const { cookieStoreId, windowId} = options ;
477479
478480 const userContextId = backgroundLogic . getUserContextIdFromCookieStoreId ( cookieStoreId ) ;
479481
@@ -513,7 +515,7 @@ const backgroundLogic = {
513515 } ,
514516
515517 cookieStoreId ( userContextId ) {
516- if ( userContextId === 0 ) return "firefox-default" ;
518+ if ( userContextId === 0 ) return "firefox-default" ;
517519 return `firefox-container-${ userContextId } ` ;
518520 }
519521} ;
0 commit comments