import server from "../../services/server.js"; import utils from "../../services/utils.js"; import appContext from "../../services/app_context.js"; const FONT_FAMILIES = [ { value: "theme", label: "Theme defined" }, { value: "serif", label: "Serif" }, { value: "sans-serif", label: "Sans Serif" }, { value: "monospace", label: "Monospace" }, { value: "Arial", label: "Arial" }, { value: "Verdana", label: "Verdana" }, { value: "Helvetica", label: "Helvetica" }, { value: "Tahoma", label: "Tahoma" }, { value: "Trebuchet MS", label: "Trebuchet MS" }, { value: "Times New Roman", label: "Times New Roman" }, { value: "Georgia", label: "Georgia" }, { value: "Garamond", label: "Garamond" }, { value: "Courier New", label: "Courier New" }, { value: "Brush Script MT", label: "Brush Script MT" }, { value: "Impact", label: "Impact" }, { value: "American Typewriter", label: "American Typewriter" }, { value: "Andalé Mono", label: "Andalé Mono" }, { value: "Lucida Console", label: "Lucida Console" }, { value: "Monaco", label: "Monaco" }, { value: "Bradley Hand", label: "Bradley Hand" }, { value: "Luminari", label: "Luminari" }, { value: "Comic Sans MS", label: "Comic Sans MS" }, ]; const TPL = `
Settings on this options tab are saved automatically after each change.
`; export default class ApperanceOptions { constructor() { $("#options-appearance").html(TPL); this.$zoomFactorSelect = $("#zoom-factor-select"); this.$nativeTitleBarSelect = $("#native-title-bar-select"); this.$headingStyle = $("#heading-style"); this.$themeSelect = $("#theme-select"); this.$overrideThemeFonts = $("#override-theme-fonts"); this.$overridenFontSettings = $("#overriden-font-settings"); this.$mainFontSize = $("#main-font-size"); this.$mainFontFamily = $("#main-font-family"); this.$treeFontSize = $("#tree-font-size"); this.$treeFontFamily = $("#tree-font-family"); this.$detailFontSize = $("#detail-font-size"); this.$detailFontFamily = $("#detail-font-family"); this.$monospaceFontSize = $("#monospace-font-size"); this.$monospaceFontFamily = $("#monospace-font-family"); $("#reload-frontend-button").on("click", () => utils.reloadFrontendApp("font changes")); this.$body = $("body"); this.$themeSelect.on('change', async () => { const newTheme = this.$themeSelect.val(); await server.put('options/theme/' + newTheme); utils.reloadFrontendApp("theme change"); }); this.$overrideThemeFonts.on('change', async () => { const isOverriden = this.$overrideThemeFonts.is(":checked"); await server.put('options/overrideThemeFonts/' + isOverriden.toString()); this.$overridenFontSettings.toggle(isOverriden); }); this.$zoomFactorSelect.on('change', () => { appContext.triggerCommand('setZoomFactorAndSave', {zoomFactor: this.$zoomFactorSelect.val()}); }); this.$nativeTitleBarSelect.on('change', () => { const nativeTitleBarVisible = this.$nativeTitleBarSelect.val() === 'show' ? 'true' : 'false'; server.put('options/nativeTitleBarVisible/' + nativeTitleBarVisible); }); this.$headingStyle.on('change', () => { const newHeadingStyle = this.$headingStyle.val(); this.toggleBodyClass("heading-style-", newHeadingStyle); server.put('options/headingStyle/' + newHeadingStyle); }); const optionsToSave = [ 'mainFontFamily', 'mainFontSize', 'treeFontFamily', 'treeFontSize', 'detailFontFamily', 'detailFontSize', 'monospaceFontFamily', 'monospaceFontSize' ]; for (const optionName of optionsToSave) { this['$' + optionName].on('change', () => server.put(`options/${optionName}/${this['$' + optionName].val()}`)); } } toggleBodyClass(prefix, value) { for (const clazz of Array.from(this.$body[0].classList)) { // create copy to safely iterate over while removing classes if (clazz.startsWith(prefix)) { this.$body.removeClass(clazz); } } this.$body.addClass(prefix + value); } async optionsLoaded(options) { if (utils.isElectron()) { this.$zoomFactorSelect.val(options.zoomFactor); } else { this.$zoomFactorSelect.prop('disabled', true); } this.$nativeTitleBarSelect.val(options.nativeTitleBarVisible === 'true' ? 'show' : 'hide'); this.$headingStyle.val(options.headingStyle); const themes = [ { val: 'light', title: 'Light' }, { val: 'dark', title: 'Dark' } ].concat(await server.get('options/user-themes')); this.$themeSelect.empty(); for (const theme of themes) { this.$themeSelect.append($("