Skip to content

Commit ba482db

Browse files
committed
feat(electron): build process and auto update; typescript
1 parent 9079183 commit ba482db

File tree

13 files changed

+4769
-284
lines changed

13 files changed

+4769
-284
lines changed

electron-wrapper/.compilerc

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"env": {
3+
"development": {
4+
"application/javascript": {
5+
"presets": [
6+
[
7+
"env",
8+
{
9+
"targets": {
10+
"electron": "1.8"
11+
}
12+
}
13+
],
14+
"react"
15+
],
16+
"plugins": [
17+
"transform-async-to-generator"
18+
],
19+
"sourceMaps": "inline"
20+
},
21+
"text/typescript": {
22+
"removeComments": false,
23+
"preserveConstEnums": true,
24+
"declaration": true,
25+
"noImplicitAny": true,
26+
"noImplicitReturns": true,
27+
"suppressImplicitAnyIndexErrors": true,
28+
"strictNullChecks": true,
29+
"noUnusedLocals": true,
30+
"noImplicitThis": true,
31+
"noUnusedParameters": true,
32+
"inlineSourceMap": true,
33+
"inlineSources": true,
34+
"importHelpers": true,
35+
"noEmitHelpers": true,
36+
"experimentalDecorators": true,
37+
"target": "es2015",
38+
"module": "commonjs"
39+
}
40+
},
41+
"production": {
42+
"application/javascript": {
43+
"presets": [
44+
[
45+
"env",
46+
{
47+
"targets": {
48+
"electron": "1.8"
49+
}
50+
}
51+
],
52+
"react"
53+
],
54+
"plugins": [
55+
"transform-async-to-generator"
56+
],
57+
"sourceMaps": "none"
58+
},
59+
"text/typescript": {
60+
"removeComments": false,
61+
"preserveConstEnums": true,
62+
"declaration": true,
63+
"noImplicitAny": true,
64+
"noImplicitReturns": true,
65+
"suppressImplicitAnyIndexErrors": true,
66+
"strictNullChecks": true,
67+
"noUnusedLocals": true,
68+
"noImplicitThis": true,
69+
"noUnusedParameters": true,
70+
"sourceMap": false,
71+
"importHelpers": true,
72+
"noEmitHelpers": true,
73+
"experimentalDecorators": true,
74+
"target": "es2015"
75+
}
76+
}
77+
}
78+
}

electron-wrapper/.eslintrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "eslint-config-airbnb",
3+
"rules": {
4+
"import/extensions": 0,
5+
"import/no-extraneous-dependencies": 0,
6+
"import/no-unresolved": [2, { "ignore": ["electron"] }],
7+
"linebreak-style": 0
8+
}
9+
}

electron-wrapper/.eslintrc.js

-3
This file was deleted.

electron-wrapper/.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
!build/
2-
dist/
1+
node_modules
2+
out
File renamed without changes.
File renamed without changes.

electron-wrapper/main.js

-42
This file was deleted.

electron-wrapper/package.json

