Skip to content

Commit

Permalink
Fix config reload after vim edit (#2718)
Browse files Browse the repository at this point in the history
  • Loading branch information
chabou authored Mar 3, 2018
1 parent 24b8361 commit bf2d6ea
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const _watch = function() {
}, 100);
};

// Windows
if (process.platform === 'win32') {
// watch for changes on config every 2s on Windows
// https://github.com/zeit/hyper/pull/1772
Expand All @@ -35,8 +36,24 @@ const _watch = function() {
onChange();
}
});
} else {
_watcher = fs.watch(cfgPath);
return;
}
// macOS/Linux
setWatcher();
function setWatcher() {
try {
_watcher = fs.watch(cfgPath, eventType => {
if (eventType === 'rename') {
_watcher.close();
// Ensure that new file has been written
setTimeout(() => setWatcher(), 500);
}
});
} catch (e) {
//eslint-disable-next-line no-console
console.error('Failed to watch config file:', cfgPath, e);
return;
}
_watcher.on('change', onChange);
_watcher.on('error', error => {
//eslint-disable-next-line no-console
Expand Down

0 comments on commit bf2d6ea

Please sign in to comment.