mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-02-22 01:19:36 +08:00
feat(plugin): proxy plugin properties
Rename RequiresPlugin decorator to CordovaProperty and replace getter so we can forward property access to the underlying plugin property.
This commit is contained in:
parent
f360827b20
commit
fc54fefde5
@ -1,4 +1,6 @@
|
|||||||
import {Plugin, Cordova} from './plugin';
|
import {Plugin, Cordova, CordovaProperty} from './plugin';
|
||||||
|
|
||||||
|
declare var window;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The AppRate plugin makes it easy to prompt the user to rate your app, either now, later, or never.
|
* The AppRate plugin makes it easy to prompt the user to rate your app, either now, later, or never.
|
||||||
@ -43,8 +45,10 @@ export class AppRate {
|
|||||||
* customLocale {Object} null - custom locale object
|
* customLocale {Object} null - custom locale object
|
||||||
* @type {{}}
|
* @type {{}}
|
||||||
*/
|
*/
|
||||||
@Cordova()
|
@CordovaProperty
|
||||||
static preferences = {};
|
static get preferences(){
|
||||||
|
return window.AppRate.preferences;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prompts the user for rating
|
* Prompts the user for rating
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {Plugin, RequiresPlugin} from './plugin';
|
import {Plugin, CordovaProperty} from './plugin';
|
||||||
|
|
||||||
declare var window: {
|
declare var window: {
|
||||||
device: Device
|
device: Device
|
||||||
@ -49,8 +49,8 @@ export class Device {
|
|||||||
*
|
*
|
||||||
* @returns {Object} The device object.
|
* @returns {Object} The device object.
|
||||||
*/
|
*/
|
||||||
@RequiresPlugin
|
@CordovaProperty
|
||||||
static getDevice() {
|
static get device() {
|
||||||
return window.device;
|
return window.device;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,20 +170,20 @@ export function Cordova(opts:any = {}) {
|
|||||||
/**
|
/**
|
||||||
* Before calling the original method, ensure Cordova and the plugin are installed.
|
* Before calling the original method, ensure Cordova and the plugin are installed.
|
||||||
*/
|
*/
|
||||||
export function RequiresPlugin(target: Function, key: string, descriptor: TypedPropertyDescriptor<any>) {
|
export function CordovaProperty(target: Function, key: string, descriptor: TypedPropertyDescriptor<any>) {
|
||||||
let originalMethod = descriptor.value;
|
let originalMethod = descriptor.get;
|
||||||
|
|
||||||
descriptor.value = function(...args: any[]) {
|
descriptor.get = function(...args: any[]) {
|
||||||
// console.log('Calling', this);
|
// console.log('Calling', this);
|
||||||
if(!window.cordova) {
|
if(!window.cordova) {
|
||||||
cordovaWarn(this.name, null);
|
cordovaWarn(this.name, null);
|
||||||
return;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
let pluginInstance = getPlugin(this.pluginRef);
|
let pluginInstance = getPlugin(this.pluginRef);
|
||||||
if(!pluginInstance) {
|
if(!pluginInstance) {
|
||||||
pluginWarn(this, key);
|
pluginWarn(this, key);
|
||||||
return;
|
return {};
|
||||||
}
|
}
|
||||||
return originalMethod.apply(this, args);
|
return originalMethod.apply(this, args);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {Plugin, Cordova, RequiresPlugin} from './plugin';
|
import {Plugin, Cordova, CordovaProperty} from './plugin';
|
||||||
|
|
||||||
declare var window;
|
declare var window;
|
||||||
|
|
||||||
@ -102,8 +102,8 @@ export class StatusBar {
|
|||||||
/**
|
/**
|
||||||
* Whether the StatusBar is currently visible or not.
|
* Whether the StatusBar is currently visible or not.
|
||||||
*/
|
*/
|
||||||
@RequiresPlugin
|
@CordovaProperty
|
||||||
static isVisible() {
|
static get isVisible() {
|
||||||
return window.StatusBar.isVisible;
|
return window.StatusBar.isVisible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user