Skip to content

Commit 12280dd

Browse files
Michel Ruffieuxihadeed
authored andcommitted
feat(app-preferences): added cordova-plugin-app-preferences support (#1084)
* (feat) added cordova-plugin-app-preferences support * replaced callback functions with promises * updated example * (feat) added cordova-plugin-browsertab support * Revert "(feat) added cordova-plugin-browsertab support" This reverts commit 00eb5cf. * (update) synchronize fetch
1 parent 5d091d2 commit 12280dd

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { AndroidFingerprintAuth } from './plugins/android-fingerprint-auth';
1010
import { AppAvailability } from './plugins/appavailability';
1111
import { Appodeal } from './plugins/appodeal';
1212
import { AppRate } from './plugins/apprate';
13+
import { AppPreferences } from './plugins/apppreferences';
1314
import { AppUpdate } from './plugins/app-update';
1415
import { AppVersion } from './plugins/appversion';
1516
import { Badge } from './plugins/badge';
@@ -138,6 +139,7 @@ export * from './plugins/admob';
138139
export * from './plugins/alipay';
139140
export * from './plugins/android-fingerprint-auth';
140141
export * from './plugins/appavailability';
142+
export * from './plugins/apppreferences';
141143
export * from './plugins/appodeal';
142144
export * from './plugins/apprate';
143145
export * from './plugins/app-update';
@@ -270,6 +272,7 @@ window['IonicNative'] = {
270272
Alipay,
271273
AndroidFingerprintAuth,
272274
AppAvailability,
275+
AppPreferences,
273276
Appodeal,
274277
AppRate,
275278
AppUpdate,

src/plugins/apppreferences.ts

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import { Cordova, Plugin } from './plugin';
2+
import { Observable } from 'rxjs/Observable';
3+
4+
/**
5+
* @name AppPreferences
6+
* @description
7+
* This plugin allows you to read and write app preferences
8+
*
9+
* @usage
10+
* ```
11+
* import { AppPreferences } from 'ionic-native';
12+
*
13+
* AppPreferences.fetch('key').then((res) => { console.log(res); });
14+
*
15+
*
16+
*/
17+
@Plugin({
18+
pluginName: 'AppPreferences',
19+
plugin: 'cordova-plugin-app-preferences', // npm package name, example: cordova-plugin-camera
20+
pluginRef: 'plugins.appPreferences', // the variable reference to call the plugin, example: navigator.geolocation
21+
repo: 'https://github.com/apla/me.apla.cordova.app-preferences', // the github repository URL for the plugin
22+
})
23+
export class AppPreferences {
24+
25+
/**
26+
* Get a preference value
27+
*
28+
* @param {string} dict Dictionary for key (OPTIONAL)
29+
* @param {string} key Key
30+
* @return {Promise<any>} Returns a promise
31+
*/
32+
@Cordova({
33+
sync: true,
34+
callbackOrder: 'reverse'
35+
})
36+
static fetch(dict: string, key?: string): Promise<any> { return; }
37+
38+
/**
39+
* Set a preference value
40+
*
41+
* @param {string} dict Dictionary for key (OPTIONAL)
42+
* @param {string} key Key
43+
* @param {string} value Value
44+
* @return {Promise<any>} Returns a promise
45+
*/
46+
@Cordova({
47+
callbackOrder: 'reverse'
48+
})
49+
static store(dict: string, key: string, value?: string): Promise<any> {
50+
return;
51+
}
52+
53+
/**
54+
* Remove value from preferences
55+
*
56+
* @param {string} dict Dictionary for key (OPTIONAL)
57+
* @param {string} key Key
58+
* @return {Promise<any>} Returns a promise
59+
*/
60+
@Cordova({
61+
callbackOrder: 'reverse'
62+
})
63+
static remove(dict: string, key?: string): Promise<any> { return; }
64+
65+
/**
66+
* Clear preferences
67+
*
68+
* @return {Promise<any>} Returns a promise
69+
*/
70+
@Cordova({
71+
callbackOrder: 'reverse'
72+
})
73+
static clearAll(): Promise<any> { return; }
74+
75+
/**
76+
* Show native preferences interface
77+
*
78+
* @return {Promise<any>} Returns a promise
79+
*/
80+
@Cordova({
81+
callbackOrder: 'reverse'
82+
})
83+
static show(): Promise<any> { return; }
84+
85+
/**
86+
* Show native preferences interface
87+
*
88+
* @param {boolean} subscribe true value to subscribe, false - unsubscribe
89+
* @return {Observable<any>} Returns an observable
90+
*/
91+
@Cordova({
92+
observable: true
93+
})
94+
static watch(subscribe: boolean): Observable<any> { return; }
95+
96+
/**
97+
* Return named configuration context
98+
* In iOS you'll get a suite configuration, on Android — named file
99+
* Supports: Android, iOS
100+
* @param {string} suiteName suite name
101+
* @returns {Object} Custom object, bound to that suite
102+
*/
103+
@Cordova({
104+
platforms: ['Android']
105+
})
106+
static suite(suiteName: string): Object { return; }
107+
108+
@Cordova({
109+
platforms: ['iOS']
110+
})
111+
static iosSuite(suiteName: string): Object { return; }
112+
113+
/**
114+
* Return cloud synchronized configuration context
115+
* Currently supports Windows and iOS/macOS
116+
* @returns {Object} Custom object, bound to that suite
117+
*/
118+
@Cordova({
119+
platforms: ['iOS', 'Windows', 'Windows Phone 8']
120+
})
121+
static cloudSync(): Object { return; }
122+
123+
/**
124+
* Return default configuration context
125+
* Currently supports Windows and iOS/macOS
126+
* @returns {Object} Custom Object, bound to that suite
127+
*/
128+
@Cordova({
129+
platforms: ['iOS', 'Windows', 'Windows Phone 8']
130+
})
131+
static defaults(): Object { return; }
132+
133+
}

0 commit comments

Comments
 (0)