@@ -6,11 +6,9 @@ import {
66 ScanResult ,
77} from '@capacitor-community/bluetooth-le' ;
88import { Wifi } from '@capacitor-community/wifi' ;
9- import { Plugins } from '@capacitor/core' ;
109import { isPlatform } from '@ionic/core' ;
1110import { isEqual } from 'lodash-es' ;
12-
13- const { Storage } = Plugins ;
11+ import { PreferenceManager } from '../../../../shared/preference-manager/preference-manager.service' ;
1412
1513interface GoProWiFiCreds {
1614 wifiPASS : string ;
@@ -58,6 +56,12 @@ export class GoProBluetoothService {
5856
5957 private hasInitialized = false ;
6058
59+ readonly id = 'GoProBluetoothService' ;
60+
61+ private readonly preferences = this . preferenceManager . getPreferences ( this . id ) ;
62+
63+ constructor ( private readonly preferenceManager : PreferenceManager ) { }
64+
6165 private async initialize ( ) {
6266 if ( this . hasInitialized ) {
6367 return ;
@@ -122,24 +126,27 @@ export class GoProBluetoothService {
122126 private async getConnectedDeviceFromStorage ( ) : Promise <
123127 ScanResult | undefined
124128 > {
125- const result = await Storage . get ( {
126- key : this . GO_PRO_BLUETOOTH_STORAGE_KEY ,
127- } ) ;
128- if ( result . value ) {
129- return JSON . parse ( result . value ) as ScanResult ;
129+ const res = await this . preferences . getString (
130+ PrefKeys . LAST_CONNECTED_BLUETOOTH_DEVICE
131+ ) ;
132+ if ( res !== '' ) {
133+ return JSON . parse ( res ) as ScanResult ;
130134 }
131135 }
132136
133137 async saveConnectedDeviceToStorage ( scanResult : ScanResult ) {
134- await Storage . set ( {
135- key : this . GO_PRO_BLUETOOTH_STORAGE_KEY ,
136- value : JSON . stringify ( scanResult ) ,
137- } ) ;
138+ await this . preferences . setString (
139+ PrefKeys . LAST_CONNECTED_BLUETOOTH_DEVICE ,
140+ JSON . stringify ( scanResult )
141+ ) ;
138142 }
139143
140144 // eslint-disable-next-line @typescript-eslint/no-unused-vars
141145 async removeConnectedDeviceFromStorage ( scanResult : ScanResult ) {
142- await Storage . remove ( { key : this . GO_PRO_BLUETOOTH_STORAGE_KEY } ) ;
146+ await this . preferences . setString (
147+ PrefKeys . LAST_CONNECTED_BLUETOOTH_DEVICE ,
148+ ''
149+ ) ;
143150 }
144151
145152 async getConnectedDevice ( ) : Promise < ScanResult | undefined > {
@@ -241,3 +248,7 @@ export class GoProBluetoothService {
241248 await this . getGoProWiFiCreds ( ) ;
242249 }
243250}
251+
252+ const enum PrefKeys {
253+ LAST_CONNECTED_BLUETOOTH_DEVICE = 'GO_PRO_LAST_CONNECTED_BLUETOOTH_DEVICE' ,
254+ }
0 commit comments