mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-02-22 01:19:36 +08:00
feat(plugin): checkInstall w/ warning msg
This commit is contained in:
parent
1b87af86bf
commit
47112c7c24
@ -18,7 +18,7 @@ export const getPlugin = function(pluginRef: string): any {
|
|||||||
* @param pluginObj
|
* @param pluginObj
|
||||||
* @param method
|
* @param method
|
||||||
*/
|
*/
|
||||||
export const pluginWarn = function(pluginObj: any, method: string) {
|
export const pluginWarn = function(pluginObj: any, method?: string) {
|
||||||
let pluginName = pluginObj.name, plugin = pluginObj.plugin;
|
let pluginName = pluginObj.name, plugin = pluginObj.plugin;
|
||||||
if (method) {
|
if (method) {
|
||||||
console.warn('Native: tried calling ' + pluginName + '.' + method + ', but the ' + pluginName + ' plugin is not installed.');
|
console.warn('Native: tried calling ' + pluginName + '.' + method + ', but the ' + pluginName + ' plugin is not installed.');
|
||||||
@ -322,7 +322,7 @@ export function Plugin(config) {
|
|||||||
cls[k] = config[k];
|
cls[k] = config[k];
|
||||||
}
|
}
|
||||||
|
|
||||||
cls['installed'] = function() {
|
cls['installed'] = function(printWarning?: boolean) {
|
||||||
return !!getPlugin(config.pluginRef);
|
return !!getPlugin(config.pluginRef);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -330,6 +330,16 @@ export function Plugin(config) {
|
|||||||
return getPlugin(config.pluginRef);
|
return getPlugin(config.pluginRef);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
cls['checkInstall'] = function() {
|
||||||
|
let pluginInstance = getPlugin(config.pluginRef);
|
||||||
|
|
||||||
|
if (!pluginInstance) {
|
||||||
|
pluginWarn(cls);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
return cls;
|
return cls;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user