Skip to content

Commit

Permalink
Merge pull request #144 from tkambler/developmentIntoMaster
Browse files Browse the repository at this point in the history
Merge development into master
  • Loading branch information
pvrobays authored Mar 29, 2022
2 parents e6c856c + bbaa999 commit 83e6bb9
Show file tree
Hide file tree
Showing 10 changed files with 7,733 additions and 6 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Set defaults for new preferences added in a group after app has started (#141)
- Include files to be exposed in npm build (#119)
- Correct `menuBar` option in README (#130)
- Updated dependencies
- Improve README.md

### Added
- Button component. Will trigger an event on the preferences.click when clicked.
- Button component. Will trigger an event on the `preferences.click` when clicked. (#99)
- Expose `close` function on preference object to close the preference window if opened (#130)
- Expose `closePreferences` function on the ipcRenderer to close the preference window if opened (#130)

## [2.5.0] - 2021-09-18
### Fixed
Expand Down
5 changes: 4 additions & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
<link rel="stylesheet" href="style.css">
</head>
<body>
<button class="bt">Click here to launch the preferences window</button>
<div class="buttons">
<button class="bt">Click here to launch the preferences window</button>
<button class="bt">Close preference window if opened</button>
</div>
<pre class="preferences"></pre>
<script src="renderer.js"></script>
</body>
Expand Down
19 changes: 17 additions & 2 deletions example/preferences.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

// Const electron = require('electron');
// const app = electron.app;
const electron = require('electron');
const { Menu } = electron;
const path = require('path');
const os = require('os');
const ElectronPreferences = require('../');
Expand All @@ -23,6 +23,21 @@ const preferences = new ElectronPreferences({
webPreferences: {
webSecurity: true,
},
menuBar: Menu.buildFromTemplate(
[
{
label: 'Window',
role: 'window',
submenu: [
{
label: 'Close',
accelerator: 'CmdOrCtrl+W',
role: 'close',
},
],
},
],
),
browserWindowOverrides: {
title: 'My Electron Preferences',
},
Expand Down
5 changes: 5 additions & 0 deletions example/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ contextBridge.exposeInMainWorld('api', {

ipcRenderer.send('showPreferences');

},
closePreferences: () => {

ipcRenderer.send('closePreferences');

},
getPreferences: () => ipcRenderer.sendSync('getPreferences'),
onPreferencesChanged(handler) {
Expand Down
7 changes: 7 additions & 0 deletions example/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict';

const bt = document.querySelectorAll('.bt')[0];
const bt2 = document.querySelectorAll('.bt')[1];
const prefsElement = document.querySelectorAll('.preferences')[0];
prefsElement.innerHTML = JSON.stringify(api.getPreferences(), null, 4);

Expand All @@ -11,6 +12,12 @@ bt.addEventListener('click', () => {

});

bt2.addEventListener('click', () => {

api.closePreferences();

});

api.onPreferencesChanged(preferences => {

console.log('Preferences were updated', preferences);
Expand Down
6 changes: 6 additions & 0 deletions example/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ body {
background: white;
}

.buttons {
display: flex;
flex-direction: row;
justify-content: space-between;
}

.bt {
margin: 25px;
}
Expand Down
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ class ElectronPreferences extends EventEmitter2 {

});

ipcMain.on('closePreferences', _ => {

this.close();

});

ipcMain.on('getSections', event => {

event.returnValue = this.options.sections;
Expand Down Expand Up @@ -269,6 +275,7 @@ class ElectronPreferences extends EventEmitter2 {

const unOverridableWebPreferences = {
contextIsolation: true,
devTools: this.options.debug ? true : undefined,
};

// User provided `browserWindow`, we load those
Expand Down Expand Up @@ -375,6 +382,18 @@ class ElectronPreferences extends EventEmitter2 {

}

close() {

if (!this.prefsWindow) {

return;

}

this.prefsWindow.close();

}

}

module.exports = ElectronPreferences;
Loading

0 comments on commit 83e6bb9

Please sign in to comment.