diff --git a/holo-key-manager-extension/scripts/background.ts b/holo-key-manager-extension/scripts/background.ts index c1a6fd4..3c8f4bb 100644 --- a/holo-key-manager-extension/scripts/background.ts +++ b/holo-key-manager-extension/scripts/background.ts @@ -58,41 +58,33 @@ const createWindowProperties = (parsedMessage?: MessageWithId): WindowProperties left: 1100 }); -const updateWindow = ( +const createOrUpdateWindow = ( windowProperties: WindowProperties, handleWindowUpdateOrCreate: () => Promise -) => - chrome.windows.update( - windowId!, - { ...windowProperties, focused: true }, - handleWindowUpdateOrCreate - ); - -const createWindow = ( - windowProperties: WindowProperties, - handleWindowUpdateOrCreate: () => Promise -) => - chrome.windows.create(windowProperties, (newWindow) => { +) => { + const onWindowCreated = (newWindow: chrome.windows.Window | undefined) => { if (!newWindow) return; windowId = newWindow.id; chrome.windows.onRemoved.addListener((id) => { if (id === windowId) windowId = undefined; }); handleWindowUpdateOrCreate(); - }); + }; -const manageWindow = ( - windowProperties: WindowProperties, - handleWindowUpdateOrCreate: () => Promise -) => - windowId - ? updateWindow(windowProperties, handleWindowUpdateOrCreate) - : createWindow(windowProperties, handleWindowUpdateOrCreate); + if (windowId) { + chrome.windows.remove(windowId, () => { + windowId = undefined; + chrome.windows.create(windowProperties, onWindowCreated); + }); + } else { + chrome.windows.create(windowProperties, onWindowCreated); + } +}; const updateOrCreateWindowCommon = ( handleWindowUpdateOrCreate: () => Promise, parsedMessage?: MessageWithId -) => manageWindow(createWindowProperties(parsedMessage), handleWindowUpdateOrCreate); +) => createOrUpdateWindow(createWindowProperties(parsedMessage), handleWindowUpdateOrCreate); const updateOrCreateWindow = ( successAction: typeof NEEDS_SETUP, diff --git a/holo-key-manager-extension/static/manifest.json b/holo-key-manager-extension/static/manifest.json index 32b01f7..7c464b9 100644 --- a/holo-key-manager-extension/static/manifest.json +++ b/holo-key-manager-extension/static/manifest.json @@ -1,7 +1,7 @@ { "name": "Holo key manager", "description": "A browser extension to manage holo keys", - "version": "0.0.73", + "version": "0.0.74", "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiAtKvbHNTN3O2BLRZH7RkLczaMLenSeZu+YP+KomPQPZ18nt4DY9boIN/+GWts7gCzEeQq59l8edGdF2P7xAbsRxYR88+zFEbxMtIyfyqJZIlzXwnvPJkwGu/S6arNtX48K7q1+xnJEE7VyeYSj6/i2LR+LmPigCzY9JCP7+SmWVeYbdm3kZmReK0ecfh15RXSNjZpXJUgrbea/RVxweggYKnmhhOUBmuJSCLoWTXIuJPBMwGQK1O2GKBqHOq94bPVSF7j+4WzSpPan70ZZJX/reFsOFE/idfFN6wbizjR1Ne50Po03kudEmfQgoqUhVpd0wP8A3YbqE7ODdZcCPPwIDAQAB", "manifest_version": 3, "action": {