+82-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,95 @@
11
{
22
"name": "electron-wrapper",
3+
"productName": "ReactTypescriptBoilerplateExample",
34
"version": "1.0.0",
4-
"main": "main.js",
5-
"license": "MIT",
6-
"author": "Austin Peterson <[email protected]> (https://blog.akpwebdesign.com)",
5+
"description": "Just a simple electron wrapper for my boilerplate.",
6+
"main": "src/index.ts",
77
"scripts": {
8-
"start": "electron ."
8+
"start": "electron-forge start",
9+
"package": "electron-forge package",
10+
"make": "electron-forge make",
11+
"deploy": "electron-forge publish",
12+
"lint": "tslint --project tsconfig.json --type-check --force"
13+
},
14+
"keywords": [],
15+
"author": "Austin Peterson <[email protected]> (https://blog.akpwebdesign.com)",
16+
"license": "MIT",
17+
"config": {
18+
"forge": {
19+
"make_targets": {
20+
"win32": [
21+
"squirrel"
22+
],
23+
"darwin": [
24+
"zip"
25+
],
26+
"linux": [
27+
"deb",
28+
"rpm"
29+
]
30+
},
31+
"electronPackagerConfig": {
32+
"packageManager": "yarn",
33+
"asar": true,
34+
"icon": "./images/icon"
35+
},
36+
"electronWinstallerConfig": {
37+
"name": "ReactTypescriptBoilerplateExample",
38+
"setupIcon": "./images/icon.ico",
39+
"remoteReleases": "https://github.com/AKPWebDesign/react-electron-typescript-firebase-boilerplate"
40+
},
41+
"electronInstallerDebian": {
42+
"icon": "./images/icon.png",
43+
"categories": [
44+
"Utility",
45+
"Development"
46+
],
47+
"homepage": "https://github.com/AKPWebDesign/react-electron-typescript-firebase-boilerplate"
48+
},
49+
"electronInstallerRedhat": {
50+
"license": "MIT",
51+
"icon": "./images/icon.png",
52+
"compressionLevel": 9,
53+
"categories": [
54+
"Utility",
55+
"Development"
56+
]
57+
},
58+
"github_repository": {
59+
"owner": "AKPWebDesign",
60+
"name": "react-electron-typescript-firebase-boilerplate"
61+
},
62+
"windowsStoreConfig": {
63+
"packageName": "",
64+
"name": "electronwrappertemp"
65+
}
66+
}
967
},
1068
"dependencies": {
11-
"electron": "^1.8.4",
69+
"@types/electron-devtools-installer": "^2.0.2",
70+
"@types/electron-is-dev": "^0.3.0",
71+
"@types/yargs": "^11.0.0",
72+
"devtron": "^1.4.0",
73+
"electron-compile": "^6.4.2",
1274
"electron-debug": "^1.5.0",
1375
"electron-devtools-installer": "^2.2.3",
14-
"eslint": "^4.19.1",
15-
"eslint-config-airbnb-base": "^12.1.0",
16-
"eslint-plugin-import": "^2.10.0",
76+
"electron-is-dev": "^0.3.0",
77+
"electron-squirrel-startup": "^1.0.0",
78+
"tslib": "^1.9.0",
1779
"yargs": "^11.0.0"
1880
},
1981
"devDependencies": {
20-
"devtron": "^1.4.0",
21-
"electron-react-devtools": "^0.5.3"
82+
"babel-plugin-transform-async-to-generator": "^6.24.1",
83+
"babel-preset-env": "^1.6.1",
84+
"babel-preset-react": "^6.24.1",
85+
"electron-forge": "^5.1.1",
86+
"electron-prebuilt-compile": "1.8.4",
87+
"eslint": "^3",
88+
"eslint-config-airbnb": "^15",
89+
"eslint-plugin-import": "^2",
90+
"eslint-plugin-jsx-a11y": "^5",
91+
"eslint-plugin-react": "^7",
92+
"tslint": "^5.9.1",
93+
"typescript": "^2.8.1"
2294
}
2395
}

