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

View File

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