Add save/restore of CSS editor window bounds
This commit is contained in:
parent
a9a45e0f20
commit
c581ba1b75
|
@ -17,6 +17,7 @@ export default class {
|
|||
static init() {
|
||||
ClientIPC.on('bd-get-scss', () => this.sendToEditor('set-scss', { scss: this.scss }));
|
||||
ClientIPC.on('bd-update-scss', (e, scss) => this.updateScss(scss));
|
||||
ClientIPC.on('bd-save-csseditor-bounds', (e, bounds) => this.saveEditorBounds(bounds));
|
||||
|
||||
ClientIPC.on('bd-save-scss', async (e, scss) => {
|
||||
await this.updateScss(scss);
|
||||
|
@ -25,7 +26,7 @@ export default class {
|
|||
}
|
||||
|
||||
static async show() {
|
||||
await ClientIPC.send('openCssEditor', {});
|
||||
await ClientIPC.send('openCssEditor', this.editor_bounds);
|
||||
}
|
||||
|
||||
static updateScss(scss, sendSource) {
|
||||
|
@ -49,6 +50,11 @@ export default class {
|
|||
Settings.saveSettings();
|
||||
}
|
||||
|
||||
static saveEditorBounds(bounds) {
|
||||
this.editor_bounds = bounds;
|
||||
Settings.saveSettings();
|
||||
}
|
||||
|
||||
static async compile(scss) {
|
||||
return await ClientIPC.send('bd-compileSass', { data: scss });
|
||||
}
|
||||
|
@ -62,8 +68,7 @@ export default class {
|
|||
}
|
||||
|
||||
static set scss(scss) {
|
||||
this.sendToEditor('set-scss', { scss: this.scss });
|
||||
this.updateScss(scss);
|
||||
this.updateScss(scss, true);
|
||||
}
|
||||
|
||||
static set css(css) {
|
||||
|
|
|
@ -21,7 +21,7 @@ export default class {
|
|||
|
||||
const settingsPath = path.resolve(this.dataPath, 'user.settings.json');
|
||||
const user_config = await FileUtils.readJsonFromFile(settingsPath);
|
||||
const { settings, scss } = user_config;
|
||||
const { settings, scss, css_editor_bounds } = user_config;
|
||||
|
||||
this.settings = defaultSettings;
|
||||
|
||||
|
@ -43,6 +43,7 @@ export default class {
|
|||
}
|
||||
|
||||
CssEditor.updateScss(scss, true);
|
||||
CssEditor.editor_bounds = css_editor_bounds;
|
||||
} catch (err) {
|
||||
// There was an error loading settings
|
||||
// This probably means that the user doesn't have any settings yet
|
||||
|
@ -72,7 +73,13 @@ export default class {
|
|||
})
|
||||
};
|
||||
}),
|
||||
scss: CssEditor.scss
|
||||
scss: CssEditor.scss,
|
||||
css_editor_bounds: {
|
||||
width: CssEditor.editor_bounds.width,
|
||||
height: CssEditor.editor_bounds.height,
|
||||
x: CssEditor.editor_bounds.x,
|
||||
y: CssEditor.editor_bounds.y
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
// There was an error loading settings
|
||||
|
|
|
@ -45,7 +45,8 @@ console.log(dummyArgs);
|
|||
|
||||
class Comms {
|
||||
|
||||
constructor() {
|
||||
constructor(bd) {
|
||||
this.bd = bd;
|
||||
this.initListeners();
|
||||
}
|
||||
|
||||
|
@ -54,8 +55,11 @@ class Comms {
|
|||
o.reply(Common.Config.config);
|
||||
});
|
||||
|
||||
BDIpc.on('bd-openCssEditor', o => CSSEditor.openEditor(o));
|
||||
BDIpc.on('bd-sendToCssEditor', o => CSSEditor.send(o.args.channel, o.args.data));
|
||||
BDIpc.on('bd-sendToDiscord', event => this.bd.windowUtils.send(event.args.channel, event.args.message));
|
||||
|
||||
BDIpc.on('bd-openCssEditor', o => this.bd.csseditor.openEditor(o));
|
||||
// BDIpc.on('bd-setScss', o => this.bd.csseditor.setSCSS(o.args.scss));
|
||||
BDIpc.on('bd-sendToCssEditor', o => this.bd.csseditor.send(o.args.channel, o.args.data));
|
||||
|
||||
BDIpc.on('bd-readFile', this.readFile);
|
||||
BDIpc.on('bd-readJson', o => this.readFile(o, true));
|
||||
|
@ -102,10 +106,17 @@ class Comms {
|
|||
class BetterDiscord {
|
||||
|
||||
constructor(args) {
|
||||
if (BetterDiscord.loaded) {
|
||||
// Creating two BetterDiscord objects???
|
||||
console.log('Creating two BetterDiscord objects???');
|
||||
return null;
|
||||
}
|
||||
BetterDiscord.loaded = true;
|
||||
|
||||
this.injectScripts = this.injectScripts.bind(this);
|
||||
this.ignite = this.ignite.bind(this);
|
||||
Common.Config = new Config(args || dummyArgs);
|
||||
this.comms = new Comms();
|
||||
this.comms = new Comms(this);
|
||||
this.init();
|
||||
}
|
||||
|
||||
|
@ -113,6 +124,8 @@ class BetterDiscord {
|
|||
const window = await this.waitForWindow();
|
||||
this.windowUtils = new WindowUtils({ window });
|
||||
|
||||
this.csseditor = new CSSEditor(this);
|
||||
|
||||
//Log some events for now
|
||||
//this.windowUtils.webContents.on('did-start-loading', e => this.windowUtils.executeJavascript(`console.info('did-start-loading');`));
|
||||
//this.windowUtils.webContents.on('did-stop-loading', e => this.windowUtils.executeJavascript(`console.info('did-stop-loading');`));
|
||||
|
@ -130,8 +143,6 @@ class BetterDiscord {
|
|||
this.windowUtils.send('did-navigate-in-page', { event, url, isMainFrame });
|
||||
});
|
||||
|
||||
BDIpc.on('bd-sendToDiscord', event => this.windowUtils.send(event.args.channel, event.args.message))
|
||||
|
||||
setTimeout(() => {
|
||||
if (__DEV) { this.injectScripts(); }
|
||||
}, 500);
|
||||
|
|
|
@ -16,6 +16,11 @@ const { WindowUtils } = require('./utils');
|
|||
|
||||
class CSSEditor extends Module {
|
||||
|
||||
constructor(bd) {
|
||||
super();
|
||||
this.bd = bd;
|
||||
}
|
||||
|
||||
openEditor(o) {
|
||||
if (this.editor) {
|
||||
if (this.editor.isFocused()) return;
|
||||
|
@ -26,12 +31,18 @@ class CSSEditor extends Module {
|
|||
return;
|
||||
}
|
||||
|
||||
this.editor = new BrowserWindow(this.options);
|
||||
const options = this.options;
|
||||
for (let option in o.args) {
|
||||
options[option] = o.args[option];
|
||||
}
|
||||
|
||||
this.editor = new BrowserWindow(options);
|
||||
this.editor.loadURL('about:blank');
|
||||
this.editor.setSheetOffset(33);
|
||||
this.editorUtils = new WindowUtils({ window: this.editor });
|
||||
|
||||
this.editor.webContents.on('close', () => {
|
||||
this.editor.on('close', () => {
|
||||
this.bd.windowUtils.send('bd-save-csseditor-bounds', this.editor.getBounds());
|
||||
this.editor = null;
|
||||
});
|
||||
|
||||
|
@ -59,7 +70,6 @@ class CSSEditor extends Module {
|
|||
this.editor.setAlwaysOnTop(state);
|
||||
}
|
||||
|
||||
//TODO user options from config
|
||||
get options() {
|
||||
return {
|
||||
width: 800,
|
||||
|
@ -77,6 +87,4 @@ class CSSEditor extends Module {
|
|||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
CSSEditor: new CSSEditor()
|
||||
};
|
||||
module.exports = { CSSEditor };
|
||||
|
|
Loading…
Reference in New Issue