From 514c492966d188936ccb2b354e402f97aa39371c Mon Sep 17 00:00:00 2001 From: mru Date: Thu, 16 Feb 2017 17:31:38 +0100 Subject: [PATCH] (feat) added cordova-plugin-app-preferences support --- src/index.ts | 3 + src/plugins/apppreferences.ts | 141 ++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 src/plugins/apppreferences.ts diff --git a/src/index.ts b/src/index.ts index 470cca181..bcf14402e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,6 +9,7 @@ import { AdMob } from './plugins/admob'; import { AndroidFingerprintAuth } from './plugins/android-fingerprint-auth'; import { AppAvailability } from './plugins/appavailability'; import { AppRate } from './plugins/apprate'; +import { AppPreferences } from './plugins/apppreferences'; import { AppVersion } from './plugins/appversion'; import { Badge } from './plugins/badge'; import { BackgroundGeolocation } from './plugins/background-geolocation'; @@ -130,6 +131,7 @@ export * from './plugins/actionsheet'; export * from './plugins/admob'; export * from './plugins/android-fingerprint-auth'; export * from './plugins/appavailability'; +export * from './plugins/apppreferences'; export * from './plugins/apprate'; export * from './plugins/appversion'; export * from './plugins/background-geolocation'; @@ -254,6 +256,7 @@ window['IonicNative'] = { AdMob, AndroidFingerprintAuth, AppAvailability, + AppPreferences, AppRate, AppVersion, Badge, diff --git a/src/plugins/apppreferences.ts b/src/plugins/apppreferences.ts new file mode 100644 index 000000000..401f11790 --- /dev/null +++ b/src/plugins/apppreferences.ts @@ -0,0 +1,141 @@ +import { Cordova, Plugin } from './plugin'; +import { Observable } from 'rxjs/Observable'; + +/** + * @name AppPreferences + * @description + * This plugin allows you to read and write app preferences + * + * @usage + * ``` + * import { AppPreferences } from 'ionic-native'; + * + * AppPreferences.fetch(prefsRead, prefsErr, 'key'); + * + * prefsRead(value) { + * console.log(value); + * } + * + * prefsErr(error) { + * console.log(error); + * } + * + */ +@Plugin({ + pluginName: 'AppPreferences', + plugin: 'cordova-plugin-app-preferences', // npm package name, example: cordova-plugin-camera + pluginRef: 'plugins.appPreferences', // the variable reference to call the plugin, example: navigator.geolocation + repo: 'https://github.com/apla/me.apla.cordova.app-preferences', // the github repository URL for the plugin +}) +export class AppPreferences { + + /** + * Get a preference value + * + * @param {Function} successCallback The function to call when the value is available + * @param {Function} errorCallback The function to call when value is unavailable + * @param {string} dict Dictionary for key + * @param {string} key Key + * @return {Promise} Returns a promise + */ + @Cordova() + static fetch(successCallback: Function, errorCallback: Function, dict: string, key?: string): Promise { return; } + + /** + * Set a preference value + * + * @param {Function} successCallback The function to call when the value is set successfully + * @param {Function} errorCallback The function to call when value is not set + * @param {string} dict Dictionary for key + * @param {string} key Key + * @param {string} value Value + * @return {Promise} Returns a promise + */ + @Cordova() + static store(successCallback: Function, errorCallback: Function, dict: string, key: string, value?: string): Promise { + return; + } + + /** + * Remove value from preferences + * + * @param {Function} successCallback The function to call when the value is available + * @param {Function} errorCallback The function to call when value is unavailable + * @param {string} dict Dictionary for key + * @param {string} key Key + * @return {Promise} Returns a promise + */ + @Cordova() + static remove(successCallback: Function, errorCallback: Function, dict: string, key?: string): Promise { return; } + + /** + * Clear preferences + * + * @param {Function} successCallback The function to call when the value is available + * @param {Function} errorCallback The function to call when value is unavailable + * @return {Promise} Returns a promise + */ + @Cordova() + static clearAll(successCallback: Function, errorCallback: Function): Promise { return; } + + /** + * Show native preferences interface + * + * @param {Function} successCallback The function to call when the value is available + * @param {Function} errorCallback The function to call when value is unavailable + * @return {Promise} Returns a promise + */ + @Cordova() + static show(successCallback: Function, errorCallback: Function): Promise { return; } + + /** + * Show native preferences interface + * + * @param {Function} successCallback The function to call when the value is available + * @param {Function} errorCallback The function to call when value is unavailable + * @param {boolean} subscribe true value to subscribe, false - unsubscribe + * @return {Observable} Returns an observable + */ + @Cordova({ + observable: true + }) + static watch(successCallback: Function, errorCallback: Function, subscribe: boolean): Observable { return; } + + /** + * Return named configuration context + * In iOS you'll get a suite configuration, on Android — named file + * Supports: Android, iOS + * @param {string} suiteName suite name + * @returns {Object} Custom object, bound to that suite + */ + @Cordova({ + platforms: ['Android'] + }) + static suite(suiteName: string): Object { return; } + + @Cordova({ + platforms: ['iOS'] + }) + static iosSuite(suiteName: string): Object { return; } + + /** + * Return cloud synchronized configuration context + * Currently supports Windows and iOS/macOS + * @returns {Object} Custom object, bound to that suite + */ + @Cordova({ + platforms: ['iOS', 'Windows', 'Windows Phone 8'] + }) + static cloudSync(): Object { return; } + + /** + * Return default configuration context + * Currently supports Windows and iOS/macOS + * @returns {Object} Custom Object, bound to that suite + */ + @Cordova({ + platforms: ['iOS', 'Windows', 'Windows Phone 8'] + }) + static defaults(): Object { return; } + +}