Skip to content

Commit 58b4649

Browse files
committed
0.9.64 no auto update
1 parent 9b62180 commit 58b4649

File tree

6 files changed

+241
-51
lines changed

6 files changed

+241
-51
lines changed

main.js

Lines changed: 98 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { app, BrowserWindow, ipcMain, shell, dialog, globalShortcut, Menu, session } from 'electron';
1+
import { app, BrowserWindow, ipcMain, shell, dialog, globalShortcut, Menu, session, Notification } from 'electron';
22
import fs from 'fs/promises';
33
import fsSync from 'fs';
44
import path from 'path';
@@ -903,53 +903,30 @@ ipcMain.handle('get-versions', async () => {
903903
return {current: pjson.version, latest: latestVersion};
904904
});
905905

906-
app.whenReady().then(() => {
907-
// Check for updates on startup
908-
autoUpdater.checkForUpdatesAndNotify();
909-
910-
autoUpdater.on('checking-for-update', () => {
911-
console.log('Checking for update...');
912-
});
913-
914-
autoUpdater.on('update-available', (info) => {
915-
console.log('Update available.', info);
916-
});
917-
918-
autoUpdater.on('update-not-available', (info) => {
919-
console.log('Update not available.', info);
920-
});
921-
922-
autoUpdater.on('error', (err) => {
923-
console.error('Error in auto-updater.', err);
924-
});
925-
926-
autoUpdater.on('download-progress', (progressObj) => {
927-
let log_message = "Download speed: " + progressObj.bytesPerSecond;
928-
log_message = log_message + ' - Downloaded ' + progressObj.percent + '%';
929-
log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')';
930-
console.log(log_message);
931-
});
932-
933-
autoUpdater.on('update-downloaded', (info) => {
934-
console.log('Update downloaded', info);
935-
});
936-
937-
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
938-
callback({
939-
responseHeaders: {
940-
...details.responseHeaders,
941-
"Access-Control-Allow-Origin": ["*"], // Allow all origins
942-
"Access-Control-Allow-Methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
943-
"Access-Control-Allow-Headers": ["*"]
944-
}
945-
});
946-
});
906+
// Manual update handlers
907+
ipcMain.handle('check-for-updates', async () => {
908+
try {
909+
await autoUpdater.checkForUpdates();
910+
return { success: true };
911+
} catch (error) {
912+
console.error('Manual update check failed:', error);
913+
return { success: false, error: error.message };
914+
}
915+
});
947916

948-
createWindows();
917+
ipcMain.handle('download-update', async () => {
918+
try {
919+
await autoUpdater.downloadUpdate();
920+
return { success: true };
921+
} catch (error) {
922+
console.error('Update download failed:', error);
923+
return { success: false, error: error.message };
924+
}
925+
});
949926

950-
globalShortcut.register('Ctrl+Shift+K', () => {
951-
killChildProcesses(childProcesses);
952-
});
927+
ipcMain.handle('quit-and-install', async () => {
928+
app.relaunch({ args: process.argv.slice(1).concat(['--restarted']) });
929+
autoUpdater.quitAndInstall();
953930
});
954931

