mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2026-07-16 00:00:04 +08:00
feat(): make instance based plugins injectable
This commit is contained in:
@@ -57,7 +57,6 @@ export interface IContactProperties {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@Injectable()
|
||||
export class Contact implements IContactProperties {
|
||||
private _objectInstance: any;
|
||||
@InstanceProperty id: string;
|
||||
@@ -143,7 +142,6 @@ export interface IContactName {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@Injectable()
|
||||
export class ContactName implements IContactName {
|
||||
constructor(public formatted?: string,
|
||||
public familyName?: string,
|
||||
@@ -165,7 +163,6 @@ export interface IContactField {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@Injectable()
|
||||
export class ContactField implements IContactField {
|
||||
constructor(public type?: string,
|
||||
public value?: string,
|
||||
@@ -194,7 +191,6 @@ export interface IContactAddress {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@Injectable()
|
||||
export class ContactAddress implements IContactAddress {
|
||||
constructor(public pref?: boolean,
|
||||
public type?: string,
|
||||
@@ -222,7 +218,6 @@ export interface IContactOrganization {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@Injectable()
|
||||
export class ContactOrganization implements IContactOrganization {
|
||||
constructor(
|
||||
public type?: string,
|
||||
@@ -250,7 +245,6 @@ export interface IContactFindOptions {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@Injectable()
|
||||
export class ContactFindOptions implements IContactFindOptions {
|
||||
constructor(public filter?: string,
|
||||
public multiple?: boolean,
|
||||
|
||||
@@ -202,7 +202,7 @@ export class Transfer {
|
||||
* NOT_MODIFIED_ERR: 5 Return on "304 Not Modified" HTTP response
|
||||
* @enum {number}
|
||||
*/
|
||||
public static FileTransferErrorCode = {
|
||||
static FileTransferErrorCode = {
|
||||
FILE_NOT_FOUND_ERR: 1,
|
||||
INVALID_URL_ERR: 2,
|
||||
CONNECTION_ERR: 3,
|
||||
@@ -252,9 +252,8 @@ export class Transfer {
|
||||
|
||||
/**
|
||||
* Registers a listener that gets called whenever a new chunk of data is transferred.
|
||||
* @param {function} Listener that takes a progress event.
|
||||
* @param listener {function} Listener that takes a progress event.
|
||||
*/
|
||||
|
||||
onProgress(listener: (event: ProgressEvent) => any): void {
|
||||
this._objectInstance.onprogress = listener;
|
||||
}
|
||||
|
||||
@@ -39,80 +39,9 @@ export const GoogleMapsAnimation = {
|
||||
};
|
||||
|
||||
/**
|
||||
* @name Google Maps
|
||||
* @description This plugin uses the native Google Maps SDK
|
||||
* @usage
|
||||
* ```
|
||||
* import {
|
||||
* GoogleMap,
|
||||
* GoogleMapsEvent,
|
||||
* GoogleMapsLatLng,
|
||||
* CameraPosition,
|
||||
* GoogleMapsMarkerOptions,
|
||||
* GoogleMapsMarker
|
||||
* } from 'ionic-native';
|
||||
*
|
||||
* @Injectable()
|
||||
export class MapPage {
|
||||
* constructor() {}
|
||||
*
|
||||
* // Load map only after view is initialize
|
||||
* ngAfterViewInit() {
|
||||
* this.loadMap();
|
||||
* }
|
||||
*
|
||||
* loadMap() {
|
||||
* // make sure to create following structure in your view.html file
|
||||
* // and add a height (for example 100%) to it, else the map won't be visible
|
||||
* // <ion-content>
|
||||
* // <div #map id="map" style="height:100%;"></div>
|
||||
* // </ion-content>
|
||||
*
|
||||
* // create a new map by passing HTMLElement
|
||||
* let element: HTMLElement = document.getElementById('map');
|
||||
*
|
||||
* let map = new GoogleMap(element);
|
||||
*
|
||||
* // listen to MAP_READY event
|
||||
* map.one(GoogleMapsEvent.MAP_READY).then(() => console.log('Map is ready!'));
|
||||
*
|
||||
* // create LatLng object
|
||||
* let ionic: GoogleMapsLatLng = new GoogleMapsLatLng(43.0741904,-89.3809802);
|
||||
*
|
||||
* // create CameraPosition
|
||||
* let position: CameraPosition = {
|
||||
* target: ionic,
|
||||
* zoom: 18,
|
||||
* tilt: 30
|
||||
* };
|
||||
*
|
||||
* // move the map's camera to position
|
||||
* map.moveCamera(position);
|
||||
*
|
||||
* // create new marker
|
||||
* let markerOptions: GoogleMapsMarkerOptions = {
|
||||
* position: ionic,
|
||||
* title: 'Ionic'
|
||||
* };
|
||||
*
|
||||
* map.addMarker(markerOptions)
|
||||
* .then((marker: GoogleMapsMarker) => {
|
||||
* marker.showInfoWindow();
|
||||
* });
|
||||
* }
|
||||
*
|
||||
* }
|
||||
* ```
|
||||
* @private
|
||||
*/
|
||||
@Plugin({
|
||||
pluginName: 'GoogleMap',
|
||||
pluginRef: 'plugin.google.maps.Map',
|
||||
plugin: 'cordova-plugin-googlemaps',
|
||||
repo: 'https://github.com/mapsplugin/cordova-plugin-googlemaps',
|
||||
install: 'ionic plugin add cordova-plugin-googlemaps --variable API_KEY_FOR_ANDROID="YOUR_ANDROID_API_KEY_IS_HERE" --variable API_KEY_FOR_IOS="YOUR_IOS_API_KEY_IS_HERE"'
|
||||
})
|
||||
@Injectable()
|
||||
export class GoogleMap {
|
||||
export class GoogleMapsObject {
|
||||
_objectInstance: any;
|
||||
|
||||
/**
|
||||
@@ -477,6 +406,95 @@ export class GoogleMap {
|
||||
|
||||
@CordovaInstance({ sync: true })
|
||||
panBy(): void { }
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Google Maps
|
||||
* @description This plugin uses the native Google Maps SDK
|
||||
* @usage
|
||||
* ```
|
||||
* import {
|
||||
* GoogleMap,
|
||||
* GoogleMapsEvent,
|
||||
* GoogleMapsLatLng,
|
||||
* CameraPosition,
|
||||
* GoogleMapsMarkerOptions,
|
||||
* GoogleMapsMarker
|
||||
* } from 'ionic-native';
|
||||
*
|
||||
* @Injectable()
|
||||
export class MapPage {
|
||||
* constructor() {}
|
||||
*
|
||||
* // Load map only after view is initialize
|
||||
* ngAfterViewInit() {
|
||||
* this.loadMap();
|
||||
* }
|
||||
*
|
||||
* loadMap() {
|
||||
* // make sure to create following structure in your view.html file
|
||||
* // and add a height (for example 100%) to it, else the map won't be visible
|
||||
* // <ion-content>
|
||||
* // <div #map id="map" style="height:100%;"></div>
|
||||
* // </ion-content>
|
||||
*
|
||||
* // create a new map by passing HTMLElement
|
||||
* let element: HTMLElement = document.getElementById('map');
|
||||
*
|
||||
* let map = new GoogleMap(element);
|
||||
*
|
||||
* // listen to MAP_READY event
|
||||
* map.one(GoogleMapsEvent.MAP_READY).then(() => console.log('Map is ready!'));
|
||||
*
|
||||
* // create LatLng object
|
||||
* let ionic: GoogleMapsLatLng = new GoogleMapsLatLng(43.0741904,-89.3809802);
|
||||
*
|
||||
* // create CameraPosition
|
||||
* let position: CameraPosition = {
|
||||
* target: ionic,
|
||||
* zoom: 18,
|
||||
* tilt: 30
|
||||
* };
|
||||
*
|
||||
* // move the map's camera to position
|
||||
* map.moveCamera(position);
|
||||
*
|
||||
* // create new marker
|
||||
* let markerOptions: GoogleMapsMarkerOptions = {
|
||||
* position: ionic,
|
||||
* title: 'Ionic'
|
||||
* };
|
||||
*
|
||||
* map.addMarker(markerOptions)
|
||||
* .then((marker: GoogleMapsMarker) => {
|
||||
* marker.showInfoWindow();
|
||||
* });
|
||||
* }
|
||||
*
|
||||
* }
|
||||
* ```
|
||||
* @classes
|
||||
* GoogleMapsObject
|
||||
*/
|
||||
@Plugin({
|
||||
pluginName: 'GoogleMap',
|
||||
pluginRef: 'plugin.google.maps.Map',
|
||||
plugin: 'cordova-plugin-googlemaps',
|
||||
repo: 'https://github.com/mapsplugin/cordova-plugin-googlemaps',
|
||||
install: 'ionic plugin add cordova-plugin-googlemaps --variable API_KEY_FOR_ANDROID="YOUR_ANDROID_API_KEY_IS_HERE" --variable API_KEY_FOR_IOS="YOUR_IOS_API_KEY_IS_HERE"'
|
||||
})
|
||||
@Injectable()
|
||||
export class GoogleMap {
|
||||
|
||||
/**
|
||||
* Creates a new GoogleMap instance
|
||||
* @param element {string | HTMLElement} Element ID or reference to attach the map to
|
||||
* @param options {any} Options
|
||||
* @returns {GoogleMapsObject}
|
||||
*/
|
||||
create(element: string | HTMLElement, options?: any): GoogleMapsObject {
|
||||
return new GoogleMapsObject(element, options);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Plugin, CordovaInstance } from '@ionic-native/core';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/observable/fromEvent';
|
||||
|
||||
declare var cordova: any;
|
||||
|
||||
@@ -14,50 +15,20 @@ export interface InAppBrowserEvent extends Event {
|
||||
/** the error message, only in the case of loaderror. */
|
||||
message: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name InAppBrowser
|
||||
* @description Launches in app Browser
|
||||
* @usage
|
||||
* ```typescript
|
||||
* import {InAppBrowser} from 'ionic-native';
|
||||
*
|
||||
*
|
||||
* ...
|
||||
*
|
||||
*
|
||||
* let browser = new InAppBrowser('https://ionic.io', '_system');
|
||||
* browser.executeScript(...);
|
||||
* browser.insertCSS(...);
|
||||
* browser.close();
|
||||
* ```
|
||||
* @interfaces
|
||||
* InAppBrowserEvent
|
||||
* @private
|
||||
*/
|
||||
@Plugin({
|
||||
pluginName: 'InAppBrowser',
|
||||
plugin: 'cordova-plugin-inappbrowser',
|
||||
pluginRef: 'cordova.InAppBrowser',
|
||||
repo: 'https://github.com/apache/cordova-plugin-inappbrowser'
|
||||
})
|
||||
@Injectable()
|
||||
export class InAppBrowser {
|
||||
export class InAppBrowserObject {
|
||||
|
||||
private _objectInstance: any;
|
||||
|
||||
/**
|
||||
* Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser.
|
||||
* @param url The URL to load.
|
||||
* @param target The target in which to load the URL, an optional parameter that defaults to _self.
|
||||
* @param options Options for the InAppBrowser. Optional, defaulting to: location=yes.
|
||||
* The options string must not contain any blank space, and each feature's
|
||||
* name/value pairs must be separated by a comma. Feature names are case insensitive.
|
||||
*/
|
||||
constructor(url: string, target?: string, options?: string) {
|
||||
try {
|
||||
this._objectInstance = cordova.InAppBrowser.open(url, target, options);
|
||||
} catch (e) {
|
||||
window.open(url);
|
||||
console.warn('Native: InAppBrowser is not installed or you are running on a browser. Falling back to window.open, all instance methods will NOT work.');
|
||||
console.warn('Native: InAppBrowser is not installed or you are running on a browser. Falling back to window.open.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,14 +70,55 @@ export class InAppBrowser {
|
||||
|
||||
/**
|
||||
* A method that allows you to listen to events happening in the browser.
|
||||
* @param {string} name of the event
|
||||
* @param event {string} Name of the event
|
||||
* @returns {Observable<InAppBrowserEvent>} Returns back an observable that will listen to the event on subscribe, and will stop listening to the event on unsubscribe.
|
||||
*/
|
||||
on(event: string): Observable<InAppBrowserEvent> {
|
||||
return new Observable<InAppBrowserEvent>((observer) => {
|
||||
this._objectInstance.addEventListener(event, observer.next.bind(observer));
|
||||
return () => this._objectInstance.removeEventListener(event, observer.next.bind(observer));
|
||||
});
|
||||
return Observable.fromEvent(this._objectInstance, event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name InAppBrowser
|
||||
* @description Launches in app Browser
|
||||
* @usage
|
||||
* ```typescript
|
||||
* import {InAppBrowser} from 'ionic-native';
|
||||
*
|
||||
*
|
||||
* ...
|
||||
*
|
||||
*
|
||||
* let browser = new InAppBrowser('https://ionic.io', '_system');
|
||||
* browser.executeScript(...);
|
||||
* browser.insertCSS(...);
|
||||
* browser.close();
|
||||
* ```
|
||||
* @classes
|
||||
* InAppBrowserObject
|
||||
* @interfaces
|
||||
* InAppBrowserEvent
|
||||
*/
|
||||
@Plugin({
|
||||
pluginName: 'InAppBrowser',
|
||||
plugin: 'cordova-plugin-inappbrowser',
|
||||
pluginRef: 'cordova.InAppBrowser',
|
||||
repo: 'https://github.com/apache/cordova-plugin-inappbrowser'
|
||||
})
|
||||
@Injectable()
|
||||
export class InAppBrowser {
|
||||
|
||||
/**
|
||||
* Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser.
|
||||
* @param url {string} The URL to load.
|
||||
* @param target {string} The target in which to load the URL, an optional parameter that defaults to _self.
|
||||
* @param options {string} Options for the InAppBrowser. Optional, defaulting to: location=yes.
|
||||
* The options string must not contain any blank space, and each feature's
|
||||
* name/value pairs must be separated by a comma. Feature names are case insensitive.
|
||||
* @returns {InAppBrowserObject}
|
||||
*/
|
||||
create(url: string, target?: string, options?: string): InAppBrowserObject {
|
||||
return new InAppBrowserObject(url, target, options);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,77 +9,9 @@ export interface MediaError {
|
||||
}
|
||||
|
||||
/**
|
||||
* @name MediaPlugin
|
||||
* @description
|
||||
* @usage
|
||||
* ```typescript
|
||||
* import { MediaPlugin } from 'ionic-native';
|
||||
*
|
||||
*
|
||||
*
|
||||
* // Create a MediaPlugin instance. Expects path to file or url as argument
|
||||
* // We can optionally pass a second argument to track the status of the media
|
||||
*
|
||||
* const onStatusUpdate = (status) => console.log(status);
|
||||
*
|
||||
* const file = new MediaPlugin('path/to/file.mp3', onStatusUpdate);
|
||||
*
|
||||
* // Catch the Success & Error Output
|
||||
* // Platform Quirks
|
||||
* // iOS calls success on completion of playback only
|
||||
* // Android calls success on completion of playback AND on release()
|
||||
* file.init.then(() => {
|
||||
* console.log('Playback Finished');
|
||||
* }, (err) => {
|
||||
* console.log('somthing went wrong! error code: ' + err.code + ' message: ' + err.message);
|
||||
* });
|
||||
*
|
||||
* // play the file
|
||||
* file.play();
|
||||
*
|
||||
* // pause the file
|
||||
* file.pause();
|
||||
*
|
||||
* // get current playback position
|
||||
* file.getCurrentPosition().then((position) => {
|
||||
* console.log(position);
|
||||
* });
|
||||
*
|
||||
* // get file duration
|
||||
* file.getDuration().then((duration) => {
|
||||
* console.log(position);
|
||||
* });
|
||||
*
|
||||
* // skip to 10 seconds (expects int value in ms)
|
||||
* file.seekTo(10000);
|
||||
*
|
||||
* // stop playing the file
|
||||
* file.stop();
|
||||
*
|
||||
* // release the native audio resource
|
||||
* // Platform Quirks:
|
||||
* // iOS simply create a new instance and the old one will be overwritten
|
||||
* // Android you must call release() to destroy instances of media when you are done
|
||||
* file.release();
|
||||
*
|
||||
* // Recording to a file
|
||||
* var newFile = new MediaPlugin('path/to/file.mp3');
|
||||
* newFile.startRecord();
|
||||
*
|
||||
* newFile.stopRecord();
|
||||
*
|
||||
*
|
||||
*
|
||||
* ```
|
||||
* @private
|
||||
*/
|
||||
@Plugin({
|
||||
pluginName: 'MediaPlugin',
|
||||
repo: 'https://github.com/apache/cordova-plugin-media',
|
||||
plugin: 'cordova-plugin-media',
|
||||
pluginRef: 'Media'
|
||||
})
|
||||
@Injectable()
|
||||
export class MediaPlugin {
|
||||
export class MediaObject {
|
||||
|
||||
// Constants
|
||||
/**
|
||||
@@ -237,5 +169,90 @@ export class MediaPlugin {
|
||||
sync: true
|
||||
})
|
||||
stop(): void { }
|
||||
}
|
||||
|
||||
/**
|
||||
* @name MediaPlugin
|
||||
* @description
|
||||
* @usage
|
||||
* ```typescript
|
||||
* import { MediaPlugin } from 'ionic-native';
|
||||
*
|
||||
*
|
||||
*
|
||||
* // Create a MediaPlugin instance. Expects path to file or url as argument
|
||||
* // We can optionally pass a second argument to track the status of the media
|
||||
*
|
||||
* const onStatusUpdate = (status) => console.log(status);
|
||||
*
|
||||
* const file = new MediaPlugin('path/to/file.mp3', onStatusUpdate);
|
||||
*
|
||||
* // Catch the Success & Error Output
|
||||
* // Platform Quirks
|
||||
* // iOS calls success on completion of playback only
|
||||
* // Android calls success on completion of playback AND on release()
|
||||
* file.init.then(() => {
|
||||
* console.log('Playback Finished');
|
||||
* }, (err) => {
|
||||
* console.log('somthing went wrong! error code: ' + err.code + ' message: ' + err.message);
|
||||
* });
|
||||
*
|
||||
* // play the file
|
||||
* file.play();
|
||||
*
|
||||
* // pause the file
|
||||
* file.pause();
|
||||
*
|
||||
* // get current playback position
|
||||
* file.getCurrentPosition().then((position) => {
|
||||
* console.log(position);
|
||||
* });
|
||||
*
|
||||
* // get file duration
|
||||
* file.getDuration().then((duration) => {
|
||||
* console.log(position);
|
||||
* });
|
||||
*
|
||||
* // skip to 10 seconds (expects int value in ms)
|
||||
* file.seekTo(10000);
|
||||
*
|
||||
* // stop playing the file
|
||||
* file.stop();
|
||||
*
|
||||
* // release the native audio resource
|
||||
* // Platform Quirks:
|
||||
* // iOS simply create a new instance and the old one will be overwritten
|
||||
* // Android you must call release() to destroy instances of media when you are done
|
||||
* file.release();
|
||||
*
|
||||
* // Recording to a file
|
||||
* var newFile = new MediaPlugin('path/to/file.mp3');
|
||||
* newFile.startRecord();
|
||||
*
|
||||
* newFile.stopRecord();
|
||||
*
|
||||
*
|
||||
*
|
||||
* ```
|
||||
* @classes
|
||||
* MediaObject
|
||||
*/
|
||||
@Plugin({
|
||||
pluginName: 'MediaPlugin',
|
||||
repo: 'https://github.com/apache/cordova-plugin-media',
|
||||
plugin: 'cordova-plugin-media',
|
||||
pluginRef: 'Media'
|
||||
})
|
||||
@Injectable()
|
||||
class MediaPlugin {
|
||||
|
||||
/**
|
||||
* Open a media file
|
||||
* @param src {string} A URI containing the audio content.
|
||||
* @param onStatusUpdate {Function} A callback function to be invoked when the status of the file changes
|
||||
*/
|
||||
create(src: string, onStatusUpdate?: Function): MediaObject {
|
||||
return new MediaObject(src, onStatusUpdate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,47 @@ import { Injectable } from '@angular/core';
|
||||
import { CordovaInstance, Plugin } from '@ionic-native/core';
|
||||
|
||||
declare var cordova: any;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
export class SecureStorageObject {
|
||||
|
||||
constructor(private _objectInstance: any) {}
|
||||
|
||||
/**
|
||||
* Gets a stored item
|
||||
* @param reference {string}
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
@CordovaInstance({
|
||||
callbackOrder: 'reverse'
|
||||
})
|
||||
get(reference: string): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* Stores a value
|
||||
* @param reference {string}
|
||||
* @param value {string}
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
@CordovaInstance({
|
||||
callbackOrder: 'reverse'
|
||||
})
|
||||
set(reference: string, value: string): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* Removes a single stored item
|
||||
* @param reference {string}
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
@CordovaInstance({
|
||||
callbackOrder: 'reverse'
|
||||
})
|
||||
remove(reference: string): Promise<any> { return; }
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Secure Storage
|
||||
* @description
|
||||
@@ -39,6 +80,8 @@ declare var cordova: any;
|
||||
* error => console.log(error)
|
||||
* );
|
||||
* ```
|
||||
* @classes
|
||||
* SecureStorageObject
|
||||
*/
|
||||
@Plugin({
|
||||
pluginName: 'SecureStorage',
|
||||
@@ -50,49 +93,15 @@ declare var cordova: any;
|
||||
@Injectable()
|
||||
export class SecureStorage {
|
||||
|
||||
private _objectInstance: any;
|
||||
|
||||
constructor() {}
|
||||
|
||||
/**
|
||||
* Creates a namespaced storage.
|
||||
* @param store {string}
|
||||
* @returns {Promise<any>}
|
||||
* @returns {Promise<SecureStorageObject>}
|
||||
*/
|
||||
create(store: string): Promise<any> {
|
||||
create(store: string): Promise<SecureStorageObject> {
|
||||
return new Promise((res, rej) => {
|
||||
this._objectInstance = new cordova.plugins.SecureStorage(res, rej, store);
|
||||
const instance = new cordova.plugins.SecureStorage(() => res(new SecureStorageObject(instance)), rej, store);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a stored item
|
||||
* @param reference {string}
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
@CordovaInstance({
|
||||
callbackOrder: 'reverse'
|
||||
})
|
||||
get(reference: string): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* Stores a value
|
||||
* @param reference {string}
|
||||
* @param value {string}
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
@CordovaInstance({
|
||||
callbackOrder: 'reverse'
|
||||
})
|
||||
set(reference: string, value: string): Promise<any> { return; }
|
||||
|
||||
/**
|
||||
* Removes a single stored item
|
||||
* @param reference {string}
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
@CordovaInstance({
|
||||
callbackOrder: 'reverse'
|
||||
})
|
||||
remove(reference: string): Promise<any> { return; }
|
||||
}
|
||||
|
||||
@@ -1,98 +1,18 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {Cordova, CordovaInstance, Plugin, pluginWarn, InstanceProperty} from '@ionic-native/core';
|
||||
import { Cordova, CordovaInstance, Plugin, pluginWarn, InstanceProperty } from '@ionic-native/core';
|
||||
|
||||
|
||||
declare var sqlitePlugin;
|
||||
|
||||
/**
|
||||
* @name SQLite
|
||||
*
|
||||
* @description
|
||||
* Access SQLite databases on the device.
|
||||
*
|
||||
* @usage
|
||||
*
|
||||
* ```typescript
|
||||
* import { SQLite } from 'ionic-native';
|
||||
*
|
||||
* // OPTION A: Use static constructor
|
||||
* SQLite.openDatabase({
|
||||
* name: 'data.db',
|
||||
* location: 'default'
|
||||
* })
|
||||
* .then((db: SQLite) => {
|
||||
*
|
||||
* db.executeSql('create table danceMoves(name VARCHAR(32))', {}).then(() => {}).catch(() => {});
|
||||
*
|
||||
* })
|
||||
* .catch(error => console.error('Error opening database', error);
|
||||
*
|
||||
*
|
||||
* // OPTION B: Create a new instance of SQLite
|
||||
* let db = new SQLite();
|
||||
* db.openDatabase({
|
||||
* name: 'data.db',
|
||||
* location: 'default' // the location field is required
|
||||
* }).then(() => {
|
||||
* db.executeSql('create table danceMoves(name VARCHAR(32))', {}).then(() => {
|
||||
*
|
||||
* }, (err) => {
|
||||
* console.error('Unable to execute sql: ', err);
|
||||
* });
|
||||
* }, (err) => {
|
||||
* console.error('Unable to open database: ', err);
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
@Plugin({
|
||||
pluginName: 'SQLite',
|
||||
pluginRef: 'sqlitePlugin',
|
||||
plugin: 'cordova-sqlite-storage',
|
||||
repo: 'https://github.com/litehelpers/Cordova-sqlite-storage'
|
||||
})
|
||||
@Injectable()
|
||||
export class SQLite {
|
||||
export class SQLiteObject {
|
||||
|
||||
private _objectInstance: any;
|
||||
constructor(private _objectInstance: any){ }
|
||||
|
||||
@InstanceProperty databaseFeatures: any;
|
||||
|
||||
constructor() { }
|
||||
|
||||
/*
|
||||
openDatabase(config: any): Promise<SQLite> {
|
||||
return new SQLite().openDatabase(config);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Open or create a SQLite database file.
|
||||
*
|
||||
* See the plugin docs for an explanation of all options: https://github.com/litehelpers/Cordova-sqlite-storage#opening-a-database
|
||||
*
|
||||
* @param config the config for opening the database.
|
||||
*/
|
||||
openDatabase(config: any): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (typeof sqlitePlugin !== 'undefined') {
|
||||
sqlitePlugin.openDatabase(config, db => {
|
||||
this._objectInstance = db;
|
||||
resolve(db);
|
||||
}, error => {
|
||||
console.warn(error);
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
pluginWarn({
|
||||
pluginName: 'SQLite',
|
||||
plugin: 'cordova-sqlite-storage'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@CordovaInstance({
|
||||
sync: true
|
||||
})
|
||||
@@ -218,3 +138,78 @@ export class SQLite {
|
||||
deleteDatabase(first): Promise<any> { return; }
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @name SQLite
|
||||
*
|
||||
* @description
|
||||
* Access SQLite databases on the device.
|
||||
*
|
||||
* @usage
|
||||
*
|
||||
* ```typescript
|
||||
* import { SQLite } from 'ionic-native';
|
||||
*
|
||||
* // OPTION A: Use static constructor
|
||||
* SQLite.openDatabase({
|
||||
* name: 'data.db',
|
||||
* location: 'default'
|
||||
* })
|
||||
* .then((db: SQLite) => {
|
||||
*
|
||||
* db.executeSql('create table danceMoves(name VARCHAR(32))', {}).then(() => {}).catch(() => {});
|
||||
*
|
||||
* })
|
||||
* .catch(error => console.error('Error opening database', error);
|
||||
*
|
||||
*
|
||||
* // OPTION B: Create a new instance of SQLite
|
||||
* let db = new SQLite();
|
||||
* db.openDatabase({
|
||||
* name: 'data.db',
|
||||
* location: 'default' // the location field is required
|
||||
* }).then(() => {
|
||||
* db.executeSql('create table danceMoves(name VARCHAR(32))', {}).then(() => {
|
||||
*
|
||||
* }, (err) => {
|
||||
* console.error('Unable to execute sql: ', err);
|
||||
* });
|
||||
* }, (err) => {
|
||||
* console.error('Unable to open database: ', err);
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @classes
|
||||
* SQLiteObject
|
||||
*/
|
||||
@Plugin({
|
||||
pluginName: 'SQLite',
|
||||
pluginRef: 'sqlitePlugin',
|
||||
plugin: 'cordova-sqlite-storage',
|
||||
repo: 'https://github.com/litehelpers/Cordova-sqlite-storage'
|
||||
})
|
||||
@Injectable()
|
||||
export class SQLite {
|
||||
|
||||
/**
|
||||
* Open or create a SQLite database file.
|
||||
*
|
||||
* See the plugin docs for an explanation of all options: https://github.com/litehelpers/Cordova-sqlite-storage#opening-a-database
|
||||
*
|
||||
* @param config the config for opening the database.
|
||||
* @return Promise<SQLiteObject>
|
||||
*/
|
||||
create(config: any): Promise<SQLiteObject> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (typeof sqlitePlugin !== 'undefined') {
|
||||
sqlitePlugin.openDatabase(config, db => resolve(new SQLiteObject(db)), reject);
|
||||
} else {
|
||||
pluginWarn({
|
||||
pluginName: 'SQLite',
|
||||
plugin: 'cordova-sqlite-storage'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -67,6 +67,72 @@ export interface ThemeableBrowserOptions {
|
||||
fullscreen?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
export class ThemeableBrowserObject {
|
||||
|
||||
private _objectInstance: any;
|
||||
|
||||
constructor(url: string, target: string, styleOptions: ThemeableBrowserOptions) {
|
||||
try {
|
||||
this._objectInstance = cordova.ThemeableBrowser.open(url, target, styleOptions);
|
||||
} catch (e) {
|
||||
window.open(url);
|
||||
console.warn('Native: ThemeableBrowser is not installed or you are running on a browser. Falling back to window.open.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an browser window that was opened hidden. Calling this has no effect
|
||||
* if the browser was already visible.
|
||||
*/
|
||||
@CordovaInstance({sync: true})
|
||||
show(): void { }
|
||||
|
||||
/**
|
||||
* Closes the browser window.
|
||||
*/
|
||||
@CordovaInstance({sync: true})
|
||||
close(): void { }
|
||||
|
||||
/**
|
||||
* Reloads the current page
|
||||
*/
|
||||
@CordovaInstance({ sync: true })
|
||||
reload(): void { }
|
||||
|
||||
/**
|
||||
* Injects JavaScript code into the browser window.
|
||||
* @param script Details of the script to run, specifying either a file or code key.
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
@CordovaInstance()
|
||||
executeScript(script: {file?: string, code?: string}): Promise<any> {return; }
|
||||
|
||||
/**
|
||||
* Injects CSS into the browser window.
|
||||
* @param css Details of the script to run, specifying either a file or code key.
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
@CordovaInstance()
|
||||
insertCss(css: {file?: string, code?: string}): Promise<any> {return; }
|
||||
|
||||
/**
|
||||
* A method that allows you to listen to events happening in the browser.
|
||||
* Available events are: `ThemeableBrowserError`, `ThemeableBrowserWarning`, `critical`, `loadfail`, `unexpected`, `undefined`
|
||||
* @param event Event name
|
||||
* @returns {Observable<any>} Returns back an observable that will listen to the event on subscribe, and will stop listening to the event on unsubscribe.
|
||||
*/
|
||||
on(event: string): Observable<any> {
|
||||
return new Observable<any>((observer) => {
|
||||
this._objectInstance.addEventListener(event, observer.next.bind(observer));
|
||||
return () => this._objectInstance.removeEventListener(event, observer.next.bind(observer));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @name ThemeableBrowser
|
||||
* @description
|
||||
@@ -142,6 +208,8 @@ export interface ThemeableBrowserOptions {
|
||||
*
|
||||
* ```
|
||||
* We suggest that you refer to the plugin's repository for additional information on usage that may not be covered here.
|
||||
* @classes
|
||||
* ThemeableBrowserObject
|
||||
* @interfaces
|
||||
* ThemeableBrowserButton
|
||||
* ThemeableBrowserOptions
|
||||
@@ -154,63 +222,16 @@ export interface ThemeableBrowserOptions {
|
||||
})
|
||||
@Injectable()
|
||||
export class ThemeableBrowser {
|
||||
private _objectInstance: any;
|
||||
|
||||
constructor(url: string, target: string, styleOptions: ThemeableBrowserOptions) {
|
||||
try {
|
||||
this._objectInstance = cordova.ThemeableBrowser.open(url, target, styleOptions);
|
||||
} catch (e) {
|
||||
window.open(url);
|
||||
console.warn('Native: ThemeableBrowser is not installed or you are running on a browser. Falling back to window.open, all instance methods will NOT work.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an browser window that was opened hidden. Calling this has no effect
|
||||
* if the browser was already visible.
|
||||
* Creates a browser instance
|
||||
* @param url {string} URL to open
|
||||
* @param target {string} Target
|
||||
* @param styleOptions {ThemeableBrowserOptions} Themeable browser options
|
||||
* @returns {ThemeableBrowserObject}
|
||||
*/
|
||||
@CordovaInstance({sync: true})
|
||||
show(): void { }
|
||||
|
||||
/**
|
||||
* Closes the browser window.
|
||||
*/
|
||||
@CordovaInstance({sync: true})
|
||||
close(): void { }
|
||||
|
||||
/**
|
||||
* Reloads the current page
|
||||
*/
|
||||
@CordovaInstance({ sync: true })
|
||||
reload(): void { }
|
||||
|
||||
/**
|
||||
* Injects JavaScript code into the browser window.
|
||||
* @param script Details of the script to run, specifying either a file or code key.
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
@CordovaInstance()
|
||||
executeScript(script: {file?: string, code?: string}): Promise<any> {return; }
|
||||
|
||||
/**
|
||||
* Injects CSS into the browser window.
|
||||
* @param css Details of the script to run, specifying either a file or code key.
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
@CordovaInstance()
|
||||
insertCss(css: {file?: string, code?: string}): Promise<any> {return; }
|
||||
|
||||
/**
|
||||
* A method that allows you to listen to events happening in the browser.
|
||||
* Available events are: `ThemeableBrowserError`, `ThemeableBrowserWarning`, `critical`, `loadfail`, `unexpected`, `undefined`
|
||||
* @param event Event name
|
||||
* @returns {Observable<any>} Returns back an observable that will listen to the event on subscribe, and will stop listening to the event on unsubscribe.
|
||||
*/
|
||||
on(event: string): Observable<any> {
|
||||
return new Observable<any>((observer) => {
|
||||
this._objectInstance.addEventListener(event, observer.next.bind(observer));
|
||||
return () => this._objectInstance.removeEventListener(event, observer.next.bind(observer));
|
||||
});
|
||||
create(url: string, target: string, styleOptions: ThemeableBrowserOptions): ThemeableBrowserObject {
|
||||
return new ThemeableBrowserObject(url, target, styleOptions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user