mirror of
https://github.com/logseq/logseq.git
synced 2026-04-25 06:35:02 +00:00
fix(mobile): skip initial fs watcher notification
This commit is contained in:
@@ -201,9 +201,11 @@ public class FsWatcher extends Plugin {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.tick(false); // skip initial notification
|
||||
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
this.tick();
|
||||
this.tick(true);
|
||||
Thread.sleep(2000); // The same as iOS fswatcher, 2s interval
|
||||
} catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
@@ -214,7 +216,7 @@ public class FsWatcher extends Plugin {
|
||||
|
||||
}
|
||||
|
||||
private void tick() {
|
||||
private void tick(boolean shouldNotify) {
|
||||
Map<String, SimpleFileMetadata> newMetaDb = new HashMap();
|
||||
|
||||
Stack<String> paths = new Stack();
|
||||
@@ -241,7 +243,12 @@ public class FsWatcher extends Plugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.updateMetaDb(newMetaDb);
|
||||
|
||||
if (shouldNotify) {
|
||||
this.updateMetaDb(newMetaDb);
|
||||
} else {
|
||||
this.metaDb = newMetaDb;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMetaDb(Map<String, SimpleFileMetadata> newMetaDb) {
|
||||
|
||||
@@ -28,6 +28,7 @@ public class FsWatcher: CAPPlugin, PollingWatcherDelegate {
|
||||
self.baseUrl = url
|
||||
self.watcher = PollingWatcher(at: url)
|
||||
self.watcher?.delegate = self
|
||||
self.watcher?.start()
|
||||
|
||||
call.resolve(["ok": true])
|
||||
|
||||
@@ -167,15 +168,19 @@ public class PollingWatcher {
|
||||
|
||||
public init?(at: URL) {
|
||||
url = at
|
||||
|
||||
}
|
||||
|
||||
public func start() {
|
||||
|
||||
self.tick(notify: false)
|
||||
|
||||
let queue = DispatchQueue(label: Bundle.main.bundleIdentifier! + ".timer")
|
||||
timer = DispatchSource.makeTimerSource(queue: queue)
|
||||
timer!.setEventHandler(qos: .background, flags: []) { [weak self] in
|
||||
self?.tick()
|
||||
self?.tick(notify: true)
|
||||
}
|
||||
timer!.schedule(deadline: .now())
|
||||
timer!.resume()
|
||||
|
||||
}
|
||||
|
||||
deinit {
|
||||
@@ -187,7 +192,7 @@ public class PollingWatcher {
|
||||
timer = nil
|
||||
}
|
||||
|
||||
private func tick() {
|
||||
private func tick(notify: Bool) {
|
||||
// let startTime = DispatchTime.now()
|
||||
|
||||
if let enumerator = FileManager.default.enumerator(
|
||||
@@ -223,7 +228,11 @@ public class PollingWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
self.updateMetaDb(with: newMetaDb)
|
||||
if notify {
|
||||
self.updateMetaDb(with: newMetaDb)
|
||||
} else {
|
||||
self.metaDb = newMetaDb
|
||||
}
|
||||
}
|
||||
|
||||
// let elapsedNanoseconds = DispatchTime.now().uptimeNanoseconds - startTime.uptimeNanoseconds
|
||||
|
||||
@@ -122,18 +122,18 @@
|
||||
(let [dir (config/get-repo-dir graph)]
|
||||
(p/let [files (fs/readdir dir :path-only? true)]
|
||||
(doseq [file files]
|
||||
(when-let [ext (util/get-file-ext file)]
|
||||
(when-let [_ext (util/get-file-ext file)]
|
||||
(->
|
||||
(when-not (fs-util/ignored-path? dir file)
|
||||
(p/let [content (fs/read-file dir file)
|
||||
stat (fs/stat dir file)
|
||||
type (if (db/file-exists? graph file)
|
||||
"change"
|
||||
"add")]
|
||||
(handle-changed! type
|
||||
{:dir dir
|
||||
:path file
|
||||
:content content
|
||||
:stat stat})))
|
||||
(p/catch (fn [error]
|
||||
(js/console.dir error))))))))))
|
||||
(when-not (fs-util/ignored-path? dir file)
|
||||
(p/let [content (fs/read-file dir file)
|
||||
stat (fs/stat dir file)
|
||||
type (if (db/file-exists? graph file)
|
||||
"change"
|
||||
"add")]
|
||||
(handle-changed! type
|
||||
{:dir dir
|
||||
:path file
|
||||
:content content
|
||||
:stat stat})))
|
||||
(p/catch (fn [error]
|
||||
(js/console.dir error))))))))))
|
||||
|
||||
Reference in New Issue
Block a user