1
+ import { checkWindowId , findFolder , getCustomDirectoryId } from '~/background/util.ts' ;
1
2
import { exchangeBars , install } from '~/background/service.ts' ;
2
- import { findFolder , getCustomDirectoryId } from '~/background/util.ts' ;
3
3
import { getActiveBar , getLastWorkspaceId , updateLastWorkspaceId } from '~/background/storage.ts' ;
4
4
5
5
const SHORTCUT_DELAY = 100 ;
6
- let MAIN_WINDOW_ID : number | undefined ;
7
6
8
7
/**
9
8
* Handle changes to bookmarks.
@@ -58,10 +57,11 @@ export const handleRemove = async (id: string, removeInfo: { node: { title: stri
58
57
* @param _info - Info about the activated tab.
59
58
*/
60
59
export const handleWorkspaceSwitch = async ( _info : chrome . tabs . TabActiveInfo ) => {
61
- if ( MAIN_WINDOW_ID !== _info . windowId ) {
62
- console . log ( 'Tab is not in mainWindow. Do not chaning Bar.' , MAIN_WINDOW_ID , _info . windowId ) ;
60
+ const validWindow = await checkWindowId ( _info . windowId ) ;
61
+ if ( ! validWindow ) {
63
62
return ;
64
63
}
64
+
65
65
const lastWorkspaceId = await getLastWorkspaceId ( ) ;
66
66
const currentBar = await getActiveBar ( ) ;
67
67
const lastActiveBar = await getActiveBar ( lastWorkspaceId ) ;
@@ -75,13 +75,12 @@ export const handleWorkspaceSwitch = async (_info: chrome.tabs.TabActiveInfo) =>
75
75
*
76
76
* @param window - The newly created window object.
77
77
*/
78
- export const handleWindowCreate = ( window : chrome . windows . Window ) => {
79
- console . log ( 'MAIN_WINDOW_ID' , MAIN_WINDOW_ID , 'currentWindowId' , window . id ) ;
80
- if ( window . id && MAIN_WINDOW_ID === undefined && window . type === 'normal' ) {
81
- MAIN_WINDOW_ID = window . id ;
82
- console . log ( 'Setting mainWindowId:' , MAIN_WINDOW_ID ) ;
78
+ export const handleWindowCreate = async ( window : chrome . windows . Window ) => {
79
+ if ( window . id && window . type === 'normal' ) {
80
+ console . log ( 'New Window created:' , window . id ) ;
81
+ await checkWindowId ( window . id ) ;
83
82
} else {
84
- console . log ( 'Main Window is already set.' ) ;
83
+ console . warn ( ' Window is not normal:' , window ) ;
85
84
}
86
85
} ;
87
86
0 commit comments