Add saving to the CSS editor
This commit is contained in:
parent
5ca04f0652
commit
729657f345
|
@ -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) {
|
||||||
this.compile(scss).then(css => {
|
if (sendSource)
|
||||||
this.css = css;
|
this.sendToEditor('set-scss', { scss });
|
||||||
this._scss = scss;
|
|
||||||
this.sendToEditor('scss-error', null);
|
return new Promise((resolve, reject) => {
|
||||||
}).catch(err => {
|
this.compile(scss).then(css => {
|
||||||
this.sendToEditor('scss-error', err);
|
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) {
|
static async save() {
|
||||||
console.log('Saving SCSS:', scss);
|
Settings.saveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
static async compile(scss) {
|
static async compile(scss) {
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue