diff --git a/src-electron/electron-main.ts b/src-electron/electron-main.ts index d491e498bb..6d66a833a7 100644 --- a/src-electron/electron-main.ts +++ b/src-electron/electron-main.ts @@ -35,6 +35,13 @@ if (process.env.PORTABLE_EXECUTABLE_DIR) { 'Meeting Media Manager - User Data', ), ); + app.setPath( + 'temp', + join( + process.env.PORTABLE_EXECUTABLE_DIR, + 'Meeting Media Manager - Temporary Files', + ), + ); } initSentry({ diff --git a/src-electron/main/window/window-base.ts b/src-electron/main/window/window-base.ts index f154e60570..9c9b35bad3 100644 --- a/src-electron/main/window/window-base.ts +++ b/src-electron/main/window/window-base.ts @@ -96,12 +96,18 @@ export function createWindow( ); // Devtools + let devToolsOpenedCount = 0; // Track the number of times the devtools-opened event is fired if (process.env.DEBUGGING) { win.webContents.openDevTools(); // I like having dev tools open for all windows in dev } else { - // Prevent devtools from being opened in production + // Prevent devtools from being opened in production unless it's attempted more than twice win.webContents.on('devtools-opened', () => { - win?.webContents.closeDevTools(); + devToolsOpenedCount += 1; // Increment the counter + if (devToolsOpenedCount <= 2) { + win?.webContents.closeDevTools(); // Close devtools for the first two attempts + } else { + console.debug('DevTools opened after 2 attempts'); // Log for debugging + } }); } diff --git a/src-electron/main/window/window-main.ts b/src-electron/main/window/window-main.ts index 64f1692645..92867c559e 100644 --- a/src-electron/main/window/window-main.ts +++ b/src-electron/main/window/window-main.ts @@ -1,5 +1,6 @@ import type { BrowserWindow } from 'electron'; +import { PLATFORM } from 'app/src-electron/constants'; import { throttle } from 'app/src-electron/utils'; import { cancelAllDownloads } from '../downloads'; @@ -27,6 +28,8 @@ export function createMainWindow() { throttle(() => moveMediaWindow(), 100), ); + if (PLATFORM !== 'darwin') mainWindow.on('moved', moveMediaWindow); // On macOS, the 'moved' event is just an alias for 'move' + mainWindow.on('close', (e) => { if (mainWindow && authorizedClose) { cancelAllDownloads(); diff --git a/src-electron/main/window/window-media.ts b/src-electron/main/window/window-media.ts index 43907752f4..d294e8bcaf 100644 --- a/src-electron/main/window/window-media.ts +++ b/src-electron/main/window/window-media.ts @@ -78,7 +78,6 @@ export const moveMediaWindow = ( } setWindowPosition(displayNr, fullscreen, noEvent); - sendToWindow(mainWindow, 'screenChange'); } catch (e) { errorCatcher(e); } @@ -95,26 +94,50 @@ const setWindowPosition = ( const screens = getAllScreens(); const currentDisplayNr = getWindowScreen(mediaWindow); const targetDisplay = screens[displayNr ?? 0]; - if (!targetDisplay) return; const targetScreenBounds = targetDisplay.bounds; - if (!targetScreenBounds) return; + const boundsChanged = ( + current: Electron.Rectangle, + target: Electron.Rectangle, + ) => + ['height', 'width', 'x', 'y'].some( + (prop) => + current[prop as keyof Electron.Rectangle] !== + target[prop as keyof Electron.Rectangle], + ); + + const setWindowBounds = ( + bounds: Partial, + alwaysOnTop = false, + fullScreen = false, + ) => { + if (!mediaWindow) return; + mediaWindow.setBounds(bounds); + if (mediaWindow.isAlwaysOnTop() !== alwaysOnTop) { + mediaWindow.setAlwaysOnTop(alwaysOnTop); + } + if (mediaWindow.isFullScreen() !== fullScreen) { + mediaWindow.setFullScreen(fullScreen); + } + sendToWindow(mainWindow, 'screenChange'); + }; + + const handleMacFullScreenTransition = (callback: () => void) => { + if (PLATFORM === 'darwin' && mediaWindow && mediaWindow.isFullScreen()) { + mediaWindow.once('leave-full-screen', callback); + mediaWindow.setFullScreen(false); + } else { + callback(); + } + }; if (fullscreen) { if (displayNr === currentDisplayNr && mediaWindow.isAlwaysOnTop()) return; - - mediaWindow.setPosition(targetScreenBounds.x, targetScreenBounds.y); - - // macOS doesn't play nice when trying to share a fullscreen window in Zoom if it's set to always be on top - if (PLATFORM !== 'darwin' && !mediaWindow.isAlwaysOnTop()) { - mediaWindow.setAlwaysOnTop(true); - } - // On macOS, fullscreen transitions take place asynchronously. Let's not check for isFullScreen() if we're on that platform - if (PLATFORM === 'darwin' || !mediaWindow.isFullScreen()) { - mediaWindow.setFullScreen(true); - } + handleMacFullScreenTransition(() => { + setWindowBounds(targetScreenBounds, PLATFORM !== 'darwin', true); + }); } else { const newBounds = { height: 720, @@ -122,38 +145,21 @@ const setWindowPosition = ( x: targetScreenBounds.x + 50, y: targetScreenBounds.y + 50, }; - if ( - mediaWindow.isAlwaysOnTop() || - // On macOS, fullscreen transitions take place asynchronously. Let's not check for isFullScreen() if we're on that platform - PLATFORM === 'darwin' || - mediaWindow.isFullScreen() + displayNr !== currentDisplayNr && + boundsChanged(mediaWindow.getBounds(), newBounds) ) { - // macOS doesn't play nice when trying to share a fullscreen window in Zoom if it's set to always be on top - if (PLATFORM !== 'darwin') mediaWindow.setAlwaysOnTop(false); - mediaWindow.setFullScreen(false); - mediaWindow.setBounds(newBounds); - } - - if (displayNr === currentDisplayNr) return; - - const currentBounds = mediaWindow.getBounds(); - if ( - currentBounds.height !== newBounds.height || - currentBounds.width !== newBounds.width || - currentBounds.x !== newBounds.x || - currentBounds.y !== newBounds.y - ) { - mediaWindow.setBounds(newBounds); + handleMacFullScreenTransition(() => { + setWindowBounds(newBounds, false, false); + }); } } if (!noEvent) { - const prefs: ScreenPreferences = { + sendToWindow(mainWindow, 'screenPrefsChange', { preferredScreenNumber: displayNr ?? 0, preferWindowed: !fullscreen, - }; - sendToWindow(mainWindow, 'screenPrefsChange', prefs); + } as ScreenPreferences); } } catch (err) { errorCatcher(err); diff --git a/src/pages/MediaPlayerPage.vue b/src/pages/MediaPlayerPage.vue index fb14f7d188..a627b97d43 100644 --- a/src/pages/MediaPlayerPage.vue +++ b/src/pages/MediaPlayerPage.vue @@ -1,8 +1,8 @@