diff --git a/src/windows/fileOpener2Proxy.js b/src/windows/fileOpener2Proxy.js index 71692ca..ce13e32 100644 --- a/src/windows/fileOpener2Proxy.js +++ b/src/windows/fileOpener2Proxy.js @@ -2,13 +2,51 @@ var cordova = require('cordova'), fileOpener2 = require('./FileOpener2'); + var schemes = [ + { protocol: 'ms-app', getFile: getFileFromApplicationUri }, + { protocol: 'file:///', getFile: getFileFromFileUri } + ] + + function getFileFromApplicationUri(uri) { + var applicationUri = new Windows.Foundation.Uri(uri); + + return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri); + } + + function getFileFromFileUri(uri) { + var path = Windows.Storage.ApplicationData.current.localFolder.path + + uri.substr(8); + + return getFileFromNativePath(path); + } + + function getFileFromNativePath(path) { + var nativePath = path.split("/").join("\\"); + + return Windows.Storage.StorageFile.getFileFromPathAsync(nativePath); + } + + function getFileLoaderForScheme(path) { + var fileLoader = getFileFromNativePath; + + schemes.some(function (scheme) { + return path.indexOf(scheme.protocol) === 0 ? ((fileLoader = scheme.getFile), true) : false; + }); + + return fileLoader; + } + module.exports = { open: function (successCallback, errorCallback, args) { - Windows.Storage.StorageFile.getFileFromPathAsync(args[0]).then(function (file) { - var options = new Windows.System.LauncherOptions(); - options.displayApplicationPicker = true; + var path = args[0]; + + var getFile = getFileLoaderForScheme(path); + getFile(path).then(function (file) { + var options = new Windows.System.LauncherOptions(); + options.displayApplicationPicker = true; + Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { if (success) { successCallback(); @@ -17,6 +55,8 @@ } }); + }, function (errror) { + console.log("Error abriendo el archivo"); }); }