Skip to content

Commit

Permalink
Merge pull request #67 from tkambler/updateElectron12
Browse files Browse the repository at this point in the history
Update electron12
  • Loading branch information
pvrobays authored Mar 29, 2021
2 parents 7088d86 + 5841849 commit 7328090
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 16,293 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 'step' property to slider input
- hover state to sidebar items

### Changed
- update to electron v12
- enable context isolation
- disable remote module

## [2.2.0] - 2020-03-14
### Added
- Dark theme! 🌗
Expand Down
3 changes: 2 additions & 1 deletion example/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function createWindow() {
'height': 700,
'accept-first-mouse': true,
webPreferences: {
preload: path.join(__dirname, './Preload.js')
preload: path.join(__dirname, './Preload.js'),
contextIsolation: true
}
});

Expand Down
22 changes: 21 additions & 1 deletion example/preload.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
"use strict";

const electron = require("electron");
window.ipcRenderer = electron.ipcRenderer;
const contextBridge = electron.contextBridge;
const ipcRenderer = electron.ipcRenderer;

let onPreferencesChangedHandler = (preferences) => {};

contextBridge.exposeInMainWorld("api", {
showPreferences: () => {
ipcRenderer.send('showPreferences');
},
getPreferences: () => {
return ipcRenderer.sendSync('getPreferences');
},
onPreferencesChanged: (handler) => {
onPreferencesChangedHandler = handler;
}
});

ipcRenderer.on('preferencesUpdated', (e, preferences) => {
onPreferencesChangedHandler(preferences);
});


console.log("Preloaded");
8 changes: 3 additions & 5 deletions example/renderer.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
'use strict';

// const { ipcRenderer } = require('electron');
const ipcRenderer = window.ipcRenderer;
const bt = document.getElementsByClassName('bt')[0];
const prefsEl = document.getElementsByClassName('preferences')[0];
prefsEl.innerHTML = JSON.stringify(ipcRenderer.sendSync('getPreferences'), null, 4);
prefsEl.innerHTML = JSON.stringify(api.getPreferences(), null, 4);

bt.addEventListener('click', () => {
ipcRenderer.send('showPreferences');
api.showPreferences();
});

ipcRenderer.on('preferencesUpdated', (e, preferences) => {
api.onPreferencesChanged((preferences) => {
console.log('Preferences were updated', preferences);
prefsEl.innerHTML = JSON.stringify(preferences, null, 4);
});
4 changes: 4 additions & 0 deletions example/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
body {
background: white;
}

.bt {
margin: 25px;
}
Expand Down
18 changes: 12 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const electron = require('electron');
const { app, BrowserWindow, ipcMain, webContents } = electron;
const { BrowserWindow, ipcMain, webContents, dialog } = electron;
const path = require('path');
const url = require('url');
const fs = require('fs-extra');
Expand Down Expand Up @@ -69,17 +69,17 @@ class ElectronPreferences extends EventEmitter2 {
event.returnValue = this.options;
});

ipcMain.on('restoreDefaults', (event, value) => {
ipcMain.on('restoreDefaults', (event) => {
this.preferences = this.defaults;
this.save();
this.broadcast();
});

ipcMain.on('getDefaults', (event, value) => {
ipcMain.on('getDefaults', (event) => {
event.returnValue = this.defaults;
});

ipcMain.on('getPreferences', (event, value) => {
ipcMain.on('getPreferences', (event) => {
event.returnValue = this.preferences;
});

Expand All @@ -91,6 +91,10 @@ class ElectronPreferences extends EventEmitter2 {
event.returnValue = null;
});

ipcMain.on('showOpenDialog', (event, dialogOptions) => {
event.returnValue = dialog.showOpenDialogSync(dialogOptions);
});

if (_.isFunction(options.afterLoad)) {
options.afterLoad(this);
}
Expand Down Expand Up @@ -179,8 +183,10 @@ class ElectronPreferences extends EventEmitter2 {
};

const defaultWebPreferences = {
nodeIntegration: true,
enableRemoteModule: true
nodeIntegration: false,
enableRemoteModule: false,
contextIsolation: true,
preload: path.join(__dirname, './preload.js')
}
if (browserWindowOpts.webPreferences) {
browserWindowOpts.webPreferences = Object.assign(defaultWebPreferences, browserWindowOpts.webPreferences)
Expand Down
Loading

0 comments on commit 7328090

Please sign in to comment.