Restore maximized/fullscreen state on startup

Please refer to #4
This commit is contained in:
Yuya Ochiai 2016-01-12 22:08:24 +09:00
parent f2209aa9dd
commit 48f63b6bcb

View file

@ -111,6 +111,9 @@ app.on('ready', function() {
}
window_options.icon = __dirname + '/resources/appicon.png';
mainWindow = new BrowserWindow(window_options);
if (window_options.maximized) {
mainWindow.maximize();
}
// and load the index.html of the app.
mainWindow.loadURL('file://' + __dirname + '/browser/index.html');
@ -118,10 +121,16 @@ app.on('ready', function() {
// Open the DevTools.
// mainWindow.openDevTools();
var saveWindowState = function(file, window) {
var window_state = window.getBounds();
window_state.maximized = window.isMaximized();
window_state.fullscreen = window.isFullScreen();
fs.writeFileSync(bounds_info_path, JSON.stringify(window_state));
};
mainWindow.on('close', function(event) {
if (willAppQuit) { // when [Ctrl|Cmd]+Q
var bounds = mainWindow.getBounds();
fs.writeFileSync(bounds_info_path, JSON.stringify(bounds));
saveWindowState(bounds_info_path, mainWindow);
}
else { // Minimize or hide the window for close button.
event.preventDefault();
@ -144,8 +153,7 @@ app.on('ready', function() {
// 'blur' event was effective in order to avoid this.
// Ideally, app should detect that OS is shutting down.
mainWindow.on('blur', function() {
var bounds = mainWindow.getBounds();
fs.writeFileSync(bounds_info_path, JSON.stringify(bounds));
saveWindowState(bounds_info_path, mainWindow);
});
var app_menu = appMenu.createMenu(mainWindow);