Skip to content

Commit 1a0ca54

Browse files
committed
Setup mac os build with autoupdate using electron-builder
1 parent 70047f4 commit 1a0ca54

File tree

7 files changed

+820
-201
lines changed

7 files changed

+820
-201
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ jspm_packages
3636
# Optional REPL history
3737
.node_repl_history
3838
dist
39+
src/app.min.js

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
});
3434
require('./src/index.js');
3535
} else {
36-
require('./dist/app.min.js');
36+
require('./src/app.min.js');
3737
}
3838
</script>
3939
</html>

index.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const url = require('url');
33
const path = require('path');
44
const electron = require('electron');
5+
const {autoUpdater} = require('electron-updater');
56

67
// Module to control application life.
78
const app = electron.app;
@@ -13,6 +14,9 @@ const BrowserWindow = electron.BrowserWindow;
1314
let mainWindow;
1415

1516
function createWindow() {
17+
// trigger autoupdate check
18+
autoUpdater.checkForUpdates();
19+
1620
// Create the browser window.
1721
mainWindow = new BrowserWindow({
1822
width: 800,
@@ -62,5 +66,33 @@ app.on('activate', function() {
6266
}
6367
});
6468

65-
// In this file you can include the rest of your app's specific main process
66-
// code. You can also put them in separate files and require them here.
69+
//-------------------------------------------------------------------
70+
// Auto updates
71+
//-------------------------------------------------------------------
72+
autoUpdater.on('checking-for-update', () => {
73+
console.log('Checking for update...');
74+
});
75+
autoUpdater.on('update-available', info => {
76+
console.log('Update available.');
77+
});
78+
autoUpdater.on('update-not-available', info => {
79+
console.log('Update not available.');
80+
});
81+
autoUpdater.on('error', err => {
82+
console.log('Error in auto-updater.');
83+
});
84+
autoUpdater.on('download-progress', progressObj => {
85+
console.log(
86+
`Download speed: ${progressObj.bytesPerSecond} - Downloaded ${progressObj.percent}% (${progressObj.transferred} + '/' + ${progressObj.total} + )`
87+
);
88+
});
89+
autoUpdater.on('update-downloaded', info => {
90+
console.log('Update downloaded; will install now');
91+
});
92+
93+
autoUpdater.on('update-downloaded', info => {
94+
// Wait 5 seconds, then quit and install
95+
// In your application, you don't need to wait 500 ms.
96+
// You could call autoUpdater.quitAndInstall(); immediately
97+
autoUpdater.quitAndInstall();
98+
});

package.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
{
22
"name": "bpjs-electron",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "BPJS Electron app",
55
"main": "index.js",
66
"repository": "[email protected]:yamalight/bpjs-electron.git",
77
"author": "Tim Ermilov <[email protected]>",
88
"license": "MIT",
9+
"build": {
10+
"appId": "com.bpjs.ElectronDemo",
11+
"mac": {
12+
"category": "com.bpjs.demo",
13+
"target": [
14+
"dmg"
15+
]
16+
}
17+
},
918
"scripts": {
1019
"start": "NODE_ENV=test electron .",
1120
"production": "electron .",
1221
"lint": "eslint **/*.js",
1322
"inspect-main": "electron-inspector",
1423
"build": "rollup -c",
15-
"package": "electron-packager . bpjs-electron --platform=darwin --arch=x64 --overwrite",
24+
"pack": "electron-builder --dir",
25+
"dist": "electron-builder --x64",
26+
"gh-publish": "electron-builder --x64 -p always",
1627
"test": "NODE_ENV=test mocha"
1728
},
1829
"devDependencies": {
@@ -21,7 +32,7 @@
2132
"babel-preset-react": "^6.23.0",
2233
"babel-register": "^6.24.0",
2334
"electron": "^1.6.2",
24-
"electron-packager": "^8.7.2",
35+
"electron-builder": "^19.26.3",
2536
"eslint": "^3.19.0",
2637
"eslint-config-airbnb": "^14.1.0",
2738
"eslint-config-prettier": "^1.5.0",
@@ -42,6 +53,7 @@
4253
"big-integer": "^1.6.22",
4354
"bulma": "^0.4.0",
4455
"cheerio": "^0.22.0",
56+
"electron-updater": "^2.8.7",
4557
"font-awesome": "^4.7.0",
4658
"lodash": "^4.17.4",
4759
"playlist-parser": "^0.0.12",

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {minify} from 'uglify-es';
55
export default {
66
entry: 'src/index.js',
77
format: 'cjs',
8-
dest: 'dist/app.min.js',
8+
dest: 'src/app.min.js',
99
plugins: [babel({exclude: 'node_modules/**'}), uglify({}, minify)],
1010
external: [
1111
'big-integer',

src/pages/settings.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ export default class Settings extends React.Component {
1212
this.state = {};
1313
}
1414

15-
componentDidMount() {
16-
}
15+
componentDidMount() {}
1716

18-
componentWillUnmount() {
19-
}
17+
componentWillUnmount() {}
2018

2119
render() {
2220
// const {series} = this.state;
@@ -34,6 +32,12 @@ export default class Settings extends React.Component {
3432
</Link>
3533
</div>
3634
</div>
35+
36+
<div className="nav-right nav-menu">
37+
<div className="nav-item">
38+
I was updated
39+
</div>
40+
</div>
3741
</nav>
3842

3943
<div className="content columns">

0 commit comments

Comments
 (0)