Skip to content

Commit

Permalink
fix(android): handle path with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Aug 29, 2022
1 parent 5164605 commit 1e921b3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
5 changes: 4 additions & 1 deletion android/app/src/main/java/com/logseq/app/FolderPicker.java
Expand Up @@ -20,6 +20,8 @@
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;

import java.io.File;


@CapacitorPlugin(name = "FolderPicker")
public class FolderPicker extends Plugin {
Expand Down Expand Up @@ -63,7 +65,8 @@ private void folderPickerResult(PluginCall call, ActivityResult result) {
if (path == null || path.isEmpty()) {
call.reject("Cannot support this directory type: " + docUri);
} else {
ret.put("path", "file://" + path);
Uri folderUri = Uri.fromFile(new File(path));
ret.put("path", folderUri.toString());
call.resolve(ret);
}
}
Expand Down
13 changes: 6 additions & 7 deletions android/app/src/main/java/com/logseq/app/FsWatcher.java
Expand Up @@ -58,7 +58,7 @@ public void watch(PluginCall call) {

int mask = FileObserver.CLOSE_WRITE |
FileObserver.MOVE_SELF | FileObserver.MOVED_FROM | FileObserver.MOVED_TO |
FileObserver.DELETE | FileObserver.DELETE_SELF;
FileObserver.DELETE | FileObserver.DELETE_SELF | FileObserver.CREATE;

if (observers != null) {
call.reject("already watching");
Expand All @@ -72,7 +72,7 @@ public void watch(PluginCall call) {
if (files != null) {
for (File file : files) {
String filename = file.getName();
if (file.isDirectory() && !filename.startsWith(".") && !filename.equals("bak") && !filename.equals("node_modules")) {
if (file.isDirectory() && !filename.startsWith(".") && !filename.equals("bak") && !filename.equals("version-files") && !filename.equals("node_modules")) {
observers.add(new SingleFileObserver(file, mask));
}
}
Expand All @@ -90,7 +90,7 @@ public void watch(PluginCall call) {

@PluginMethod()
public void unwatch(PluginCall call) {
Log.i("FsWatcher", "unwatching...");
Log.i("FsWatcher", "unwatch all...");

if (observers != null) {
for (int i = 0; i < observers.size(); ++i)
Expand Down Expand Up @@ -129,11 +129,9 @@ public void initialNotify(File pathObj, int maxDepth) {
public void onObserverEvent(int event, String path) {
JSObject obj = new JSObject();
String content = null;
// FIXME: Current repo/path impl requires path to be a URL, dir to be a bare
// path.
File f = new File(path);
obj.put("path", Uri.fromFile(f));
obj.put("dir", "file://" + mPath);
obj.put("dir", Uri.fromFile(new File(mPath)));

switch (event) {
case FileObserver.CLOSE_WRITE:
Expand Down Expand Up @@ -223,7 +221,8 @@ public SingleFileObserver(File path, int mask) {
@Override
public void onEvent(int event, String path) {
if (path != null && !path.equals("graphs-txid.edn") && !path.equals("broken-config.edn")) {
Log.d("FsWatcher", "got path=" + path + " event=" + event);
Log.d("FsWatcher", "got path=" + mPath + "/" + path + " event=" + event);
// TODO: handle newly created directory
if (Pattern.matches("(?i)[^.].*?\\.(md|org|css|edn|js|markdown)$", path)) {
String fullPath = mPath + "/" + path;
if (event == FileObserver.MOVE_SELF || event == FileObserver.MOVED_FROM ||
Expand Down
10 changes: 4 additions & 6 deletions src/main/frontend/fs/capacitor_fs.cljs
Expand Up @@ -281,12 +281,10 @@
(readdir dir)))
(unlink! [this repo path _opts]
(p/let [path (get-file-path nil path)
path (if (string/starts-with? path "file://")
(string/replace-first path "file://" "")
path)
repo-dir (config/get-local-dir repo)
recycle-dir (str repo-dir config/app-name "/.recycle") ;; logseq/.recycle
file-name (-> (string/replace path repo-dir "")
repo-url (config/get-local-dir repo)
recycle-dir (str repo-url config/app-name "/.recycle") ;; logseq/.recycle
;; convert url to pure path
file-name (-> (string/replace path repo-url "")
(string/replace "/" "_")
(string/replace "\\" "_"))
new-path (str recycle-dir "/" file-name)]
Expand Down

0 comments on commit 1e921b3

Please sign in to comment.