sysinfo.md
@@ -539,12 +540,12 @@ async function _loadContent(fn, content, editorElement) {
if (content instanceof Uint8Array && !willDisasm) {
hexViewer(content.buffer, editorElement)
editor = null
- } else if (fn.endsWith('.md') && QID('render-markdown').checked) {
+ } else if (fn.endsWith('.md') && getSetting('render-markdown')) {
editorElement.innerHTML = `
` + marked(content) + `
`
editor = null
} else {
let readOnly = false
- if (fn.endsWith('.json') && QID('expand-minify-json').checked) {
+ if (fn.endsWith('.json') && getSetting('expand-minify-json')) {
try {
// Prettify JSON
content = JSON.stringify(JSON.parse(content), null, 2)
@@ -559,7 +560,7 @@ async function _loadContent(fn, content, editorElement) {
editorElement.innerHTML = '' // Clear existing content
editor = await createNewEditor(editorElement, fn, content, {
- wordWrap: QID('use-word-wrap').checked,
+ wordWrap: getSetting('use-word-wrap'),
devInfo,
readOnly,
})
@@ -592,7 +593,7 @@ export async function saveCurrentFile() {
}
let content = editor.state.doc.toString()
- if (editorFn.endsWith('.json') && QID('expand-minify-json').checked) {
+ if (editorFn.endsWith('.json') && getSetting('expand-minify-json')) {
try {
// Minify JSON
content = JSON.stringify(JSON.parse(content))
@@ -731,7 +732,7 @@ async function _raw_installPkg(raw, pkg, { version=null } = {}) {
const pkg_info = await rawInstallPkg(raw, pkg, {
version,
dev: dev_info,
- prefer_source: QID('install-package-source').checked,
+ prefer_source: getSetting('install-package-source'),
})
if (pkg_info.version) {
toastr.success(`Installed ${pkg_info.name}@${pkg_info.version}`)
@@ -967,10 +968,9 @@ export function applyTranslation() {
const currentLang = i18next.resolvedLanguage || 'en';
- const lang_sel = QID('lang')
- lang_sel.value = currentLang
- lang_sel.addEventListener('change', async function() {
- await i18next.changeLanguage(this.value)
+ updateSetting('lang', currentLang)
+ onSettingChange('lang', async function(newValue) {
+ await i18next.changeLanguage(newValue)
applyTranslation()
})
@@ -1040,10 +1040,8 @@ export function applyTranslation() {
}
}
- const zoom_sel = QID('zoom')
- zoom_sel.value = '1.00'
- zoom_sel.addEventListener('change', async function() {
- const size = 14 * parseFloat(this.value)
+ onSettingChange('zoom', function(newValue) {
+ const size = 14 * parseFloat(newValue)
document.documentElement.style.setProperty('--font-size', (size).toFixed(1) + 'px')
term.options.fontSize = (size * 0.9).toFixed(1)
})
@@ -1114,6 +1112,9 @@ export function applyTranslation() {
}
})
+ // set zoom level in newly created terminal
+ updateSetting('zoom', getSetting('zoom'))
+
const fitAddon = new FitAddon()
term.loadAddon(fitAddon)
fitAddon.fit()
diff --git a/src/settings.js b/src/settings.js
new file mode 100644
index 0000000..b0ae166
--- /dev/null
+++ b/src/settings.js
@@ -0,0 +1,123 @@
+import { QID } from './utils.js'
+
+
+const settingsElement = QID("menu-settings")
+let callbacks = new Map()
+let settings = _loadSettings()
+
+/**
+ *
+ * @param {string} setting The name of the setting to query
+ * @returns {boolean} Returns the value of the setting if found, else undefined
+ */
+export function getSetting(setting) {
+ return settings[setting]
+}
+
+
+/**
+ *
+ * @param {string} setting The name of the setting to update
+ * @param {string|boolean} newValue The new value to set the setting to (string for dropdowns, boolean for checkboxes)
+ */
+export function updateSetting(setting, newValue) {
+ // set the DOM
+ const settingElement = settingsElement.querySelector(`#${setting}`)
+ if (settingElement.tagName == "SELECT") {
+ settingElement.value = newValue
+ } else if (settingElement.type == "checkbox") {
+ settingElement.checked = newValue
+ } else {
+ console.error(`Element is not