Skip to content

Commit

Permalink
fix(updates): Use isStable to check as soon as possible for updates
Browse files Browse the repository at this point in the history
Fixes: runbox#704
  • Loading branch information
castaway committed Feb 19, 2025
1 parent 09068cb commit 7a47aa0
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/app/updatealert/updatealert.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
// along with Runbox 7. If not, see <https://www.gnu.org/licenses/>.
// ---------- END RUNBOX LICENSE ----------

import { Injectable, NgZone } from '@angular/core';
import { ApplicationRef, Injectable, NgZone } from '@angular/core';
import { SwUpdate, VersionReadyEvent } from '@angular/service-worker';
import { MatLegacyDialog as MatDialog } from '@angular/material/legacy-dialog';
import { UpdateAlertComponent } from './updatealert.component';
import { environment } from '../../environments/environment';
import {filter, map} from 'rxjs/operators';
import { concat, timer } from 'rxjs';
import { filter, map, first } from 'rxjs/operators';

@Injectable()
export class UpdateAlertService {
constructor(
private appRef: ApplicationRef,
private swupdate: SwUpdate,
private ngZone: NgZone,
dialog: MatDialog
) {
if (environment.production && swupdate.isEnabled) {
Expand All @@ -45,12 +46,12 @@ export class UpdateAlertService {
dialog.open(UpdateAlertComponent, { data: ev });
});

this.ngZone.runOutsideAngular(() => {
this.checkForUpdates();
setTimeout(() => this.ngZone.run(() =>
this.checkForUpdates()
), 5 * 60 * 1000);
});
const appIsStable = this.appRef.isStable.pipe(first(isStable => isStable === true));
const everyFiveMins = timer(0, 5 * 60 * 1000);
const everyFiveMinsOnceAppIsStable = concat(appIsStable, everyFiveMins);
everyFiveMinsOnceAppIsStable.subscribe(() =>
this.checkForUpdates()
);
}
}

Expand Down

0 comments on commit 7a47aa0

Please sign in to comment.