Restore window position and size on startup
This commit is contained in:
27
src/main.js
27
src/main.js
@@ -6,6 +6,8 @@ const BrowserWindow = electron.BrowserWindow; // Module to create native browser
|
|||||||
const Menu = electron.Menu;
|
const Menu = electron.Menu;
|
||||||
const Tray = electron.Tray;
|
const Tray = electron.Tray;
|
||||||
const ipc = electron.ipcMain;
|
const ipc = electron.ipcMain;
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
var appMenu = require('./menus/app');
|
var appMenu = require('./menus/app');
|
||||||
|
|
||||||
var client = null;
|
var client = null;
|
||||||
@@ -76,11 +78,16 @@ app.on('ready', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
mainWindow = new BrowserWindow({
|
var bounds_info_path = app.getPath("userData") + "/bounds-info.json";
|
||||||
width: 800,
|
var window_options;
|
||||||
height: 600,
|
try {
|
||||||
icon: __dirname + '/resources/appicon.png'
|
window_options = require(bounds_info_path);
|
||||||
});
|
}
|
||||||
|
catch (e) {
|
||||||
|
// follow Electron's defaults
|
||||||
|
}
|
||||||
|
window_options.icon = __dirname + '/resources/appicon.png';
|
||||||
|
mainWindow = new BrowserWindow(window_options);
|
||||||
|
|
||||||
// and load the index.html of the app.
|
// and load the index.html of the app.
|
||||||
mainWindow.loadURL('file://' + __dirname + '/index.html');
|
mainWindow.loadURL('file://' + __dirname + '/index.html');
|
||||||
@@ -105,6 +112,16 @@ app.on('ready', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// App should save bounds when a window is closed.
|
||||||
|
// However, 'close' is not fired in some situations(shutdown, ctrl+c)
|
||||||
|
// because main process is killed in such situations.
|
||||||
|
// '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));
|
||||||
|
});
|
||||||
|
|
||||||
var app_menu = appMenu.createMenu(mainWindow);
|
var app_menu = appMenu.createMenu(mainWindow);
|
||||||
Menu.setApplicationMenu(app_menu);
|
Menu.setApplicationMenu(app_menu);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user