-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathcommon.ts
86 lines (68 loc) · 1.75 KB
/
common.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
import { ApplicationSettings } from '@nativescript/core';
export interface SetOptions {
accessGroup?: string;
service?: string;
key: string;
value: string;
}
export interface GetOptions {
accessGroup?: string;
service?: string;
key: string;
}
export interface RemoveOptions {
accessGroup?: string;
service?: string;
key: string;
}
export interface RemoveAllOptions {
service?: string;
}
export abstract class SecureStorageCommon {
protected static IS_FIRST_RUN = '__IS_FIRST_RUN__';
private isFirst: boolean;
constructor() {
this.isFirst = ApplicationSettings.getBoolean(SecureStorageCommon.IS_FIRST_RUN, true);
if (this.isFirst) {
ApplicationSettings.setBoolean(SecureStorageCommon.IS_FIRST_RUN, false);
}
}
abstract get(arg: GetOptions): Promise<any>;
abstract getSync(arg: GetOptions): any;
abstract set(arg: SetOptions): Promise<boolean>;
abstract setSync(arg: SetOptions): boolean;
abstract remove(arg: RemoveOptions): Promise<boolean>;
abstract removeSync(arg: RemoveOptions): boolean;
abstract removeAll(arg?: RemoveAllOptions): Promise<boolean>;
abstract removeAllSync(arg?: RemoveAllOptions): boolean;
public isFirstRunSync(): boolean {
return this.isFirst;
}
public isFirstRun(): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
resolve(this.isFirstRunSync());
});
}
public clearAllOnFirstRun(): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
if (this.isFirstRunSync()) {
this.removeAll();
resolve(true);
} else {
resolve(false);
}
});
}
public clearAllOnFirstRunSync(): boolean {
try {
if (this.isFirstRunSync()) {
this.removeAllSync();
return true;
}
return false;
} catch (e) {
console.log(e);
return false;
}
}
}