mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 11:41:20 +08:00
Moved to Plugins
This commit is contained in:
50
ionic/plugins/plugin.ts
Normal file
50
ionic/plugins/plugin.ts
Normal file
@ -0,0 +1,50 @@
|
||||
export class NativePluginDecorator {
|
||||
constructor(cls, config) {
|
||||
this.cls = cls;
|
||||
this.config = config;
|
||||
|
||||
cls.ifPlugin = (cb, returnType=null) => {
|
||||
// Convert to boolean the plugin param
|
||||
var exists = !!check;
|
||||
if(typeof this.config.pluginCheck === 'function') {
|
||||
exists = this.config.pluginCheck();
|
||||
}
|
||||
if(exists) {
|
||||
return cb();
|
||||
}
|
||||
|
||||
// We don't have the plugin, so print a warning message
|
||||
cls.pluginWarn();
|
||||
|
||||
// If the user supplied a default return value, return it here.
|
||||
return (typeof returnType === 'function') ? returnType() : returnType;
|
||||
};
|
||||
|
||||
cls.pluginWarn = () => {
|
||||
if(cls._pluginWarned) {
|
||||
// Only warn once
|
||||
return;
|
||||
}
|
||||
|
||||
let platformString = [];
|
||||
for(var k in this.config.platforms) {
|
||||
platformString.push('\t' + k + ': '+ this.config.platforms[k]);
|
||||
}
|
||||
console.warn('Plugin for ' + this.config.name +
|
||||
' not installed. For native functionality, please install the correct plugin for your platform:\n' +
|
||||
platformString.join('\n'));
|
||||
|
||||
// Set a flag so we don't warn again
|
||||
cls._pluginWarned = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function NativePlugin(config) {
|
||||
return function(cls) {
|
||||
var annotations = Reflect.getMetadata('annotations', cls) || [];
|
||||
annotations.push(new NativePluginDecorator(cls, config));
|
||||
Reflect.defineMetadata('annotations', annotations, cls);
|
||||
return cls;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user