electron-wrapper/src/index.ts

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* This is a fairly basic electron script, with the sole purpose of loading
3+
* either the development or live site within a browser window. Consider it your
4+
* starting point for adding all sorts of fun electron goodies.
5+
*/
6+
import { app, autoUpdater, BrowserWindow, dialog } from 'electron';
7+
import installExtension, { REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS } from 'electron-devtools-installer';
8+
import * as isDev from 'electron-is-dev';
9+
import { argv } from 'yargs';
10+
11+
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
12+
if (require('electron-squirrel-startup')) {
13+
app.quit();
14+
}
15+
16+
// auto-update functionality
17+
if (!isDev) {
18+
const server = 'https://nuts-react-electron-typescript.herokuapp.com';
19+
const feed = `${server}/update/${process.platform}/${app.getVersion()}`;
20+
autoUpdater.setFeedURL(feed);
21+
22+
setInterval(() => {
23+
autoUpdater.checkForUpdates();
24+
}, 300000); // check for updates every 5 minutes or so
25+
}
26+
27+
// Keep a global reference of the window object, if you don't, the window will
28+
// be closed automatically when the JavaScript object is garbage collected.
29+
let mainWindow: Electron.BrowserWindow | null = null;
30+
31+
const urls = {
32+
dev: 'http://localhost:3000',
33+
34+
// replace with your firebase app URL (or whatever else you might be using)
35+
live: 'https://react-electron-firebase.firebaseapp.com',
36+
};
37+
38+
if (argv.dev) {
39+
require('electron-debug')({
40+
showDevTools: 'undocked',
41+
enabled: true,
42+
});
43+
}
44+
45+
const createWindow = async () => {
46+
// Create the browser window.
47+
mainWindow = new BrowserWindow({
48+
width: 800,
49+
height: 600,
50+
});
51+
52+
// and load the URL of the app.
53+
const winURL = argv.dev ? urls.dev : urls.live;
54+
mainWindow.loadURL(winURL);
55+
56+
if (argv.dev) {
57+
await installExtension(REACT_DEVELOPER_TOOLS);
58+
await installExtension(REDUX_DEVTOOLS);
59+
}
60+
61+
// Emitted when the window is closed.
62+
mainWindow.on('closed', () => {
63+
// Dereference the window object, usually you would store windows
64+
// in an array if your app supports multi windows, this is the time
65+
// when you should delete the corresponding element.
66+
mainWindow = null;
67+
});
68+
};
69+
70+
// This method will be called when Electron has finished
71+
// initialization and is ready to create browser windows.
72+
// Some APIs can only be used after this event occurs.
73+
app.on('ready', createWindow);
74+
75+
// Quit when all windows are closed.
76+
app.on('window-all-closed', () => {
77+
// On OS X it is common for applications and their menu bar
78+
// to stay active until the user quits explicitly with Cmd + Q
79+
if (process.platform !== 'darwin') {
80+
app.quit();
81+
}
82+
});
83+
84+
app.on('activate', () => {
85+
// On OS X it's common to re-create a window in the app when the
86+
// dock icon is clicked and there are no other windows open.
87+
if (mainWindow === null) {
88+
createWindow();
89+
}
90+
});
91+
92+
autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
93+
const dialogOpts = {
94+
type: 'info',
95+
buttons: ['Restart', 'Later'],
96+
title: 'Application Update',
97+
message: process.platform === 'win32' ? releaseNotes : releaseName,
98+
detail: 'A new version has been downloaded. Restart the application to apply the updates.',
99+
};
100+
101+
dialog.showMessageBox(dialogOpts, (response) => {
102+
if (response === 0) autoUpdater.quitAndInstall();
103+
});
104+
});
105+
106+
autoUpdater.on('error', message => {
107+
console.error('There was a problem updating the application');
108+
console.error(message);
109+
});
110+
111+
// In this file you can include the rest of your app's specific main process
112+
// code. You can also put them in separate files and import them here.

electron-wrapper/tsconfig.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"removeComments": false,
4+
"preserveConstEnums": true,
5+
"sourceMap": true,
6+
"declaration": true,
7+
"noImplicitAny": true,
8+
"noImplicitReturns": true,
9+
"suppressImplicitAnyIndexErrors": true,
10+
"strictNullChecks": true,
11+
"noUnusedLocals": true,
12+
"noImplicitThis": true,
13+
"noUnusedParameters": true,
14+
"importHelpers": true,
15+
"noEmitHelpers": true,
16+
"module": "commonjs",
17+
"moduleResolution": "node",
18+
"pretty": true,
19+
"target": "es2015",
20+
},
21+
"formatCodeOptions": {
22+
"indentSize": 2,
23+
"tabSize": 2
24+
}
25+
}

0 commit comments

Comments
 (0)