Skip to content

Commit

Permalink
fix(time): Atomic clock won't speed up when the app is backgrounded
Browse files Browse the repository at this point in the history
Better management of the Pause and resume state
  • Loading branch information
MathieuNls committed Mar 28, 2017
1 parent acfa962 commit e04ffad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="Toolwatch.Toolwatch" version="1.3.6" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget id="toolwatch.toolwatch" version="1.3.7" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Toolwatch - Watch accuracy app</name>
<description>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!</description>
<author email="[email protected]" href="https://toolwatch.io/">Mathieu Nayrolles</author>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 14 additions & 7 deletions src/pages/time/time.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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
) {
Expand All @@ -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() {
Expand All @@ -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();
Expand Down

0 comments on commit e04ffad

Please sign in to comment.