From 9589365bb7ec265e1234d934d81615b413f1d997 Mon Sep 17 00:00:00 2001 From: Lars Saalbach Date: Sat, 5 Oct 2024 12:44:30 +0200 Subject: [PATCH] #805 - Removing insomnia plugin and using from capacitor now. --- android/app/capacitor.build.gradle | 1 + android/capacitor.settings.gradle | 3 ++ ios/App/Podfile | 1 + ios/App/Podfile.lock | 8 ++++- package-lock.json | 36 ++++++------------- package.json | 3 +- .../brew/brew-add/brew-add.component.spec.ts | 2 -- src/app/brew/brew-add/brew-add.component.ts | 16 +++------ .../brew-edit/brew-edit.component.spec.ts | 2 -- src/app/brew/brew-edit/brew-edit.component.ts | 12 ++----- src/app/shared/shared.module.ts | 2 -- src/services/uiHelper.ts | 12 +++++++ 12 files changed, 42 insertions(+), 56 deletions(-) diff --git a/android/app/capacitor.build.gradle b/android/app/capacitor.build.gradle index 6e4e3f66..69c78c4b 100644 --- a/android/app/capacitor.build.gradle +++ b/android/app/capacitor.build.gradle @@ -9,6 +9,7 @@ android { apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle" dependencies { + implementation project(':capacitor-community-keep-awake') implementation project(':capacitor-app') implementation project(':capacitor-barcode-scanner') implementation project(':capacitor-camera') diff --git a/android/capacitor.settings.gradle b/android/capacitor.settings.gradle index b1cee40f..7762a332 100644 --- a/android/capacitor.settings.gradle +++ b/android/capacitor.settings.gradle @@ -2,6 +2,9 @@ include ':capacitor-android' project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor') +include ':capacitor-community-keep-awake' +project(':capacitor-community-keep-awake').projectDir = new File('../node_modules/@capacitor-community/keep-awake/android') + include ':capacitor-app' project(':capacitor-app').projectDir = new File('../node_modules/@capacitor/app/android') diff --git a/ios/App/Podfile b/ios/App/Podfile index adee1431..1dc9db83 100644 --- a/ios/App/Podfile +++ b/ios/App/Podfile @@ -11,6 +11,7 @@ install! 'cocoapods', :disable_input_output_paths => true def capacitor_pods pod 'Capacitor', :path => '../../node_modules/@capacitor/ios' pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios' + pod 'CapacitorCommunityKeepAwake', :path => '../../node_modules/@capacitor-community/keep-awake' pod 'CapacitorApp', :path => '../../node_modules/@capacitor/app' pod 'CapacitorBarcodeScanner', :path => '../../node_modules/@capacitor/barcode-scanner' pod 'CapacitorCamera', :path => '../../node_modules/@capacitor/camera' diff --git a/ios/App/Podfile.lock b/ios/App/Podfile.lock index 2ec4f087..85c23487 100644 --- a/ios/App/Podfile.lock +++ b/ios/App/Podfile.lock @@ -10,6 +10,8 @@ PODS: - Capacitor - CapacitorClipboard (6.0.1): - Capacitor + - CapacitorCommunityKeepAwake (5.0.1): + - Capacitor - CapacitorCordova (6.1.2) - CapacitorDevice (6.0.1): - Capacitor @@ -40,6 +42,7 @@ DEPENDENCIES: - "CapacitorBarcodeScanner (from `../../node_modules/@capacitor/barcode-scanner`)" - "CapacitorCamera (from `../../node_modules/@capacitor/camera`)" - "CapacitorClipboard (from `../../node_modules/@capacitor/clipboard`)" + - "CapacitorCommunityKeepAwake (from `../../node_modules/@capacitor-community/keep-awake`)" - "CapacitorCordova (from `../../node_modules/@capacitor/ios`)" - "CapacitorDevice (from `../../node_modules/@capacitor/device`)" - "CapacitorFilesystem (from `../../node_modules/@capacitor/filesystem`)" @@ -68,6 +71,8 @@ EXTERNAL SOURCES: :path: "../../node_modules/@capacitor/camera" CapacitorClipboard: :path: "../../node_modules/@capacitor/clipboard" + CapacitorCommunityKeepAwake: + :path: "../../node_modules/@capacitor-community/keep-awake" CapacitorCordova: :path: "../../node_modules/@capacitor/ios" CapacitorDevice: @@ -97,6 +102,7 @@ SPEC CHECKSUMS: CapacitorBarcodeScanner: 3057910347ab6c3db06e1a38bdf688a6a469227a CapacitorCamera: ed022171dbf3853e68eec877b4d78995378af6b7 CapacitorClipboard: 756cd7e83e8d5d19b0c74f40b57517c287bd5fe2 + CapacitorCommunityKeepAwake: e2ddd50812e3407f8dc3a2c28e97d66e9b59b2f5 CapacitorCordova: f48c89f96c319101cd2f0ce8a2b7449b5fb8b3dd CapacitorDevice: 7097a1deb4224b77fd13a6e60a355d0062a5d772 CapacitorFilesystem: 37fb3aa5c945b4539ab11c74a5c57925a302bf24 @@ -111,6 +117,6 @@ SPEC CHECKSUMS: OSBarcodeLib: 4bb4cc0b9850451fe71ba4953c1c934368e767df OSInAppBrowserLib: c3d0b21a0c8b6d81e69117ad08bb6b8a4849c4e1 -PODFILE CHECKSUM: 30fb69e4e19accf809b98b75f801bdc0e4181b2a +PODFILE CHECKSUM: ad0e379d6401d3e70e089ff32db2ec36e5499426 COCOAPODS: 1.15.2 diff --git a/package-lock.json b/package-lock.json index e12cc881..c1f9a8bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,8 +19,8 @@ "@awesome-cordova-plugins/deeplinks": "^6.4.0", "@awesome-cordova-plugins/file-chooser": "^6.4.0", "@awesome-cordova-plugins/image-picker": "^6.4.0", - "@awesome-cordova-plugins/insomnia": "^6.4.0", "@awesome-cordova-plugins/three-dee-touch": "^6.4.0", + "@capacitor-community/keep-awake": "^5.0.1", "@capacitor/android": "6.1.2", "@capacitor/app": "6.0.1", "@capacitor/barcode-scanner": "^1.0.1", @@ -88,7 +88,6 @@ "cordova-plugin-android-permissions": "^1.1.5", "cordova-plugin-ble-central": "^1.7.4", "cordova-plugin-health": "^2.1.0", - "cordova-plugin-insomnia": "^4.3.0", "cordova-sqlite-storage": "^5.1.0", "elliptic": ">=6.5.4", "husky": "^8.0.1", @@ -2110,18 +2109,6 @@ "rxjs": "^5.5.0 || ^6.5.0 || ^7.3.0" } }, - "node_modules/@awesome-cordova-plugins/insomnia": { - "version": "6.4.0", - "resolved": "https://registry.npmjs.org/@awesome-cordova-plugins/insomnia/-/insomnia-6.4.0.tgz", - "integrity": "sha512-WPNmpVM4JEcbBdHnKYAR8jEA1njirPR0sQvB/E9lul9biTKTe8J5CynzSSg1iQ+VDbwH2S6kVAI0DiB4V8TAVA==", - "dependencies": { - "@types/cordova": "latest" - }, - "peerDependencies": { - "@awesome-cordova-plugins/core": "^6.0.1", - "rxjs": "^5.5.0 || ^6.5.0 || ^7.3.0" - } - }, "node_modules/@awesome-cordova-plugins/three-dee-touch": { "version": "6.4.0", "resolved": "https://registry.npmjs.org/@awesome-cordova-plugins/three-dee-touch/-/three-dee-touch-6.4.0.tgz", @@ -3769,6 +3756,15 @@ "node": ">=6.9.0" } }, + "node_modules/@capacitor-community/keep-awake": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@capacitor-community/keep-awake/-/keep-awake-5.0.1.tgz", + "integrity": "sha512-5ZeJ5DQE5Aa1NwzD1kKv8IkHoLwKhkGYlURWHh4/SDrug0KBaGocKuk1q1TAk1nsCs6ndbSsEvUt2LZDoPo9SQ==", + "license": "MIT", + "peerDependencies": { + "@capacitor/core": "^6.0.0" + } + }, "node_modules/@capacitor/android": { "version": "6.1.2", "resolved": "https://registry.npmjs.org/@capacitor/android/-/android-6.1.2.tgz", @@ -7502,18 +7498,6 @@ } ] }, - "node_modules/cordova-plugin-insomnia": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/cordova-plugin-insomnia/-/cordova-plugin-insomnia-4.3.0.tgz", - "integrity": "sha512-MdlRFsyfmf6Q/8+npDeVSTo487eyrp7vbuGO3SPbnqR94DXmFRJWLbZGwf34dMeH6GQL45baxozUwhLTPxrQwg==", - "dev": true, - "engines": [ - { - "name": "cordova", - "version": ">=3.0.0" - } - ] - }, "node_modules/cordova-sqlite-storage": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/cordova-sqlite-storage/-/cordova-sqlite-storage-5.1.0.tgz", diff --git a/package.json b/package.json index 69ba35f5..3d17634b 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,8 @@ "@awesome-cordova-plugins/deeplinks": "^6.4.0", "@awesome-cordova-plugins/file-chooser": "^6.4.0", "@awesome-cordova-plugins/image-picker": "^6.4.0", - "@awesome-cordova-plugins/insomnia": "^6.4.0", "@awesome-cordova-plugins/three-dee-touch": "^6.4.0", + "@capacitor-community/keep-awake": "^5.0.1", "@capacitor/android": "6.1.2", "@capacitor/app": "6.0.1", "@capacitor/barcode-scanner": "^1.0.1", @@ -96,7 +96,6 @@ "cordova-plugin-android-permissions": "^1.1.5", "cordova-plugin-ble-central": "^1.7.4", "cordova-plugin-health": "^2.1.0", - "cordova-plugin-insomnia": "^4.3.0", "cordova-sqlite-storage": "^5.1.0", "elliptic": ">=6.5.4", "husky": "^8.0.1", diff --git a/src/app/brew/brew-add/brew-add.component.spec.ts b/src/app/brew/brew-add/brew-add.component.spec.ts index 8feb0983..d4d7b9f2 100644 --- a/src/app/brew/brew-add/brew-add.component.spec.ts +++ b/src/app/brew/brew-add/brew-add.component.spec.ts @@ -17,7 +17,6 @@ import { UIBrewStorage } from '../../../services/uiBrewStorage'; import { UISettingsStorage } from '../../../services/uiSettingsStorage'; import { UIMillStorage } from '../../../services/uiMillStorage'; import { UIBrewHelper } from '../../../services/uiBrewHelper'; -import { Insomnia } from '@awesome-cordova-plugins/insomnia/ngx'; import { BrewTrackingService } from '../../../services/brewTracking/brew-tracking.service'; import { UIAnalytics } from '../../../services/uiAnalytics'; import { VisualizerService } from '../../../services/visualizerService/visualizer-service.service'; @@ -85,7 +84,6 @@ describe('BrewAddComponent', () => { { provide: UIAnalytics, useValue: {} }, { provide: BrewTrackingService, useValue: {} }, { provide: VisualizerService, useValue: {} }, - Insomnia, { provide: Router }, { provide: UIHelper, useClass: UIHelperMock }, ], diff --git a/src/app/brew/brew-add/brew-add.component.ts b/src/app/brew/brew-add/brew-add.component.ts index d0a3a12b..24a48097 100644 --- a/src/app/brew/brew-add/brew-add.component.ts +++ b/src/app/brew/brew-add/brew-add.component.ts @@ -22,7 +22,6 @@ import { UILog } from '../../../services/uiLog'; import { UIBrewHelper } from '../../../services/uiBrewHelper'; import { Settings } from '../../../classes/settings/settings'; import { UIHealthKit } from '../../../services/uiHealthKit'; -import { Insomnia } from '@awesome-cordova-plugins/insomnia/ngx'; import { BrewBrewingComponent } from '../../../components/brews/brew-brewing/brew-brewing.component'; import { UIAlert } from '../../../services/uiAlert'; import { BrewTrackingService } from '../../../services/brewTracking/brew-tracking.service'; @@ -47,6 +46,7 @@ import { XeniaDevice } from '../../../classes/preparationDevice/xenia/xeniaDevic import { BrewFlow } from '../../../classes/brew/brewFlow'; import { REFERENCE_GRAPH_TYPE } from '../../../enums/brews/referenceGraphType'; import { ReferenceGraph } from '../../../classes/brew/referenceGraph'; +import { UIHelper } from '../../../services/uiHelper'; declare var Plotly; @@ -88,14 +88,14 @@ export class BrewAddComponent implements OnInit, OnDestroy { private readonly uiLog: UILog, private readonly uiBrewHelper: UIBrewHelper, private readonly uiHealthKit: UIHealthKit, - private readonly insomnia: Insomnia, private readonly uiAlert: UIAlert, private readonly brewTracking: BrewTrackingService, private readonly uiAnalytics: UIAnalytics, private readonly bleManager: CoffeeBluetoothDevicesService, private readonly visualizerService: VisualizerService, private readonly changeDetectorRef: ChangeDetectorRef, - private readonly hapticService: HapticService + private readonly hapticService: HapticService, + private readonly uiHelper: UIHelper ) { // Initialize to standard in drop down @@ -135,10 +135,7 @@ export class BrewAddComponent implements OnInit, OnDestroy { public ionViewDidEnter(): void { this.uiAnalytics.trackEvent(BREW_TRACKING.TITLE, BREW_TRACKING.ACTIONS.ADD); if (this.settings.wake_lock) { - this.insomnia.keepAwake().then( - () => {}, - () => {} - ); + this.uiHelper.deviceKeepAwake(); } // TODO Capacitor migration: There is a race condition here, as this function @@ -192,10 +189,7 @@ export class BrewAddComponent implements OnInit, OnDestroy { public ionViewWillLeave() { if (this.settings.wake_lock) { - this.insomnia.allowSleepAgain().then( - () => {}, - () => {} - ); + this.uiHelper.deviceAllowSleepAgain(); } } diff --git a/src/app/brew/brew-edit/brew-edit.component.spec.ts b/src/app/brew/brew-edit/brew-edit.component.spec.ts index 36218478..b692a480 100644 --- a/src/app/brew/brew-edit/brew-edit.component.spec.ts +++ b/src/app/brew/brew-edit/brew-edit.component.spec.ts @@ -11,7 +11,6 @@ import { ImagePicker } from '@awesome-cordova-plugins/image-picker/ngx'; import { Router } from '@angular/router'; import { AsyncImageComponent } from '../../../components/async-image/async-image.component'; import { HttpClientTestingModule } from '@angular/common/http/testing'; -import { Insomnia } from '@awesome-cordova-plugins/insomnia/ngx'; import { PipesModule } from 'src/pipes/pipes.module'; describe('BrewEditComponent', () => { @@ -36,7 +35,6 @@ describe('BrewEditComponent', () => { { provide: Storage }, { provide: ImagePicker }, { provide: Router }, - { provide: Insomnia }, ], }).compileComponents(); })); diff --git a/src/app/brew/brew-edit/brew-edit.component.ts b/src/app/brew/brew-edit/brew-edit.component.ts index c202855c..bc09b880 100644 --- a/src/app/brew/brew-edit/brew-edit.component.ts +++ b/src/app/brew/brew-edit/brew-edit.component.ts @@ -12,7 +12,6 @@ import { BrewTrackingService } from '../../../services/brewTracking/brew-trackin import BREW_TRACKING from '../../../data/tracking/brewTracking'; import { UIAnalytics } from '../../../services/uiAnalytics'; import { UISettingsStorage } from '../../../services/uiSettingsStorage'; -import { Insomnia } from '@awesome-cordova-plugins/insomnia/ngx'; import { Settings } from '../../../classes/settings/settings'; import { SettingsPopoverBluetoothActionsComponent } from '../../settings/settings-popover-bluetooth-actions/settings-popover-bluetooth-actions.component'; import { @@ -53,7 +52,6 @@ export class BrewEditComponent implements OnInit { private readonly brewTracking: BrewTrackingService, private readonly uiAnalytics: UIAnalytics, private readonly uiSettingsStorage: UISettingsStorage, - private readonly insomnia: Insomnia, private readonly bleManager: CoffeeBluetoothDevicesService, private readonly uiAlert: UIAlert, private readonly visualizerService: VisualizerService, @@ -80,19 +78,13 @@ export class BrewEditComponent implements OnInit { } public ionViewDidEnter(): void { if (this.settings.wake_lock) { - this.insomnia.keepAwake().then( - () => {}, - () => {} - ); + this.uiHelper.deviceKeepAwake(); } this.initialBeanData = JSON.stringify(this.data); } public ionViewWillLeave() { if (this.settings.wake_lock) { - this.insomnia.allowSleepAgain().then( - () => {}, - () => {} - ); + this.uiHelper.deviceAllowSleepAgain(); } } diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 4c96c9fa..0f7cdc74 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -90,7 +90,6 @@ import { GreenBeanEditComponent } from '../roasting-section/green-beans/green-be import { GreenBeanDetailComponent } from '../roasting-section/green-beans/green-bean-detail/green-bean-detail.component'; import { GreenBeanPopoverActionsComponent } from '../roasting-section/green-beans/green-bean-popover-actions/green-bean-popover-actions.component'; import { GreenBeanInformationComponent } from '../../components/green-bean-information/green-bean-information.component'; -import { Insomnia } from '@awesome-cordova-plugins/insomnia/ngx'; import { PhotoPopoverComponent } from '../../popover/photo-popover/photo-popover.component'; import { PhotoAddComponent } from '../../components/photo-add/photo-add.component'; import { BeanRoastInformationComponent } from '../../components/beans/bean-roast-information/bean-roast-information.component'; @@ -379,7 +378,6 @@ import { BluetoothDeviceChooserPopoverComponent } from '../../popover/bluetooth- ThreeDeeTouch, ImagePicker, AndroidPermissions, - Insomnia, ], exports: [ SettingsPage, diff --git a/src/services/uiHelper.ts b/src/services/uiHelper.ts index 4b3ccd33..a9ad4870 100755 --- a/src/services/uiHelper.ts +++ b/src/services/uiHelper.ts @@ -16,6 +16,7 @@ import { cloneDeep } from 'lodash'; import { UIToast } from './uiToast'; import { UISettingsStorage } from './uiSettingsStorage'; import { InAppBrowser } from '@capacitor/inappbrowser'; +import { KeepAwake } from '@capacitor-community/keep-awake'; /** * Handles every helping functionalities */ @@ -245,6 +246,17 @@ export class UIHelper { return promise; } + public deviceKeepAwake() { + try { + KeepAwake.keepAwake(); + } catch (ex) {} + } + public deviceAllowSleepAgain() { + try { + KeepAwake.allowSleep(); + } catch (ex) {} + } + public convertToNumber(event: any): number { let eventInput: any = event; if (eventInput === '') {