Stop watching theme files when unloading themes

This commit is contained in:
Samuel Elliott 2019-03-18 20:44:49 +00:00
parent 854262e79a
commit 92334e9a02
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
3 changed files with 23 additions and 5 deletions

View File

@ -118,7 +118,7 @@ export default class Content extends AsyncEventEmitter {
* @return {Promise}
*/
async enable(save = true) {
if (this.enabled) return;
if (this.enabled || this.unloaded) return;
await this.emit('enable');
await this.emit('start');

View File

@ -366,6 +366,8 @@ export default class {
if (!content) throw {message: `Could not find a ${this.contentType} from ${content}.`};
try {
Object.defineProperty(content, 'unloaded', {configurable: true, value: true});
const disablePromise = content.disable(false);
const unloadPromise = content.emit('unload', reload);
@ -378,8 +380,14 @@ export default class {
if (this.unloadContentHook) this.unloadContentHook(content);
if (reload) return content.packed ? this.preloadPackedContent(content.dirName.pkg, true, index) : this.preloadContent(content.dirName, true, index);
if (reload) {
const newcontent = content.packed ? this.preloadPackedContent(content.dirName.pkg, true, index) :
this.preloadContent(content.dirName, true, index);
Object.defineProperty(content, 'unloaded', {value: newcontent});
return newcontent;
}
Object.defineProperty(content, 'unloaded', {value: true});
this.localContent.splice(index, 1);
} catch (err) {
Logger.err(this.moduleName, err);

View File

@ -22,10 +22,20 @@ export default class Theme extends Content {
const watchfiles = Settings.getSetting('css', 'default', 'watch-files');
if (watchfiles.value) this.watchfiles = this.files;
watchfiles.on('setting-updated', event => {
watchfiles.on('setting-updated', this.__watchFilesSettingUpdated = event => {
if (event.value) this.watchfiles = this.files;
else this.watchfiles = [];
});
this.on('unload', () => {
watchfiles.off('setting-updated', this.__watchFilesSettingUpdated);
if (this._filewatcher) {
this._filewatcher.removeAll();
delete this._filewatcher;
}
});
}
get type() { return 'theme' }
@ -61,7 +71,7 @@ export default class Theme extends Content {
async compile() {
Logger.log(this.name, 'Compiling CSS');
if (this.info.type === 'sass') {
if (this.info.type === 'sass' || this.info.type === 'scss') {
const config = await ThemeManager.getConfigAsSCSS(this.settings);
const result = await ClientIPC.send('bd-compileSass', {
@ -147,7 +157,7 @@ export default class Theme extends Content {
* @param {Array} files Files to watch
*/
set watchfiles(files) {
if (this.packed) {
if (this.unloaded || this.packed) {
// Don't watch files for packed themes
return;
}