-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.component.ts
46 lines (41 loc) · 1.69 KB
/
app.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Component, OnInit, OnDestroy, NgZone } from '@angular/core';
import { TNSFontIconService } from 'nativescript-ng2-fonticon';
import { BackgroundService } from './service/core/background.service';
import * as connectivity from 'connectivity';
import * as moment from 'moment';
@Component({
selector: 'app',
templateUrl: 'app.component.html'
})
export class AppComponent implements OnInit, OnDestroy {
constructor(private tnsFontIconService: TNSFontIconService,
private backgroundService: BackgroundService, private zone: NgZone) {
moment.locale('zh-cn');
}
ngOnInit() {
console.log('app component on init');
connectivity.startMonitoring((newConnectionType: number) => {
this.zone.run(() => {
console.log('connecction type ' + newConnectionType);
switch (newConnectionType) {
case connectivity.connectionType.none:
this.backgroundService.connectionChange('none');
console.log('connection type change to none');
break;
case connectivity.connectionType.wifi:
this.backgroundService.connectionChange('wifi');
console.log('Connection type changed to WiFi.');
break;
default:
this.backgroundService.connectionChange('mobile');
console.log('Connection type changed to mobile.');
break;
}
});
});
}
ngOnDestroy() {
console.log('app component on destroy');
connectivity.stopMonitoring();
}
}