Skip to content

Commit

Permalink
added copy/paste, hiding window before its ready
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-ev committed Dec 28, 2016
1 parent e0bae9b commit 0568558
Showing 1 changed file with 139 additions and 6 deletions.
145 changes: 139 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -55,6 +55,7 @@ function createWindow () {

backgroundColor: '#EBEBEB',
icon: __dirname + '/build/icons/512x512.png',
show: false,

webPreferences: {
allowDisplayingInsecureContent: true,
Expand Down Expand Up @@ -82,7 +83,7 @@ function createWindow () {
});
});

win.focus();
setApplicationMenu();

copyAndRenameUserFolder().then(function(pathToUserContent) {

Expand Down Expand Up @@ -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);
});
Expand All @@ -130,16 +137,142 @@ 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
// dock icon is clicked and there are no other windows open.
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) {
Expand Down

0 comments on commit 0568558

Please sign in to comment.