Skip to content

Commit b263545

Browse files
committed
Fixed update check debouncing
1 parent 664606b commit b263545

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/renderer/components/menu-bar/MenuBar.vue

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export default {
153153
availableSMMUpdate: null,
154154
modUpdates: [],
155155
nextCheckForUpdates: -1,
156-
updateCheckInProgress: false,
156+
currentCheckForUpdates: -1,
157157
viewChangelogUpdate: null,
158158
showIgnoredUpdates: false,
159159
ignoredUpdates: [],
@@ -240,20 +240,28 @@ export default {
240240
}
241241
},
242242
async checkForUpdates() {
243-
if (this.updateCheckInProgress) return;
244-
this.updateCheckInProgress = true;
243+
this.currentCheckForUpdates += 1;
244+
const thisCheckForUpdates = this.currentCheckForUpdates;
245245
clearTimeout(this.nextCheckForUpdates);
246246
// don't check for updates while something is in progress
247247
while (this.inProgress.length > 0) {
248248
// eslint-disable-next-line no-await-in-loop
249-
await new Promise((resolve) => setTimeout(() => resolve(), 500));
249+
await new Promise((res) => setTimeout(() => res(), 500));
250+
if (thisCheckForUpdates !== this.currentCheckForUpdates) {
251+
return;
252+
}
253+
}
254+
if (thisCheckForUpdates !== this.currentCheckForUpdates) {
255+
return;
250256
}
251257
this.$electron.ipcRenderer.send('checkForUpdates');
252-
this.modUpdates = (await this.$store.state.selectedInstall.checkForUpdates()).map((update) => Object.assign(update, {
258+
const modUpdates = (await this.$store.state.selectedInstall.checkForUpdates()).map((update) => Object.assign(update, {
253259
name: this.allMods.find((mod) => mod.modInfo.mod_reference === update.item)?.modInfo.name || update.item,
254260
}));
255-
this.nextCheckForUpdates = setTimeout(() => this.checkForUpdates(), UPDATE_CHECK_INTERVAL);
256-
this.updateCheckInProgress = false;
261+
if (thisCheckForUpdates === this.currentCheckForUpdates) {
262+
this.modUpdates = modUpdates;
263+
this.nextCheckForUpdates = setTimeout(() => this.checkForUpdates(), UPDATE_CHECK_INTERVAL);
264+
}
257265
},
258266
updateSMMNow() {
259267
this.$root.$emit('downloadUpdate');

0 commit comments

Comments
 (0)