Skip to content

Commit b6bf2cc

Browse files
committed
some where in the middle
1 parent 3509741 commit b6bf2cc

5 files changed

Lines changed: 246 additions & 62 deletions

File tree

src/main/preload.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ const validChannels = {
2929
'check-for-updates',
3030
'check-for-updates-menu',
3131
'download-update',
32+
'download-and-install',
3233
'install-update',
34+
'enable-auto-install',
3335
'get-update-status',
3436
'get-app-version',
3537
],

src/main/updater.ts

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,33 @@ export class AppUpdater {
114114

115115
ipcMain.handle('download-update', async () => {
116116
try {
117-
await autoUpdater.downloadUpdate();
118-
return { success: true };
117+
log.info('[AppUpdater] Download request received');
118+
119+
// Check if already downloaded first
120+
if (this.lastStatus === 'downloaded') {
121+
log.info('[AppUpdater] Update already downloaded, notifying UI');
122+
this.sendStatusToWindow('downloaded', this.lastInfo);
123+
return { success: true, alreadyDownloaded: true };
124+
}
125+
126+
// If we have update info but no download yet, start download
127+
if (this.lastInfo && this.lastStatus === 'available') {
128+
log.info('[AppUpdater] Starting download for available update');
129+
this.sendStatusToWindow('downloading', this.lastInfo, undefined, { percent: 0, transferred: 0, total: 0 });
130+
131+
await autoUpdater.downloadUpdate();
132+
log.info('[AppUpdater] Download completed');
133+
return { success: true };
134+
}
135+
136+
// No update available
137+
log.warn('[AppUpdater] No update available to download');
138+
this.sendStatusToWindow('error', null, 'No update available to download');
139+
return { success: false, error: 'No update available to download' };
140+
119141
} catch (error) {
120142
log.error('[AppUpdater] Download failed:', error);
143+
this.sendStatusToWindow('error', null, error instanceof Error ? error.message : 'Unknown error');
121144
return { success: false, error: error instanceof Error ? error.message : 'Unknown error' };
122145
}
123146
});
@@ -189,6 +212,42 @@ export class AppUpdater {
189212
this.checkPromise = null;
190213
}
191214
});
215+
216+
ipcMain.handle('enable-auto-install', () => {
217+
log.info('[AppUpdater] Enabling auto-install on next quit');
218+
autoUpdater.autoInstallOnAppQuit = true;
219+
return { success: true };
220+
});
221+
222+
ipcMain.handle('download-and-install', async () => {
223+
try {
224+
log.info('[AppUpdater] Download and install requested');
225+
226+
// Check current status
227+
if (this.lastStatus === 'downloaded') {
228+
log.info('[AppUpdater] Update already downloaded, ready to install');
229+
return { success: true, readyToInstall: true };
230+
}
231+
232+
if (this.lastStatus === 'available' && this.lastInfo) {
233+
log.info('[AppUpdater] Starting download...');
234+
this.sendStatusToWindow('downloading', this.lastInfo, undefined, { percent: 0, transferred: 0, total: 0 });
235+
236+
// Download the update
237+
await autoUpdater.downloadUpdate();
238+
239+
log.info('[AppUpdater] Download completed, ready to install');
240+
return { success: true, readyToInstall: true };
241+
}
242+
243+
return { success: false, error: 'No update available to download' };
244+
245+
} catch (error) {
246+
log.error('[AppUpdater] Download and install failed:', error);
247+
this.sendStatusToWindow('error', null, error instanceof Error ? error.message : 'Unknown error');
248+
return { success: false, error: error instanceof Error ? error.message : 'Unknown error' };
249+
}
250+
});
192251
}
193252

194253
private sendStatusToWindow(status: string, info?: any, error?: string, progress?: any) {
@@ -200,7 +259,9 @@ export class AppUpdater {
200259
log.info(`[AppUpdater] Sending status to window: ${status}`, {
201260
hasMainWindow: !!this.mainWindow,
202261
isDestroyed: this.mainWindow?.isDestroyed(),
203-
info: info ? { version: info.version } : undefined
262+
info: info ? { version: info.version } : undefined,
263+
error,
264+
progress
204265
});
205266

206267
if (this.mainWindow && !this.mainWindow.isDestroyed()) {
@@ -210,20 +271,21 @@ export class AppUpdater {
210271
error,
211272
progress
212273
});
274+
log.info(`[AppUpdater] Status sent to renderer: ${status}`);
275+
} else {
276+
log.warn('[AppUpdater] Cannot send status - main window not available');
213277
}
214278
}
215279

