fix(mobile): skip initial fs watcher notification

This commit is contained in:
Andelf
2022-12-09 21:57:13 +08:00
committed by Tienson Qin
parent 158b6e07be
commit 992914dc2f
3 changed files with 38 additions and 22 deletions

View File

@@ -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) {