Skip to content

Commit 602f085

Browse files
committed
autoupdate test
1 parent 3e45696 commit 602f085

File tree

9 files changed

+134
-59
lines changed

9 files changed

+134
-59
lines changed

.github/workflows/.push.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Build and Store Artifact
2+
3+
permissions:
4+
contents: write
5+
6+
on: [push]
7+
# push:
8+
# tags:
9+
# - 'v*'
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repo
16+
uses: actions/checkout@v4
17+
18+
- name: Install libs
19+
run: |
20+
npm install
21+
22+
- name: Build project
23+
run: |
24+
npm run build
25+
26+
- name: Upload artifact
27+
uses: actions/upload-artifact@v4
28+
with:
29+
name: package
30+
path: dist
31+
32+
# - name: Publish artifact
33+
# uses: softprops/action-gh-release@v2
34+
# with:
35+
# files: dist/*.deb
36+
# env:
37+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+

.github/workflows/push.yml renamed to .github/workflows/pushblish.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ name: Build and Store Artifact
33
permissions:
44
contents: write
55

6-
on: [push]
7-
# push:
8-
# tags:
9-
# - 'v*'
6+
on:
7+
push:
8+
tags:
9+
- 'v*'
1010

1111
jobs:
1212
build:

config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@
9090
"desktop_filename": "webpage_accessor.desktop",
9191
"extension": "autostart"
9292
},
93+
"autoupdate":
94+
{
95+
"extension": "autoupdate",
96+
"enabled": true
97+
},
9398
"splashscreen":
9499
{
95100
"enabled": true,

extensions/autostart/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Autostarter extends require('../../lib/BaseModule')
1717
{
1818
const file_content = `[Desktop Entry]
1919
Name=` + this.getAppConfig().app_info.app_name + `
20-
Comment=webpage accessor autostart script
20+
Comment=webpage accessor autostarter
2121
Type=Application
2222
Exec=` + this.getAppConfig().app_info.app_executable;
2323
// debug location

extensions/autoupdate/main.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const { dialog } = require('electron')
2+
const { autoUpdater } = require('electron-updater')
3+
4+
// WARNING: THIS SCRIPT WILL CHANGE THE MACHINE'S STARTUP BEHAVIOUR.
5+
// TO DISABLE REMOVE .desktop FILE
6+
// WILL TAKE EFFECT ONLY ON BUILD MODE, NOT ON DEV MODE
7+
class Autoupdater extends require('../../lib/BaseModule')
8+
{
9+
MODULE_NAME = "autoupdate";
10+
11+
setup_linux()
12+
{
13+
// You can control this behavior:
14+
autoUpdater.autoDownload = false; // ask first
15+
autoUpdater.autoInstallOnAppQuit = true; // install after app closes
16+
17+
this.log('Checking for updates...');
18+
autoUpdater.checkForUpdates();
19+
20+
autoUpdater.on('update-available', info => {
21+
this.log(`Update available: ${info.version}`);
22+
dialog.showMessageBox(mainWindow, {
23+
type: 'info',
24+
title: 'Update Available',
25+
message: `Version ${info.version} is available. Download now?`,
26+
buttons: ['Yes', 'Later']
27+
}).then(result => {
28+
if (result.response === 0) {
29+
autoUpdater.downloadUpdate();
30+
}
31+
});
32+
});
33+
34+
autoUpdater.on('download-progress', progressObj => {
35+
const logMsg = `Download speed: ${progressObj.bytesPerSecond} - ${progressObj.percent.toFixed(2)}%`;
36+
this.log(logMsg);
37+
mainWindow.setTitle(`Downloading update... ${progressObj.percent.toFixed(0)}%`);
38+
});
39+
40+
autoUpdater.on('update-downloaded', info => {
41+
this.log('Update downloaded, will install now.');
42+
dialog.showMessageBox(mainWindow, {
43+
title: 'Install Update',
44+
message: 'Update downloaded. The app will restart to install.'
45+
}).then(() => {
46+
autoUpdater.quitAndInstall();
47+
});
48+
});
49+
50+
autoUpdater.on('update-not-available', () => {
51+
this.log('No updates available.');
52+
});
53+
54+
autoUpdater.on('error', err => {
55+
log.error('Updater error:', err);
56+
dialog.showErrorBox('Update Error', err == null ? "unknown" : (err.stack || err).toString());
57+
});
58+
}
59+
60+
setup_windows()
61+
{
62+
63+
}
64+
}
65+
66+
module.exports = Autoupdater;

extensions/autoupdate/update_git.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

main.js

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
const path = require('./lib/path2');
3-
const {app, WebContentsView, BaseWindow, screen, dialog } = require('electron');
3+
const {app, WebContentsView, BaseWindow, screen } = require('electron');
44
const url = require('url');
55
const fs = require('fs');
66
const os = require('os');
@@ -88,54 +88,6 @@ function checkActiveModules()
8888
});
8989
}
9090

91-
const { autoUpdater } = require('electron-updater')
92-
// Auto-updater event handlers
93-
autoUpdater.on('checking-for-update', () => {
94-
console.log('Checking for updates...')
95-
mainWindow?.webContents.send('update-check', { status: 'checking' })
96-
})
97-
98-
autoUpdater.on('update-available', (info) => {
99-
console.log('Update available:', info)
100-
mainWindow?.webContents.send('update-available', info)
101-
})
102-
103-
autoUpdater.on('update-not-available', (info) => {
104-
console.log('Update not available', info)
105-
mainWindow?.webContents.send('update-not-available', info)
106-
})
107-
108-
autoUpdater.on('error', (err) => {
109-
log.error('Update error:', err)
110-
mainWindow?.webContents.send('update-error', { message: err == null ? "unknown" : (err.stack || err).toString() })
111-
})
112-
113-
autoUpdater.on('download-progress', (progressObj) => {
114-
console.log('Download progress', progressObj)
115-
mainWindow?.webContents.send('update-download-progress', progressObj)
116-
})
117-
118-
autoUpdater.on('update-downloaded', (info) => {
119-
console.log('Update downloaded', info)
120-
// Option A: prompt user to restart now
121-
const choice = dialog.showMessageBoxSync(mainWindow, {
122-
type: 'question',
123-
buttons: ['Restart and install', 'Later'],
124-
defaultId: 0,
125-
cancelId: 1,
126-
title: 'Update ready',
127-
message: 'A new version has been downloaded. Restart the application to apply the update?'
128-
})
129-
if (choice === 0) {
130-
// Will quit and install on Windows/macOS (installer-specific)
131-
autoUpdater.quitAndInstall()
132-
} else {
133-
// user deferred; you can install later via IPC call to autoUpdater.quitAndInstall()
134-
mainWindow?.webContents.send('update-postponed')
135-
}
136-
})
137-
138-
13991

14092
// app.on('browser-window-created', (event, window) => {
14193
// console.log('New window created:', window.id);

package-lock.json

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

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
"deb"
2323
],
2424
"category": "Utility"
25+
},
26+
"publish": {
27+
"provider": "github",
28+
"owner": "leopollini",
29+
"repo": "webpage-accessor-interface"
2530
}
2631
},
2732
"keywords": [
@@ -31,6 +36,7 @@
3136
],
3237
"license": "ISC",
3338
"devDependencies": {
39+
"dialog": "^0.3.1",
3440
"electron": "^37.4.0",
3541
"electron-builder": "^26.0.12"
3642
},

0 commit comments

Comments
 (0)