cordova-plugin-file-opener2
Advanced tools
Comparing version 2.0.2 to 2.0.3
{ | ||
"name": "cordova-plugin-file-opener2", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "A File Opener Plugin for Cordova. (The Original Version)", | ||
@@ -5,0 +5,0 @@ "cordova": { |
Contributors | ||
------------ | ||
[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro) | ||
[@Gillardo](https://github.com/Gillardo/), [@TankOs](https://github.com/TankOs), [@Rovi23](https://github.com/Rovi23), [@josemanuelbd](https://github.com/josemanuelbd), [@ielcoro](https://github.com/ielcoro), [@keturn](https://github.com/keturn), [@conform](https://github.com/conform), [@guyc](https://github.com/guyc), [@J3r0M3D3V](https://github.com/J3r0M3D3V) | ||
@@ -10,3 +10,3 @@ | ||
Current Version: 2.0.1 | ||
Current Version: 2.0.2 | ||
---------------- | ||
@@ -13,0 +13,0 @@ |
@@ -7,8 +7,23 @@ | ||
{ protocol: 'ms-app', getFile: getFileFromApplicationUri }, | ||
{ protocol: 'file:///', getFile: getFileFromFileUri } | ||
{ protocol: 'cdvfile', getFile: getFileFromFileUri } //protocol cdvfile | ||
] | ||
function nthIndex(str, pat, n) { | ||
var L = str.length, i = -1; | ||
while (n-- && i++ < L) { | ||
i = str.indexOf(pat, i); | ||
if (i < 0) break; | ||
} | ||
return i; | ||
} | ||
function getFileFromApplicationUri(uri) { | ||
var applicationUri = new Windows.Foundation.Uri(uri); | ||
/* bad path from a file entry due to the last '//' | ||
example: ms-appdata:///local//path/to/file | ||
*/ | ||
var index = nthIndex(uri, "//", 3); | ||
var newUri = uri.substr(0, index) + uri.substr(index + 1); | ||
var applicationUri = new Windows.Foundation.Uri(newUri); | ||
return Windows.Storage.StorageFile.getFileFromApplicationUriAsync(applicationUri); | ||
@@ -18,5 +33,18 @@ } | ||
function getFileFromFileUri(uri) { | ||
var path = Windows.Storage.ApplicationData.current.localFolder.path + | ||
uri.substr(8); | ||
/* uri example: | ||
cdvfile://localhost/persistent|temporary|another-fs-root/path/to/file | ||
*/ | ||
var indexFrom = nthIndex(uri, "/", 3) + 1; | ||
var indexTo = nthIndex(uri, "/", 4); | ||
var whichFolder = uri.substring(indexFrom, indexTo); | ||
var filePath = uri.substr(indexTo + 1); | ||
var path = "\\" + filePath; | ||
if (whichFolder == "persistent") { | ||
path = Windows.Storage.ApplicationData.current.localFolder.path + path; | ||
} | ||
else { //temporary, note: no roaming management | ||
path = Windows.Storage.ApplicationData.current.temporaryFolder.path + path; | ||
} | ||
return getFileFromNativePath(path); | ||
@@ -44,19 +72,19 @@ } | ||
open: function (successCallback, errorCallback, args) { | ||
var path = args[0]; | ||
var getFile = getFileLoaderForScheme(path); | ||
getFile(path).then(function (file) { | ||
var options = new Windows.System.LauncherOptions(); | ||
Windows.System.Launcher.launchFileAsync(file, options).then(function (success) { | ||
if (success) { | ||
successCallback(); | ||
} else { | ||
errorCallback(); | ||
} | ||
successCallback(); | ||
}, function (error) { | ||
errorCallback(error); | ||
}); | ||
}, function (errror) { | ||
console.log("Error abriendo el archivo"); | ||
}, function (error) { | ||
console.log("Error while opening the file: "+error); | ||
errorCallback(error); | ||
}); | ||
@@ -63,0 +91,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25091
103