Skip to content

TagSpaces is an offline, open source, document manager with tagging support

Directory watcher implemented for node webkit

Borislav Sapundzhiev1ed396dca72d
diff --git a/data/cordova/cordova.api.js b/data/cordova/cordova.api.js
index cc1e059dc..f92fbd147 100644
--- a/data/cordova/cordova.api.js
+++ b/data/cordova/cordova.api.js
@@ -377,7 +377,7 @@ define(function(require, exports, module) {
function(error) { // error get file system
console.log("listDirectory error: " + JSON.stringify(error));
pendingCallbacks--;
- if(pendingCallbacks === 0 && i === entries.length){
+ if (pendingCallbacks === 0 && i === entries.length) {
TSPOSTIO.listDirectory(anotatedDirList);
}
} // jshint ignore:line
diff --git a/data/js/directories.ui.js b/data/js/directories.ui.js
index 016af5e7b..e703be9ce 100644
--- a/data/js/directories.ui.js
+++ b/data/js/directories.ui.js
@@ -98,6 +98,11 @@ define(function(require, exports, module) {
// Saving the last opened location path in the settings
TSCORE.Config.setLastOpenedLocation(path);
TSCORE.Config.saveSettings();
+ if (typeof TSCORE.IO.watchDirecotory === 'function') {
+ TSCORE.IO.watchDirecotory(path, function(event, file) {
+ TSCORE.IO.listDirectory(path);
+ });
+ }
}
// Clear search query
TSCORE.clearSearchFilter();
diff --git a/data/node-webkit/node-webkit.api.js b/data/node-webkit/node-webkit.api.js
index c76a553ff..327120509 100644
--- a/data/node-webkit/node-webkit.api.js
+++ b/data/node-webkit/node-webkit.api.js
@@ -13,9 +13,8 @@ define(function(require, exports, module) {
var TSCORE = require("tscore");
var TSPOSTIO = require("tspostioapi");
-
+ var fsWatcher;
var win = gui.Window.get();
- document.addEventListener("initApp", onApplicationLoad, false);
/* var splashwin = gui.Window.open('splashscreen.html', {
'frame': false,
'toolbar': false,
@@ -25,14 +24,6 @@ define(function(require, exports, module) {
"height": 200
}); */
- function onApplicationLoad(event) {
- if (TSCORE.currentPath) {
- watchDirecotory(TSCORE.currentPath, function(event, file) {
- TSCORE.IO.listDirectory(TSCORE.currentPath);
- });
- }
- }
-
var showMainWindow = function() {
//splashwin.hide();
win.show();
@@ -634,7 +625,10 @@ define(function(require, exports, module) {
};
var watchDirecotory = function(dirPath, listener) {
- fs.watch(dirPath, { persistent: true, recursive: true }, listener);
+ if (fsWatcher) {
+ fsWatcher.close();
+ }
+ fsWatcher = fs.watch(dirPath, { persistent: true, recursive: true }, listener);
};
exports.createDirectory = createDirectory;
@@ -662,4 +656,5 @@ define(function(require, exports, module) {
exports.handleTray = handleTray;
exports.focusWindow = focusWindow;
exports.showMainWindow = showMainWindow;
+ exports.watchDirecotory = watchDirecotory;
});