Skip to content

Commit f443d6d

Browse files
committed
[DDW-1061]: Clear downloads after update install
1 parent ce56d89 commit f443d6d

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

source/renderer/app/stores/AppUpdateStore.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,21 @@ export default class AppUpdateStore extends Store {
102102
}
103103

104104
// ================= REACTIONS ==================
105-
_watchForNewsfeedUpdates = () => {
105+
_watchForNewsfeedUpdates = async () => {
106106
const { update } = this.stores.newsFeed.newsFeedData;
107-
if (update) this._checkNewAppUpdate(update);
107+
if (update) {
108+
this._checkNewAppUpdate(update);
109+
} else {
110+
const isFileInDownloads = await this._checkFileExists();
111+
if (isFileInDownloads && !this.availableUpdate) {
112+
this._clearDownloads();
113+
}
114+
}
115+
};
116+
117+
_clearDownloads = async () => {
118+
this._removeUpdateFile();
119+
await this._removeLocalDataInfo();
108120
};
109121

110122
// ==================== PUBLIC ==================
@@ -185,7 +197,9 @@ export default class AppUpdateStore extends Store {
185197
* We can't simply compare with the `package.json` version
186198
* otherwise we would trigger the local data cleaning on every app load
187199
*/
188-
if (appUpdateCompleted === version) return false;
200+
if (appUpdateCompleted === version) {
201+
return false;
202+
}
189203

190204
// Was the update already installed?
191205
if (this.isUpdateInstalled(update)) {
@@ -261,26 +275,31 @@ export default class AppUpdateStore extends Store {
261275
await this._removeLocalDataInfo();
262276
return this._requestUpdateDownload(update);
263277
};
278+
264279
_removeLocalDataInfo = async () => {
265280
clearDownloadLocalDataChannel.request({
266281
id: APP_UPDATE_DOWNLOAD_ID,
267282
});
268283
};
284+
269285
_removeUpdateFile = () => {
270286
deleteDownloadedFile.request({
271287
id: APP_UPDATE_DOWNLOAD_ID,
272288
});
273289
};
290+
274291
_getUpdateDownloadLocalData = async (): Promise<
275292
DownloadLocalDataMainResponse
276293
> =>
277294
getDownloadLocalDataChannel.request({
278295
id: APP_UPDATE_DOWNLOAD_ID,
279296
});
297+
280298
_checkFileExists = async (): Promise<CheckFileExistsMainResponse> =>
281299
checkFileExistsChannel.request({
282300
id: APP_UPDATE_DOWNLOAD_ID,
283301
});
302+
284303
_manageUpdateResponse = ({
285304
eventType,
286305
info,
@@ -329,6 +348,7 @@ export default class AppUpdateStore extends Store {
329348
fileUrl: '',
330349
});
331350
};
351+
332352
_requestResumeUpdateDownload = async () => {
333353
await requestResumeDownloadChannel.request({
334354
id: APP_UPDATE_DOWNLOAD_ID,
@@ -339,6 +359,7 @@ export default class AppUpdateStore extends Store {
339359
},
340360
});
341361
};
362+
342363
// @ts-ignore ts-migrate(2749) FIXME: 'News' refers to a value, but is being used as a t... Remove this comment to see the full error message
343364
_requestUpdateDownload = (update: News) => {
344365
const { url: fileUrl } = this.getUpdateInfo(update);
@@ -352,6 +373,7 @@ export default class AppUpdateStore extends Store {
352373
},
353374
});
354375
};
376+
355377
_installUpdate = async () => {
356378
if (
357379
!this.availableUpdate ||
@@ -384,6 +406,7 @@ export default class AppUpdateStore extends Store {
384406
hash,
385407
});
386408
};
409+
387410
_manageQuitAndInstallResponse = ({
388411
status,
389412
data,
@@ -412,22 +435,26 @@ export default class AppUpdateStore extends Store {
412435
hash: '',
413436
});
414437
};
438+
415439
_setAppAutomaticUpdateFailed = async () => {
416440
// @ts-ignore ts-migrate(1320) FIXME: Type of 'await' operand must either be a valid pro... Remove this comment to see the full error message
417441
await this.setAppAutomaticUpdateFailedRequest.execute();
418442
runInAction(() => {
419443
this.isAutomaticUpdateFailed = true;
420444
});
421445
};
446+
422447
@action
423448
_openAppUpdateOverlay = () => {
424449
this.isUpdateProgressOpen = true;
425450
this.isUpdatePostponed = false;
426451
};
452+
427453
@action
428454
_closeAppUpdateOverlay = () => {
429455
this.isUpdateProgressOpen = false;
430456
};
457+
431458
@action
432459
_postponeUpdate = () => {
433460
this.isUpdatePostponed = true;

0 commit comments

Comments
 (0)