From 514c492966d188936ccb2b354e402f97aa39371c Mon Sep 17 00:00:00 2001 From: mru Date: Thu, 16 Feb 2017 17:31:38 +0100 Subject: [PATCH 1/6] (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 470cca1814..bcf14402e8 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 0000000000..401f11790a --- /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; } + +} From 1e1920f524a4ed697498bb51fd50757921da7e41 Mon Sep 17 00:00:00 2001 From: mru Date: Thu, 16 Feb 2017 18:38:09 +0100 Subject: [PATCH 2/6] replaced callback functions with promises --- src/plugins/apppreferences.ts | 50 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/src/plugins/apppreferences.ts b/src/plugins/apppreferences.ts index 401f11790a..268497d275 100644 --- a/src/plugins/apppreferences.ts +++ b/src/plugins/apppreferences.ts @@ -32,74 +32,72 @@ 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} dict Dictionary for key (OPTIONAL) * @param {string} key Key * @return {Promise} Returns a promise */ - @Cordova() - static fetch(successCallback: Function, errorCallback: Function, dict: string, key?: string): Promise { return; } + @Cordova({ + callbackOrder: 'reverse' + }) + static fetch(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} dict Dictionary for key (OPTIONAL) * @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 { + @Cordova({ + callbackOrder: 'reverse' + }) + static store(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} dict Dictionary for key (OPTIONAL) * @param {string} key Key * @return {Promise} Returns a promise */ - @Cordova() - static remove(successCallback: Function, errorCallback: Function, dict: string, key?: string): Promise { return; } + @Cordova({ + callbackOrder: 'reverse' + }) + static remove(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; } + @Cordova({ + callbackOrder: 'reverse' + }) + static clearAll(): 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; } + @Cordova({ + callbackOrder: 'reverse' + }) + static show(): 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; } + static watch(subscribe: boolean): Observable { return; } /** * Return named configuration context From ba0f6ec6e5b8d05a5b9640b4766e05cbeaf4e09e Mon Sep 17 00:00:00 2001 From: mru Date: Fri, 17 Feb 2017 09:50:19 +0100 Subject: [PATCH 3/6] updated example --- src/plugins/apppreferences.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/plugins/apppreferences.ts b/src/plugins/apppreferences.ts index 268497d275..6333a4e8b3 100644 --- a/src/plugins/apppreferences.ts +++ b/src/plugins/apppreferences.ts @@ -10,15 +10,8 @@ import { Observable } from 'rxjs/Observable'; * ``` * import { AppPreferences } from 'ionic-native'; * - * AppPreferences.fetch(prefsRead, prefsErr, 'key'); + * AppPreferences.fetch('key').then((res) => { console.log(res); }); * - * prefsRead(value) { - * console.log(value); - * } - * - * prefsErr(error) { - * console.log(error); - * } * */ @Plugin({ From 00eb5cf5d8aaac9d798f9d8450e0f35f57ffb52a Mon Sep 17 00:00:00 2001 From: mru Date: Tue, 21 Feb 2017 15:00:48 +0100 Subject: [PATCH 4/6] (feat) added cordova-plugin-browsertab support --- src/index.ts | 5 +++- src/plugins/browser-tab.ts | 57 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/plugins/browser-tab.ts diff --git a/src/index.ts b/src/index.ts index bcf14402e8..fe4f0b3025 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,8 +8,8 @@ import { ActionSheet } from './plugins/actionsheet'; 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 { AppRate } from './plugins/apprate'; import { AppVersion } from './plugins/appversion'; import { Badge } from './plugins/badge'; import { BackgroundGeolocation } from './plugins/background-geolocation'; @@ -22,6 +22,7 @@ import { Brightness } from './plugins/brightness'; import { BLE } from './plugins/ble'; import { BluetoothSerial } from './plugins/bluetoothserial'; import { Broadcaster } from './plugins/broadcaster'; +import { BrowserTab } from './plugins/browser-tab'; import { Calendar } from './plugins/calendar'; import { CallNumber } from './plugins/call-number'; import { Camera } from './plugins/camera'; @@ -145,6 +146,7 @@ export * from './plugins/ble'; export * from './plugins/bluetoothserial'; export * from './plugins/brightness'; export * from './plugins/broadcaster'; +export * from './plugins/browser-tab'; export * from './plugins/calendar'; export * from './plugins/call-number'; export * from './plugins/camera'; @@ -270,6 +272,7 @@ window['IonicNative'] = { BLE, BluetoothSerial, Broadcaster, + BrowserTab, Calendar, CallNumber, Camera, diff --git a/src/plugins/browser-tab.ts b/src/plugins/browser-tab.ts new file mode 100644 index 0000000000..ddd2c00143 --- /dev/null +++ b/src/plugins/browser-tab.ts @@ -0,0 +1,57 @@ +import { Plugin, Cordova } from './plugin'; + +/** + * @name BrowserTab + * @description + * This plugin opens a new tab in the system prefered browser + * + * @usage + * ``` + * import { BrowserTab } from 'ionic-native'; + * + * const URL = 'http://ionicframework.com/docs/' + * + * BrowserTab.isAvailable() + * .then((result) => { + * console.log('BrowserTab is available'); + * + * BrowserTab.openUrl(URL).catch((error) => { console.log(error); }); + * + * }).catch((error) => { + * console.log('BrowserTab is not available'); + * }); + * + * + * ``` + */ +@Plugin({ + pluginName: 'BrowserTab', + plugin: 'cordova-plugin-browsertab', // npm package name, example: cordova-plugin-camera + pluginRef: 'cordova.plugins.browsertab', // the variable reference to call the plugin, example: navigator.geolocation + repo: 'https://github.com/google/cordova-plugin-browsertab', // the github repository URL for the plugin +}) +export class BrowserTab { + + /** + * This function test if browserTab is available or not + * @return {Promise} Returns a promise + */ + @Cordova() + static isAvailable(): Promise { return; } + + /** + * This function opens a new tab in the system default browser + * @param url {string} URL to open + * @return {Promise} Returns a promise + */ + @Cordova() + static openUrl(url: string): Promise { return; } + + /** + * This function closes a tab + * @return {Promise} Returns a promise + */ + @Cordova() + static close(): Promise { return; } + +} From 26d3adcfc1af82e67d2bd37e8be78053c09930ae Mon Sep 17 00:00:00 2001 From: mru Date: Tue, 21 Feb 2017 15:33:45 +0100 Subject: [PATCH 5/6] Revert "(feat) added cordova-plugin-browsertab support" This reverts commit 00eb5cf5d8aaac9d798f9d8450e0f35f57ffb52a. --- src/index.ts | 5 +--- src/plugins/browser-tab.ts | 57 -------------------------------------- 2 files changed, 1 insertion(+), 61 deletions(-) delete mode 100644 src/plugins/browser-tab.ts diff --git a/src/index.ts b/src/index.ts index fe4f0b3025..bcf14402e8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,8 +8,8 @@ import { ActionSheet } from './plugins/actionsheet'; import { AdMob } from './plugins/admob'; import { AndroidFingerprintAuth } from './plugins/android-fingerprint-auth'; import { AppAvailability } from './plugins/appavailability'; -import { AppPreferences } from './plugins/apppreferences'; 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'; @@ -22,7 +22,6 @@ import { Brightness } from './plugins/brightness'; import { BLE } from './plugins/ble'; import { BluetoothSerial } from './plugins/bluetoothserial'; import { Broadcaster } from './plugins/broadcaster'; -import { BrowserTab } from './plugins/browser-tab'; import { Calendar } from './plugins/calendar'; import { CallNumber } from './plugins/call-number'; import { Camera } from './plugins/camera'; @@ -146,7 +145,6 @@ export * from './plugins/ble'; export * from './plugins/bluetoothserial'; export * from './plugins/brightness'; export * from './plugins/broadcaster'; -export * from './plugins/browser-tab'; export * from './plugins/calendar'; export * from './plugins/call-number'; export * from './plugins/camera'; @@ -272,7 +270,6 @@ window['IonicNative'] = { BLE, BluetoothSerial, Broadcaster, - BrowserTab, Calendar, CallNumber, Camera, diff --git a/src/plugins/browser-tab.ts b/src/plugins/browser-tab.ts deleted file mode 100644 index ddd2c00143..0000000000 --- a/src/plugins/browser-tab.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { Plugin, Cordova } from './plugin'; - -/** - * @name BrowserTab - * @description - * This plugin opens a new tab in the system prefered browser - * - * @usage - * ``` - * import { BrowserTab } from 'ionic-native'; - * - * const URL = 'http://ionicframework.com/docs/' - * - * BrowserTab.isAvailable() - * .then((result) => { - * console.log('BrowserTab is available'); - * - * BrowserTab.openUrl(URL).catch((error) => { console.log(error); }); - * - * }).catch((error) => { - * console.log('BrowserTab is not available'); - * }); - * - * - * ``` - */ -@Plugin({ - pluginName: 'BrowserTab', - plugin: 'cordova-plugin-browsertab', // npm package name, example: cordova-plugin-camera - pluginRef: 'cordova.plugins.browsertab', // the variable reference to call the plugin, example: navigator.geolocation - repo: 'https://github.com/google/cordova-plugin-browsertab', // the github repository URL for the plugin -}) -export class BrowserTab { - - /** - * This function test if browserTab is available or not - * @return {Promise} Returns a promise - */ - @Cordova() - static isAvailable(): Promise { return; } - - /** - * This function opens a new tab in the system default browser - * @param url {string} URL to open - * @return {Promise} Returns a promise - */ - @Cordova() - static openUrl(url: string): Promise { return; } - - /** - * This function closes a tab - * @return {Promise} Returns a promise - */ - @Cordova() - static close(): Promise { return; } - -} From 0f3fd7b32237f65a6a2ce98cb347d003b2a41c4a Mon Sep 17 00:00:00 2001 From: mru Date: Thu, 23 Feb 2017 16:11:50 +0100 Subject: [PATCH 6/6] (update) synchronize fetch --- src/plugins/apppreferences.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/apppreferences.ts b/src/plugins/apppreferences.ts index 6333a4e8b3..3f5430ea07 100644 --- a/src/plugins/apppreferences.ts +++ b/src/plugins/apppreferences.ts @@ -30,6 +30,7 @@ export class AppPreferences { * @return {Promise} Returns a promise */ @Cordova({ + sync: true, callbackOrder: 'reverse' }) static fetch(dict: string, key?: string): Promise { return; }