216280
checkForUpdatesOnStartup() {
217281
if (!app.isPackaged) {
282+
log.info('[AppUpdater] Skipping startup check - not packaged');
218283
return;
219284
}
220285

221-
if (app.isPackaged) {
222-
return;
223-
}
224-
225-
// Check for updates 3 seconds after startup to avoid conflicts
286+
// Check for updates 3 seconds after startup to avoid conflicts
226287
setTimeout(() => {
288+
log.info('[AppUpdater] Starting automatic update check');
227289
this.sendStatusToWindow('checking');
228290
autoUpdater.checkForUpdatesAndNotify().catch(err => {
229291
log.error('[AppUpdater] Startup check failed:', err.message);

src/renderer/components/UpdateNotification/UpdateNotification.css

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
background-color: #2A2F35;
66
border: 1px solid #7CA97E;
77
border-radius: 8px;
8-
padding: 16px;
8+
padding: 14px;
99
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
1010
z-index: 1000;
1111
animation: slideIn 0.3s ease-out;
12-
max-width: 400px;
12+
max-width: 350px;
1313
}
1414

1515
@keyframes slideIn {
@@ -79,42 +79,70 @@
7979
}
8080

8181
.update-button {
82-
padding: 6px 16px;
82+
padding: 8px 12px;
8383
background-color: #7CA97E;
8484
color: #1E2329;
8585
border: none;
86-
border-radius: 4px;
86+
border-radius: 6px;
8787
cursor: pointer;
8888
font-weight: 500;
89-
transition: background-color 0.2s;
89+
font-size: 13px;
90+
transition: all 0.2s ease;
91+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
9092
}
9193

9294
.update-button:hover {
9395
background-color: #8FB996;
96+
transform: translateY(-1px);
97+
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
98+
}
99+
100+
.update-button.primary {
101+
background-color: #7CA97E;
102+
color: white;
103+
font-weight: 600;
104+
}
105+
106+
.update-button.secondary {
107+
background-color: transparent;
108+
border: 1px solid #7CA97E;
109+
color: #7CA97E;
110+
font-weight: 500;
111+
}
112+
113+
.update-button.primary:hover {
114+
background-color: #6B8F6D;
115+
}
116+
117+
.update-button.secondary:hover {
118+
background-color: rgba(124, 169, 126, 0.1);
119+
border-color: #8FB996;
94120
}
95121

96122
.dismiss-button {
97-
padding: 6px 12px;
123+
padding: 6px 10px;
98124
background-color: transparent;
99125
color: #8A9BA8;
100126
border: 1px solid #3A424A;
101-
border-radius: 4px;
127+
border-radius: 6px;
102128
cursor: pointer;
103-
transition: all 0.2s;
129+
font-size: 13px;
130+
transition: all 0.2s ease;
104131
}
105132

106133
.dismiss-button:hover {
107134
border-color: #8A9BA8;
108135
color: #C5D8BC;
136+
transform: translateY(-1px);
109137
}
110138

111139
.progress-bar {
112-
width: 100px;
113-
height: 6px;
114-
background-color: #3A424A;
115-
border-radius: 3px;
140+
width: 100%;
141+
height: 4px;
142+
background-color: rgba(124, 169, 126, 0.2);
143+
border-radius: 2px;
116144
overflow: hidden;
117-
margin-top: 12px;
145+
margin: 8px 0;
118146
}
119147

120148
.progress-fill {
@@ -125,7 +153,7 @@
125153

126154
.progress-text {
127155
font-size: 12px;
128-
color: #8A9BA8;
156+
color: #7CA97E;
129157
}
130158

131159
.error-detail {
@@ -151,4 +179,11 @@
151179
opacity: 0;
152180
transform: translateX(100%);
153181
}
182+
}
183+
184+
.update-actions {
185+
display: flex;
186+
flex-direction: column;
187+
gap: 6px;
188+
margin-top: 10px;
154189
}

0 commit comments

Comments
 (0)