mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-02-01 02:53:03 +08:00
Use AngularJS promise if available
This commit is contained in:
parent
fc9dcc8e64
commit
0cc1a2b2ff
@ -2,13 +2,15 @@ import { CordovaOptions } from './interfaces';
|
|||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import 'rxjs/add/observable/fromEvent';
|
import 'rxjs/add/observable/fromEvent';
|
||||||
|
|
||||||
|
declare const window: any;
|
||||||
|
|
||||||
export const ERR_CORDOVA_NOT_AVAILABLE = { error: 'cordova_not_available' };
|
export const ERR_CORDOVA_NOT_AVAILABLE = { error: 'cordova_not_available' };
|
||||||
export const ERR_PLUGIN_NOT_INSTALLED = { error: 'plugin_not_installed' };
|
export const ERR_PLUGIN_NOT_INSTALLED = { error: 'plugin_not_installed' };
|
||||||
|
|
||||||
export function getPromise(callback: Function) {
|
export function getPromise<T>(callback: (resolve: Function, reject?: Function) => any): Promise<T> {
|
||||||
const tryNativePromise = () => {
|
const tryNativePromise = () => {
|
||||||
if (Promise) {
|
if (Promise) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise<T>((resolve, reject) => {
|
||||||
callback(resolve, reject);
|
callback(resolve, reject);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -16,6 +18,17 @@ export function getPromise(callback: Function) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (window.angular) {
|
||||||
|
const injector = window.angular.element(document.querySelector('[ng-app]') || document.body).injector();
|
||||||
|
if (injector) {
|
||||||
|
let $q = injector.get('$q');
|
||||||
|
return $q((resolve: Function, reject: Function) => {
|
||||||
|
callback(resolve, reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
console.warn('Angular 1 was detected but $q couldn\'t be retrieved. This is usually when the app is not bootstrapped on the html or body tag. Falling back to native promises which won\'t trigger an automatic digest when promises resolve.');
|
||||||
|
}
|
||||||
|
|
||||||
return tryNativePromise();
|
return tryNativePromise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Cordova, CordovaCheck, IonicNativePlugin, Plugin } from '@ionic-native/core';
|
import { Cordova, CordovaCheck, IonicNativePlugin, Plugin, getPromise } from '@ionic-native/core';
|
||||||
|
|
||||||
export interface EmailComposerOptions {
|
export interface EmailComposerOptions {
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ export class EmailComposer extends IonicNativePlugin {
|
|||||||
*/
|
*/
|
||||||
@CordovaCheck()
|
@CordovaCheck()
|
||||||
isAvailable(app?: string): Promise<any> {
|
isAvailable(app?: string): Promise<any> {
|
||||||
return new Promise<boolean>((resolve, reject) => {
|
return getPromise<boolean>((resolve, reject) => {
|
||||||
if (app) {
|
if (app) {
|
||||||
EmailComposer.getPlugin().isAvailable(app, (isAvailable: boolean) => {
|
EmailComposer.getPlugin().isAvailable(app, (isAvailable: boolean) => {
|
||||||
if (isAvailable) {
|
if (isAvailable) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CordovaCheck, CordovaProperty, IonicNativePlugin, Plugin } from '@ionic-native/core';
|
import { CordovaCheck, CordovaProperty, IonicNativePlugin, Plugin, getPromise } from '@ionic-native/core';
|
||||||
|
|
||||||
export interface IFile extends Blob {
|
export interface IFile extends Blob {
|
||||||
/**
|
/**
|
||||||
@ -715,7 +715,7 @@ export class File extends IonicNativePlugin {
|
|||||||
*/
|
*/
|
||||||
@CordovaCheck()
|
@CordovaCheck()
|
||||||
getFreeDiskSpace(): Promise<number> {
|
getFreeDiskSpace(): Promise<number> {
|
||||||
return new Promise<any>((resolve, reject) => {
|
return getPromise<any>((resolve, reject) => {
|
||||||
cordova.exec(resolve, reject, 'File', 'getFreeDiskSpace', []);
|
cordova.exec(resolve, reject, 'File', 'getFreeDiskSpace', []);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1150,7 +1150,7 @@ export class File extends IonicNativePlugin {
|
|||||||
*/
|
*/
|
||||||
@CordovaCheck()
|
@CordovaCheck()
|
||||||
resolveLocalFilesystemUrl(fileUrl: string): Promise<Entry> {
|
resolveLocalFilesystemUrl(fileUrl: string): Promise<Entry> {
|
||||||
return new Promise<Entry>((resolve, reject) => {
|
return getPromise<Entry>((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
window.resolveLocalFileSystemURL(fileUrl, (entry: Entry) => {
|
window.resolveLocalFileSystemURL(fileUrl, (entry: Entry) => {
|
||||||
resolve(entry);
|
resolve(entry);
|
||||||
@ -1193,7 +1193,7 @@ export class File extends IonicNativePlugin {
|
|||||||
*/
|
*/
|
||||||
@CordovaCheck()
|
@CordovaCheck()
|
||||||
getDirectory(directoryEntry: DirectoryEntry, directoryName: string, flags: Flags): Promise<DirectoryEntry> {
|
getDirectory(directoryEntry: DirectoryEntry, directoryName: string, flags: Flags): Promise<DirectoryEntry> {
|
||||||
return new Promise<DirectoryEntry>((resolve, reject) => {
|
return getPromise<DirectoryEntry>((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
directoryEntry.getDirectory(directoryName, flags, (de) => {
|
directoryEntry.getDirectory(directoryName, flags, (de) => {
|
||||||
resolve(de);
|
resolve(de);
|
||||||
@ -1217,7 +1217,7 @@ export class File extends IonicNativePlugin {
|
|||||||
*/
|
*/
|
||||||
@CordovaCheck()
|
@CordovaCheck()
|
||||||
getFile(directoryEntry: DirectoryEntry, fileName: string, flags: Flags): Promise<FileEntry> {
|
getFile(directoryEntry: DirectoryEntry, fileName: string, flags: Flags): Promise<FileEntry> {
|
||||||
return new Promise<FileEntry>((resolve, reject) => {
|
return getPromise<FileEntry>((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
directoryEntry.getFile(fileName, flags, resolve, (err) => {
|
directoryEntry.getFile(fileName, flags, resolve, (err) => {
|
||||||
this.fillErrorMessage(err);
|
this.fillErrorMessage(err);
|
||||||
@ -1267,7 +1267,7 @@ export class File extends IonicNativePlugin {
|
|||||||
})
|
})
|
||||||
.then((fileEntry: FileEntry) => {
|
.then((fileEntry: FileEntry) => {
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
return new Promise<T>((resolve, reject) => {
|
return getPromise<T>((resolve, reject) => {
|
||||||
reader.onloadend = () => {
|
reader.onloadend = () => {
|
||||||
if (reader.result !== undefined || reader.result !== null) {
|
if (reader.result !== undefined || reader.result !== null) {
|
||||||
resolve(<T><any>reader.result);
|
resolve(<T><any>reader.result);
|
||||||
@ -1302,7 +1302,7 @@ export class File extends IonicNativePlugin {
|
|||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
private remove(fe: Entry): Promise<RemoveResult> {
|
private remove(fe: Entry): Promise<RemoveResult> {
|
||||||
return new Promise<RemoveResult>((resolve, reject) => {
|
return getPromise<RemoveResult>((resolve, reject) => {
|
||||||
fe.remove(() => {
|
fe.remove(() => {
|
||||||
resolve({ success: true, fileRemoved: fe });
|
resolve({ success: true, fileRemoved: fe });
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
@ -1316,7 +1316,7 @@ export class File extends IonicNativePlugin {
|
|||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
private move(srce: Entry, destdir: DirectoryEntry, newName: string): Promise<Entry> {
|
private move(srce: Entry, destdir: DirectoryEntry, newName: string): Promise<Entry> {
|
||||||
return new Promise<Entry>((resolve, reject) => {
|
return getPromise<Entry>((resolve, reject) => {
|
||||||
srce.moveTo(destdir, newName, (deste) => {
|
srce.moveTo(destdir, newName, (deste) => {
|
||||||
resolve(deste);
|
resolve(deste);
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
@ -1330,7 +1330,7 @@ export class File extends IonicNativePlugin {
|
|||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
private copy(srce: Entry, destdir: DirectoryEntry, newName: string): Promise<Entry> {
|
private copy(srce: Entry, destdir: DirectoryEntry, newName: string): Promise<Entry> {
|
||||||
return new Promise<Entry>((resolve, reject) => {
|
return getPromise<Entry>((resolve, reject) => {
|
||||||
srce.copyTo(destdir, newName, (deste) => {
|
srce.copyTo(destdir, newName, (deste) => {
|
||||||
resolve(deste);
|
resolve(deste);
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
@ -1344,7 +1344,7 @@ export class File extends IonicNativePlugin {
|
|||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
private readEntries(dr: DirectoryReader): Promise<Entry[]> {
|
private readEntries(dr: DirectoryReader): Promise<Entry[]> {
|
||||||
return new Promise<Entry[]>((resolve, reject) => {
|
return getPromise<Entry[]>((resolve, reject) => {
|
||||||
dr.readEntries((entries) => {
|
dr.readEntries((entries) => {
|
||||||
resolve(entries);
|
resolve(entries);
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
@ -1358,7 +1358,7 @@ export class File extends IonicNativePlugin {
|
|||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
private rimraf(de: DirectoryEntry): Promise<RemoveResult> {
|
private rimraf(de: DirectoryEntry): Promise<RemoveResult> {
|
||||||
return new Promise<RemoveResult>((resolve, reject) => {
|
return getPromise<RemoveResult>((resolve, reject) => {
|
||||||
de.removeRecursively(() => {
|
de.removeRecursively(() => {
|
||||||
resolve({ success: true, fileRemoved: de });
|
resolve({ success: true, fileRemoved: de });
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
@ -1372,7 +1372,7 @@ export class File extends IonicNativePlugin {
|
|||||||
* @hidden
|
* @hidden
|
||||||
*/
|
*/
|
||||||
private createWriter(fe: FileEntry): Promise<FileWriter> {
|
private createWriter(fe: FileEntry): Promise<FileWriter> {
|
||||||
return new Promise<FileWriter>((resolve, reject) => {
|
return getPromise<FileWriter>((resolve, reject) => {
|
||||||
fe.createWriter((writer) => {
|
fe.createWriter((writer) => {
|
||||||
resolve(writer);
|
resolve(writer);
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
@ -1390,7 +1390,7 @@ export class File extends IonicNativePlugin {
|
|||||||
return this.writeFileInChunks(writer, gu);
|
return this.writeFileInChunks(writer, gu);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise<any>((resolve, reject) => {
|
return getPromise<any>((resolve, reject) => {
|
||||||
writer.onwriteend = (evt) => {
|
writer.onwriteend = (evt) => {
|
||||||
if (writer.error) {
|
if (writer.error) {
|
||||||
reject(writer.error);
|
reject(writer.error);
|
||||||
@ -1417,7 +1417,7 @@ export class File extends IonicNativePlugin {
|
|||||||
writer.write(chunk);
|
writer.write(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise<any>((resolve, reject) => {
|
return getPromise<any>((resolve, reject) => {
|
||||||
writer.onerror = reject;
|
writer.onerror = reject;
|
||||||
writer.onwrite = () => {
|
writer.onwrite = () => {
|
||||||
if (writtenSize < file.size) {
|
if (writtenSize < file.size) {
|
||||||
|
@ -6,7 +6,8 @@ import {
|
|||||||
InstanceCheck,
|
InstanceCheck,
|
||||||
InstanceProperty,
|
InstanceProperty,
|
||||||
IonicNativePlugin,
|
IonicNativePlugin,
|
||||||
Plugin
|
Plugin,
|
||||||
|
getPromise
|
||||||
} from '@ionic-native/core';
|
} from '@ionic-native/core';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import 'rxjs/add/observable/fromEvent';
|
import 'rxjs/add/observable/fromEvent';
|
||||||
@ -1013,7 +1014,7 @@ export class BaseClass {
|
|||||||
*/
|
*/
|
||||||
@InstanceCheck()
|
@InstanceCheck()
|
||||||
addListenerOnce(eventName: string): Promise<any> {
|
addListenerOnce(eventName: string): Promise<any> {
|
||||||
return new Promise<any>((resolve) => {
|
return getPromise<any>((resolve) => {
|
||||||
this._objectInstance.one(eventName, (...args: any[]) => {
|
this._objectInstance.one(eventName, (...args: any[]) => {
|
||||||
if (args[args.length - 1] instanceof GoogleMaps.getPlugin().BaseClass) {
|
if (args[args.length - 1] instanceof GoogleMaps.getPlugin().BaseClass) {
|
||||||
if (args[args.length - 1].type === 'Map') {
|
if (args[args.length - 1].type === 'Map') {
|
||||||
@ -1110,7 +1111,7 @@ export class BaseClass {
|
|||||||
*/
|
*/
|
||||||
@InstanceCheck()
|
@InstanceCheck()
|
||||||
one(eventName: string): Promise<any> {
|
one(eventName: string): Promise<any> {
|
||||||
return new Promise<any>((resolve) => {
|
return getPromise<any>((resolve) => {
|
||||||
this._objectInstance.one(eventName, (...args: any[]) => {
|
this._objectInstance.one(eventName, (...args: any[]) => {
|
||||||
if (args[args.length - 1] instanceof GoogleMaps.getPlugin().BaseClass) {
|
if (args[args.length - 1] instanceof GoogleMaps.getPlugin().BaseClass) {
|
||||||
if (args[args.length - 1].type === 'Map') {
|
if (args[args.length - 1].type === 'Map') {
|
||||||
@ -1210,7 +1211,7 @@ export class BaseArrayClass<T> extends BaseClass {
|
|||||||
*/
|
*/
|
||||||
@CordovaCheck()
|
@CordovaCheck()
|
||||||
forEachAsync(fn: ((element: T, callback: () => void) => void)): Promise<void> {
|
forEachAsync(fn: ((element: T, callback: () => void) => void)): Promise<void> {
|
||||||
return new Promise<void>((resolve) => {
|
return getPromise<void>((resolve) => {
|
||||||
this._objectInstance.forEach(fn, resolve);
|
this._objectInstance.forEach(fn, resolve);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1236,7 +1237,7 @@ export class BaseArrayClass<T> extends BaseClass {
|
|||||||
*/
|
*/
|
||||||
@CordovaCheck()
|
@CordovaCheck()
|
||||||
mapAsync(fn: ((element: T, callback: (newElement: any) => void) => void)): Promise<any[]> {
|
mapAsync(fn: ((element: T, callback: (newElement: any) => void) => void)): Promise<any[]> {
|
||||||
return new Promise<any[]>((resolve) => {
|
return getPromise<any[]>((resolve) => {
|
||||||
this._objectInstance.map(fn, resolve);
|
this._objectInstance.map(fn, resolve);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1260,7 +1261,7 @@ export class BaseArrayClass<T> extends BaseClass {
|
|||||||
*/
|
*/
|
||||||
@CordovaCheck()
|
@CordovaCheck()
|
||||||
filterAsync(fn: (element: T, callback: (result: boolean) => void) => void): Promise<T[]> {
|
filterAsync(fn: (element: T, callback: (result: boolean) => void) => void): Promise<T[]> {
|
||||||
return new Promise<any[]>((resolve) => {
|
return getPromise<any[]>((resolve) => {
|
||||||
this._objectInstance.filter(fn, resolve);
|
this._objectInstance.filter(fn, resolve);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1566,7 +1567,7 @@ export class Environment {
|
|||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
static getLicenseInfo(): Promise<any> {
|
static getLicenseInfo(): Promise<any> {
|
||||||
return new Promise<any>((resolve) => {
|
return getPromise<any>((resolve) => {
|
||||||
GoogleMaps.getPlugin().environment.getLicenseInfo((text: string) => resolve(text));
|
GoogleMaps.getPlugin().environment.getLicenseInfo((text: string) => resolve(text));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -1626,7 +1627,7 @@ export class Geocoder {
|
|||||||
// ]
|
// ]
|
||||||
// })
|
// })
|
||||||
// -------------------------
|
// -------------------------
|
||||||
return new Promise<BaseArrayClass<GeocoderResult>>((resolve, reject) => {
|
return getPromise<BaseArrayClass<GeocoderResult>>((resolve, reject) => {
|
||||||
GoogleMaps.getPlugin().Geocoder.geocode(request, (mvcArray: any) => {
|
GoogleMaps.getPlugin().Geocoder.geocode(request, (mvcArray: any) => {
|
||||||
if (mvcArray) {
|
if (mvcArray) {
|
||||||
resolve(new BaseArrayClass(mvcArray));
|
resolve(new BaseArrayClass(mvcArray));
|
||||||
@ -1641,7 +1642,7 @@ export class Geocoder {
|
|||||||
// address: "Kyoto, Japan"
|
// address: "Kyoto, Japan"
|
||||||
// })
|
// })
|
||||||
// -------------------------
|
// -------------------------
|
||||||
return new Promise<GeocoderResult[]>((resolve, reject) => {
|
return getPromise<GeocoderResult[]>((resolve, reject) => {
|
||||||
GoogleMaps.getPlugin().Geocoder.geocode(request, (results: GeocoderResult[]) => {
|
GoogleMaps.getPlugin().Geocoder.geocode(request, (results: GeocoderResult[]) => {
|
||||||
if (results) {
|
if (results) {
|
||||||
resolve(results);
|
resolve(results);
|
||||||
@ -1945,7 +1946,7 @@ export class GoogleMap extends BaseClass {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
this._objectInstance.one = this._objectInstance.addEventListenerOnce;
|
this._objectInstance.one = this._objectInstance.addEventListenerOnce;
|
||||||
(new Promise<any>((resolve, reject) => {
|
(getPromise<any>((resolve, reject) => {
|
||||||
let count: number = 0;
|
let count: number = 0;
|
||||||
let timer: any = setInterval(() => {
|
let timer: any = setInterval(() => {
|
||||||
let target = document.querySelector('.show-page #' + element);
|
let target = document.querySelector('.show-page #' + element);
|
||||||
@ -2193,7 +2194,7 @@ export class GoogleMap extends BaseClass {
|
|||||||
delete this.get('_overlays')[overlayId];
|
delete this.get('_overlays')[overlayId];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return new Promise<any>((resolve) => {
|
return getPromise<any>((resolve) => {
|
||||||
this._objectInstance.remove(() => resolve());
|
this._objectInstance.remove(() => resolve());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -2210,7 +2211,7 @@ export class GoogleMap extends BaseClass {
|
|||||||
delete this.get('_overlays')[overlayId];
|
delete this.get('_overlays')[overlayId];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return new Promise<any>((resolve) => {
|
return getPromise<any>((resolve) => {
|
||||||
this._objectInstance.clear(() => resolve());
|
this._objectInstance.clear(() => resolve());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -2315,7 +2316,7 @@ export class GoogleMap extends BaseClass {
|
|||||||
*/
|
*/
|
||||||
@InstanceCheck()
|
@InstanceCheck()
|
||||||
addMarker(options: MarkerOptions): Promise<Marker | any> {
|
addMarker(options: MarkerOptions): Promise<Marker | any> {
|
||||||
return new Promise<Marker>((resolve, reject) => {
|
return getPromise<Marker>((resolve, reject) => {
|
||||||
this._objectInstance.addMarker(options, (marker: any) => {
|
this._objectInstance.addMarker(options, (marker: any) => {
|
||||||
if (marker) {
|
if (marker) {
|
||||||
let overlayId: string = marker.getId();
|
let overlayId: string = marker.getId();
|
||||||
@ -2337,7 +2338,7 @@ export class GoogleMap extends BaseClass {
|
|||||||
|
|
||||||
@InstanceCheck()
|
@InstanceCheck()
|
||||||
addMarkerCluster(options: MarkerClusterOptions): Promise<MarkerCluster | any> {
|
addMarkerCluster(options: MarkerClusterOptions): Promise<MarkerCluster | any> {
|
||||||
return new Promise<MarkerCluster>((resolve, reject) => {
|
return getPromise<MarkerCluster>((resolve, reject) => {
|
||||||
this._objectInstance.addMarkerCluster(options, (markerCluster: any) => {
|
this._objectInstance.addMarkerCluster(options, (markerCluster: any) => {
|
||||||
if (markerCluster) {
|
if (markerCluster) {
|
||||||
let overlayId = markerCluster.getId();
|
let overlayId = markerCluster.getId();
|
||||||
@ -2364,7 +2365,7 @@ export class GoogleMap extends BaseClass {
|
|||||||
*/
|
*/
|
||||||
@InstanceCheck()
|
@InstanceCheck()
|
||||||
addCircle(options: CircleOptions): Promise<Circle | any> {
|
addCircle(options: CircleOptions): Promise<Circle | any> {
|
||||||
return new Promise<Circle>((resolve, reject) => {
|
return getPromise<Circle>((resolve, reject) => {
|
||||||
this._objectInstance.addCircle(options, (circle: any) => {
|
this._objectInstance.addCircle(options, (circle: any) => {
|
||||||
if (circle) {
|
if (circle) {
|
||||||
let overlayId: string = circle.getId();
|
let overlayId: string = circle.getId();
|
||||||
@ -2390,7 +2391,7 @@ export class GoogleMap extends BaseClass {
|
|||||||
*/
|
*/
|
||||||
@InstanceCheck()
|
@InstanceCheck()
|
||||||
addPolygon(options: PolygonOptions): Promise<Polygon | any> {
|
addPolygon(options: PolygonOptions): Promise<Polygon | any> {
|
||||||
return new Promise<Polygon>((resolve, reject) => {
|
return getPromise<Polygon>((resolve, reject) => {
|
||||||
this._objectInstance.addPolygon(options, (polygon: any) => {
|
this._objectInstance.addPolygon(options, (polygon: any) => {
|
||||||
if (polygon) {
|
if (polygon) {
|
||||||
let overlayId: string = polygon.getId();
|
let overlayId: string = polygon.getId();
|
||||||
@ -2416,7 +2417,7 @@ export class GoogleMap extends BaseClass {
|
|||||||
*/
|
*/
|
||||||
@InstanceCheck()
|
@InstanceCheck()
|
||||||
addPolyline(options: PolylineOptions): Promise<Polyline | any> {
|
addPolyline(options: PolylineOptions): Promise<Polyline | any> {
|
||||||
return new Promise<Polyline>((resolve, reject) => {
|
return getPromise<Polyline>((resolve, reject) => {
|
||||||
this._objectInstance.addPolyline(options, (polyline: any) => {
|
this._objectInstance.addPolyline(options, (polyline: any) => {
|
||||||
if (polyline) {
|
if (polyline) {
|
||||||
let overlayId: string = polyline.getId();
|
let overlayId: string = polyline.getId();
|
||||||
@ -2441,7 +2442,7 @@ export class GoogleMap extends BaseClass {
|
|||||||
*/
|
*/
|
||||||
@InstanceCheck()
|
@InstanceCheck()
|
||||||
addTileOverlay(options: TileOverlayOptions): Promise<TileOverlay | any> {
|
addTileOverlay(options: TileOverlayOptions): Promise<TileOverlay | any> {
|
||||||
return new Promise<TileOverlay>((resolve, reject) => {
|
return getPromise<TileOverlay>((resolve, reject) => {
|
||||||
this._objectInstance.addTileOverlay(options, (tileOverlay: any) => {
|
this._objectInstance.addTileOverlay(options, (tileOverlay: any) => {
|
||||||
if (tileOverlay) {
|
if (tileOverlay) {
|
||||||
let overlayId: string = tileOverlay.getId();
|
let overlayId: string = tileOverlay.getId();
|
||||||
@ -2466,7 +2467,7 @@ export class GoogleMap extends BaseClass {
|
|||||||
*/
|
*/
|
||||||
@InstanceCheck()
|
@InstanceCheck()
|
||||||
addGroundOverlay(options: GroundOverlayOptions): Promise<GroundOverlay | any> {
|
addGroundOverlay(options: GroundOverlayOptions): Promise<GroundOverlay | any> {
|
||||||
return new Promise<GroundOverlay>((resolve, reject) => {
|
return getPromise<GroundOverlay>((resolve, reject) => {
|
||||||
this._objectInstance.addGroundOverlay(options, (groundOverlay: any) => {
|
this._objectInstance.addGroundOverlay(options, (groundOverlay: any) => {
|
||||||
if (groundOverlay) {
|
if (groundOverlay) {
|
||||||
let overlayId: string = groundOverlay.getId();
|
let overlayId: string = groundOverlay.getId();
|
||||||
@ -2507,7 +2508,7 @@ export class GoogleMap extends BaseClass {
|
|||||||
// */
|
// */
|
||||||
// @InstanceCheck()
|
// @InstanceCheck()
|
||||||
// addKmlOverlay(options: KmlOverlayOptions): Promise<KmlOverlay | any> {
|
// addKmlOverlay(options: KmlOverlayOptions): Promise<KmlOverlay | any> {
|
||||||
// return new Promise<KmlOverlay>((resolve, reject) => {
|
// return getPromise<KmlOverlay>((resolve, reject) => {
|
||||||
// this._objectInstance.addKmlOverlay(options, (kmlOverlay: any) => {
|
// this._objectInstance.addKmlOverlay(options, (kmlOverlay: any) => {
|
||||||
// if (kmlOverlay) {
|
// if (kmlOverlay) {
|
||||||
// resolve(new KmlOverlay(kmlOverlay));
|
// resolve(new KmlOverlay(kmlOverlay));
|
||||||
@ -3530,7 +3531,7 @@ export class TileOverlay extends BaseClass {
|
|||||||
// if (!this._objectInstance) {
|
// if (!this._objectInstance) {
|
||||||
// return Promise.reject({ error: 'plugin_not_installed' });
|
// return Promise.reject({ error: 'plugin_not_installed' });
|
||||||
// }
|
// }
|
||||||
// return new Promise<any>(
|
// return getPromise<any>(
|
||||||
// resolve => this._objectInstance.addListenerOnce(eventName, resolve)
|
// resolve => this._objectInstance.addListenerOnce(eventName, resolve)
|
||||||
// );
|
// );
|
||||||
// }
|
// }
|
||||||
@ -3579,7 +3580,7 @@ export class TileOverlay extends BaseClass {
|
|||||||
// if (!this._objectInstance) {
|
// if (!this._objectInstance) {
|
||||||
// return Promise.reject({ error: 'plugin_not_installed' });
|
// return Promise.reject({ error: 'plugin_not_installed' });
|
||||||
// }
|
// }
|
||||||
// return new Promise<any>(
|
// return getPromise<any>(
|
||||||
// resolve => this._objectInstance.one(eventName, resolve)
|
// resolve => this._objectInstance.one(eventName, resolve)
|
||||||
// );
|
// );
|
||||||
// }
|
// }
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Cordova, CordovaCheck, IonicNativePlugin, Plugin } from '@ionic-native/core';
|
import { Cordova, CordovaCheck, IonicNativePlugin, Plugin, getPromise } from '@ionic-native/core';
|
||||||
|
|
||||||
export interface PrintOptions {
|
export interface PrintOptions {
|
||||||
/**
|
/**
|
||||||
@ -90,7 +90,7 @@ export class Printer extends IonicNativePlugin {
|
|||||||
*/
|
*/
|
||||||
@CordovaCheck()
|
@CordovaCheck()
|
||||||
check(): Promise<any> {
|
check(): Promise<any> {
|
||||||
return new Promise<any>((resolve: Function) => {
|
return getPromise<any>((resolve: Function) => {
|
||||||
Printer.getPlugin()
|
Printer.getPlugin()
|
||||||
.check((avail: boolean, count: any) => {
|
.check((avail: boolean, count: any) => {
|
||||||
resolve({ avail, count });
|
resolve({ avail, count });
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { IonicNativePlugin, Plugin } from '@ionic-native/core';
|
import { IonicNativePlugin, Plugin, getPromise } from '@ionic-native/core';
|
||||||
|
|
||||||
declare const navigator: any;
|
declare const navigator: any;
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ export class Screenshot extends IonicNativePlugin {
|
|||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
save(format?: string, quality?: number, filename?: string): Promise<any> {
|
save(format?: string, quality?: number, filename?: string): Promise<any> {
|
||||||
return new Promise<any>(
|
return getPromise<any>(
|
||||||
(resolve, reject) => {
|
(resolve, reject) => {
|
||||||
navigator.screenshot.save(
|
navigator.screenshot.save(
|
||||||
(error: any, result: any) => {
|
(error: any, result: any) => {
|
||||||
@ -68,7 +68,7 @@ export class Screenshot extends IonicNativePlugin {
|
|||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
URI(quality?: number): Promise<any> {
|
URI(quality?: number): Promise<any> {
|
||||||
return new Promise<any>(
|
return getPromise<any>(
|
||||||
(resolve, reject) => {
|
(resolve, reject) => {
|
||||||
navigator.screenshot.URI(
|
navigator.screenshot.URI(
|
||||||
(error: any, result: any) => {
|
(error: any, result: any) => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { CordovaCheck, CordovaInstance, IonicNativePlugin, Plugin } from '@ionic-native/core';
|
import { CordovaCheck, CordovaInstance, IonicNativePlugin, Plugin, getPromise } from '@ionic-native/core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @hidden
|
* @hidden
|
||||||
@ -142,7 +142,7 @@ export class SecureStorage extends IonicNativePlugin {
|
|||||||
*/
|
*/
|
||||||
@CordovaCheck()
|
@CordovaCheck()
|
||||||
create(store: string): Promise<SecureStorageObject> {
|
create(store: string): Promise<SecureStorageObject> {
|
||||||
return new Promise((res: Function, rej: Function) => {
|
return getPromise<SecureStorageObject>((res: Function, rej: Function) => {
|
||||||
const instance = new (SecureStorage.getPlugin())(() => res(new SecureStorageObject(instance)), rej, store);
|
const instance = new (SecureStorage.getPlugin())(() => res(new SecureStorageObject(instance)), rej, store);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,8 @@ import {
|
|||||||
CordovaInstance,
|
CordovaInstance,
|
||||||
InstanceProperty,
|
InstanceProperty,
|
||||||
IonicNativePlugin,
|
IonicNativePlugin,
|
||||||
Plugin
|
Plugin,
|
||||||
|
getPromise
|
||||||
} from '@ionic-native/core';
|
} from '@ionic-native/core';
|
||||||
|
|
||||||
declare const sqlitePlugin: any;
|
declare const sqlitePlugin: any;
|
||||||
@ -192,7 +193,7 @@ export class SQLite extends IonicNativePlugin {
|
|||||||
*/
|
*/
|
||||||
@CordovaCheck()
|
@CordovaCheck()
|
||||||
create(config: SQLiteDatabaseConfig): Promise<SQLiteObject> {
|
create(config: SQLiteDatabaseConfig): Promise<SQLiteObject> {
|
||||||
return new Promise((resolve, reject) => {
|
return getPromise<SQLiteObject>((resolve, reject) => {
|
||||||
sqlitePlugin.openDatabase(config, (db: any) => resolve(new SQLiteObject(db)), reject);
|
sqlitePlugin.openDatabase(config, (db: any) => resolve(new SQLiteObject(db)), reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user