Skip to content

feat(windows): known folders support #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ xmlns:android="http://schemas.android.com/apk/res/android"
<issue>https://issues.apache.org/jira/browse/CB/component/12320651</issue>

<engines>
<engine name="cordova-android" version=">=6.3.0" />
<engine name="cordova-android" version=">=6.0.0" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact we have still build configurations with cordova-android: 6.0.0
We haven't recognized an incompatibility with cordova-plugin-file. Was there a serious reason behind to restrict a higher cordova-android version?

</engines>

<js-module src="www/DirectoryEntry.js" name="DirectoryEntry">
Expand Down
2 changes: 2 additions & 0 deletions src/android/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,8 @@ private JSONObject requestAllPaths() throws JSONException {
ret.put("applicationStorageDirectory", toDirUrl(context.getFilesDir().getParentFile()));
ret.put("dataDirectory", toDirUrl(context.getFilesDir()));
ret.put("cacheDirectory", toDirUrl(context.getCacheDir()));
// databasepath
ret.put("databaseDirectory", toDirUrl(context.getDatabasePath("dummy").getParentFile()));
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
try {
ret.put("externalApplicationStorageDirectory", toDirUrl(context.getExternalFilesDir(null).getParentFile()));
Expand Down
24 changes: 24 additions & 0 deletions src/windows/FileProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,30 @@ var windowsPaths = {
applicationStorageDirectory: 'ms-appx:///'
};

if (Windows.Storage.UserDataPaths) {
var userDataPaths = null;
if (typeof Windows.Storage.UserDataPaths.getDefault === 'function') {
userDataPaths = Windows.Storage.UserDataPaths.getDefault();
}
if (!userDataPaths && typeof Windows.Storage.UserDataPaths.getForUser === 'function') {
userDataPaths = Windows.Storage.UserDataPaths.getForUser();
}
if (userDataPaths) {
if (userDataPaths.documents) {
windowsPaths.documentsDirectory = 'file:///' + nativePathToCordova(userDataPaths.documents);
}
if (userDataPaths.music) {
windowsPaths.musicDirectory = 'file:///' + nativePathToCordova(userDataPaths.music);
}
if (userDataPaths.pictures) {
windowsPaths.picturesDirectory = 'file:///' + nativePathToCordova(userDataPaths.pictures);
}
if (userDataPaths.videos) {
windowsPaths.videosDirectory = 'file:///' + nativePathToCordova(userDataPaths.videos);
}
}
}

var AllFileSystems;

function getAllFS () {
Expand Down
9 changes: 8 additions & 1 deletion www/fileSystemPaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,16 @@ exports.file = {
// iOS: Holds app-specific files that should be synced (e.g. to iCloud).
syncedDataDirectory: null,
// iOS: Files private to the app, but that are meaningful to other applications (e.g. Office files)
// Windows: Gets the path to a user's Documents folder.
documentsDirectory: null,
// BlackBerry10: Files globally available to all apps
sharedDirectory: null
sharedDirectory: null,
// Windows: Gets the path to a user's Music folder.
musicDirectory: null,
// Windows: Gets the path to a user's Pictures folder.
picturesDirectory: null,
// Windows: Gets the path to a user's Videos folder.
videoDirectory: null
};

channel.waitForInitialization('onFileSystemPathsReady');
Expand Down
3 changes: 2 additions & 1 deletion www/resolveLocalFileSystemURI.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
};
// sanity check for 'not:valid:filename' or '/not:valid:filename'
// file.spec.12 window.resolveLocalFileSystemURI should error (ENCODING_ERR) when resolving invalid URI with leading /.
if (!uri || uri.split(':').length > 2) {
// now, better no check than bad check!
if (!uri) {
setTimeout(function () {
fail(FileError.ENCODING_ERR);
}, 0);
Expand Down