Add saving to the CSS editor

This commit is contained in:
Samuel Elliott 2018-02-13 20:05:38 +00:00
parent 5ca04f0652
commit 729657f345
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 26 additions and 14 deletions

View File

@ -9,6 +9,7 @@
*/
import { ClientIPC } from 'common';
import Settings from './settings';
import { DOM } from 'ui';
export default class {
@ -18,8 +19,8 @@ export default class {
ClientIPC.on('bd-update-scss', (e, scss) => this.updateScss(scss));
ClientIPC.on('bd-save-scss', async (e, scss) => {
this.updateScss(scss);
e.reply(await this.save(scss));
await this.updateScss(scss);
await this.save();
});
}
@ -27,18 +28,25 @@ export default class {
await ClientIPC.send('openCssEditor', {});
}
static updateScss(scss) {
this.compile(scss).then(css => {
this.css = css;
this._scss = scss;
this.sendToEditor('scss-error', null);
}).catch(err => {
this.sendToEditor('scss-error', err);
static updateScss(scss, sendSource) {
if (sendSource)
this.sendToEditor('set-scss', { scss });
return new Promise((resolve, reject) => {
this.compile(scss).then(css => {
this.css = css;
this._scss = scss;
this.sendToEditor('scss-error', null);
resolve();
}).catch(err => {
this.sendToEditor('scss-error', err);
reject(err);
});
});
}
static async save(scss) {
console.log('Saving SCSS:', scss);
static async save() {
Settings.saveSettings();
}
static async compile(scss) {

View File

@ -9,7 +9,8 @@
*/
import defaultSettings from '../data/user.settings.default';
import { default as Globals } from './globals';
import Globals from './globals';
import CssEditor from './csseditor';
import { FileUtils, ClientLogger as Logger } from 'common';
import path from 'path';
@ -20,7 +21,7 @@ export default class {
const settingsPath = path.resolve(this.dataPath, 'user.settings.json');
const user_config = await FileUtils.readJsonFromFile(settingsPath);
const { settings } = user_config;
const { settings, scss } = user_config;
this.settings = defaultSettings;
@ -40,6 +41,8 @@ export default class {
}
}
}
CssEditor.updateScss(scss, true);
} catch (err) {
// There was an error loading settings
// This probably means that the user doesn't have any settings yet
@ -68,7 +71,8 @@ export default class {
};
})
};
})
}),
scss: CssEditor.scss
});
} catch (err) {
// There was an error loading settings