Skip to content

Commit f0f4407

Browse files
committed
autoUpdate added and external browser now open links
1 parent 58a1914 commit f0f4407

File tree

5 files changed

+112
-64
lines changed

5 files changed

+112
-64
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
<p> Development of an application for the Implemantation and use of search methods in a visualized environment</p>
77

88
<h3>ToDo's</h3>
9-
10-
1. Some minor fixes
11-
2. Auto Update
12-
3. Publish releases for Linux and Mac OS
13-
4. Make a minimal menu for the app
14-
5. Materialize the view
15-
6. Anything that comes to my mind
16-
7. Feel Free to open an issue to post your thoughts
9+
10+
1. [ ] Some minor fixes
11+
2. [x] Open links externally in the default browser
12+
3. [x] Auto Update
13+
4. [ ] Publish releases for Linux and Mac OS
14+
5. [ ] Make a minimal menu for the app
15+
6. [ ] Materialize the view
16+
7. [ ] Anything that comes to my mind
17+
8. [ ] Feel Free to open an issue to post your thoughts
1718

1819
<h3>Download the App in Development Mode</h3>
1920
You will have to install NodeJs first for the npm package manager.
@@ -26,6 +27,8 @@ $ npm install
2627
```
2728
Not Every time necessary but sometimes useful
2829
```shell
30+
$ npm i electron-log
31+
$ npm i electron-updater
2932
$ npm i -S @fortawesome/fontawesome-free
3033
$ npm i -S electron
3134
$ npm i -S bootstrap

main.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// Modules to control application life and create native browser window
22
const {app, BrowserWindow} = require('electron')
33

4+
const {autoUpdater}=require('electron-updater');
5+
const log = require('electron-log');
6+
autoUpdater.logger = log;
7+
autoUpdater.logger.transports.file.level = 'info';
8+
log.info('App starting...');
9+
410

511
// Keep a global reference of the window object, if you don't, the window will
612
// be closed automatically when the JavaScript object is garbage collected.
@@ -28,6 +34,11 @@ function createWindow () {
2834
})
2935
}
3036

37+
function sendStatusToWindow(text) {
38+
log.info(text);
39+
mainWindow.webContents.send('message', text);
40+
}
41+
3142
var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
3243
// Someone tried to run a second instance, we should focus our window.
3344
if (mainWindow) {
@@ -44,7 +55,10 @@ return;
4455
// This method will be called when Electron has finished
4556
// initialization and is ready to create browser windows.
4657
// Some APIs can only be used after this event occurs.
47-
app.on('ready', createWindow)
58+
app.on('ready', ()=>{
59+
createWindow();
60+
autoUpdater.checkForUpdatesAndNotify();
61+
})
4862

4963
// Quit when all windows are closed.
5064
app.on('window-all-closed', function () {
@@ -66,6 +80,29 @@ app.on('activate', function () {
6680
// In this file you can include the rest of your app's specific main process
6781
// code. You can also put them in separate files and require them here.
6882

83+
84+
autoUpdater.on('checking-for-update', () => {
85+
sendStatusToWindow('Checking for update...');
86+
})
87+
autoUpdater.on('update-available', (info) => {
88+
sendStatusToWindow('Update available.');
89+
})
90+
autoUpdater.on('update-not-available', (info) => {
91+
sendStatusToWindow('Update not available.');
92+
})
93+
autoUpdater.on('error', (err) => {
94+
sendStatusToWindow('Error in auto-updater. ' + err);
95+
})
96+
autoUpdater.on('download-progress', (progressObj) => {
97+
let log_message = "Download speed: " + progressObj.bytesPerSecond;
98+
log_message = log_message + ' - Downloaded ' + progressObj.percent + '%';
99+
log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')';
100+
sendStatusToWindow(log_message);
101+
})
102+
autoUpdater.on('update-downloaded', (info) => {
103+
sendStatusToWindow('Update downloaded');
104+
autoUpdater.quitAndInstall();
105+
});
69106
//------------------------------------------------------------//
70107
const appVersion = require('./package.json').version;
71108
const {ipcMain} = require('electron');

modal.html

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,14 @@
44
<link rel="stylesheet" href="node_modules/@fortawesome/fontawesome-free/css/all.css">
55

66
<script>
7-
const shell = require('electron').shell
8-
9-
const links = document.querySelectorAll('a[href]')
10-
11-
Array.prototype.forEach.call(links, (link) => {
12-
const url = link.getAttribute('href')
13-
if (url.indexOf('http') === 0) {
14-
link.addEventListener('click', (e) => {
15-
e.preventDefault()
16-
shell.openExternal(url)
17-
})
18-
}
19-
})
7+
// Open all links in external browser
8+
let shell = require('electron').shell
9+
document.addEventListener('click', function (event) {
10+
if (event.target.tagName === 'A' && event.target.href.startsWith('http')) {
11+
event.preventDefault()
12+
shell.openExternal(event.target.href)
13+
}
14+
})
2015
</script>
2116

2217
<script>
@@ -85,7 +80,7 @@
8580
<i class="fas fa-link" style="font-size:50px"></i>
8681
</td>
8782
<td>
88-
<a href="https://git.io/vAM41">Github Repository</a>
83+
<a href="https://git.io/fALxo">Github Repository</a>
8984
</td>
9085
</tr>
9186
<tr>
@@ -94,7 +89,7 @@
9489
</td>
9590
<td>
9691
<p>
97-
<a href="https://git.io/vAM4F">MIT License</a>
92+
<a href="https://git.io/fALx1">MIT License</a>
9893
<br/>Copyright &copy;
9994
<a href="https://git.io/vNjE6">Anastasios Tilsizoglou</a>
10095
</p>

package-lock.json

Lines changed: 43 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)