955932
ipcMain.handle('install-flatpak', async (event, appId) => {
@@ -1151,3 +1128,78 @@ ipcMain.handle('get-flatpak-download-size', async (event, appId) => {
11511128
});
11521129
});
11531130
});
1131+
1132+
// Manual update system - no auto-check on startup
1133+
app.whenReady().then(() => {
1134+
autoUpdater.on('checking-for-update', () => {
1135+
mainWindow.webContents.send('update-status', { status: 'checking' });
1136+
});
1137+
1138+
autoUpdater.on('update-available', (info) => {
1139+
new Notification({
1140+
title: 'Update Available',
1141+
body: `Emulsion ${info.version} is available for download`
1142+
}).show();
1143+
mainWindow.webContents.send('update-status', {
1144+
status: 'available',
1145+
info: info,
1146+
version: info.version
1147+
});
1148+
});
1149+
1150+
autoUpdater.on('update-not-available', (info) => {
1151+
new Notification({
1152+
title: 'No Updates Available',
1153+
body: 'You are running the latest version of Emulsion'
1154+
}).show();
1155+
mainWindow.webContents.send('update-status', { status: 'up-to-date' });
1156+
});
1157+
1158+
autoUpdater.on('error', (err) => {
1159+
new Notification({
1160+
title: 'Update Error',
1161+
body: `Failed to check for updates: ${err.message}`
1162+
}).show();
1163+
mainWindow.webContents.send('update-status', { status: 'error', error: err.message });
1164+
});
1165+
1166+
autoUpdater.on('download-progress', (progressObj) => {
1167+
const progress = Math.round(progressObj.percent);
1168+
const speedMBs = (progressObj.bytesPerSecond / 1024 / 1024).toFixed(2);
1169+
const downloadedMB = (progressObj.transferred / 1024 / 1024).toFixed(2);
1170+
const totalMB = (progressObj.total / 1024 / 1024).toFixed(2);
1171+
1172+
mainWindow.webContents.send('update-status', {
1173+
status: 'downloading',
1174+
progress: progress,
1175+
speed: speedMBs,
1176+
downloaded: downloadedMB,
1177+
total: totalMB
1178+
});
1179+
});
1180+
1181+
autoUpdater.on('update-downloaded', (info) => {
1182+
new Notification({
1183+
title: 'Update Downloaded',
1184+
body: 'Restart Emulsion to apply the update'
1185+
}).show();
1186+
mainWindow.webContents.send('update-status', { status: 'downloaded', info: info });
1187+
});
1188+
1189+
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
1190+
callback({
1191+
responseHeaders: {
1192+
...details.responseHeaders,
1193+
"Access-Control-Allow-Origin": ["*"], // Allow all origins
1194+
"Access-Control-Allow-Methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
1195+
"Access-Control-Allow-Headers": ["*"]
1196+
}
1197+
});
1198+
});
1199+
1200+
createWindows();
1201+
1202+
globalShortcut.register('Ctrl+Shift+K', () => {
1203+
killChildProcesses(childProcesses);
1204+
});
1205+
});

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "emulsion",
3-
"version": "0.9.63",
3+
"version": "0.9.64",
44
"summary": "Better gaming throught chemistry",
55
"description": "Display your games collection into responsive galleries, manage game metadata, cover art and emulator configuration. Launch your games in style.",
66
"homepage": "https://yphil.gitlab.io/emulsion",

src/css/dialog.css

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,45 @@ dd.disabled {
495495
width: auto; /* let it size to content */
496496
}
497497

