fix fullscreen on Windows

The win.isFullScreen() state takes a second to update so we should just
pass the state manually into onToggleFullScreen().
This commit is contained in:
Feross Aboukhadijeh
2016-03-07 21:46:17 -08:00
parent 7c68be4fd4
commit 0cca67a436
4 changed files with 25 additions and 19 deletions

View File

@@ -2,9 +2,10 @@ module.exports = {
init: init init: init
} }
var electron = require('electron')
var debug = require('debug')('webtorrent-app:ipcMain') var debug = require('debug')('webtorrent-app:ipcMain')
var electron = require('electron')
var ipcMain = electron.ipcMain var ipcMain = electron.ipcMain
var menu = require('./menu')
var windows = require('./windows') var windows = require('./windows')
function init () { function init () {
@@ -28,8 +29,8 @@ function init () {
setProgress(progress) setProgress(progress)
}) })
ipcMain.on('toggleFullScreen', function (e) { ipcMain.on('toggleFullScreen', function (e, flag) {
windows.main.setFullScreen(!windows.main.isFullScreen()) menu.toggleFullScreen(flag)
}) })
ipcMain.on('setTitle', function (e, title) { ipcMain.on('setTitle', function (e, title) {

View File

@@ -5,19 +5,21 @@ var windows = require('./windows')
var app = electron.app var app = electron.app
function toggleFullScreen () { function toggleFullScreen (flag) {
debug('toggleFullScreen') debug('toggleFullScreen %s', flag)
if (windows.main && windows.main.isVisible()) { 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 // Sets whether the window should always show on top of other windows
function toggleFloatOnTop () { function toggleFloatOnTop (flag) {
debug('toggleFloatOnTop %s') debug('toggleFloatOnTop %s', flag)
if (windows.main) { if (windows.main) {
windows.main.setAlwaysOnTop(!windows.main.isAlwaysOnTop()) flag = flag != null ? flag : !windows.main.isAlwaysOnTop()
getMenuItem('Float on Top').checked = windows.main.isAlwaysOnTop() windows.main.setAlwaysOnTop(flag)
getMenuItem('Float on Top').checked = flag
} }
} }
@@ -37,6 +39,7 @@ function reloadWindow () {
} }
function addFakeDevice (device) { function addFakeDevice (device) {
debug('addFakeDevice %s', device)
windows.main.send('addFakeDevice', device) windows.main.send('addFakeDevice', device)
} }
@@ -53,9 +56,11 @@ function onWindowHide () {
} }
function onToggleFullScreen () { function onToggleFullScreen () {
windows.main.setMenuBarVisibility(!windows.main.isFullScreen()) function onToggleFullScreen (isFullScreen) {
getMenuItem('Full Screen').checked = windows.main.isFullScreen() isFullScreen = isFullScreen != null ? isFullScreen : windows.main.isFullScreen()
windows.main.send('fullscreenChanged', windows.main.isFullScreen()) windows.main.setMenuBarVisibility(!isFullScreen)
getMenuItem('Full Screen').checked = isFullScreen
windows.main.send('fullscreenChanged', isFullScreen)
} }
function getMenuItem (label) { function getMenuItem (label) {
@@ -150,12 +155,12 @@ function getMenuTemplate () {
if (process.platform === 'darwin') return 'Ctrl+Command+F' if (process.platform === 'darwin') return 'Ctrl+Command+F'
else return 'F11' else return 'F11'
})(), })(),
click: toggleFullScreen click: () => toggleFullScreen()
}, },
{ {
label: 'Float on Top', label: 'Float on Top',
type: 'checkbox', type: 'checkbox',
click: toggleFloatOnTop click: () => toggleFloatOnTop()
}, },
{ {
type: 'separator' type: 'separator'

View File

@@ -42,8 +42,8 @@ function createMainWindow (menu) {
win.on('blur', menu.onWindowHide) win.on('blur', menu.onWindowHide)
win.on('focus', menu.onWindowShow) win.on('focus', menu.onWindowShow)
win.on('enter-full-screen', menu.onToggleFullScreen) win.on('enter-full-screen', () => menu.onToggleFullScreen(true))
win.on('leave-full-screen', menu.onToggleFullScreen) win.on('leave-full-screen', () => menu.onToggleFullScreen(false))
win.on('close', function (e) { win.on('close', function (e) {
if (process.platform === 'darwin' && !isQuitting) { if (process.platform === 'darwin' && !isQuitting) {

View File

@@ -193,7 +193,7 @@ function dispatch (action, ...args) {
update() update()
} }
if (action === 'toggleFullScreen') { if (action === 'toggleFullScreen') {
ipcRenderer.send('toggleFullScreen') ipcRenderer.send('toggleFullScreen', args[0])
update() update()
} }
if (action === 'videoMouseMoved') { if (action === 'videoMouseMoved') {
@@ -448,7 +448,7 @@ function closePlayer () {
update() update()
if (state.isFullScreen) { if (state.isFullScreen) {
ipcRenderer.send('toggleFullScreen') dispatch('toggleFullScreen', false)
} }
restoreBounds() restoreBounds()
stopServer() stopServer()