Skip to content

Commit

Permalink
Merge pull request #24 from swsnr/23-refresh-after-switching-source
Browse files Browse the repository at this point in the history
Refresh immediately if source changed
  • Loading branch information
swsnr authored Nov 19, 2023
2 parents 10c6ad3 + f0b25af commit db6d279
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
21 changes: 16 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ class EnabledExtension implements Destructible {
(_selector, source): undefined => {
this.updateDownloader();
this.indicator.updateSelectedSource(source.metadata);
// Refresh immediately; the source only ever changes when the user
// explicitly asked for it to change.
this.refreshAfterUserAction();
},
);

Expand Down Expand Up @@ -168,11 +171,7 @@ class EnabledExtension implements Destructible {
});
this.indicator.connect("activated::refresh", () => {
console.log("Refresh emitted");
this.refreshService.refresh().catch((error) => {
// For any refresh triggered manually we always show any error, including
// network errors.
this.errorHandler.showError(error);
});
this.refreshAfterUserAction();
});
this.indicator.connect("activated::cancel-refresh", () => {
void this.refreshService.cancelRefresh();
Expand Down Expand Up @@ -203,6 +202,18 @@ class EnabledExtension implements Destructible {
);
}

/**
* Trigger an immediate refresh after a user action.
*
* Unlike scheduled refreshes we immediately show all errors, and do not handle
* intermittent network errors in any special way.
*/
private refreshAfterUserAction(): void {
this.refreshService.refresh().catch((error) => {
this.errorHandler.showError(error);
});
}

/**
* Get the base directories this extension should use for storage.
*
Expand Down
6 changes: 4 additions & 2 deletions src/lib/services/source-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ export class SourceSelector
}

selectSource(key: string): void {
this._selectedSource = findSourceByKey(key);
this.emit("source-changed", this._selectedSource);
if (this._selectedSource.metadata.key !== key) {
this._selectedSource = findSourceByKey(key);
this.emit("source-changed", this._selectedSource);
}
}

get selectedSource(): Source {
Expand Down

0 comments on commit db6d279

Please sign in to comment.