From 27d2652e8e66f17dffbac6fb09bf953bc5389012 Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Mon, 21 Oct 2024 04:04:30 +0545 Subject: [PATCH] feat: add option to toggle each section on dashboard (#344) Co-authored-by: Jas Singh --- modules/menus/dashboard/index.ts | 40 +++++++++++-------- options.ts | 5 +++ .../settings/pages/config/menus/dashboard.ts | 6 ++- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/modules/menus/dashboard/index.ts b/modules/menus/dashboard/index.ts index 0569109..9bac607 100644 --- a/modules/menus/dashboard/index.ts +++ b/modules/menus/dashboard/index.ts @@ -8,7 +8,7 @@ import Window from 'types/widgets/window.js'; import { Attribute, Child } from 'lib/types/widget.js'; import options from 'options.js'; -const { enabled: directoriesEnabled } = options.menus.dashboard.directories; +const { controls, shortcuts, stats, directories } = options.menus.dashboard; export default (): Window => { return DropdownMenu({ @@ -22,21 +22,29 @@ export default (): Window => { Widget.Box({ class_name: 'dashboard-content-container', vertical: true, - children: directoriesEnabled.bind('value').as((isDirectoriesEnabled) => { - return [ - Widget.Box({ - class_name: 'dashboard-content-items', - vertical: true, - children: [ - Profile(), - Shortcuts(), - Controls(), - ...(isDirectoriesEnabled ? [Directories()] : []), - Stats(), - ], - }), - ]; - }), + children: Utils.merge( + [ + controls.enabled.bind('value'), + shortcuts.enabled.bind('value'), + stats.enabled.bind('value'), + directories.enabled.bind('value'), + ], + (isControlsEnabled, isShortcutsEnabled, isStatsEnabled, isDirectoriesEnabled) => { + return [ + Widget.Box({ + class_name: 'dashboard-content-items', + vertical: true, + children: [ + Profile(), + ...(isShortcutsEnabled ? [Shortcuts()] : []), + ...(isControlsEnabled ? [Controls()] : []), + ...(isDirectoriesEnabled ? [Directories()] : []), + ...(isStatsEnabled ? [Stats()] : []), + ], + }), + ]; + }, + ), }), ], }), diff --git a/options.ts b/options.ts index 98b202a..e6a1cfd 100644 --- a/options.ts +++ b/options.ts @@ -1064,9 +1064,14 @@ const options = mkOptions(OPTIONS, { }, }, stats: { + enabled: opt(true), enable_gpu: opt(false), }, + controls: { + enabled: opt(true), + }, shortcuts: { + enabled: opt(true), left: { shortcut1: { icon: opt('󰇩'), diff --git a/widget/settings/pages/config/menus/dashboard.ts b/widget/settings/pages/config/menus/dashboard.ts index e6ef528..fbb7128 100644 --- a/widget/settings/pages/config/menus/dashboard.ts +++ b/widget/settings/pages/config/menus/dashboard.ts @@ -43,16 +43,18 @@ export const DashboardMenuSettings = (): Scrollable => { Option({ opt: options.menus.dashboard.powermenu.reboot, title: 'Reboot Command', type: 'string' }), Option({ opt: options.menus.dashboard.powermenu.logout, title: 'Logout Command', type: 'string' }), Option({ opt: options.menus.dashboard.powermenu.sleep, title: 'Sleep Command', type: 'string' }), - + Header('Controls'), + Option({ opt: options.menus.dashboard.controls.enabled, title: 'Enabled', type: 'boolean' }), Header('Resource Usage Metrics'), + Option({ opt: options.menus.dashboard.stats.enabled, title: 'Enabled', type: 'boolean' }), Option({ opt: options.menus.dashboard.stats.enable_gpu, title: 'Track GPU', subtitle: "NOTE: This is currently only available for NVidia GPUs and requires 'python-gpustat'.", type: 'boolean', }), - Header('Shortcuts'), + Option({ opt: options.menus.dashboard.shortcuts.enabled, title: 'Enabled', type: 'boolean' }), Option({ opt: options.menus.dashboard.shortcuts.left.shortcut1.icon, title: 'Left - Shortcut 1 (Icon)',