From 056855808c85a0ab66d0533b8cd29cbfe753bbed Mon Sep 17 00:00:00 2001 From: Louis Eveillard Date: Wed, 28 Dec 2016 15:01:09 +0100 Subject: [PATCH] added copy/paste, hiding window before its ready --- main.js | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 139 insertions(+), 6 deletions(-) diff --git a/main.js b/main.js index 2285619f1..addfa3665 100644 --- a/main.js +++ b/main.js @@ -1,5 +1,5 @@ const electron = require('electron'); -const {app, BrowserWindow} = electron; +const {app, BrowserWindow, Menu} = electron; const path = require('path'); const fs = require('fs-extra'); @@ -18,7 +18,7 @@ let win; app.commandLine.appendSwitch('--ignore-certificate-errors'); -function createWindow () { +function createWindow() { var JSONStorage = require('node-localstorage').JSONStorage; var storageLocation = app.getPath('userData'); @@ -55,6 +55,7 @@ function createWindow () { backgroundColor: '#EBEBEB', icon: __dirname + '/build/icons/512x512.png', + show: false, webPreferences: { allowDisplayingInsecureContent: true, @@ -82,7 +83,7 @@ function createWindow () { }); }); - win.focus(); + setApplicationMenu(); copyAndRenameUserFolder().then(function(pathToUserContent) { @@ -111,6 +112,12 @@ function createWindow () { // when you should delete the corresponding element. win = null }); + + win.on('ready-to-show', function() { + win.show(); + win.focus(); + }); + }, function(err) { dev.error( 'Failed to check existing content folder : ' + err); }); @@ -130,7 +137,7 @@ app.on('window-all-closed', () => { // if (process.platform !== 'darwin') { app.quit(); // } -}) +}); app.on('activate', () => { // On macOS it's common to re-create a window in the app when the @@ -138,8 +145,134 @@ app.on('activate', () => { if (win === null) { createWindow(); } -}) - +}); + +function setApplicationMenu() { + // Create the Application's main menu + var template = [{ + label: 'Electron', + submenu: [ + { + label: 'About Electron', + selector: 'orderFrontStandardAboutPanel:' + }, + { + type: 'separator' + }, + { + label: 'Services', + submenu: [] + }, + { + type: 'separator' + }, + { + label: 'Hide Electron', + accelerator: 'Command+H', + selector: 'hide:' + }, + { + label: 'Hide Others', + accelerator: 'Command+Shift+H', + selector: 'hideOtherApplications:' + }, + { + label: 'Show All', + selector: 'unhideAllApplications:' + }, + { + type: 'separator' + }, + { + label: 'Quit', + accelerator: 'Command+Q', + click: function() { app.quit(); } + }, + ] + }, + { + label: 'Edit', + submenu: [ + { + label: 'Undo', + accelerator: 'Command+Z', + selector: 'undo:' + }, + { + label: 'Redo', + accelerator: 'Shift+Command+Z', + selector: 'redo:' + }, + { + type: 'separator' + }, + { + label: 'Cut', + accelerator: 'Command+X', + selector: 'cut:' + }, + { + label: 'Copy', + accelerator: 'Command+C', + selector: 'copy:' + }, + { + label: 'Paste', + accelerator: 'Command+V', + selector: 'paste:' + }, + { + label: 'Select All', + accelerator: 'Command+A', + selector: 'selectAll:' + }, + ] + }, + { + label: 'View', + submenu: [ + { + label: 'Reload', + accelerator: 'Command+R', + click: function() { BrowserWindow.getFocusedWindow().reloadIgnoringCache(); } + }, + { + label: 'Toggle DevTools', + accelerator: 'Alt+Command+I', + click: function() { BrowserWindow.getFocusedWindow().toggleDevTools(); } + }, + ] + }, + { + label: 'Window', + submenu: [ + { + label: 'Minimize', + accelerator: 'Command+M', + selector: 'performMiniaturize:' + }, + { + label: 'Close', + accelerator: 'Command+W', + selector: 'performClose:' + }, + { + type: 'separator' + }, + { + label: 'Bring All to Front', + selector: 'arrangeInFront:' + }, + ] + }, + { + label: 'Help', + submenu: [] + }]; + + menu = Menu.buildFromTemplate(template); + Menu.setApplicationMenu(menu); +} function copyAndRenameUserFolder() { return new Promise(function(resolve, reject) {