Merge pull request #31 from ielcoro/feature/UriSchemes

Windows: Add support for URI schemes
This commit is contained in:
pwlin 2015-10-19 12:15:50 +02:00
commit ccd34cb42f

View File

@ -2,10 +2,48 @@
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 path = args[0];
var getFile = getFileLoaderForScheme(path);
getFile(path).then(function (file) {
var options = new Windows.System.LauncherOptions();
options.displayApplicationPicker = true;
@ -17,6 +55,8 @@
}
});
}, function (errror) {
console.log("Error abriendo el archivo");
});
}