From 0cca67a4369af69c9453b8fa7b43b5dda6db3d18 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Mon, 7 Mar 2016 21:46:17 -0800 Subject: [PATCH] fix fullscreen on Windows The win.isFullScreen() state takes a second to update so we should just pass the state manually into onToggleFullScreen(). --- main/ipc.js | 7 ++++--- main/menu.js | 29 +++++++++++++++++------------ main/windows.js | 4 ++-- renderer/index.js | 4 ++-- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/main/ipc.js b/main/ipc.js index ea476b06..29bc4ca8 100644 --- a/main/ipc.js +++ b/main/ipc.js @@ -2,9 +2,10 @@ module.exports = { init: init } -var electron = require('electron') var debug = require('debug')('webtorrent-app:ipcMain') +var electron = require('electron') var ipcMain = electron.ipcMain +var menu = require('./menu') var windows = require('./windows') function init () { @@ -28,8 +29,8 @@ function init () { setProgress(progress) }) - ipcMain.on('toggleFullScreen', function (e) { - windows.main.setFullScreen(!windows.main.isFullScreen()) + ipcMain.on('toggleFullScreen', function (e, flag) { + menu.toggleFullScreen(flag) }) ipcMain.on('setTitle', function (e, title) { diff --git a/main/menu.js b/main/menu.js index 73b55f5c..47a2fdf9 100644 --- a/main/menu.js +++ b/main/menu.js @@ -5,19 +5,21 @@ var windows = require('./windows') var app = electron.app -function toggleFullScreen () { - debug('toggleFullScreen') +function toggleFullScreen (flag) { + debug('toggleFullScreen %s', flag) if (windows.main && windows.main.isVisible()) { - windows.main.setFullScreen(!windows.main.isFullScreen()) + flag = flag != null ? flag : !windows.main.isFullScreen() + windows.main.setFullScreen(flag) } } // Sets whether the window should always show on top of other windows -function toggleFloatOnTop () { - debug('toggleFloatOnTop %s') +function toggleFloatOnTop (flag) { + debug('toggleFloatOnTop %s', flag) if (windows.main) { - windows.main.setAlwaysOnTop(!windows.main.isAlwaysOnTop()) - getMenuItem('Float on Top').checked = windows.main.isAlwaysOnTop() + flag = flag != null ? flag : !windows.main.isAlwaysOnTop() + windows.main.setAlwaysOnTop(flag) + getMenuItem('Float on Top').checked = flag } } @@ -37,6 +39,7 @@ function reloadWindow () { } function addFakeDevice (device) { + debug('addFakeDevice %s', device) windows.main.send('addFakeDevice', device) } @@ -53,9 +56,11 @@ function onWindowHide () { } function onToggleFullScreen () { - windows.main.setMenuBarVisibility(!windows.main.isFullScreen()) - getMenuItem('Full Screen').checked = windows.main.isFullScreen() - windows.main.send('fullscreenChanged', windows.main.isFullScreen()) +function onToggleFullScreen (isFullScreen) { + isFullScreen = isFullScreen != null ? isFullScreen : windows.main.isFullScreen() + windows.main.setMenuBarVisibility(!isFullScreen) + getMenuItem('Full Screen').checked = isFullScreen + windows.main.send('fullscreenChanged', isFullScreen) } function getMenuItem (label) { @@ -150,12 +155,12 @@ function getMenuTemplate () { if (process.platform === 'darwin') return 'Ctrl+Command+F' else return 'F11' })(), - click: toggleFullScreen + click: () => toggleFullScreen() }, { label: 'Float on Top', type: 'checkbox', - click: toggleFloatOnTop + click: () => toggleFloatOnTop() }, { type: 'separator' diff --git a/main/windows.js b/main/windows.js index 2d65065d..ecdc2c2f 100644 --- a/main/windows.js +++ b/main/windows.js @@ -42,8 +42,8 @@ function createMainWindow (menu) { win.on('blur', menu.onWindowHide) win.on('focus', menu.onWindowShow) - win.on('enter-full-screen', menu.onToggleFullScreen) - win.on('leave-full-screen', menu.onToggleFullScreen) + win.on('enter-full-screen', () => menu.onToggleFullScreen(true)) + win.on('leave-full-screen', () => menu.onToggleFullScreen(false)) win.on('close', function (e) { if (process.platform === 'darwin' && !isQuitting) { diff --git a/renderer/index.js b/renderer/index.js index 6b1e1ca6..84045280 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -193,7 +193,7 @@ function dispatch (action, ...args) { update() } if (action === 'toggleFullScreen') { - ipcRenderer.send('toggleFullScreen') + ipcRenderer.send('toggleFullScreen', args[0]) update() } if (action === 'videoMouseMoved') { @@ -448,7 +448,7 @@ function closePlayer () { update() if (state.isFullScreen) { - ipcRenderer.send('toggleFullScreen') + dispatch('toggleFullScreen', false) } restoreBounds() stopServer()