2
我想使用Chokidar在我的应用程序中观看文件。问题是,只要你尝试实例化chokidar.watch,电子就会抛出一个错误。我想知道这是否是两者之间的已知兼容性问题,以及是否有内置解决方案来解决此问题。 Google迄今为止没有在电子应用程序中观看文件。只有在使用chokidar对象时才会出现此错误。要求它不会导致问题。如何在Electron App中查看文件?
我在渲染过程中的代码如下。注释掉var观察者代码将完全消除控制台错误。代码直接来自他们的文档。
var chokidar = remote.require('chokidar');
chokidar.watch('.', {ignored: /[\/\\]\./}).on('all', function(event, path) {
console.log(event, path);
});
控制台错误:
Uncaught Error: criterion.test is not a function
TypeError: criterion.test is not a function
at testCriteria (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/node_modules/anymatch/index.js:29:26)
at Array.some (native)
at anymatch (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/node_modules/anymatch/index.js:59:48)
at EventEmitter.FSWatcher._isIgnored (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/index.js:221:15)
at EventEmitter.NodeFsHandler._addToNodeFs (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/lib/nodefs-handler.js:429:12)
at EventEmitter.<anonymous> (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/index.js:410:12)
at /Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/node_modules/async-each/index.js:16:7
at Array.forEach (native)
at each (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/node_modules/async-each/index.js:15:11)
at EventEmitter.FSWatcher.add (/Users/guest/Desktop/prototype/yeti-launch/node_modules/chokidar/index.js:409:5)
如何添加看我的项目中的任何意见是非常赞赏。 Atom编辑器使用文件资源管理器检测文件和文件夹的添加时间,并在侧边栏中适当地显示最新的文件夹信息。如果原子能做到这一点,我的应用程序也能做到!
我的解决方案迄今已经实施的主要过程chokidar和使用含有IPC消息路径被监视到主进程。一个新的文件/文件夹触发Webview将回调发送回呈现器。这并不完美......主要是因为Chokidar坚持在每次检测到新链接/非链接文件夹时发送多个事件......但这是一项改进。这是我的应用程序所必需的,因为用户可以为保存的文件选择默认目录。该应用程序需要能够检测并显示在应用程序之外添加的文件(实时)。它是一种痛苦。 – CodeManiak
也许这是相关的? http://ourcodeworld.com/articles/read/160/watch-files-and-directories-with-electron-framework – cladelpino