Skip to content

Commit bd15744

Browse files
committed
[[globalMenu]] support for customisable quick actions
1 parent 7422181 commit bd15744

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

ui/core/kernel/prefs.js

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const defaultPreferencesContent = `
1818
# DO NOT SHARE YOUR PREFERENCES FILE WITH ANYONE.
1919
# IT CONTAINS YOUR PRIVATE KEYS.
2020
#
21-
[preferences]
21+
[Preferences]
2222
theme = "light"
2323
textSize = "prose-lg"
2424
limit = "40"
@@ -33,6 +33,16 @@ blog = "all"
3333
contact = "following"
3434
about = "all"
3535
gathering = "all"
36+
37+
[[QuickActions]]
38+
label = "Public"
39+
pkg = "hub"
40+
view = "public"
41+
42+
[[QuickActions]]
43+
label = "Mentions"
44+
pkg = "hub"
45+
view = "mentions"
3646
`
3747

3848
let savedData = {}
@@ -43,8 +53,8 @@ const preferencesFileExists = () => {
4353
if (fileExists) {
4454
const data = TOML.parse(fs.readFileSync(prefsFile))
4555
console.log(data)
46-
if (data?.preferences?.defaultIdentity &&
47-
data[data?.preferences?.defaultIdentity]?.id) {
56+
if (data?.Preferences?.defaultIdentity &&
57+
data[data?.Preferences?.defaultIdentity]?.id) {
4858
return true
4959
}
5060
}
@@ -79,8 +89,8 @@ const loadSavedData = async () => {
7989
}
8090
}
8191

82-
const getPref = (key, defaultValue, namespace = "preferences") => {
83-
if (!savedData.hasOwnProperty("preferences")) {
92+
const getPref = (key, defaultValue, namespace = "Preferences") => {
93+
if (!savedData.hasOwnProperty("Preferences")) {
8494
// maybe not loaded. Preferences should always be present. It is added
8595
// by the first-time setup.
8696
if (preferencesFileExists()) {
@@ -96,6 +106,21 @@ const getPref = (key, defaultValue, namespace = "preferences") => {
96106
return defaultValue
97107
}
98108

109+
const getNamespace = (namespace, defaultValue) => {
110+
if (!savedData.hasOwnProperty("Preferences")) {
111+
// maybe not loaded. Preferences should always be present. It is added
112+
// by the first-time setup.
113+
if (preferencesFileExists()) {
114+
savedData = TOML.parse(fs.readFileSync(prefsFile))
115+
}
116+
}
117+
118+
if (savedData[namespace]) {
119+
return savedData[namespace]
120+
}
121+
return defaultValue
122+
}
123+
99124
function writePreferencesFile() {
100125
let header = `
101126
#
@@ -134,7 +159,7 @@ const removeIdentity = (key) => {
134159
}
135160

136161

137-
const setPref = (key, value, namespace = "preferences") => {
162+
const setPref = (key, value, namespace = "Preferences") => {
138163
savedData[namespace] = savedData[namespace] || {}
139164
savedData[namespace][key] = value
140165

@@ -250,4 +275,5 @@ module.exports = {
250275
initialisePreferencesFileIfNeeded,
251276
setMessageTypeVisibility,
252277
getVisibilityForMessageType,
278+
getNamespace,
253279
}

ui/packages/globalMenu/globalMenuView.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const m = require("mithril")
22
const queryString = require("query-string")
33
const ipcRenderer = require("electron").ipcRenderer
44
const { when } = require("../../core/kernel/utils.js")
5+
const { getNamespace } = require("../../core/kernel/prefs.js")
56
const ThemeSwitcher = require("../../core/components/ThemeSwitcher.js")
67

78
//const IdentitySwitcher = require("../../core/components/IdentitySwitcher.js")
@@ -57,6 +58,10 @@ const GlobalMenuView = {
5758
)
5859
}
5960

61+
const defaultActions = [{label: "Public", pkg: "hub", view: "public"}, {label: "Mentions", pkg: "hub", view: "mentions"}]
62+
const actions = getNamespace("QuickActions", defaultActions)
63+
const quickActions = actions.map(a => makeButton(a.label, a.pkg, a.view, a.data))
64+
6065
const search = ev => {
6166
let query = document.getElementById("search-box").value
6267

@@ -104,7 +109,7 @@ const GlobalMenuView = {
104109
m.trust("→")
105110
),
106111
]),
107-
m(".navbar-center", [makeButton("Public", "hub", "public"), makeButton("Mentions", "hub", "mentions")]),
112+
m(".navbar-center", quickActions),
108113
m(".navbar-end", [
109114
m("form",{
110115
role: "search",

0 commit comments

Comments
 (0)