Last active
September 29, 2015 03:09
-
-
Save jameslk/f59714b04d6c199ecd2b to your computer and use it in GitHub Desktop.
Atom Shell Fullscreen Monkey Patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To use this, import the Fullscreen class, instantiate it and call implementHtml5FullscreenApi(). | |
import remote from 'remote'; | |
export default class Fullscreen { | |
constructor() { | |
this.browserWindow = remote.getCurrentWindow(); | |
this.elementPrototype = Element.prototype; | |
this._fullscreenElement = null; | |
} | |
implementHtml5FullscreenApi() { | |
var controller = this; | |
this._assignAllTo( | |
[this.elementPrototype, document], | |
['requestFullscreen', 'webkitRequestFullscreen', 'webkitRequestFullScreen'], | |
function() { | |
controller._fullscreenElement = this; | |
controller.browserWindow.setFullScreen(true); | |
} | |
); | |
this._assignAllTo( | |
[this.elementPrototype, document], | |
['exitFullscreen', 'webkitExitFullscreen', 'webkitCancelFullScreen'], | |
() => { | |
this.browserWindow.setFullScreen(false); | |
} | |
); | |
this._defineAll( | |
[this.elementPrototype, document], | |
['fullscreenEnabled', 'webkitFullscreenEnabled', 'webkitIsFullScreen'], | |
{get: () => this.browserWindow.isFullScreen()} | |
); | |
this._defineAll( | |
[this.elementPrototype, document], | |
['fullscreenElement', 'webkitFullscreenElement', 'webkitCurrentFullScreenElement'], | |
{get: () => this._fullscreenElement} | |
); | |
let triggerFullscreenChange = () => { | |
let eventOptions = {bubbles: true, cancelable: false}; | |
document.dispatchEvent(new Event('fullscreenchange', eventOptions)); | |
document.dispatchEvent(new Event('webkitfullscreenchange', eventOptions)); | |
}; | |
this.browserWindow.on('enter-full-screen', () => { | |
triggerFullscreenChange(); | |
}); | |
this.browserWindow.on('leave-full-screen', () => { | |
triggerFullscreenChange(); | |
this._fullscreenElement = null; | |
}); | |
} | |
_assignAllTo(objects, properties, value) { | |
this._forEveryObjectForEachProperty(objects, properties, | |
(object, property) => object[property] = value); | |
} | |
_defineAll(objects, properties, definition) { | |
this._forEveryObjectForEachProperty(objects, properties, | |
(object, property) => Object.defineProperty(object, property, definition)); | |
} | |
_forEveryObjectForEachProperty(objects, properties, iterator) { | |
objects.forEach(object => { | |
properties.forEach(property => { | |
iterator(object, property); | |
}); | |
}); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a hack to address this issue in Atom Shell:
electron/electron#1314