Skip to content

Commit

Permalink
fix(updates): Revert updates to NgZone, issues with isStable
Browse files Browse the repository at this point in the history
isStable doesn't happen in an app that starts scheduled tasks
immediately
  • Loading branch information
castaway committed Feb 20, 2025
1 parent bd60c7a commit 1c0b6b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import { ResizerModule } from './directives/resizer.module';
import { MainContainerComponent } from './maincontainer.component';
import { HeaderToolbarComponent } from './menu/headertoolbar.component';
import { LocalSearchIndexModule } from './xapian/localsearchindex.module';
import { ServiceWorkerModule } from '@angular/service-worker';
import { ServiceWorkerModule, SwRegistrationOptions } from '@angular/service-worker';
import { environment } from '../environments/environment';
import { SearchExpressionBuilderModule } from './xapian/search-expression-builder/search-expression-builder.module';
import { UpdateAlertModule } from './updatealert/updatealert.module';
Expand Down Expand Up @@ -201,6 +201,8 @@ const routes: Routes = [
StorageService,
{ provide: HTTP_INTERCEPTORS, useClass: RMMHttpInterceptorService, multi: true },
{ provide: ErrorHandler, useClass: SentryErrorHandler },
{ provide: SwRegistrationOptions,
useFactory: () => ({ registrationStrategy: 'registerWithDelay:5000' }) }
],
bootstrap: [MainContainerComponent]
})
Expand Down
21 changes: 10 additions & 11 deletions src/app/updatealert/updatealert.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
// along with Runbox 7. If not, see <https://www.gnu.org/licenses/>.
// ---------- END RUNBOX LICENSE ----------

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

interface UpdateStatus {
type: string;
Expand All @@ -47,7 +47,7 @@ export class UpdateAlertService {
{'hash':'blah', 'appData':{'commit':'test', 'build_time': 'time', 'build_epoch':'XX'}},
};
constructor(
private appRef: ApplicationRef,
private ngZone: NgZone,
private swupdate: SwUpdate,
dialog: MatDialog
) {
Expand All @@ -70,19 +70,18 @@ export class UpdateAlertService {
this.updateIsReady.next(true);
});

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

checkForUpdates() {
console.log(' checking for updates');
this.swupdate.checkForUpdate()
.then(() => this.checkForUpdates())
.catch((err) => console.log('Unable to check for updates', err));
}
}

0 comments on commit 1c0b6b1

Please sign in to comment.