-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
app.component.ts
986 lines (924 loc) · 32.8 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
import {
AfterViewInit,
Component,
ViewChild,
ViewEncapsulation,
} from '@angular/core';
import { Router } from '@angular/router';
import { AppMinimize } from '@ionic-native/app-minimize/ngx';
import { Globalization } from '@ionic-native/globalization/ngx';
import { Keyboard } from '@ionic-native/keyboard/ngx';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import {
ThreeDeeTouch,
ThreeDeeTouchQuickAction,
} from '@ionic-native/three-dee-touch/ngx';
import {
IonRouterOutlet,
MenuController,
ModalController,
Platform,
} from '@ionic/angular';
import { TranslateService } from '@ngx-translate/core';
import { Chart, registerables } from 'chart.js';
/** Third party */
import moment from 'moment';
import { Settings } from '../classes/settings/settings';
import LINK_TRACKING from '../data/tracking/linkTracking';
import STARTUP_TRACKING from '../data/tracking/startupTracking';
import { STARTUP_VIEW_ENUM } from '../enums/settings/startupView';
import { environment } from '../environments/environment';
import { AnalyticsPopoverComponent } from '../popover/analytics-popover/analytics-popover.component';
import { WelcomePopoverComponent } from '../popover/welcome-popover/welcome-popover.component';
import { AndroidPlatformService } from '../services/androidPlatform/android-platform.service';
import { CleanupService } from '../services/cleanupService/cleanup.service';
import { IntentHandlerService } from '../services/intentHandler/intent-handler.service';
import { IosPlatformService } from '../services/iosPlatform/ios-platform.service';
import { UIAlert } from '../services/uiAlert';
import { UIAnalytics } from '../services/uiAnalytics';
import { UIBeanHelper } from '../services/uiBeanHelper';
import { UIBeanStorage } from '../services/uiBeanStorage';
import { UIBrewHelper } from '../services/uiBrewHelper';
import { UIBrewStorage } from '../services/uiBrewStorage';
import { UIGreenBeanStorage } from '../services/uiGreenBeanStorage';
import { UIHelper } from '../services/uiHelper';
import { UILog } from '../services/uiLog';
import { UIMillHelper } from '../services/uiMillHelper';
import { UIMillStorage } from '../services/uiMillStorage';
import { UIPreparationHelper } from '../services/uiPreparationHelper';
import { UIPreparationStorage } from '../services/uiPreparationStorage';
import { UIRoastingMachineStorage } from '../services/uiRoastingMachineStorage';
import { UISettingsStorage } from '../services/uiSettingsStorage';
import { UIUpdate } from '../services/uiUpdate';
import { UiVersionStorage } from '../services/uiVersionStorage';
import { UIWaterStorage } from '../services/uiWaterStorage';
import { Device } from '@ionic-native/device/ngx';
import { AppVersion } from '@ionic-native/app-version/ngx';
import { Storage } from '@ionic/storage';
import 'chartjs-adapter-luxon';
import ChartStreaming from 'chartjs-plugin-streaming';
import zoomPlugin from 'chartjs-plugin-zoom';
import annotationPlugin from 'chartjs-plugin-annotation';
import { UIToast } from '../services/uiToast';
import {
CoffeeBluetoothDevicesService,
CoffeeBluetoothServiceEvent,
} from '../services/coffeeBluetoothDevices/coffee-bluetooth-devices.service';
import { PressureType, ScaleType, TemperatureType } from '../classes/devices';
import { Logger } from '../classes/devices/common/logger';
declare var AppRate;
declare var window;
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
encapsulation: ViewEncapsulation.None,
})
export class AppComponent implements AfterViewInit {
public toggleAbout: boolean = false;
public registerBackFunction: any;
@ViewChild(IonRouterOutlet, { static: false })
public routerOutlet: IonRouterOutlet;
public pages = {
home: { title: 'NAV_HOME', url: '/', icon: 'home-outline', active: true },
scale: {
title: 'SCALE',
url: '/scale-test',
icon: 'home-outline',
active: true,
},
roasting_section: {
title: 'NAV_ROASTING_SECTION',
url: '/roasting-section',
active: false,
},
water_section: {
title: 'NAV_WATER_SECTION',
url: '/water-section',
active: false,
},
settings: {
title: 'NAV_SETTINGS',
url: '/settings',
icon: 'settings-outline',
active: false,
},
info: {
title: 'NAV_INFORMATION_TO_APP',
url: '/info',
icon: 'information-circle-outline',
active: false,
},
about: {
title: 'NAV_ABOUT_US',
url: '/info/about',
icon: 'information-circle-outline',
active: false,
},
contact: {
title: 'NAV_CONTACT',
url: '/info/contact',
icon: 'mail-outline',
active: false,
},
privacy: {
title: 'NAV_PRIVACY',
url: '/info/privacy',
icon: 'documents-outline',
active: false,
},
credits: {
title: 'NAV_CREDITS',
url: '/info/credits',
icon: 'documents-outline',
active: false,
},
terms: {
title: 'NAV_TERMS',
url: '/info/terms',
icon: 'documents-outline',
active: false,
},
thanks: {
title: 'NAV_THANKS',
url: '/info/thanks',
icon: 'happy-outline',
active: false,
},
licences: {
title: 'NAV_LICENCES',
url: '/info/licences',
icon: 'copy-outline',
active: false,
},
statistic: {
title: 'NAV_STATISTICS',
url: '/statistic',
icon: 'analytics-outline',
active: false,
},
logs: {
title: 'NAV_LOGS',
url: '/info/logs',
icon: 'logo-buffer',
active: false,
},
helper: {
title: 'NAV_HELPER',
url: '/helper',
icon: 'logo-buffer',
active: false,
},
helper_brew_ratio: {
title: 'PAGE_HELPER_BREW_RATIO',
url: '/helper/brew-ratio',
icon: 'construct-outline',
active: false,
},
helper_water_hardness: {
title: 'PAGE_HELPER_WATER_HARDNESS',
url: '/helper/water-hardness',
icon: 'construct-outline',
active: false,
},
brew_parameter: {
title: 'NAV_BREW_PARAMS',
url: '/brew-parameter',
icon: 'construct-outline',
active: false,
},
bean_parameter: {
title: 'NAV_BEAN_PARAMS',
url: '/bean-parameter',
icon: 'construct-outline',
active: false,
},
};
constructor(
private readonly router: Router,
public platform: Platform,
public statusBar: StatusBar,
public splashScreen: SplashScreen,
private readonly uiLog: UILog,
private readonly uiBeanStorage: UIBeanStorage,
private readonly uiBrewStorage: UIBrewStorage,
private readonly uiPreparationStorage: UIPreparationStorage,
private readonly uiMillStorage: UIMillStorage,
private readonly uiBrewHelper: UIBrewHelper,
private readonly menuCtrl: MenuController,
private readonly appMinimize: AppMinimize,
private readonly uiSettingsStorage: UISettingsStorage,
private readonly keyboard: Keyboard,
private readonly threeDeeTouch: ThreeDeeTouch,
private readonly modalCtrl: ModalController,
private readonly uiHelper: UIHelper,
private readonly uiAlert: UIAlert,
private _translate: TranslateService,
private globalization: Globalization,
private readonly uiAnalytics: UIAnalytics,
private readonly menu: MenuController,
private readonly uiUpdate: UIUpdate,
private readonly uiVersionStorage: UiVersionStorage,
private readonly uiGreenBeanStorage: UIGreenBeanStorage,
private readonly uiRoastingMachineStorage: UIRoastingMachineStorage,
private readonly intentHandlerService: IntentHandlerService,
private readonly iosPlatformService: IosPlatformService,
private readonly androidPlatformService: AndroidPlatformService,
private readonly uiWaterStorage: UIWaterStorage,
private readonly uiBeanHelper: UIBeanHelper,
private readonly uiMillHelper: UIMillHelper,
private readonly uiPreparationHelper: UIPreparationHelper,
private readonly bleManager: CoffeeBluetoothDevicesService,
private readonly cleanupService: CleanupService,
private readonly device: Device,
private readonly appVersion: AppVersion,
private readonly storage: Storage,
private readonly uiToast: UIToast
) {
// Dont remove androidPlatformService, we need to initialize it via constructor
try {
// Touch DB Factory to make sure, it is properly initialized even on iOS 14.6
const db = window.indexedDB;
} catch (ex) {}
try {
// Touch DB Factory to make sure, it is properly initialized even on iOS 14.6
const db = window.sqlitePlugin;
} catch (ex) {}
}
public ngOnInit() {}
public ngAfterViewInit(): void {
this.uiLog.log('Platform ready, init app');
Chart.register(...registerables);
Chart.register(ChartStreaming);
Chart.register(zoomPlugin);
Chart.register(annotationPlugin);
this.__appReady();
}
public dismiss() {
this.menu.close();
}
public isAndroid() {
try {
const isAndroid: boolean = this.platform.is('android');
return isAndroid;
} catch (ex) {
return false;
}
}
private __appReady(): void {
this.uiLog.log(`App Ready, wait for Platform ready`);
this.platform.ready().then(async () => {
try {
// #285 - Add more device loggings
this.uiLog.log(`Device-Model: ${this.device.model}`);
this.uiLog.log(`Manufacturer: ${this.device.manufacturer}`);
this.uiLog.log(`Platform: ${this.device.platform}`);
this.uiLog.log(`Version: ${this.device.version}`);
if (this.platform.is('cordova')) {
const versionCode: string | number =
await this.appVersion.getVersionNumber();
this.uiLog.log(`App-Version: ${versionCode}`);
this.uiLog.log(`Storage-Driver: ${this.storage.driver}`);
}
} catch (ex) {}
try {
Logger.attachOnLog().subscribe((_msg) => {
if (_msg.type === 'LOG') {
this.uiLog.log(_msg.log);
}
if (_msg.type === 'INFO') {
this.uiLog.info(_msg.log);
}
if (_msg.type === 'ERROR') {
this.uiLog.error(_msg.log);
}
if (_msg.type === 'DEBUG') {
this.uiLog.debug(_msg.log);
}
});
} catch (ex) {}
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
// #7
this.statusBar.show();
this.statusBar.styleDefault();
this.splashScreen.hide();
this.keyboard.hideFormAccessoryBar(false);
if (environment.production === true) {
// When we're in cordova, disable the log messages
this.uiLog.disable();
}
Logger.disableLog();
if (this.platform.is('ios')) {
this.uiLog.log(`iOS Device - attach to home icon pressed`);
this.threeDeeTouch.onHomeIconPressed().subscribe(async (payload) => {
/* We need to wait for app finished loading, but already attach on platform start, else
* the event won't get triggered **/
this.uiHelper.isBeanconqurorAppReady().then(async () => {
const payloadType = payload.type;
try {
this.uiAnalytics.trackEvent(
STARTUP_TRACKING.TITLE,
STARTUP_TRACKING.ACTIONS.FORCE_TOUCH.CATEGORY,
payloadType.toUpperCase()
);
this.uiLog.log(`iOS Device - Home icon was pressed`);
} catch (ex) {}
if (payload.type === 'Brew') {
await this.__trackNewBrew();
} else if (payload.type === 'Bean') {
await this.__trackNewBean();
} else if (payload.type === 'Preparation') {
await this.__trackNewPreparation();
} else if (payload.type === 'Mill') {
await this.__trackNewMill();
}
});
// returns an object that is the button you presed
});
}
if (this.platform.is('cordova')) {
// Just support deeplinks on devices.
this.intentHandlerService.attachOnHandleOpenUrl();
}
// Before we update and show messages, we need atleast to set one default language.
this._translate.setDefaultLang('en');
await this._translate.use('en').toPromise();
if (this.platform.is('ios')) {
await this.__checkIOSBackup();
} else if (this.platform.is('android')) {
await this.__checkAndroidBackup();
}
try {
await this.uiBeanStorage.initializeStorage();
await this.uiPreparationStorage.initializeStorage();
await this.uiSettingsStorage.initializeStorage();
await this.uiBrewStorage.initializeStorage();
await this.uiMillStorage.initializeStorage();
await this.uiVersionStorage.initializeStorage();
await this.uiGreenBeanStorage.initializeStorage();
await this.uiRoastingMachineStorage.initializeStorage();
await this.uiWaterStorage.initializeStorage();
// Wait for every necessary service to be ready before starting the app
// Settings and version, will create a new object on start, so we need to wait for this in the end.
const beanStorageReadyCallback = this.uiBeanStorage.storageReady();
const preparationStorageReadyCallback =
this.uiPreparationStorage.storageReady();
const uiSettingsStorageReadyCallback =
this.uiSettingsStorage.storageReady();
const brewStorageReadyCallback = this.uiBrewStorage.storageReady();
const millStorageReadyCallback = this.uiMillStorage.storageReady();
const versionStorageReadyCallback =
this.uiVersionStorage.storageReady();
const greenBeanStorageCallback = this.uiGreenBeanStorage.storageReady();
const roastingMachineStorageCallback =
this.uiRoastingMachineStorage.storageReady();
const waterStorageCallback = this.uiWaterStorage.storageReady();
Promise.all([
beanStorageReadyCallback,
preparationStorageReadyCallback,
brewStorageReadyCallback,
uiSettingsStorageReadyCallback,
millStorageReadyCallback,
versionStorageReadyCallback,
greenBeanStorageCallback,
roastingMachineStorageCallback,
waterStorageCallback,
]).then(
async () => {
this.uiLog.log('App finished loading');
this.uiLog.info('Everything should be fine!!!');
await this.__checkUpdate();
await this.__checkCleanup();
await this.__initApp();
this.uiHelper.setAppReady(1);
},
async () => {
await this.uiAlert.showAppShetItSelfMessage();
this.uiLog.error('App finished loading, but errors occured');
}
);
} catch (ex) {
await this.uiAlert.showAppShetItSelfMessage();
this.uiLog.error('App finished loading, but errors occured');
}
});
}
private async __checkUpdate() {
try {
await this.uiUpdate.checkUpdate();
} catch (ex) {}
}
private async __checkCleanup() {
try {
await this.cleanupService.cleanupOldBrewData();
} catch (ex) {}
}
private async __checkAndroidBackup() {
try {
await this.androidPlatformService.checkAndroidBackup();
} catch (ex) {}
}
private async __checkIOSBackup() {
try {
await this.iosPlatformService.checkIOSBackup();
} catch (ex) {}
}
public showRoastingSection() {
const settings: Settings = this.uiSettingsStorage.getSettings();
return settings.show_roasting_section;
}
public showWaterSection() {
const settings: Settings = this.uiSettingsStorage.getSettings();
return settings.show_water_section;
}
private async __setDeviceLanguage(): Promise<any> {
return new Promise(async (resolve, reject) => {
const settings: Settings = this.uiSettingsStorage.getSettings();
if (this.platform.is('cordova')) {
try {
this.uiLog.info('Its a mobile device, try to set language now');
if (
settings.language === null ||
settings.language === undefined ||
settings.language === ''
) {
this.globalization
.getPreferredLanguage()
.then(async (res) => {
// Run other functions after getting device default lang
let systemLanguage: string = res['value'].toLowerCase();
this.uiLog.log(`Found system language: ${systemLanguage}`);
if (systemLanguage.indexOf('-') > -1) {
systemLanguage = systemLanguage.split('-')[0];
}
let settingLanguage: string = '';
if (systemLanguage === 'de') {
settingLanguage = 'de';
} else if (systemLanguage === 'es') {
settingLanguage = 'es';
} else if (systemLanguage === 'tr') {
settingLanguage = 'tr';
} else if (systemLanguage === 'zh') {
settingLanguage = 'zh';
} else {
settingLanguage = 'en';
}
this.uiLog.log(`Setting language: ${settingLanguage}`);
this._translate.setDefaultLang(settingLanguage);
settings.language = settingLanguage;
await this.uiSettingsStorage.saveSettings(settings);
await this._translate.use(settingLanguage).toPromise();
moment.locale(settingLanguage);
resolve(undefined);
})
.catch(async (ex) => {
const exMessage: string = JSON.stringify(ex);
this.uiLog.error(
`Exception occured when setting language ${exMessage}`
);
this._translate.setDefaultLang('en');
await this._translate.use('en').toPromise();
moment.locale('en');
resolve(undefined);
});
} else {
this.uiLog.info('Language settings already existing, set language');
const settingLanguage: string = settings.language;
this.uiLog.log(`Setting language: ${settingLanguage}`);
this._translate.setDefaultLang(settingLanguage);
await this._translate.use(settingLanguage).toPromise();
moment.locale(settingLanguage);
resolve(undefined);
}
} catch (ex) {
const exMessage: string = JSON.stringify(ex);
this.uiLog.error(
`Exception occured when setting language ${exMessage}`
);
this._translate.setDefaultLang('en');
settings.language = 'en';
await this.uiSettingsStorage.saveSettings(settings);
await this._translate.use('en').toPromise();
moment.locale('en');
resolve(undefined);
}
} else {
this.uiLog.info(
'Cant set language for device, because no cordova device'
);
if (
settings.language !== null &&
settings.language !== undefined &&
settings.language !== ''
) {
this.uiLog.info(`Set language from settings: ${settings.language}`);
this._translate.setDefaultLang(settings.language);
await this._translate.use(settings.language).toPromise();
moment.locale(settings.language);
resolve(undefined);
} else {
this.uiLog.info(
`Set default language from settings, because no settings set: en `
);
this._translate.setDefaultLang('en');
settings.language = 'en';
await this.uiSettingsStorage.saveSettings(settings);
await this._translate.use('en').toPromise();
moment.locale(settings.language);
resolve(undefined);
}
}
});
}
private async __checkStartupView() {
const settings: Settings = this.uiSettingsStorage.getSettings();
if (settings.startup_view !== STARTUP_VIEW_ENUM.HOME_PAGE) {
this.uiAnalytics.trackEvent(
STARTUP_TRACKING.TITLE,
STARTUP_TRACKING.ACTIONS.STARTUP_VIEW.CATEGORY,
settings.startup_view
);
}
switch (settings.startup_view) {
case STARTUP_VIEW_ENUM.HOME_PAGE:
this.router.navigate(['/home/dashboard'], { replaceUrl: true });
break;
case STARTUP_VIEW_ENUM.BREW_PAGE:
this.router.navigate(['/home/brews'], { replaceUrl: true });
break;
case STARTUP_VIEW_ENUM.ADD_BREW:
await this.__trackNewBrew();
this.router.navigate(['/home/brews'], { replaceUrl: true });
break;
case STARTUP_VIEW_ENUM.BEANS_PAGE:
this.router.navigate(['/home/beans'], { replaceUrl: true });
break;
}
}
private async __initApp() {
this.__registerBack();
await this.__setDeviceLanguage();
// After we set the right device language, we check now if we can request external storage
if (this.platform.is('cordova') && this.platform.is('android')) {
try {
await this.androidPlatformService.checkHasExternalStorage();
} catch (ex) {}
}
this.__setThreeDeeTouchActions();
await this.uiAnalytics.initializeTracking();
await this.__checkWelcomePage();
await this.__checkAnalyticsInformationPage();
await this.uiUpdate.checkUpdateScreen();
// #281 - Connect smartscale before checking the startup view
setTimeout(async () => {
// Just connect after 5 seconds, to get some time, and maybe handle all the connection errors
if (this.platform.is('ios')) {
await this.bleManager.enableIOSBluetooth();
}
this.__checkBluetoothDevices();
this.__connectPressureDevice();
this.__connectSmartScale();
this.__connectTemperatureDevice();
}, 3000);
const settings = this.uiSettingsStorage.getSettings();
if (
settings.scale_log === true ||
settings.pressure_log === true ||
settings.temperature_log === true
) {
Logger.enableLog();
} else {
Logger.disableLog();
}
await this.__checkStartupView();
this.__instanceAppRating();
this.__attachOnDevicePause();
this.__attachOnDeviceResume();
const bleSubscription = this.bleManager
.attachOnEvent()
.subscribe((_type) => {
if (_type === CoffeeBluetoothServiceEvent.CONNECTED_SCALE) {
this.uiToast.showInfoToast(
this._translate.instant('SCALE.CONNECTED_SUCCESSFULLY') +
' - ' +
this.bleManager.getScale().device_name +
' / ' +
this.bleManager.getScale().device_id,
false
);
} else if (_type === CoffeeBluetoothServiceEvent.DISCONNECTED_SCALE) {
this.uiToast.showInfoToast('SCALE.DISCONNECTED_UNPLANNED');
} else if (_type === CoffeeBluetoothServiceEvent.CONNECTED_PRESSURE) {
this.uiToast.showInfoToast(
this._translate.instant('PRESSURE.CONNECTED_SUCCESSFULLY') +
' - ' +
this.bleManager.getPressureDevice().device_name +
' / ' +
this.bleManager.getPressureDevice().device_id,
false
);
} else if (
_type === CoffeeBluetoothServiceEvent.DISCONNECTED_PRESSURE
) {
this.uiToast.showInfoToast('PRESSURE.DISCONNECTED_UNPLANNED');
} else if (
_type === CoffeeBluetoothServiceEvent.CONNECTED_TEMPERATURE
) {
this.uiToast.showInfoToast(
this._translate.instant('TEMPERATURE.CONNECTED_SUCCESSFULLY') +
' - ' +
this.bleManager.getTemperatureDevice().device_name +
' / ' +
this.bleManager.getTemperatureDevice().device_id,
false
);
} else if (
_type === CoffeeBluetoothServiceEvent.DISCONNECTED_TEMPERATURE
) {
this.uiToast.showInfoToast('TEMPERATURE.DISCONNECTED_UNPLANNED');
}
});
}
private async __checkBluetoothDevices() {
const settings = this.uiSettingsStorage.getSettings();
const pressure_id: string = settings.pressure_id;
const temperature_id: string = settings.temperature_id;
const searchIds: Array<any> = [];
const scale_id: string = settings.scale_id;
if (scale_id) {
searchIds.push(scale_id);
}
if (pressure_id) {
searchIds.push(pressure_id);
}
if (temperature_id) {
searchIds.push(temperature_id);
}
try {
//this.bleManager.scanAllBluetoothDevicesAndPassBack();
this.bleManager.findDeviceWithDirectIds(searchIds, 60000);
} catch (ex) {}
}
private __connectSmartScale() {
const settings = this.uiSettingsStorage.getSettings();
const scale_id: string = settings.scale_id;
const scale_type: ScaleType = settings.scale_type;
this.uiLog.log(`Connect smartscale? ${scale_id}`);
if (scale_id !== undefined && scale_id !== '') {
this.bleManager.autoConnectScale(
scale_type,
scale_id,
false,
() => {},
() => {}
);
} else {
this.uiLog.log('Smartscale not connected, dont try to connect');
}
}
private __connectPressureDevice() {
const settings = this.uiSettingsStorage.getSettings();
const pressure_id: string = settings.pressure_id;
const pressure_type: PressureType = settings.pressure_type;
this.uiLog.log(`Connect pressure device? ${pressure_id}`);
if (pressure_id !== undefined && pressure_id !== '') {
this.bleManager.autoConnectPressureDevice(
pressure_type,
pressure_id,
false,
() => {},
() => {}
);
} else {
this.uiLog.log('Pressure device not connected, dont try to connect');
}
}
private __connectTemperatureDevice() {
const settings = this.uiSettingsStorage.getSettings();
const temperature_id: string = settings.temperature_id;
const temperature_type: TemperatureType = settings.temperature_type;
this.uiLog.log(`Connect temperature device? ${temperature_id}`);
if (temperature_id !== undefined && temperature_id !== '') {
this.bleManager.autoConnectTemperatureDevice(
temperature_type,
temperature_id,
false,
() => {},
() => {}
);
} else {
this.uiLog.log('Temperature device not connected, dont try to connect');
}
}
private __attachOnDevicePause() {
this.platform.pause.subscribe(async () => {
const settings: Settings = this.uiSettingsStorage.getSettings();
if (settings.bluetooth_scale_stay_connected === false) {
const decent_scale_id: string = settings.scale_id;
if (decent_scale_id !== undefined && decent_scale_id !== '') {
// Don't show message on device pause.
this.bleManager.disconnect(settings.scale_id, false);
}
}
if (settings.pressure_stay_connected === false) {
const pressure_id: string = settings.pressure_id;
if (pressure_id !== undefined && pressure_id !== '') {
// Don't show message on device pause.
this.bleManager.disconnectPressureDevice(settings.pressure_id, false);
}
}
if (settings.temperature_stay_connected === false) {
const temperature_id: string = settings.temperature_id;
if (temperature_id !== undefined && temperature_id !== '') {
// Don't show message on device pause.
this.bleManager.disconnectTemperatureDevice(
settings.temperature_id,
false
);
}
}
});
}
private __attachOnDeviceResume() {
this.platform.resume.subscribe(async () => {
const settings: Settings = this.uiSettingsStorage.getSettings();
if (settings.bluetooth_scale_stay_connected === false) {
this.__connectSmartScale();
}
if (settings.pressure_stay_connected === false) {
this.__connectPressureDevice();
}
if (settings.temperature_stay_connected === false) {
this.__connectTemperatureDevice();
}
});
}
private __setThreeDeeTouchActions() {
// Ignore for now
if (this.platform.is('ios')) {
const actions: ThreeDeeTouchQuickAction[] = [
{
type: 'Brew',
title: this._translate.instant('THREE_DEE_TOUCH_ACTION_BREW'),
iconType: 'Add',
},
{
type: 'Bean',
title: this._translate.instant('THREE_DEE_TOUCH_ACTION_BEAN'),
iconType: 'Add',
},
{
type: 'Preparation',
title: this._translate.instant('THREE_DEE_TOUCH_ACTION_PREPARATION'),
iconType: 'Add',
},
{
type: 'Mill',
title: this._translate.instant('THREE_DEE_TOUCH_ACTION_MILL'),
iconType: 'Add',
},
];
this.threeDeeTouch.configureQuickActions(actions);
}
}
private __instanceAppRating() {
if (this.platform.is('cordova')) {
const appLanguage = this.uiSettingsStorage.getSettings().language;
AppRate.setPreferences({
usesUntilPrompt: 25,
storeAppURL: {
ios: '1445297158',
android: 'market://details?id=com.beanconqueror.app',
},
promptAgainForEachNewVersion: false,
reviewType: {
ios: 'AppStoreReview',
android: 'InAppReview',
},
useLanguage: appLanguage,
});
AppRate.promptForRating(false);
}
}
private async __trackNewBrew() {
if (this.uiBrewHelper.canBrew()) {
await this.uiBrewHelper.addBrew();
this.router.navigate(['/home/brews'], { replaceUrl: true });
}
}
private async __checkWelcomePage() {
const settings = this.uiSettingsStorage.getSettings();
const welcomePagedShowed: boolean = settings.welcome_page_showed;
if (!welcomePagedShowed) {
const modal = await this.modalCtrl.create({
component: WelcomePopoverComponent,
id: 'welcome-popover',
});
await modal.present();
await modal.onWillDismiss();
}
}
private async __checkAnalyticsInformationPage() {
const settings = this.uiSettingsStorage.getSettings();
const matomo_analytics: boolean = settings.matomo_analytics;
if (matomo_analytics === undefined) {
const modal = await this.modalCtrl.create({
component: AnalyticsPopoverComponent,
id: AnalyticsPopoverComponent.POPOVER_ID,
});
await modal.present();
await modal.onWillDismiss();
}
}
private async __trackNewBean() {
await this.uiBeanHelper.addBean();
this.router.navigate(['/'], { replaceUrl: true });
}
private async __trackNewPreparation() {
await this.uiPreparationHelper.addPreparation();
this.router.navigate(['/'], { replaceUrl: true });
}
private async __trackNewMill() {
await this.uiMillHelper.addMill();
this.router.navigate(['/'], { replaceUrl: true });
}
private __registerBack() {
this.platform.backButton.subscribeWithPriority(0, () => {
// NAvigation handler
if (
this.router.url.indexOf('/home') === -1 &&
this.routerOutlet &&
this.routerOutlet.canGoBack()
) {
this.routerOutlet.pop();
} else if (this.router.url.indexOf('/home') >= 0) {
this.appMinimize.minimize();
// or if that doesn't work, try
// navigator['app'].exitApp();
} else {
this.router.navigate(['/home/dashboard'], { replaceUrl: true });
// this.generic.showAlert("Exit", "Do you want to exit the app?", this.onYesHandler, this.onNoHandler, "backPress");
}
});
}
public openGithub() {
this.uiAnalytics.trackEvent(
LINK_TRACKING.TITLE,
LINK_TRACKING.ACTIONS.GITHUB
);
this.uiHelper.openExternalWebpage(
'https://github.com/graphefruit/Beanconqueror'
);
}
public openDiscord() {
this.uiAnalytics.trackEvent(
LINK_TRACKING.TITLE,
LINK_TRACKING.ACTIONS.DISCORD
);
this.uiHelper.openExternalWebpage('https://discord.gg/vDzA5dZjG8');
}
public openInstagram() {
this.uiAnalytics.trackEvent(
LINK_TRACKING.TITLE,
LINK_TRACKING.ACTIONS.INSTAGRAM
);
this.uiHelper.openExternalWebpage(
'https://www.instagram.com/beanconqueror/'
);
}
public openFacebook() {
this.uiAnalytics.trackEvent(
LINK_TRACKING.TITLE,
LINK_TRACKING.ACTIONS.FACEBOOK
);
this.uiHelper.openExternalWebpage(
'https://www.facebook.com/Beanconqueror/'
);
}
public openPaypal() {
this.uiAnalytics.trackEvent(
LINK_TRACKING.TITLE,
LINK_TRACKING.ACTIONS.PAYPAL
);
this.uiHelper.openExternalWebpage(
'https://www.paypal.com/paypalme/LarsSaalbach'
);
}
public openGithubSponsor() {
this.uiAnalytics.trackEvent(
LINK_TRACKING.TITLE,
LINK_TRACKING.ACTIONS.GITHUB_SPONSOR
);
this.uiHelper.openExternalWebpage(
'https://github.com/sponsors/graphefruit'
);
}
public openDonatePage() {
this.uiAnalytics.trackEvent(
LINK_TRACKING.TITLE,
LINK_TRACKING.ACTIONS.BUY_ME_A_COFFEE
);
this.uiHelper.openExternalWebpage('https://ko-fi.com/beanconqueror');
}
}