From e04ffad900c5cbc73f13bfa16dfb2cddda1e02c6 Mon Sep 17 00:00:00 2001 From: Mathieu Nayrolles Date: Tue, 28 Mar 2017 06:48:24 -0400 Subject: [PATCH] fix(time): Atomic clock won't speed up when the app is backgrounded Better management of the Pause and resume state --- config.xml | 2 +- package.json | 2 +- src/pages/time/time.ts | 21 ++++++++++++++------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/config.xml b/config.xml index 544a488..ff27795 100755 --- a/config.xml +++ b/config.xml @@ -1,5 +1,5 @@ - + Toolwatch - Watch accuracy app Measure and track the accuracy of your mechanical watches. Toolwatch is a free watch accuracy app trusted by the watchmaking industry's leaders and 15 000+ monthly users. Is your watch accurate? Should it be serviced? How does it compare versus other watches? Find out now by measuring the accuracy of your watch! Mathieu Nayrolles diff --git a/package.json b/package.json index 1873ff9..4f91a22 100755 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "toolwatch-mobile", "author": "Mathieu Nayrolles", "homepage": "https://toolwatch.io/", - "version": "1.3.6", + "version": "1.3.7", "private": true, "scripts": { "ionic:build": "npm run assets && ionic-app-scripts build", diff --git a/src/pages/time/time.ts b/src/pages/time/time.ts index fc482fb..b145e26 100755 --- a/src/pages/time/time.ts +++ b/src/pages/time/time.ts @@ -1,4 +1,4 @@ -import {Loading, NavController, LoadingController, NavParams} from 'ionic-angular'; +import {Loading, NavController, LoadingController, NavParams, Platform } from 'ionic-angular'; import {Component, ElementRef} from '@angular/core'; @@ -35,6 +35,7 @@ export class TimePage extends ClockComponent{ private twapi: TwAPIService, private translate: TranslateService, private loadingController: LoadingController, + private platform: Platform, //injection for ClockComponent elementRef: ElementRef ) { @@ -52,13 +53,20 @@ export class TimePage extends ClockComponent{ document.addEventListener('resume', () => { console.log("resume") - this.ngAfterViewInit(); + }); - } - ionViewCanLeave():boolean { - clearInterval(this.interval); - return true; + platform.ready().then(() => { + this.platform.pause.subscribe(() => { + console.log('[INFO] App paused'); + clearInterval(this.interval); + }); + + this.platform.resume.subscribe(() => { + console.log('[INFO] App resumed'); + this.ngAfterViewInit(); + }); + }); } ngAfterViewInit() { @@ -67,7 +75,6 @@ export class TimePage extends ClockComponent{ this.twapi.accurateTime().then( date => { - clearInterval(this.interval); this.interval = setInterval(()=>{ this.date = new Date(this.date.getTime() + this.intervalTime); this.initLocalClocks();