|
| 1 | +/** |
| 2 | + * I had some ideas for application-wide preferences, but I don't think they're |
| 3 | + * more important than some missing features I need to implement right away. So, |
| 4 | + * I'm gonna leave this file here and comment out the menu entry from `SettingsView.js` |
| 5 | + * so that user's are not confusing. |
| 6 | + */ |
| 7 | + |
| 8 | +const m = require("mithril") |
| 9 | +const { getPref, setPref, setMessageTypeVisibility, getVisibilityForMessageType } = patchfox |
| 10 | +const _ = require("lodash") |
| 11 | + |
| 12 | +const quickAccessBlurb = ` |
| 13 | +Select which features should show on the quick-access menu at the top of Patchfox window. |
| 14 | +` |
| 15 | + |
| 16 | +const ApplicationPreferences = { |
| 17 | + oninit: vnode => {}, |
| 18 | + view: vnode => { |
| 19 | + let skipTaskbar = getPref("skipTaskbar", false) |
| 20 | + |
| 21 | + let setShowOnTaskbar = ev => { |
| 22 | + let skip = ev.target.checked |
| 23 | + setPref("skipTaskbar", skip) |
| 24 | + } |
| 25 | + |
| 26 | + const makeOptions = options => { |
| 27 | + return options.map(o => |
| 28 | + m( |
| 29 | + "option", |
| 30 | + { |
| 31 | + class: o.class ?? "", |
| 32 | + value: o.value, |
| 33 | + }, |
| 34 | + o.label |
| 35 | + ) |
| 36 | + ) |
| 37 | + } |
| 38 | + |
| 39 | + const makeFormControl = (label, input, inside = false) => { |
| 40 | + if (inside) { |
| 41 | + return m(".form-control.w-full", [m("label.label", m("span.label-text", label), input)]) |
| 42 | + } else { |
| 43 | + return m(".form-control.w-full", [m("label.label", m("span.label-text", label)), input]) |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + const makeSelect = (onchange, label, options) => { |
| 48 | + return makeFormControl( |
| 49 | + label, |
| 50 | + m( |
| 51 | + "select.select.selectr-bordered.w-full.max-w-ws", |
| 52 | + { |
| 53 | + onchange, |
| 54 | + }, |
| 55 | + makeOptions(options) |
| 56 | + ) |
| 57 | + ) |
| 58 | + } |
| 59 | + |
| 60 | + const makeInput = (onchange, label, type = "text", value = "") => { |
| 61 | + return makeFormControl( |
| 62 | + label, |
| 63 | + m("input.input.input-bordered", { |
| 64 | + value, |
| 65 | + type, |
| 66 | + onchange, |
| 67 | + }) |
| 68 | + ) |
| 69 | + } |
| 70 | + |
| 71 | + const makeCheckbox = (onchange, checked = true) => { |
| 72 | + return m("input.checkbox.toggle", { |
| 73 | + onchange, |
| 74 | + checked, |
| 75 | + type: "checkbox", |
| 76 | + }) |
| 77 | + } |
| 78 | + |
| 79 | + |
| 80 | + const makeRadio = (onchange, name, checked = false) => { |
| 81 | + return m("input.radio", { |
| 82 | + onchange, |
| 83 | + name, |
| 84 | + checked, |
| 85 | + type: "radio", |
| 86 | + }) |
| 87 | + } |
| 88 | + |
| 89 | + const makeToggle = (onchange, label, checked) => { |
| 90 | + return makeFormControl(label, makeCheckbox(onchange, checked), true) |
| 91 | + } |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + return [ |
| 96 | + m("h1.uppercase.font-medium.text-xl.mb-4", "Application Preferences"), |
| 97 | + makeToggle(setShowOnTaskbar, "Hide from taskbar", skipTaskbar), |
| 98 | + m("p.prose", m.trust(ssb.markdown(quickAccessBlurb))) |
| 99 | + ] |
| 100 | + }, |
| 101 | +} |
| 102 | + |
| 103 | +module.exports = ApplicationPreferences |
0 commit comments