mirror of
https://gitee.com/shuto/cordova-plugin-file-opener2.git
synced 2025-01-31 03:52:51 +08:00
Merge pull request #31 from ielcoro/feature/UriSchemes
Windows: Add support for URI schemes
This commit is contained in:
commit
ccd34cb42f
@ -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");
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user