From 47d7e2c82de09333d732d135b148fab7347299ad Mon Sep 17 00:00:00 2001 From: bordun Date: Sat, 21 Nov 2020 19:42:13 +0100 Subject: [PATCH] theme: big file reload fix --- CHANGELOG.md | 2 +- src/server/theme.js | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f167503e..87699c0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## 1.7.3 - bug fixes - - custom module: prevent reloading the module while the file is being written to + - custom module / theme: prevent reloading the module while the file is being written to - widgets - encoder: add `ticks` property back diff --git a/src/server/theme.js b/src/server/theme.js index b6d22e7f..263aa32b 100644 --- a/src/server/theme.js +++ b/src/server/theme.js @@ -23,6 +23,8 @@ class Theme { this.themes = settings.read('theme') || [] this.files = [] + if (!this.themes.length) return this + for (let theme of this.themes) { if (theme.includes('.css') && fs.existsSync(theme)) { @@ -34,11 +36,15 @@ class Theme { } } - this.watcher = chokidar.watch(this.files).on('change', ()=>{ - if (!ipc) ipc = require('./server').ipc - this.load() - ipc.send('reloadCss') - }) + if (!this.files.length) { + + this.watcher = chokidar.watch(this.files, {awaitWriteFinish: {stabilityThreshold: 200}}).on('change', ()=>{ + if (!ipc) ipc = require('./server').ipc + this.load() + ipc.send('reloadCss') + }) + + } this.load()