498+
/* Update progress indicators */
499+
.update-progress {
500+
display: none; /* Hidden by default, shown during updates */
501+
margin: 1em 0;
502+
padding: 0.5em;
503+
background: var(--color-bg-header);
504+
border-radius: 4px;
505+
border: 1px solid var(--color-border-header);
506+
}
507+
508+
.update-progress-bar {
509+
width: 0%;
510+
height: 8px;
511+
background: var(--color-selected);
512+
border-radius: 4px;
513+
transition: width 0.3s ease;
514+
}
515+
516+
.update-progress-text {
517+
margin-top: 0.5em;
518+
font-size: 0.9em;
519+
color: var(--color-text-1);
520+
text-align: center;
521+
font-family: var(--font-mono);
522+
}
523+
524+
/* Show progress when downloading */
525+
.help-dialog .update-progress.downloading {
526+
display: block;
527+
}
528+
529+
.help-dialog .update-progress.available {
530+
display: block;
531+
}
532+
533+
.help-dialog .update-progress.error {
534+
display: block;
535+
}
536+
498537
.dialog *::-webkit-scrollbar-thumb {
499538
background-color: var(--color-hr);
500539
border-radius: 6px;

src/html/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,10 @@ <h2>Emulsion <span class="current-version">x.y.z</span> <span class="up-to-date"
543543
<h3 class="update-available">
544544
<button class="upgrade button"><span class="latest-version"></span> is available!</button>
545545
</h3>
546+
<div class="update-progress">
547+
<div class="update-progress-bar"></div>
548+
<div class="update-progress-text"></div>
549+
</div>
546550

547551
<div class="container">
548552
<p class="text">

src/js/dialog.js

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,103 @@ export async function helpDialog(defaultTabId = null) {
264264
dialog.querySelector('.update-available').style.display = 'block';
265265
}
266266

267-
dialog.querySelector('button.upgrade').addEventListener('click', () => {
268-
ipcRenderer.invoke('go-to-url', 'https://github.com/yPhil-gh/Emulsion/releases');
267+
const upgradeButton = dialog.querySelector('button.upgrade');
268+
269+
// Update status tracking
270+
let updateStatus = 'idle'; // idle, checking, available, downloading, downloaded, error
271+
272+
// Listen for update status changes from main process
273+
ipcRenderer.on('update-status', (event, status) => {
274+
updateStatus = status.status;
275+
const progressContainer = dialog.querySelector('.update-progress');
276+
const progressBar = dialog.querySelector('.update-progress-bar');
277+
const progressText = dialog.querySelector('.update-progress-text');
278+
279+
switch (status.status) {
280+
case 'checking':
281+
upgradeButton.textContent = 'Checking...';
282+
upgradeButton.disabled = true;
283+
if (progressContainer) progressContainer.style.display = 'none';
284+
break;
285+
case 'available':
286+
upgradeButton.textContent = `Download Update ${status.version}`;
287+
upgradeButton.disabled = false;
288+
if (progressContainer) {
289+
progressContainer.className = 'update-progress available';
290+
progressContainer.style.display = 'block';
291+
progressBar.style.width = '0%';
292+
progressText.textContent = 'Update available for download';
293+
}
294+
break;
295+
case 'up-to-date':
296+
upgradeButton.textContent = 'Up to Date';
297+
upgradeButton.disabled = true;
298+
if (progressContainer) progressContainer.style.display = 'none';
299+
break;
300+
case 'downloading':
301+
upgradeButton.textContent = `Downloading... ${status.progress}%`;
302+
upgradeButton.disabled = true;
303+
if (progressContainer) {
304+
progressContainer.className = 'update-progress downloading';
305+
progressContainer.style.display = 'block';
306+
progressBar.style.width = `${status.progress}%`;
307+
progressText.textContent = `${status.progress}% (${status.downloaded}/${status.total} MB @ ${status.speed} MB/s)`;
308+
}
309+
break;
310+
case 'downloaded':
311+
upgradeButton.textContent = 'Install & Restart';
312+
upgradeButton.disabled = false;
313+
if (progressContainer) {
314+
progressContainer.style.display = 'none';
315+
}
316+
break;
317+
case 'error':
318+
upgradeButton.textContent = 'Check for Updates';
319+
upgradeButton.disabled = false;
320+
if (progressContainer) {
321+
progressContainer.className = 'update-progress error';
322+
progressContainer.style.display = 'block';
323+
progressBar.style.width = '0%';
324+
progressText.textContent = `Error: ${status.error}`;
325+
}
326+
console.error('Update error:', status.error);
327+
break;
328+
}
329+
});
330+
331+
upgradeButton.addEventListener('click', async () => {
332+
try {
333+
switch (updateStatus) {
334+
case 'idle':
335+
case 'up-to-date':
336+
case 'error':
337+
// Check for updates
338+
const result = await ipcRenderer.invoke('check-for-updates');
339+
if (!result.success) {
340+
console.error('Failed to check for updates:', result.error);
341+
upgradeButton.textContent = 'Check Failed - Try Again';
342+
upgradeButton.disabled = false;
343+
}
344+
break;
345+
case 'available':
346+
// Start download
347+
const downloadResult = await ipcRenderer.invoke('download-update');
348+
if (!downloadResult.success) {
349+
console.error('Failed to download update:', downloadResult.error);
350+
upgradeButton.textContent = 'Download Failed - Try Again';
351+
upgradeButton.disabled = false;
352+
}
353+
break;
354+
case 'downloaded':
355+
// Install and restart
356+
await ipcRenderer.invoke('quit-and-install');
357+
break;
358+
}
359+
} catch (error) {
360+
console.error('Update operation failed:', error);
361+
upgradeButton.textContent = 'Error - Try Again';
362+
upgradeButton.disabled = false;
363+
}
269364
});
270365

271366
dialog.querySelector('button.btn-liberapay').addEventListener('click', () => {

0 commit comments

Comments
 (0)