22 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
33 * You can obtain one at http://mozilla.org/MPL/2.0/. */
44
5+ /* global MAC_CONSTANTS */
6+
57const DEFAULT_TAB = "about:newtab" ;
68
79const backgroundLogic = {
@@ -11,22 +13,33 @@ const backgroundLogic = {
1113 "about:home" ,
1214 "about:blank"
1315 ] ) ,
14- NUMBER_OF_KEYBOARD_SHORTCUTS : 10 ,
16+ NUMBER_OF_KEYBOARD_SHORTCUTS : MAC_CONSTANTS . NUMBER_OF_KEYBOARD_SHORTCUTS ,
1517 unhideQueue : [ ] ,
16- init ( ) {
1718
18- browser . commands . onCommand . addListener ( function ( command ) {
19+ init ( ) {
20+ browser . commands . onCommand . addListener ( async function ( command ) {
1921 if ( command === "sort_tabs" ) {
2022 backgroundLogic . sortTabs ( ) ;
2123 return ;
2224 }
2325
2426 for ( let i = 0 ; i < backgroundLogic . NUMBER_OF_KEYBOARD_SHORTCUTS ; i ++ ) {
25- const key = "open_container_" + i ;
26- const cookieStoreId = identityState . keyboardShortcut [ key ] ;
27+ const key = MAC_CONSTANTS . OPEN_CONTAINER_PREFIX + i ;
28+ const reopenKey = MAC_CONSTANTS . REOPEN_IN_CONTAINER_PREFIX + i ;
2729 if ( command === key ) {
28- if ( cookieStoreId === "none" ) return ;
29- browser . tabs . create ( { cookieStoreId} ) ;
30+ const cookieStoreId = identityState . keyboardShortcut [ key ] ;
31+ if ( cookieStoreId && cookieStoreId !== "none" ) {
32+ browser . tabs . create ( { cookieStoreId} ) ;
33+ }
34+ return ;
35+ }
36+
37+ if ( command === reopenKey ) {
38+ const cookieStoreId = identityState . keyboardShortcut [ reopenKey ] ;
39+ if ( cookieStoreId && cookieStoreId !== "none" ) {
40+ backgroundLogic . reopenInContainer ( cookieStoreId ) ;
41+ }
42+ return ;
3043 }
3144 }
3245 } ) ;
@@ -69,6 +82,23 @@ const backgroundLogic = {
6982 }
7083 } ,
7184
85+ async reopenInContainer ( cookieStoreId ) {
86+ const currentTab = await browser . tabs . query ( { active : true , currentWindow : true } ) ;
87+
88+ if ( currentTab . length > 0 ) {
89+ const tab = currentTab [ 0 ] ;
90+
91+ browser . tabs . create ( {
92+ url : tab . url ,
93+ cookieStoreId,
94+ index : tab . index + 1 ,
95+ active : tab . active
96+ } ) ;
97+
98+ browser . tabs . remove ( tab . id ) ;
99+ }
100+ } ,
101+
72102 /**
73103 * We left an achievement entry in storage during a user research study in
74104 * version 8.3.1. This method removes that entry to prevent broken logic in
@@ -84,11 +114,15 @@ const backgroundLogic = {
84114 } ,
85115
86116 updateTranslationInManifest ( ) {
87- for ( let index = 0 ; index < 10 ; index ++ ) {
88- const ajustedIndex = index + 1 ; // We want to start from 1 instead of 0 in the UI.
117+ for ( let index = 0 ; index < MAC_CONSTANTS . NUMBER_OF_KEYBOARD_SHORTCUTS ; index ++ ) {
118+ const adjustedIndex = index + 1 ; // We want to start from 1 instead of 0 in the UI.
119+ browser . commands . update ( {
120+ name : `${ MAC_CONSTANTS . OPEN_CONTAINER_PREFIX } ${ index } ` ,
121+ description : browser . i18n . getMessage ( "containerShortcut" , `${ adjustedIndex } ` )
122+ } ) ;
89123 browser . commands . update ( {
90- name : `open_container_ ${ index } ` ,
91- description : browser . i18n . getMessage ( "containerShortcut " , `${ ajustedIndex } ` )
124+ name : `${ MAC_CONSTANTS . REOPEN_IN_CONTAINER_PREFIX } ${ index } ` ,
125+ description : browser . i18n . getMessage ( "reopenInContainerShortcut " , `${ adjustedIndex } ` )
92126 } ) ;
93127 }
94128 } ,
0 commit comments