Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

chore(electron): changes to upgrate electron to v5.0.0 #421

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion safe_app_electron_quick_start/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The boilerplate implements a simple single page application using [Angular.js](h

First you need to make sure you have the following tools installed to be able to work with this tutorial:
- [Git](https://git-scm.com/): to be able to clone the boilerplate code
- [Node.js](https://nodejs.org/en/download) v8.11.1 (which comes with [npm](http://npmjs.com/) v5.6.0) to be able to run the application since it's a Node.js application. All the steps in this tutorial are explained using npm, if you otherwise prefer to use [yarn](https://yarnpkg.com/en/), please make sure you install v1.6.0. Note that the use of yarn is not required and totally optional
- [Node.js](https://nodejs.org/en/download) v10 or above (which comes with [npm](http://npmjs.com/) v6.4.1) to be able to run the application since it's a Node.js application. All the steps in this tutorial are explained using npm, if you otherwise prefer to use [yarn](https://yarnpkg.com/en/), please make sure you install v1.6.0. Note that the use of yarn is not required and totally optional
- If you are using Ubuntu or Debian 9 as OS, `libgconf-2-4` and/or `build-essential` dependencies might be missing. Please install them with [Synaptic Package Mgr.](https://help.ubuntu.com/community/SynapticHowto), or with apt from a shell console: `$ sudo apt-get install libgconf-2-4 build-essential`
- If you are using Windows, run `npm install --global --production windows-build-tools`.
- If you decide to use yarn and are using Windows, run `yarn config set child-concurrency 1` because yarn attempts to build modules concurrently with multiple child processes, which causes intermittent timing issues on Windows.
Expand Down
81 changes: 45 additions & 36 deletions safe_app_electron_quick_start/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ let mainWindow

function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600})
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
},
})

// and load the index.html of the app.
mainWindow.loadURL(url.format({
Expand All @@ -32,50 +38,53 @@ function createWindow () {
// when you should delete the corresponding element.
mainWindow = null
})
}

const gotTheLock = app.requestSingleInstanceLock()

const shouldQuit = app.makeSingleInstance(function(commandLine) {
const resAuthUri = commandLine[2];
if (!gotTheLock) {
app.quit()
} else {
app.on('second-instance', (event, commandLine, workingDirectory) => {
const resAuthUri = commandLine[3];
if (resAuthUri) {
mainWindow.webContents.send('system-uri-response', resAuthUri);
}

// Someone tried to run a second instance, we should focus our window
// Someone tried to run a second instance, we should focus our window.
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
if (mainWindow.isMinimized()) mainWindow.restore()
mainWindow.focus()
}
});

if (shouldQuit) {
app.quit();
}
}
})

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Create mainWindow, load the rest of the app, etc...
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})

app.on('activate', function () {
// On OS X 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 (mainWindow === null) {
createWindow()
}
})
app.on('activate', function () {
// On OS X 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 (mainWindow === null) {
createWindow()
}
})

app.on('open-url', (e, resAuthUri) => {
mainWindow.webContents.send('system-uri-response', resAuthUri);
})
app.on('open-url', (e, resAuthUri) => {
mainWindow.webContents.send('system-uri-response', resAuthUri);
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
}
Loading