aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMehdy Dara <[email protected]>2015-06-03 13:07:25 +0200
committerSindre Sorhus <[email protected]>2015-06-03 13:08:31 +0200
commitacb2969165a7cb1c3aee0ba5997be4a719a8232c (patch)
treed0f6e190f719afaa25c319dc51d830b73fe7e9ce
parenta3c3452f3406333c9b67bfa4fe7eeafd57e4873c (diff)
downloadelectron-boilerplate-acb2969165a7cb1c3aee0ba5997be4a719a8232c.tar.xz
electron-boilerplate-acb2969165a7cb1c3aee0ba5997be4a719a8232c.zip
recreate window when clicked on dock icon
-rw-r--r--boilerplate/index.js39
1 files changed, 26 insertions, 13 deletions
diff --git a/boilerplate/index.js b/boilerplate/index.js
index 6d41b75..0382628 100644
--- a/boilerplate/index.js
+++ b/boilerplate/index.js
@@ -5,6 +5,25 @@ const BrowserWindow = require('browser-window');
// report crashes to the Electron project
require('crash-reporter').start();
+function createMainWindow () {
+ const win = new BrowserWindow({
+ width: 600,
+ height: 400,
+ resizable: false
+ });
+
+ win.loadUrl(`file://${__dirname}/index.html`);
+ win.on('closed', onClosed);
+
+ return win;
+}
+
+function onClosed () {
+ // deref the window
+ // for multiple windows store them in an array
+ mainWindow = null;
+}
+
// prevent window being GC'd
let mainWindow = null;
@@ -14,18 +33,12 @@ app.on('window-all-closed', function () {
}
});
-app.on('ready', function () {
- mainWindow = new BrowserWindow({
- width: 600,
- height: 400,
- resizable: false
- });
-
- mainWindow.loadUrl(`file://${__dirname}/index.html`);
+app.on('activate-with-no-open-windows', function () {
+ if (!mainWindow) {
+ mainWindow = createMainWindow();
+ }
+});
- mainWindow.on('closed', function () {
- // deref the window
- // for multiple windows store them in an array
- mainWindow = null;
- })
+app.on('ready', function () {
+ mainWindow = createMainWindow();
});