Skip to content

Commit bfd2bf8

Browse files
committed
implented AutoUpdate and ready for GitHub Releases
1 parent c222d9b commit bfd2bf8

File tree

7 files changed

+93
-9
lines changed

7 files changed

+93
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
22
dist/
3+
electron-builder.json

app/electron.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const fixPath = require('fix-path');
1313
const MongoClient = require('mongodb').MongoClient;
1414
// Executing terminal commands using JS
1515
const { exec } = require('child_process');
16+
const { autoUpdater } = require('electron-updater');
1617

1718
// Add React extension for development
1819
const { default: installExtension, REACT_DEVELOPER_TOOLS } = require('electron-devtools-installer');
@@ -89,6 +90,9 @@ function createWindow() {
8990
// when you should delete the corresponding element.
9091
mainWindow = null
9192
})
93+
mainWindow.once('ready-to-show', () => {
94+
autoUpdater.checkForUpdatesAndNotify();
95+
});
9296
}
9397

9498
// This method will be called when Electron has finished
@@ -121,7 +125,7 @@ if (!fs.existsSync(path.join(process.resourcesPath, "/schemafiles/"))) {
121125
}
122126
let testpath = path.join(process.resourcesPath, "/schemafiles/qlens.json")
123127

124-
if (process.resourcesPath !== 'win32') fixPath()
128+
if (process.resourcesPath !== 'win32') fixPath();
125129

126130
ipcMain.on('URI', (event, arg) => {
127131

@@ -156,3 +160,14 @@ ipcMain.on('URI', (event, arg) => {
156160
}
157161
})
158162
});
163+
164+
autoUpdater.on('update-available', () => {
165+
mainWindow.webContents.send('update_available');
166+
});
167+
autoUpdater.on('update-downloaded', () => {
168+
mainWindow.webContents.send('update_downloaded');
169+
});
170+
171+
ipcMain.on('restart_app', () => {
172+
autoUpdater.quitAndInstall();
173+
});

app/src/App.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
// Import dependencies
22
import React from "react";
33
import Container from "./containers/Container";
4+
import AutoUpdate from "./Components/AutoUpdate";
45
import "./public/index.css";
56

67
// Create main App component
7-
const App = () => (
8-
<div>
9-
<Container />
10-
</div>
11-
)
12-
8+
const App = () => {
9+
<div>
10+
<Container />
11+
<AutoUpdate />
12+
</div>
13+
}
1314
// Export the App component
1415
export default App;

app/src/Components/AutoUpdate.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react'
2+
import "./public/index.css";
3+
const { ipcRenderer } = require('electron')
4+
5+
const AutoUpdate = () => {
6+
const notification = document.getElementById('notification');
7+
const message = document.getElementById('message');
8+
const restartButton = document.getElementById('restart-button');
9+
10+
ipcRenderer.on('update_available', () => {
11+
ipcRenderer.removeAllListeners('update_available');
12+
message.innerText = 'A new update is available. Downloading now...';
13+
notification.classList.remove('hidden');
14+
});
15+
ipcRenderer.on('update_downloaded', () => {
16+
ipcRenderer.removeAllListeners('update_downloaded');
17+
message.innerText = 'Update Downloaded. It will be installed on restart. Restart now?';
18+
restartButton.classList.remove('hidden');
19+
notification.classList.remove('hidden');
20+
});
21+
22+
function closeNotification() {
23+
notification.classList.add('hidden');
24+
};
25+
function restartApp() {
26+
ipcRenderer.send('restart_app');
27+
};
28+
29+
return (
30+
<div id="notification" class="hidden">
31+
<p id="message"></p>
32+
<button id="close-button" onClick="closeNotification()">
33+
Close
34+
</button>
35+
<button id="restart-button" onClick="restartApp()" class="hidden">
36+
Restart
37+
</button>
38+
</div>
39+
)
40+
}
41+
42+
export default AutoUpdate

app/src/public/index.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,19 @@ input[type=checkbox]{
442442
transform: rotate(45deg);
443443
-webkit-transform: rotate(45deg);
444444
}
445+
446+
/* ================================ AUTO UPDATE ================================ */
447+
448+
#notification {
449+
position: fixed;
450+
bottom: 20px;
451+
left: 20px;
452+
width: 200px;
453+
padding: 20px;
454+
border-radius: 5px;
455+
background-color: white;
456+
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
457+
}
458+
.hidden {
459+
display: none;
460+
}

electron-builder.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"appId": "com.QLens.app",
3+
"publish":
4+
{
5+
"provider": "github",
6+
"token": "0b26911bfe3e37f5cb71f9f06525494dabc5548e"
7+
},
38
"asar": true,
49
"productName": "QLens",
510
"directories": {

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
"pack-mac": "npm run build && electron-builder -m",
1616
"dist": "electron-builder",
1717
"test": "jest --verbose",
18-
"test:watch": "npm run test -- --watch"
18+
"test:watch": "npm run test -- --watch",
19+
"publish-mac": "npm run build && electron-builder -m --publish always",
20+
"publish-win": "npm run build && electron-builder -w --publish always",
21+
"publish-lin": "npm run build && electron-builder -l --publish always",
22+
"deploy": "npm run build && electron-builder -mwl --publish always"
1923
},
2024
"repository": {
2125
"type": "git",
@@ -49,7 +53,7 @@
4953
"url": "https://github.com/stevenlabrie"
5054
}
5155
],
52-
"license": "ISC",
56+
"license": "MIT",
5357
"bugs": {
5458
"url": "https://github.com/stevenlabrie/QLens/issues"
5559
},

0 commit comments

Comments
 (0)