Added proper full screen support

This commit is contained in:
2025-09-09 14:20:29 +12:00
parent 7cd6048778
commit cb9a2fe897
2 changed files with 37 additions and 0 deletions
+4
View File
@@ -84,3 +84,7 @@ typings/
.idea/
site-history.json
bookmarks.json
bookmarks.backup.json
bookmarks.json
bookmarks.backup.json
+33
View File
@@ -805,6 +805,39 @@ app.on('web-contents-created', (event, contents) => {
contents.on('context-menu', (e, params) => {
buildAndShowContextMenu(contents, params);
});
// On macOS, when a page (or a <webview>) enters HTML fullscreen (e.g., YouTube video),
// also toggle the BrowserWindow into simple fullscreen so the content uses the whole
// screen and macOS traffic lights/titlebar are hidden. Revert when HTML fullscreen exits.
if (process.platform === 'darwin') {
const getOwningWindow = () => {
try {
const host = contents.hostWebContents || contents;
return BrowserWindow.fromWebContents(host) || null;
} catch { return null; }
};
contents.on('enter-html-full-screen', () => {
const win = getOwningWindow();
if (!win) return;
win.__htmlFsDepth = (win.__htmlFsDepth || 0) + 1;
// If the window is already in native fullscreen (green button), don't switch modes
const alreadyNativeFs = typeof win.isFullScreen === 'function' && win.isFullScreen();
if (!alreadyNativeFs && !win.isSimpleFullScreen?.()) {
try { win.setSimpleFullScreen?.(true); win.__htmlFsUsingSimple = true; } catch {}
}
});
contents.on('leave-html-full-screen', () => {
const win = getOwningWindow();
if (!win) return;
win.__htmlFsDepth = Math.max(0, (win.__htmlFsDepth || 1) - 1);
if (win.__htmlFsDepth === 0 && win.__htmlFsUsingSimple) {
try { if (win.isSimpleFullScreen?.()) win.setSimpleFullScreen?.(false); } catch {}
win.__htmlFsUsingSimple = false;
}
});
}
});
// --- Image save handlers ---