mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-02-07 23:03:19 +08:00
fix(secure-storage): return unfunctional SecureStorageObject if plugin doesn't exist
This commit is contained in:
parent
612cb963e1
commit
b91757e7e9
@ -1,5 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CordovaInstance, Plugin, CordovaCheck } from '@ionic-native/core';
|
import { CordovaInstance, Plugin, checkAvailability } from '@ionic-native/core';
|
||||||
|
|
||||||
declare var cordova: any;
|
declare var cordova: any;
|
||||||
|
|
||||||
@ -8,7 +8,7 @@ declare var cordova: any;
|
|||||||
*/
|
*/
|
||||||
export class SecureStorageObject {
|
export class SecureStorageObject {
|
||||||
|
|
||||||
constructor(private _objectInstance: any) {}
|
constructor(private _objectInstance?: any) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a stored item
|
* Gets a stored item
|
||||||
@ -59,8 +59,6 @@ export class SecureStorageObject {
|
|||||||
})
|
})
|
||||||
clear(): Promise<any> { return; }
|
clear(): Promise<any> { return; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,10 +120,13 @@ export class SecureStorage {
|
|||||||
* @param store {string}
|
* @param store {string}
|
||||||
* @returns {Promise<SecureStorageObject>}
|
* @returns {Promise<SecureStorageObject>}
|
||||||
*/
|
*/
|
||||||
@CordovaCheck()
|
|
||||||
create(store: string): Promise<SecureStorageObject> {
|
create(store: string): Promise<SecureStorageObject> {
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
const instance = new cordova.plugins.SecureStorage(() => res(new SecureStorageObject(instance)), rej, store);
|
if (checkAvailability('cordova.plugins.SecureStorage', null, 'SecureStorage') === true) {
|
||||||
|
const instance = new cordova.plugins.SecureStorage(() => res(new SecureStorageObject(instance)), rej, store);
|
||||||
|
} else {
|
||||||
|
res(new SecureStorageObject());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user