Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicated addons in my addons page #1443

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

goulaheau
Copy link

@goulaheau goulaheau commented Jul 15, 2023

I'm not sure if there is an issue for this on this repository, but I have previously opened one on WowUp.CF repository.
Closing WowUp/WowUp.CF#60

Explanation of the bug

The bug appears on first loading of the app when there is no electron-store saved in user app data.
The app is calling 3 times AddonStorageService.saveAll() from AddonService.rescanInstallation() from AddonService.getAddons() from MyAddonsComponent.loadAddons().

2 times by this switchMap :

 this._sessionService.autoUpdateComplete$
      .pipe(
        tap(() => console.log("Checking for addon updates...")),
        switchMap(() => from(this.loadAddons()))
      )
      .subscribe(() => {
        this._cdRef.markForCheck();
      });

Because autoUpdateComplete is a BehaviorSubject so it emits it's firstValue 0 then when SessionService.autoUpdateComplete() is called.

1 time inside MyAddonsComponent.lazyLoad().

AddonService.rescanInstallation() is called 3 times rapidly and because it's a Promise, it's beginning each call without waiting for the other one to finish.

From a UI perspective, we are updating only with one result from MyAddonsComponent.loadAddons() so we are not seeing any problem.

But the handle of IPC_ADDONS_SAVE_ALL in ipc-events.ts is not clearing the store, it can have 3 times the same addon in the store.

So when the user relaunches the application or clicks on PAGES.MY_ADDONS.CHECK_UPDATES_BUTTON_TOOLTIP button and getting the addons from the store, it shows the addons duplicated.

Explanation of my fix

It's working because IPC_ADDONS_SAVE_ALL is only called from AddonStorage.saveAll() which is only called from AddonService.rescanInstallation() so it has all the addons from the disk and it's not losing any data.

But a better fix would be to either :

  • only call 1 time MyAddonsComponent.loadAddons()
  • implement a way to not do AddonService.rescanInstallation() if one is already in progress

Testing the behavior

To test the problematic behavior, before launching the application, you should delete addons.json from your AppData\Roaming\WowUp folder, because it's the file stored by electron-store to save the store between relaunch of the app.

The bug is not happening every time because it will depend on the speed of AddonService.rescanInstallation() to finish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant