Skip to content

Commit

Permalink
fix(sltt-app): cleanup windowsCreated on close(). handle auth0 callba…
Browse files Browse the repository at this point in the history
…ck per window
  • Loading branch information
ericpyle committed Oct 4, 2024
1 parent 4c14fa7 commit dbf094f
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ function createWindow(partition?: string): BrowserWindow {
win.show()
})

win.on('close', () => {
windowsCreated.splice(windowsCreated.indexOf(win), 1)
})

win.webContents.setWindowOpenHandler((details) => {
shell.openExternal(details.url)
return { action: 'deny' }
Expand All @@ -40,6 +44,15 @@ function createWindow(partition?: string): BrowserWindow {
// Load the remote URL for development or the local html file for production.
console.log({ loadUrl: process.env['ELECTRON_RENDERER_URL'], isDev: is.dev })
loadUrlOrFile(win)

const { session: { webRequest } } = win.webContents
webRequest.onBeforeRequest({
urls: ['http://localhost/callback*']
}, async ({ url: callbackURL }) => {
const urlParts = parse(callbackURL, true)
const { search } = urlParts
loadUrlOrFile(win, search ? { search } : undefined)
})
windowsCreated.push(win)
return win
}
Expand All @@ -64,24 +77,15 @@ app.whenReady().then(() => {
optimizer.watchWindowShortcuts(window)
})

const mainWindow = createWindow()
const { session: { webRequest } } = mainWindow.webContents

webRequest.onBeforeRequest({
urls: ['http://localhost/callback*']
}, async ({ url: callbackURL }) => {
const urlParts = parse(callbackURL, true)
const { search } = urlParts
loadUrlOrFile(mainWindow, search ? { search } : undefined)
})
createWindow()

// Disable the default Alt key behavior
Menu.setApplicationMenu(null)

// Register a global shortcut for Alt+W
globalShortcut.register('Alt+W', () => {
// only create menus when Alt+W is pressed
for (const win of windowsCreated) {
for (const win of windowsCreated.filter((win) => !win.isDestroyed())) {
createMenu(win)
// only show the menu if the window is focused
if (win.isFocused()) {
Expand Down

0 comments on commit dbf094f

Please sign in to comment.