fix: watch rename syscall on Linux (#816)

This commit is contained in:
Felix Häusler 2019-03-30 18:23:19 +01:00 committed by Ran Luo
parent b4784e83c5
commit be3ea4b0ce
3 changed files with 21 additions and 6 deletions

View File

@ -1,11 +1,8 @@
/** // Set `__static` path to static files in production
* Set `__static` path to static files in production
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
*/
if (process.env.NODE_ENV !== 'development') { if (process.env.NODE_ENV !== 'development') {
global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\') global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
} }
global.MARKTEXT_DEBUG = process.env.MARKTEXT_DEBUG || process.env.NODE_ENV !== 'production' global.MARKTEXT_DEBUG = process.env.MARKTEXT_DEBUG || process.env.NODE_ENV !== 'production'
global.MARKTEXT_DEBUG_VERBOSE = global.MARKTEXT_DEBUG && process.env.MARKTEXT_DEBUG_VERBOSE
global.MARKTEXT_SAFE_MODE = false global.MARKTEXT_SAFE_MODE = false

View File

@ -4,6 +4,7 @@ import { promisify } from 'util'
import chokidar from 'chokidar' import chokidar from 'chokidar'
import { getUniqueId, log, hasMarkdownExtension } from './utils' import { getUniqueId, log, hasMarkdownExtension } from './utils'
import { loadMarkdownFile } from './utils/filesystem' import { loadMarkdownFile } from './utils/filesystem'
import { isLinux } from './config'
const EVENT_NAME = { const EVENT_NAME = {
dir: 'AGANI::update-object-tree', dir: 'AGANI::update-object-tree',
@ -102,8 +103,23 @@ class Watcher {
.on('unlink', pathname => unlink(win, pathname, type)) .on('unlink', pathname => unlink(win, pathname, type))
.on('addDir', pathname => addDir(win, pathname)) .on('addDir', pathname => addDir(win, pathname))
.on('unlinkDir', pathname => unlinkDir(win, pathname)) .on('unlinkDir', pathname => unlinkDir(win, pathname))
.on('raw', (event, path, details) => {
if (global.MARKTEXT_DEBUG_VERBOSE) {
console.log(event, path, details)
}
// rename syscall on Linux (chokidar#591)
if (isLinux && event === 'rename') {
const { watchedPath } = details
// Use the same watcher and re-watch the file.
watcher.unwatch(watchedPath)
watcher.add(watchedPath)
}
})
.on('error', error => { .on('error', error => {
log(`Watcher error: ${error}`) const msg = `Watcher error: ${error}`
console.log(msg)
log(msg)
}) })
this.watchers[id] = { this.watchers[id] = {

View File

@ -635,6 +635,8 @@ const actions = {
LISTEN_FOR_FILE_CHANGE ({ commit, state, rootState }) { LISTEN_FOR_FILE_CHANGE ({ commit, state, rootState }) {
ipcRenderer.on('AGANI::update-file', (e, { type, change }) => { ipcRenderer.on('AGANI::update-file', (e, { type, change }) => {
// TODO: Set `isSaved` to false.
// TODO: A new "changed" notification from different files overwrite the old notification - the old notification disappears.
if (type === 'unlink') { if (type === 'unlink') {
return notice.notify({ return notice.notify({
title: 'File Removed on Disk', title: 'File Removed on Disk',