Skip to content

Commit b742a8c

Browse files
committed
feat: add electron auto publish
1 parent 421ae8a commit b742a8c

File tree

3 files changed

+101
-5
lines changed

3 files changed

+101
-5
lines changed

electron/main.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,59 @@
11
const { app, BrowserWindow, ipcMain } = require('electron');
2+
const { autoUpdater } = require('electron-updater');
23
const path = require('path');
34
const mqtt = require('mqtt');
45
const isDev = !app.isPackaged;
56

67
let mainWindow;
78
let mqttClient;
89

10+
// Configure auto updater
11+
autoUpdater.autoDownload = false;
12+
autoUpdater.logger = require('electron-log');
13+
autoUpdater.logger.transports.file.level = 'info';
14+
15+
// Auto-updater events
16+
autoUpdater.on('checking-for-update', () => {
17+
mainWindow.webContents.send('update-status', 'Checking for updates...');
18+
});
19+
20+
autoUpdater.on('update-available', (info) => {
21+
mainWindow.webContents.send('update-available', info);
22+
});
23+
24+
autoUpdater.on('update-not-available', (info) => {
25+
mainWindow.webContents.send('update-not-available', info);
26+
});
27+
28+
autoUpdater.on('error', (err) => {
29+
mainWindow.webContents.send('update-error', err.message);
30+
});
31+
32+
autoUpdater.on('download-progress', (progressObj) => {
33+
mainWindow.webContents.send('download-progress', progressObj);
34+
});
35+
36+
autoUpdater.on('update-downloaded', (info) => {
37+
mainWindow.webContents.send('update-downloaded', info);
38+
});
39+
40+
// IPC handlers for updates
41+
ipcMain.handle('check-for-updates', async () => {
42+
if (!isDev) {
43+
return await autoUpdater.checkForUpdates();
44+
}
45+
});
46+
47+
ipcMain.handle('start-download', async () => {
48+
if (!isDev) {
49+
return await autoUpdater.downloadUpdate();
50+
}
51+
});
52+
53+
ipcMain.handle('quit-and-install', () => {
54+
autoUpdater.quitAndInstall(false, true);
55+
});
56+
957
function createWindow() {
1058
mainWindow = new BrowserWindow({
1159
width: 1200,
@@ -43,6 +91,13 @@ function createWindow() {
4391
if (process.env.NODE_ENV === 'development') {
4492
mainWindow.webContents.openDevTools()
4593
}
94+
95+
// Check for updates after window is created (only in production)
96+
if (!isDev) {
97+
setTimeout(() => {
98+
autoUpdater.checkForUpdates();
99+
}, 3000); // Check after 3 seconds
100+
}
46101
}
47102

48103
// MQTT Connection Handler

electron/preload.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,28 @@ contextBridge.exposeInMainWorld('electron', {
1111
removeAllListeners: (channel) => {
1212
ipcRenderer.removeAllListeners(channel);
1313
}
14-
}
14+
},
15+
16+
// Auto-updater functions
17+
checkForUpdates: () => ipcRenderer.invoke('check-for-updates'),
18+
startDownload: () => ipcRenderer.invoke('start-download'),
19+
quitAndInstall: () => ipcRenderer.invoke('quit-and-install'),
20+
21+
// Auto-updater events
22+
onUpdateStatus: (callback) => ipcRenderer.on('update-status', (_, status) => callback(status)),
23+
onUpdateAvailable: (callback) => ipcRenderer.on('update-available', (_, info) => callback(info)),
24+
onUpdateNotAvailable: (callback) => ipcRenderer.on('update-not-available', (_, info) => callback(info)),
25+
onUpdateError: (callback) => ipcRenderer.on('update-error', (_, error) => callback(error)),
26+
onDownloadProgress: (callback) => ipcRenderer.on('download-progress', (_, progressObj) => callback(progressObj)),
27+
onUpdateDownloaded: (callback) => ipcRenderer.on('update-downloaded', (_, info) => callback(info)),
28+
29+
// MQTT functions
30+
connectMQTT: (options) => ipcRenderer.send('connect-mqtt', options),
31+
subscribeTopic: (topic) => ipcRenderer.send('subscribe-topic', topic),
32+
publishMessage: (topic, message) => ipcRenderer.send('publish-message', { topic, message }),
33+
onMQTTMessage: (callback) => ipcRenderer.on('mqtt-message', (_, data) => callback(data)),
34+
onMQTTError: (callback) => ipcRenderer.on('mqtt-error', (_, error) => callback(error)),
35+
onMQTTConnected: (callback) => ipcRenderer.on('mqtt-connected', () => callback()),
36+
onMQTTDisconnected: (callback) => ipcRenderer.on('mqtt-disconnected', () => callback()),
37+
onMQTTReconnecting: (callback) => ipcRenderer.on('mqtt-reconnecting', () => callback())
1538
});

package.json

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vda5050-visualizer",
33
"author": "bekir.bostanci",
4-
"version": "0.0.0",
4+
"version": "2.0.0",
55
"scripts": {
66
"dev": "vite --host --port 8082",
77
"build:bundle": "vite build",
@@ -19,6 +19,8 @@
1919
"balm-ui": "^10.22.0",
2020
"bootstrap-icons": "^1.9.1",
2121
"buffer": "^6.0.3",
22+
"electron-log": "^5.3.1",
23+
"electron-updater": "^6.3.9",
2224
"lodash": "^4.17.21",
2325
"mqtt": "^4.3.7",
2426
"process": "^0.11.10",
@@ -91,14 +93,30 @@
9193
"to": "dist"
9294
}
9395
],
96+
"publish": [
97+
{
98+
"provider": "github",
99+
"owner": "bekirbostanci",
100+
"repo": "vda5050_visualizer"
101+
}
102+
],
94103
"win": {
95-
"target": "nsis"
104+
"target": "nsis",
105+
"publish": [
106+
"github"
107+
]
96108
},
97109
"mac": {
98-
"target": "dmg"
110+
"target": "dmg",
111+
"publish": [
112+
"github"
113+
]
99114
},
100115
"linux": {
101-
"target": "AppImage"
116+
"target": "AppImage",
117+
"publish": [
118+
"github"
119+
]
102120
}
103121
}
104122
}

0 commit comments

Comments
 (0)