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: #704
  • Loading branch information
castaway committed Aug 1, 2022
1 parent c505292 commit 5b5c8fd
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/app/updatealert/updatealert.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
// 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 } from '@angular/service-worker';
import { MatDialog } from '@angular/material/dialog';
import { UpdateAlertComponent } from './updatealert.component';
import { environment } from '../../environments/environment';
import { concat, timer } from 'rxjs';
import { first } from 'rxjs/operators';

@Injectable()
export class UpdateAlertService {
constructor(
private appRef: ApplicationRef,
private swupdate: SwUpdate,
private ngZone: NgZone,
dialog: MatDialog
Expand All @@ -36,12 +39,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 = 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 5b5c8fd

Please sign in to comment.