Looking to integrate Vue-Cordova with Cordova-plugin-file-opener2 to open PDF files within iOS/Android applications.
In the Vue-Cordova setup, plugins related to the device are defined on the data property of the App vue instance:
data: function () {
return {
cordova: Vue.cordova,
plugins: {
'cordova-plugin-camera': function () {
if (!Vue.cordova.camera) {
window.alert('Vue.cordova.camera not found !')
return
}
Vue.cordova.camera.getPicture((imageURI) => {
window.alert('Photo URI : ' + imageURI)
}, (message) => {
window.alert('FAILED : ' + message)
}, {
quality: 50,
destinationType: Vue.cordova.camera.DestinationType.FILE_URI
})
},
....
While I can access these properties on my iOS simulator, I'm facing difficulty in accessing externally installed plugins via Cordova CLI. The Cordova object that should enable calling file-opener2 commands like:
cordova.plugins.fileOpener2.open(
filePath,
fileMIMEType,
{
error : function(){ },
success : function(){ }
}
);
has additional properties not present on the Vue.cordova instance. Trying to access them via:
Vue.cordova.plugins.fileOpener2
results in undefined.
Seeking guidance on how to incorporate external plugins into Vue-Cordova, or potentially find a workaround?
EDIT:
Despite my efforts, I haven't succeeded, but progress seems near.
The steps taken include:
- cloning https://github.com/pwlin/cordova-plugin-file-opener2 into the plugins folder of the Cordova project
modifying
:node_modules/vue-cordova/index.js
function(module, exports, webpack_require) {
'use strict'; // list here all supported plugins var pluginsList = ['cordova-plugin-camera', 'cordova-plugin-device', 'cordova-plugin-geolocation', 'cordova-plugin-contacts', 'cordova-plugin-file-opener2']; exports.install = function (Vue, options) { // declare global Vue.cordova object Vue.cordova = Vue.cordova || { deviceready: false, plugins: [] }; // Cordova events wrapper Vue.cordova.on = function (eventName, cb) { document.addEventListener(eventName, cb, false); }; // let Vue know that deviceready has been triggered document.addEventListener('deviceready', function () { Vue.cordova.deviceready = true; }, false); // load supported plugins pluginsList.forEach(function (pluginName) { var plugin = __webpack_require__(1)("./" + pluginName); plugin.install(Vue, options, function (pluginLoaded) { if (pluginLoaded) { Vue.cordova.plugins.push(pluginName); } if (Vue.config.debug) { console.log('[VueCordova]', pluginName, '→', pluginLoaded ? 'loaded' : 'not loaded'); } }); }); };
// }, / 1 / // function(module, exports, webpack_require) {
var map = { "./cordova-plugin-camera": 2, "./cordova-plugin-camera.js": 2, "./cordova-plugin-contacts": 3, "./cordova-plugin-contacts.js": 3, "./cordova-plugin-device": 4, "./cordova-plugin-device.js": 4, "./cordova-plugin-geolocation": 5, "./cordova-plugin-geolocation.js": 5, "./cordova-plugin-file-opener2": 6 }; function webpackContext(req) { return __webpack_require__(webpackContextResolve(req)); }; function webpackContextResolve(req) { return map[req] || (function() { throw new Error("Cannot find module '" + req + "'.") }()); }; webpackContext.keys = function webpackContextKeys() { return Object.keys(map); }; webpackContext.resolve = webpackContextResolve; module.exports = webpackContext; webpackContext.id = 1;
/***/ },
...
/***/ function(module, exports) {
'use strict'; exports.install = function (Vue, options, cb) { document.addEventListener('deviceready', function () { if (typeof cordova.plugins.fileOpener2 === 'undefined'){ return cb(false); } // pass through the geolocation object Vue.cordova.fileOpener2 = cordova.plugins.fileOpener2; return cb(true); }, false); }; /***/ },
included the following addition to plugins in the data object in app.vue: (Unsure about further additions needed for this definition. Any recommendations?)
'cordova-plugin-file-opener2': function () { if (!Vue.cordova.fileOpener2){ window.alert('Vue.cordova.fileOpener2 not found !') return } }
Following these steps, anticipation is high for {{ fileOpener2 }} availability in the template as an object, yet it remains elusive. What am I overlooking?