diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-02-22 19:58:07 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-02-22 19:58:07 +1100 |
| commit | cf55e2613314e27243c60395e58665b9309280c8 (patch) | |
| tree | 572b6226dad2c84621deb33d765d5a67454fc842 /config.ts | |
| parent | scss: make notifpopup shadow default (diff) | |
| download | caelestia-shell-cf55e2613314e27243c60395e58665b9309280c8.tar.gz caelestia-shell-cf55e2613314e27243c60395e58665b9309280c8.tar.bz2 caelestia-shell-cf55e2613314e27243c60395e58665b9309280c8.zip | |
config: use config file
Config file at ~/.config/caelestia/shell.json
Diffstat (limited to 'config.ts')
| -rw-r--r-- | config.ts | 264 |
1 files changed, 145 insertions, 119 deletions
@@ -1,140 +1,166 @@ +import { GLib, monitorFile, readFileAsync, Variable } from "astal"; import { Astal } from "astal/gtk3"; +import { loadStyleAsync } from "./app"; -// Modules -export const bar = { - vertical: true, - modules: { - osIcon: { - enabled: true, - }, - activeWindow: { - enabled: true, - }, - mediaPlaying: { - enabled: true, +const CONFIG = `${GLib.get_user_config_dir()}/caelestia/shell.json`; + +const s = <T>(v: T): Variable<T> => Variable(v); + +const warn = (e: Error) => console.warn(`Invalid config: ${e}`); + +const updateSection = (from: { [k: string]: any }, to: { [k: string]: any }, path: string) => { + for (const [k, v] of Object.entries(from)) { + if (to.hasOwnProperty(k)) { + if (typeof v === "object" && v !== null && !Array.isArray(v)) updateSection(v, to[k], `${path}.${k}`); + else if (typeof v === typeof to[k].get()) to[k].set(v); + else console.warn(`Invalid type for ${path}.${k}: ${typeof v} != ${typeof to[k].get()}`); + } else console.warn(`Unknown config key: ${path}.${k}`); + } +}; + +export const updateConfig = async () => { + const conf: { [k: string]: any } = JSON.parse(await readFileAsync(CONFIG)); + for (const [k, v] of Object.entries(conf)) { + if (config.hasOwnProperty(k)) updateSection(v, config[k as keyof typeof config], k); + else console.warn(`Unknown config key: ${k}`); + } + loadStyleAsync().catch(console.error); +}; + +export const initConfig = () => { + monitorFile(CONFIG, () => updateConfig().catch(warn)); + updateConfig().catch(warn); +}; + +const config = { + // Modules + bar: { + vertical: s(true), + modules: { + osIcon: { + enabled: s(true), + }, + activeWindow: { + enabled: s(true), + }, + mediaPlaying: { + enabled: s(true), + }, + workspaces: { + enabled: s(true), + shown: s(5), + }, + tray: { + enabled: s(true), + }, + statusIcons: { + enabled: s(true), + }, + pkgUpdates: { + enabled: s(true), + }, + notifCount: { + enabled: s(true), + }, + battery: { + enabled: s(true), + }, + dateTime: { + enabled: s(true), + format: s("%d/%m/%y %R"), + detailedFormat: s("%c"), + }, + power: { + enabled: s(true), + }, }, - workspaces: { - enabled: true, - shown: 5, + }, + launcher: { + maxResults: s(15), // Max shown results at one time (i.e. max height of the launcher) + apps: { + maxResults: s(30), // Actual max results, -1 for infinite + pins: s([ + ["zen", "firefox", "waterfox", "google-chrome", "chromium", "brave-browser"], + ["foot", "alacritty", "kitty", "wezterm"], + ["thunar", "nemo", "nautilus"], + ["codium", "code", "clion", "intellij-idea-ultimate-edition"], + ["spotify-adblock", "spotify", "audacious", "elisa"], + ]), }, - tray: { - enabled: true, + files: { + maxResults: s(40), // Actual max results, -1 for infinite + fdOpts: s(["-a", "-t", "f"]), // Options to pass to `fd` }, - statusIcons: { - enabled: true, + math: { + maxResults: s(40), // Actual max results, -1 for infinite }, - pkgUpdates: { - enabled: true, + windows: { + maxResults: s(-1), // Actual max results, -1 for infinite + weights: { + // Weights for fuzzy sort + title: s(1), + class: s(1), + initialTitle: s(0.5), + initialClass: s(0.5), + }, }, - notifCount: { - enabled: true, + todo: { + notify: s(true), }, - battery: { - enabled: true, + }, + notifpopups: { + maxPopups: s(-1), + expire: s(false), + agoTime: s(true), // Whether to show time in ago format, e.g. 10 mins ago, or raw time, e.g. 10:42 + }, + osds: { + volume: { + position: s(Astal.WindowAnchor.RIGHT), + margin: s(20), + hideDelay: s(1500), + showValue: s(true), }, - dateTime: { - enabled: true, - format: "%d/%m/%y %R", - detailedFormat: "%c", + brightness: { + position: s(Astal.WindowAnchor.LEFT), + margin: s(20), + hideDelay: s(1500), + showValue: s(true), }, - power: { - enabled: true, + lock: { + spacing: s(5), + caps: { + hideDelay: s(1000), + }, + num: { + hideDelay: s(1000), + }, }, }, -}; - -export const launcher = { - maxResults: 15, // Max shown results at one time (i.e. max height of the launcher) - apps: { - maxResults: 30, // Actual max results, -1 for infinite - pins: [ - ["firefox", "waterfox", "google-chrome", "chromium", "brave-browser", "vivaldi-stable", "vivaldi-snapshot"], - ["foot", "alacritty", "kitty", "wezterm"], - ["thunar", "nemo", "nautilus"], - ["codium", "code", "clion", "intellij-idea-ultimate-edition"], - ["spotify-adblock", "spotify", "audacious", "elisa"], - ], - }, - files: { - maxResults: 40, // Actual max results, -1 for infinite - fdOpts: ["-a", "-t", "f"], // Options to pass to `fd` - }, + // Services math: { - maxResults: 40, // Actual max results, -1 for infinite + maxHistory: 100, }, - windows: { - maxResults: -1, // Actual max results, -1 for infinite - weights: { - // Weights for fuzzy sort - title: 1, - class: 1, - initialTitle: 0.5, - initialClass: 0.5, - }, + updates: { + interval: 900000, }, - todo: { - notify: true, + weather: { + interval: 600000, + key: "assets/weather-api-key.txt", // Path to file containing api key relative to the base directory. To get a key, visit https://weatherapi.com/ + location: "", // Location as a string or empty to autodetect + imperial: false, }, -}; - -export const notifpopups = { - maxPopups: -1, - expire: false, - agoTime: true, // Whether to show time in ago format, e.g. 10 mins ago, or raw time, e.g. 10:42 -}; - -export const osds = { - volume: { - position: Astal.WindowAnchor.RIGHT, - margin: 20, - hideDelay: 1500, - showValue: true, + cpu: { + interval: 2000, }, - brightness: { - position: Astal.WindowAnchor.LEFT, - margin: 20, - hideDelay: 1500, - showValue: true, + gpu: { + interval: 2000, }, - lock: { - spacing: 5, - caps: { - hideDelay: 1000, - }, - num: { - hideDelay: 1000, - }, + memory: { + interval: 5000, + }, + storage: { + interval: 5000, }, }; -// Services -export const math = { - maxHistory: 100, -}; - -export const updates = { - interval: 900000, -}; - -export const weather = { - interval: 600000, - key: "assets/weather-api-key.txt", // Path to file containing api key relative to the base directory. To get a key, visit https://weatherapi.com/ - location: "", // Location as a string or empty to autodetect - imperial: false, -}; - -export const cpu = { - interval: 2000, -}; - -export const gpu = { - interval: 2000, -}; - -export const memory = { - interval: 5000, -}; - -export const storage = { - interval: 5000, -}; +export const { bar, launcher, notifpopups, osds, math, updates, weather, cpu, gpu, memory, storage } = config; |