theme: automatically reload theme when the file is modified

This commit is contained in:
bordun 2020-10-28 10:50:58 +01:00
parent 6e3644d9af
commit a6542f874f
3 changed files with 13 additions and 3 deletions

View file

@ -10,6 +10,9 @@
- automatically reload custom module when the file is modified
- add support for loading submodules with `require()`
- theme
- automatically reload theme when the file is modified
## 1.5.4
- bug fixes

View file

@ -404,8 +404,6 @@ module.exports = {
reloadCss() {
// (dev) hot css reload
theme.load()
ipc.send('reloadCss')
},

View file

@ -1,6 +1,8 @@
var fs = require('fs'),
path = require('path'),
settings = require('./settings')
settings = require('./settings'),
chokidar = require('chokidar'),
ipc
class Theme {
@ -9,6 +11,7 @@ class Theme {
this.themes = []
this.files = []
this.css = []
this.watcher = null
this.defaultColor = '#151a24'
this.backgroundColor = this.defaultColor
@ -31,6 +34,12 @@ class Theme {
}
}
this.watcher = chokidar.watch(this.files).on('change', ()=>{
if (!ipc) ipc = require('./server').ipc
this.load()
ipc.send('reloadCss')
})
this.load()
return this