Skip to content

Commit

Permalink
bump deps;
Browse files Browse the repository at this point in the history
MIT;
errors to console;
  • Loading branch information
reZach committed Apr 22, 2021
1 parent 3bf6c84 commit 59d70e7
Show file tree
Hide file tree
Showing 9 changed files with 13,225 additions and 21,277 deletions.
358 changes: 19 additions & 339 deletions LICENSE

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ Built-in to this template are a number of popular frameworks already wired up to
- [Redux](https://redux.js.org/) (with [Redux toolkit](https://redux-toolkit.js.org/))
- [Babel](https://babeljs.io/)
- [Webpack](https://webpack.js.org/) (with [webpack-dev-server](https://github.com/webpack/webpack-dev-server))
- [Electron builder](https://www.electron.build/) (for packaging up your app)

## Bonus modules
What would a template be without some helpful additions?

- [i18next](https://www.i18next.com/) (with [this plugin](https://github.com/reZach/i18next-electron-fs-backend) for localization).
- [Store](https://github.com/reZach/secure-electron-store) (for saving config/data)
- [Context menu](https://github.com/reZach/secure-electron-context-menu) (supports custom context menus)
- [Electron builder](https://www.electron.build/) (for packaging up your app)
- [Easy redux undo](https://github.com/reZach/easy-redux-undo) (for undo/redoing your redux actions)
- [License key validation](https://github.com/reZach/secure-electron-license-keys) (for validating a user has the proper license to use your app) **new!**

## Roadmap
There are a number of additions that I'd like to implement in this repository, namely more release-focused enhancements and test suites, but those are lower priority (but I welcome PRs!).
There are a number of additions that I'd like to implement in this repository, namely test suites, but those are lower priority (but I welcome PRs!).

## Architecture
For a more detailed view of the architecture of the template, please check out [here](https://github.com/reZach/secure-electron-template/blob/master/docs/architecture.md). I would _highly_ recommend reading this document to get yourself familiarized with this template.
Expand Down
31 changes: 21 additions & 10 deletions app/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ async function createWindow() {
contextIsolation: true,
enableRemoteModule: false,
additionalArguments: [`storePath:${app.getPath("userData")}`],
preload: path.join(__dirname, "preload.js"), /* eng-disable PRELOAD_JS_CHECK */
preload: path.join(__dirname, "preload.js"),
/* eng-disable PRELOAD_JS_CHECK */
disableBlinkFeatures: "Auxclick"
}
});
Expand Down Expand Up @@ -121,7 +122,7 @@ async function createWindow() {
await installExtension([REDUX_DEVTOOLS, REACT_DEVELOPER_TOOLS])
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log("An error occurred: ", err))
.finally(() => {
.finally(() => {
require("electron-debug")(); // https://github.com/sindresorhus/electron-debug
win.webContents.openDevTools();
});
Expand All @@ -139,9 +140,9 @@ async function createWindow() {
// https://electronjs.org/docs/tutorial/security#4-handle-session-permission-requests-from-remote-content
const ses = session;
const partition = "default";
ses.fromPartition(partition) /* eng-disable PERMISSION_REQUEST_HANDLER_JS_CHECK */
ses.fromPartition(partition) /* eng-disable PERMISSION_REQUEST_HANDLER_JS_CHECK */
.setPermissionRequestHandler((webContents, permission, permCallback) => {
let allowedPermissions = []; // Full list here: https://developer.chrome.com/extensions/declare_permissions#manifest
const allowedPermissions = []; // Full list here: https://developer.chrome.com/extensions/declare_permissions#manifest

if (allowedPermissions.includes(permission)) {
permCallback(true); // Approve permission request
Expand Down Expand Up @@ -219,7 +220,8 @@ app.on("activate", () => {

// https://electronjs.org/docs/tutorial/security#12-disable-or-limit-navigation
app.on("web-contents-created", (event, contents) => {
contents.on("will-navigate", (contentsEvent, navigationUrl) => { /* eng-disable LIMIT_NAVIGATION_JS_CHECK */
contents.on("will-navigate", (contentsEvent, navigationUrl) => {
/* eng-disable LIMIT_NAVIGATION_JS_CHECK */
const parsedUrl = new URL(navigationUrl);
const validOrigins = [selfHost];

Expand Down Expand Up @@ -260,19 +262,28 @@ app.on("web-contents-created", (event, contents) => {
});

// https://electronjs.org/docs/tutorial/security#13-disable-or-limit-creation-of-new-windows
contents.on("new-window", (contentsEvent, navigationUrl) => { /* eng-disable LIMIT_NAVIGATION_JS_CHECK */
const parsedUrl = new URL(navigationUrl);
// This code replaces the old "new-window" event handling;
// https://github.com/electron/electron/pull/24517#issue-447670981
contents.setWindowOpenHandler(({
url
}) => {
const parsedUrl = new URL(url);
const validOrigins = [];

// Log and prevent opening up a new window
if (!validOrigins.includes(parsedUrl.origin)) {
console.error(
`The application tried to open a new window at the following address: '${navigationUrl}'. This attempt was blocked.`
`The application tried to open a new window at the following address: '${url}'. This attempt was blocked.`
);

contentsEvent.preventDefault();
return;
return {
action: "deny"
};
}

return {
action: "allow"
};
});
});

Expand Down
28 changes: 11 additions & 17 deletions app/electron/protocol.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
/*
Reasonably Secure Electron
Copyright (C) 2019 Bishop Fox
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Reasonably Secure Electron
Copyright (C) 2021 Bishop Fox
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------
Implementing a custom protocol achieves two goals:
1) Allows us to use ES6 modules/targets for Angular
Expand Down Expand Up @@ -39,9 +33,9 @@ const mimeTypes = {
};

function charset(mimeType) {
return [".html", ".htm", ".js", ".mjs"].some((m) => m === mimeType)
? "utf-8"
: null;
return [".html", ".htm", ".js", ".mjs"].some((m) => m === mimeType) ?
"utf-8" :
null;
}

function mime(filename) {
Expand Down Expand Up @@ -73,4 +67,4 @@ function requestHandler(req, next) {
module.exports = {
scheme,
requestHandler
};
};
3 changes: 3 additions & 0 deletions dev-scripts/launchDevServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const intervalId = setInterval(function () {
electronProcess.stdout.on("data", function(data) {
process.stdout.write(data);
});
electronProcess.stderr.on("data", function(data) {
process.stdout.write(data);
});
} else if (log.indexOf("Failed to compile.") >= 0) {

if (fs.existsSync(errorLogFilePath)) {
Expand Down
Binary file modified docs/imgs/intro.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 59d70e7

Please sign in to comment.