Skip to content

Commit 7422181

Browse files
committed
[[settings]] added application-wise preferences, and commented it out.
1 parent 1115096 commit 7422181

File tree

5 files changed

+123
-12
lines changed

5 files changed

+123
-12
lines changed

app.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const queryString = require("query-string")
1515
const { startDefaultPatchfoxServer } = require("./server/server.js")
1616
const {
1717
preferencesFileExists,
18-
getDefaultIdentity
18+
getDefaultIdentity,
19+
getPref
1920
} = require("./ui/core/kernel/prefs.js")
2021

2122
let windows = new Set()
@@ -47,6 +48,7 @@ const createApplicationWindow = (patchfoxEvent = {}, windowState = false) => {
4748
width: 800,
4849
height: 800,
4950
show: false,
51+
skipTaskbar: getPref("skipTaskbar", false),
5052
webPreferences: {
5153
nodeIntegration: true,
5254
contextIsolation: false,
@@ -57,6 +59,7 @@ const createApplicationWindow = (patchfoxEvent = {}, windowState = false) => {
5759
x: windowState.x,
5860
y: windowState.y,
5961
show: false,
62+
skipTaskbar: getPref("skipTaskbar", false),
6063
width: windowState.width,
6164
height: windowState.height,
6265
webPreferences: {

ui/core/kernel/prefs.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,18 @@ const loadSavedData = async () => {
7979
}
8080
}
8181

82-
const getPref = (key, defaultValue) => {
82+
const getPref = (key, defaultValue, namespace = "preferences") => {
8383
if (!savedData.hasOwnProperty("preferences")) {
84-
// maybe not loaded...
85-
// this happens when using the first time setup
84+
// maybe not loaded. Preferences should always be present. It is added
85+
// by the first-time setup.
8686
if (preferencesFileExists()) {
8787
savedData = TOML.parse(fs.readFileSync(prefsFile))
8888
}
8989
}
9090

91-
if (savedData.preferences) {
92-
if (savedData.preferences.hasOwnProperty(key)) {
93-
return savedData.preferences[key]
91+
if (savedData[namespace]) {
92+
if (savedData[namespace].hasOwnProperty(key)) {
93+
return savedData[namespace][key]
9494
}
9595
}
9696
return defaultValue
@@ -134,9 +134,9 @@ const removeIdentity = (key) => {
134134
}
135135

136136

137-
const setPref = (key, value) => {
138-
savedData.preferences = savedData.preferences || {}
139-
savedData.preferences[key] = value
137+
const setPref = (key, value, namespace = "preferences") => {
138+
savedData[namespace] = savedData[namespace] || {}
139+
savedData[namespace][key] = value
140140

141141
writePreferencesFile()
142142
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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

ui/packages/settings/DisplayPreferences.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const DisplayPreferences = {
5050
return makeFormControl(
5151
label,
5252
m(
53-
"select.select.selectr-bordered.w-full.max-w-ws",
53+
"select.select.select-bordered.w-full.max-w-ws",
5454
{
5555
onchange,
5656
},

ui/packages/settings/SettingsView.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
const m = require("mithril")
22
const Spinner = require("../../core/components/Spinner.js")
33
const DisplayPreferences = require("./DisplayPreferences.js")
4+
const ApplicationPreferences = require("./ApplicationPreferences.js")
45
const AboutView = require("./AboutView.js")
56

67
const menu = {
78
"about": {
89
label: "About Patchfox",
910
panel: AboutView
1011
},
12+
// "application": {
13+
// label: "Application Preferences",
14+
// panel: ApplicationPreferences
15+
// },
1116
"display": {
1217
label: "Display Preferences",
1318
panel: DisplayPreferences
14-
}
19+
},
1520
}
1621

1722

0 commit comments

Comments
 (0)