Reputation: 924
I see I can use any cordova plugin within ionic capacitor. But how I can use it inside vue component for example.
Just for example:
cordova-plugin-prevent-screenshot-coffice
with npmnpm i --save cordova-plugin-prevent-screenshot-coffice
import foo from "cordova-plugin-prevent-screenshot-coffice"
, but it says cannot find that module.Is there a special way to import plugins like the above example plugin (or any other plugin which is not in @ionic-native
namespace)?
This not working for cordova-plugin-prevent-screenshot-coffice
import PLUGIN_X from "PLUGIN_X"
export default defineComponent({
// ...
mounted() {
PLUGIN_X.doSomething()
}
// ...
}
Upvotes: 0
Views: 795
Reputation: 53361
You don't have to import the plugin, the plugin is available on window object.
You can do something like this:
// Enable
(<any>window).plugins.preventscreenshot.enable((a) => this.successCallback(a), (b) => this.errorCallback(b));
// Disable
(<any>window).plugins.preventscreenshot.disable((a) => this.successCallback(a), (b) => this.errorCallback(b));
successCallback(result) {
console.log(result); // true - enabled, false - disabled
}
errorCallback(error) {
console.log(error);
}
or like this if using javascript instead of typescript
document.addEventListener("deviceready", onDeviceReady, false);
// Enable
function onDeviceReady() {
window.plugins.preventscreenshot.enable(successCallback, errorCallback);
}
// Disable
function onDeviceReady() {
window.plugins.preventscreenshot.disable(successCallback, errorCallback);
}
function successCallback(result) {
console.log(result); // true - enabled, false - disabled
}
function errorCallback(error) {
console.log(error);
}
document.addEventListener("onTookScreenshot",function(){
// Receive notification when screenshot is ready;
});
document.addEventListener("onGoingBackground",function(){
// Receive notification when control center or app going in background.
});
Upvotes: 1