Skip to content

Commit

Permalink
Add setGlobal and getGlobak to packs
Browse files Browse the repository at this point in the history
This removes the need to have `electron-app-settings` as a dependency
for pacs by baking that functionality into the pack itself. There were
problems with the packs and the render process not sharing the same
settings state exactly, so this should remove such issues.
  • Loading branch information
kettek committed Mar 21, 2019
1 parent be6087d commit 1043497
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
9 changes: 9 additions & 0 deletions app/js/PackManager.js
Expand Up @@ -120,6 +120,8 @@ function makePackManager(module_name, obj={}) {
reset: () => { },
set: (key, value) => { },
get: (key) => { },
setGlobal: (key, value) => { },
getGlobal: (key) => { },
load: (file) => { },
unload: (file) => { }
}, require(filepath)));
Expand Down Expand Up @@ -156,6 +158,13 @@ function makePackManager(module_name, obj={}) {
mod.get = (key=null) => {
return settings.get(mod.key+(key === null ? '' : '.'+key));
}
mod.setGlobal = (key, value) => {
settings.set(key, value);
m.redraw();
}
mod.getGlobal = (key) => {
return settings.get(key)
}
mod.load = (file) => {
let type = path.extname(file);
if (type == '.css') {
Expand Down
6 changes: 6 additions & 0 deletions docs/packs.md
Expand Up @@ -91,6 +91,12 @@ Sets a configuration entry for the pack.
### `get(key)`
Returns the stored value for a configuration entry.

### `getGlobal(key, value)`
Sets a global configuration entry.

### `setGlobal(key)`
Returns the stored value for a global configuration entry.

### `load(filepath)`
Dynamically loads the given file into the main DOM. Used for loading external scripts and CSS.

Expand Down
5 changes: 2 additions & 3 deletions packs/editor-packs/ome-ep-codemirror/index.js
@@ -1,6 +1,5 @@
let CodeMirror = null;

const settings = require('electron-app-settings');
const fs = require('fs');
const path = require('path');

Expand Down Expand Up @@ -106,7 +105,7 @@ module.exports = {
}
function loadCustomTheming() {
// Only load our theming overrides if the Font Manager extension is loaded.
let fm_style = document.getElementById("OME-FontManager");
let fm_style = document.getElementsByTagName('head')[0].querySelector('#OME-FontManager');
if (!fm_style) return;
// Let's build our CSS!
let css = '\n.CodeMirror {\n';
Expand Down Expand Up @@ -163,7 +162,7 @@ module.exports = {
if (!pack.cm) {
pack.cm = CodeMirror.fromTextArea(dom, {
lineNumbers: true,
lineWrapping: settings.get('editor.linewrapping') ? true : false,
lineWrapping: pack.getGlobal('editor.linewrapping') ? true : false,
theme: pack.theme,
keyMap: pack.keymap
});
Expand Down
5 changes: 0 additions & 5 deletions packs/editor-packs/ome-ep-codemirror/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packs/editor-packs/ome-ep-codemirror/package.json
Expand Up @@ -9,7 +9,6 @@
"author": "",
"license": "GPL-3.0",
"dependencies": {
"codemirror": "^5.37.0",
"electron-app-settings": "^1.0.1"
"codemirror": "^5.37.0"
}
}
9 changes: 6 additions & 3 deletions packs/extension-packs/ome-ext-FontManager/extension.js
@@ -1,5 +1,4 @@
var fontManager = require('font-manager');
const settings = require('electron-app-settings');

function refreshCSS(props) {
let style = document.getElementsByTagName('head')[0].querySelector('#OME-FontManager');
Expand All @@ -25,8 +24,6 @@ function refreshCSS(props) {
style.setAttribute('id', 'OME-FontManager');
document.getElementsByTagName('head')[0].appendChild(style);
}
// This is hacky, but we need to let our editor know we've updating the CSS.
settings.set('editor.updateTheming', true)
}

module.exports = {
Expand Down Expand Up @@ -127,16 +124,22 @@ module.exports = {
if (ex.get('use_editor_size')) props.size = ex.get('editor_size') + ex.get('editor_size_units')
if (ex.get('use_editor_color')) props.color = ex.get('editor_color')
refreshCSS(props)
// This is hacky, but we need to let our editor know we've updating the CSS.
ex.setGlobal('editor.updateTheming', true)
});
ex.on('disable', () => {
refreshCSS(null)
// This is hacky, but we need to let our editor know we've updating the CSS.
ex.setGlobal('editor.updateTheming', true)
});
ex.on('conf-set', (k, v) => {
let props = {}
if (ex.get('use_editor_family')) props.family = ex.get('editor_family')
if (ex.get('use_editor_size')) props.size = ex.get('editor_size') + ex.get('editor_size_units')
if (ex.get('use_editor_color')) props.color = ex.get('editor_color')
refreshCSS(props)
// This is hacky, but we need to let our editor know we've updating the CSS.
ex.setGlobal('editor.updateTheming', true)
});
}
}

0 comments on commit 1043497

Please sign in to comment.