Skip to content

Commit

Permalink
[[globalMenu]] support for customisable quick actions
Browse files Browse the repository at this point in the history
  • Loading branch information
soapdog committed Sep 9, 2022
1 parent 7422181 commit bd15744
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
38 changes: 32 additions & 6 deletions ui/core/kernel/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const defaultPreferencesContent = `
# DO NOT SHARE YOUR PREFERENCES FILE WITH ANYONE.
# IT CONTAINS YOUR PRIVATE KEYS.
#
[preferences]
[Preferences]
theme = "light"
textSize = "prose-lg"
limit = "40"
Expand All @@ -33,6 +33,16 @@ blog = "all"
contact = "following"
about = "all"
gathering = "all"
[[QuickActions]]
label = "Public"
pkg = "hub"
view = "public"
[[QuickActions]]
label = "Mentions"
pkg = "hub"
view = "mentions"
`

let savedData = {}
Expand All @@ -43,8 +53,8 @@ const preferencesFileExists = () => {
if (fileExists) {
const data = TOML.parse(fs.readFileSync(prefsFile))
console.log(data)
if (data?.preferences?.defaultIdentity &&
data[data?.preferences?.defaultIdentity]?.id) {
if (data?.Preferences?.defaultIdentity &&
data[data?.Preferences?.defaultIdentity]?.id) {
return true
}
}
Expand Down Expand Up @@ -79,8 +89,8 @@ const loadSavedData = async () => {
}
}

const getPref = (key, defaultValue, namespace = "preferences") => {
if (!savedData.hasOwnProperty("preferences")) {
const getPref = (key, defaultValue, namespace = "Preferences") => {
if (!savedData.hasOwnProperty("Preferences")) {
// maybe not loaded. Preferences should always be present. It is added
// by the first-time setup.
if (preferencesFileExists()) {
Expand All @@ -96,6 +106,21 @@ const getPref = (key, defaultValue, namespace = "preferences") => {
return defaultValue
}

const getNamespace = (namespace, defaultValue) => {
if (!savedData.hasOwnProperty("Preferences")) {
// maybe not loaded. Preferences should always be present. It is added
// by the first-time setup.
if (preferencesFileExists()) {
savedData = TOML.parse(fs.readFileSync(prefsFile))
}
}

if (savedData[namespace]) {
return savedData[namespace]
}
return defaultValue
}

function writePreferencesFile() {
let header = `
#
Expand Down Expand Up @@ -134,7 +159,7 @@ const removeIdentity = (key) => {
}


const setPref = (key, value, namespace = "preferences") => {
const setPref = (key, value, namespace = "Preferences") => {
savedData[namespace] = savedData[namespace] || {}
savedData[namespace][key] = value

Expand Down Expand Up @@ -250,4 +275,5 @@ module.exports = {
initialisePreferencesFileIfNeeded,
setMessageTypeVisibility,
getVisibilityForMessageType,
getNamespace,
}
7 changes: 6 additions & 1 deletion ui/packages/globalMenu/globalMenuView.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const m = require("mithril")
const queryString = require("query-string")
const ipcRenderer = require("electron").ipcRenderer
const { when } = require("../../core/kernel/utils.js")
const { getNamespace } = require("../../core/kernel/prefs.js")
const ThemeSwitcher = require("../../core/components/ThemeSwitcher.js")

//const IdentitySwitcher = require("../../core/components/IdentitySwitcher.js")
Expand Down Expand Up @@ -57,6 +58,10 @@ const GlobalMenuView = {
)
}

const defaultActions = [{label: "Public", pkg: "hub", view: "public"}, {label: "Mentions", pkg: "hub", view: "mentions"}]
const actions = getNamespace("QuickActions", defaultActions)
const quickActions = actions.map(a => makeButton(a.label, a.pkg, a.view, a.data))

const search = ev => {
let query = document.getElementById("search-box").value

Expand Down Expand Up @@ -104,7 +109,7 @@ const GlobalMenuView = {
m.trust("→")
),
]),
m(".navbar-center", [makeButton("Public", "hub", "public"), makeButton("Mentions", "hub", "mentions")]),
m(".navbar-center", quickActions),
m(".navbar-end", [
m("form",{
role: "search",
Expand Down

0 comments on commit bd15744

Please sign in to comment.