Skip to content

Instantly share code, notes, and snippets.

@hawkeye64
Created November 18, 2018 19:44
Show Gist options
  • Save hawkeye64/6d6283607d8c4c74230eefeed99a6104 to your computer and use it in GitHub Desktop.
Save hawkeye64/6d6283607d8c4c74230eefeed99a6104 to your computer and use it in GitHub Desktop.
folderWatcherHandler function
folderWatcherHandler: function (newFolder, oldFolder) {
if (oldFolder && this.watcher) {
this.watcher.close()
}
if (newFolder) {
// let backend know to statically serve files from this folder
ipcRenderer.send('folder', newFolder)
this.watcher = chokidar.watch(newFolder, {
depth: 0,
ignorePermissionErrors: true
})
if (this.watcher) {
this.watcher.on('ready', () => { // initial scan done
// watch for additions
this.watcher.on('raw', (event, path, details) => {
this.$root.$emit('rescan-current-folder')
})
})
this.watcher.on('error', (error) => { // initial scan done
console.error(error)
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment