From a026a3573550984e4900c8ed00d6d876fa94f8ba Mon Sep 17 00:00:00 2001 From: Jas Singh Date: Sun, 1 Jun 2025 23:05:15 -0700 Subject: [PATCH] Chore: Add missing dependencies to the check dependencies command. (#978) --- .../cli/commander/InitializeCommand.ts | 2 +- .../commands/system/checkDependencies.ts | 257 ------------------ .../commands/system/dependencies/index.ts | 109 ++++++++ .../commands/system/dependencies/optional.ts | 88 ++++++ .../commands/system/dependencies/required.ts | 76 ++++++ .../commands/system/dependencies/types.ts | 9 + .../{listSensors.ts => sensors/index.ts} | 0 .../commands/system/{ => utility}/index.ts | 6 +- 8 files changed, 286 insertions(+), 261 deletions(-) delete mode 100644 src/services/cli/commander/commands/system/checkDependencies.ts create mode 100644 src/services/cli/commander/commands/system/dependencies/index.ts create mode 100644 src/services/cli/commander/commands/system/dependencies/optional.ts create mode 100644 src/services/cli/commander/commands/system/dependencies/required.ts create mode 100644 src/services/cli/commander/commands/system/dependencies/types.ts rename src/services/cli/commander/commands/system/{listSensors.ts => sensors/index.ts} (100%) rename src/services/cli/commander/commands/system/{ => utility}/index.ts (97%) diff --git a/src/services/cli/commander/InitializeCommand.ts b/src/services/cli/commander/InitializeCommand.ts index f88070d..8df492c 100644 --- a/src/services/cli/commander/InitializeCommand.ts +++ b/src/services/cli/commander/InitializeCommand.ts @@ -2,7 +2,7 @@ import { CommandRegistry } from './Registry'; import { Command } from './types'; import { createExplainCommand } from './helpers'; import { appearanceCommands } from './commands/appearance'; -import { utilityCommands } from './commands/system'; +import { utilityCommands } from './commands/system/utility'; import { windowManagementCommands } from './commands/windowManagement'; import { mediaCommands } from './commands/modules/media'; diff --git a/src/services/cli/commander/commands/system/checkDependencies.ts b/src/services/cli/commander/commands/system/checkDependencies.ts deleted file mode 100644 index f70578a..0000000 --- a/src/services/cli/commander/commands/system/checkDependencies.ts +++ /dev/null @@ -1,257 +0,0 @@ -import { errorHandler } from 'src/core/errors/handler'; -import { SystemUtilities } from 'src/core/system/SystemUtilities'; -import { ServiceStatus } from 'src/core/system/types'; - -const RED = '\x1b[31m'; -const GREEN = '\x1b[32m'; -const YELLOW = '\x1b[33m'; -const RESET = '\x1b[0m'; -const BOLD = '\x1b[1m'; - -const STATUS_INSTALLED = '(INSTALLED)'; -const STATUS_ACTIVE = '(ACTIVE)'; -const STATUS_DISABLED = '(DISABLED)'; -const STATUS_MISSING = '(MISSING)'; - -/** - * Colors a given text using ANSI color codes. - * - * @description Wraps the provided text with ANSI color codes. - * - * @param text - The text to color. - * @param color - The ANSI color code to use. - */ -function colorText(text: string, color: string): string { - return `${color}${text}${RESET}`; -} - -/** - * Determines the status string and color for a dependency based on its type and checks. - * - * @description Returns the formatted line indicating the status of the given dependency. - * - * @param dep - The dependency to check. - */ -function getDependencyStatus(dep: Dependency): string { - let status: ServiceStatus | 'INSTALLED' | 'MISSING'; - - switch (dep.type) { - case 'executable': - status = SystemUtilities.checkExecutable(dep.check) ? 'INSTALLED' : 'MISSING'; - break; - case 'library': - status = SystemUtilities.checkLibrary(dep.check) ? 'INSTALLED' : 'MISSING'; - break; - case 'service': - status = SystemUtilities.checkServiceStatus(dep.check); - break; - default: - status = 'MISSING'; - } - - let color: string; - let textStatus: string; - - switch (status) { - case 'ACTIVE': - textStatus = STATUS_ACTIVE; - color = GREEN; - break; - case 'INSTALLED': - textStatus = STATUS_INSTALLED; - color = GREEN; - break; - case 'DISABLED': - textStatus = STATUS_DISABLED; - color = YELLOW; - break; - case 'MISSING': - default: - textStatus = STATUS_MISSING; - color = RED; - break; - } - - if (dep.description === undefined) { - return ` ${colorText(textStatus, color)} ${dep.package}`; - } - - return ` ${colorText(textStatus, color)} ${dep.package}: ${dep.description ?? ''}`; -} - -/** - * Checks all dependencies and returns a formatted output. - * - * @description Gathers the status of both required and optional dependencies and formats the result. - */ -export function checkDependencies(): string { - try { - const dependencies: Dependency[] = [ - { - package: 'wireplumber', - required: true, - type: 'executable', - check: ['wireplumber'], - }, - { - package: 'libgtop', - required: true, - type: 'library', - check: ['gtop-2.0'], - }, - { - package: 'bluez', - required: true, - type: 'service', - check: ['bluetooth.service'], - }, - { - package: 'bluez-utils', - required: true, - type: 'executable', - check: ['bluetoothctl'], - }, - { - package: 'networkmanager', - required: true, - type: 'service', - check: ['NetworkManager.service'], - }, - { - package: 'dart-sass', - required: true, - type: 'executable', - check: ['sass'], - }, - { - package: 'wl-clipboard', - required: true, - type: 'executable', - check: ['wl-copy', 'wl-paste'], - }, - { - package: 'upower', - required: true, - type: 'service', - check: ['upower.service'], - }, - { - package: 'aylurs-gtk-shell', - required: true, - type: 'executable', - check: ['ags'], - }, - - { - package: 'python', - required: false, - type: 'executable', - check: ['python', 'python3'], - description: 'GPU usage tracking (NVidia only)', - }, - { - package: 'python-gpustat', - required: false, - type: 'executable', - check: ['gpustat'], - description: 'GPU usage tracking (NVidia only)', - }, - { - package: 'pywal', - required: false, - type: 'executable', - check: ['wal'], - description: 'Pywal hook for wallpapers', - }, - { - package: 'pacman-contrib', - required: false, - type: 'executable', - check: ['paccache', 'rankmirrors'], - description: 'Checking for pacman updates', - }, - { - package: 'power-profiles-daemon', - required: false, - type: 'service', - check: ['power-profiles-daemon.service'], - description: 'Switch power profiles', - }, - { - package: 'swww', - required: false, - type: 'executable', - check: ['swww'], - description: 'Setting wallpapers', - }, - { - package: 'grimblast', - required: false, - type: 'executable', - check: ['grimblast'], - description: 'For the snapshot shortcut', - }, - { - package: 'brightnessctl', - required: false, - type: 'executable', - check: ['brightnessctl'], - description: 'To control keyboard and screen brightness', - }, - { - package: 'btop', - required: false, - type: 'executable', - check: ['btop'], - description: 'To view system resource usage', - }, - { - package: 'wf-recorder', - required: false, - type: 'executable', - check: ['wf-recorder'], - description: 'To use the built-in screen recorder', - }, - { - package: 'hyprpicker', - required: false, - type: 'executable', - check: ['hyprpicker'], - description: 'To use the preset color picker shortcut', - }, - { - package: 'matugen', - required: false, - type: 'executable', - check: ['matugen'], - description: 'To use wallpaper-based color schemes', - }, - ]; - - let output = `${BOLD}Required Dependencies:${RESET}\n`; - - for (const dep of dependencies.filter((d) => d.required)) { - output += getDependencyStatus(dep) + '\n'; - } - - output += `\n${BOLD}Optional Dependencies:${RESET}\n`; - - for (const dep of dependencies.filter((d) => !d.required)) { - output += getDependencyStatus(dep) + '\n'; - } - - return output; - } catch (error) { - errorHandler(error); - } -} - -type DependencyType = 'executable' | 'library' | 'service'; - -type Dependency = { - package: string; - required: boolean; - type: DependencyType; - check: string[]; - description?: string; -}; diff --git a/src/services/cli/commander/commands/system/dependencies/index.ts b/src/services/cli/commander/commands/system/dependencies/index.ts new file mode 100644 index 0000000..92b722b --- /dev/null +++ b/src/services/cli/commander/commands/system/dependencies/index.ts @@ -0,0 +1,109 @@ +import { errorHandler } from 'src/core/errors/handler'; +import { SystemUtilities } from 'src/core/system/SystemUtilities'; +import { ServiceStatus } from 'src/core/system/types'; +import { requiredDependencies } from './required'; +import { optionalDependencies } from './optional'; +import { Dependency } from './types'; + +const RED = '\x1b[31m'; +const GREEN = '\x1b[32m'; +const YELLOW = '\x1b[33m'; +const RESET = '\x1b[0m'; +const BOLD = '\x1b[1m'; + +const STATUS_INSTALLED = '(INSTALLED)'; +const STATUS_ACTIVE = '(ACTIVE)'; +const STATUS_DISABLED = '(DISABLED)'; +const STATUS_MISSING = '(MISSING)'; + +/** + * Checks all dependencies and returns a formatted output. + * + * @description Gathers the status of both required and optional dependencies and formats the result. + */ +export function checkDependencies(): string { + try { + let output = `${BOLD}Required Dependencies:${RESET}\n`; + const dependencies = [...requiredDependencies, ...optionalDependencies]; + + for (const dep of dependencies.filter((d) => d.required)) { + output += getDependencyStatus(dep) + '\n'; + } + + output += `\n${BOLD}Optional Dependencies:${RESET}\n`; + + for (const dep of dependencies.filter((d) => !d.required)) { + output += getDependencyStatus(dep) + '\n'; + } + + return output; + } catch (error) { + errorHandler(error); + } +} + +/** + * Colors a given text using ANSI color codes. + * + * @description Wraps the provided text with ANSI color codes. + * + * @param text - The text to color. + * @param color - The ANSI color code to use. + */ +function colorText(text: string, color: string): string { + return `${color}${text}${RESET}`; +} + +/** + * Determines the status string and color for a dependency based on its type and checks. + * + * @description Returns the formatted line indicating the status of the given dependency. + * + * @param dep - The dependency to check. + */ +function getDependencyStatus(dep: Dependency): string { + let status: ServiceStatus | 'INSTALLED' | 'MISSING'; + + switch (dep.type) { + case 'executable': + status = SystemUtilities.checkExecutable(dep.check) ? 'INSTALLED' : 'MISSING'; + break; + case 'library': + status = SystemUtilities.checkLibrary(dep.check) ? 'INSTALLED' : 'MISSING'; + break; + case 'service': + status = SystemUtilities.checkServiceStatus(dep.check); + break; + default: + status = 'MISSING'; + } + + let color: string; + let textStatus: string; + + switch (status) { + case 'ACTIVE': + textStatus = STATUS_ACTIVE; + color = GREEN; + break; + case 'INSTALLED': + textStatus = STATUS_INSTALLED; + color = GREEN; + break; + case 'DISABLED': + textStatus = STATUS_DISABLED; + color = YELLOW; + break; + case 'MISSING': + default: + textStatus = STATUS_MISSING; + color = RED; + break; + } + + if (dep.description === undefined) { + return ` ${colorText(textStatus, color)} ${dep.package}`; + } + + return ` ${colorText(textStatus, color)} ${dep.package}: ${dep.description ?? ''}`; +} diff --git a/src/services/cli/commander/commands/system/dependencies/optional.ts b/src/services/cli/commander/commands/system/dependencies/optional.ts new file mode 100644 index 0000000..caf1d4e --- /dev/null +++ b/src/services/cli/commander/commands/system/dependencies/optional.ts @@ -0,0 +1,88 @@ +import { Dependency } from './types'; + +export const optionalDependencies: Dependency[] = [ + { + package: 'python', + required: false, + type: 'executable', + check: ['python', 'python3'], + description: 'GPU usage tracking (NVidia only)', + }, + { + package: 'python-gpustat', + required: false, + type: 'executable', + check: ['gpustat'], + description: 'GPU usage tracking (NVidia only)', + }, + { + package: 'pywal', + required: false, + type: 'executable', + check: ['wal'], + description: 'Pywal hook for wallpapers', + }, + { + package: 'pacman-contrib', + required: false, + type: 'executable', + check: ['paccache', 'rankmirrors'], + description: 'Checking for pacman updates', + }, + { + package: 'power-profiles-daemon', + required: false, + type: 'service', + check: ['power-profiles-daemon.service'], + description: 'Switch power profiles', + }, + { + package: 'swww', + required: false, + type: 'executable', + check: ['swww'], + description: 'Setting wallpapers', + }, + { + package: 'grimblast', + required: false, + type: 'executable', + check: ['grimblast'], + description: 'For the snapshot shortcut', + }, + { + package: 'brightnessctl', + required: false, + type: 'executable', + check: ['brightnessctl'], + description: 'To control keyboard and screen brightness', + }, + { + package: 'btop', + required: false, + type: 'executable', + check: ['btop'], + description: 'To view system resource usage', + }, + { + package: 'wf-recorder', + required: false, + type: 'executable', + check: ['wf-recorder'], + description: 'To use the built-in screen recorder', + }, + { + package: 'hyprpicker', + required: false, + type: 'executable', + check: ['hyprpicker'], + description: 'To use the preset color picker shortcut', + }, + { + package: 'matugen', + required: false, + type: 'executable', + check: ['matugen'], + description: 'To use wallpaper-based color schemes', + }, +]; diff --git a/src/services/cli/commander/commands/system/dependencies/required.ts b/src/services/cli/commander/commands/system/dependencies/required.ts new file mode 100644 index 0000000..f409899 --- /dev/null +++ b/src/services/cli/commander/commands/system/dependencies/required.ts @@ -0,0 +1,76 @@ +import { Dependency } from './types'; + +export const requiredDependencies: Dependency[] = [ + { + package: 'wireplumber', + required: true, + type: 'executable', + check: ['wireplumber'], + }, + { + package: 'libgtop', + required: true, + type: 'library', + check: ['gtop-2.0'], + }, + { + package: 'bluez', + required: true, + type: 'service', + check: ['bluetooth.service'], + }, + { + package: 'bluez-utils', + required: true, + type: 'executable', + check: ['bluetoothctl'], + }, + { + package: 'networkmanager', + required: true, + type: 'service', + check: ['NetworkManager.service'], + }, + { + package: 'dart-sass', + required: true, + type: 'executable', + check: ['sass'], + }, + { + package: 'wl-clipboard', + required: true, + type: 'executable', + check: ['wl-copy', 'wl-paste'], + }, + { + package: 'upower', + required: true, + type: 'service', + check: ['upower.service'], + }, + { + package: 'gvfs', + required: true, + type: 'executable', + check: ['/usr/lib/gvfsd', '/usr/libexec/gvfsd', '/usr/lib/gvfs/gvfsd'], + }, + { + package: 'gtksourceview3', + required: true, + type: 'library', + check: ['gtksourceview-3.0', 'libgtksourceview-3.0'], + }, + { + package: 'libsoup3', + required: true, + type: 'library', + check: ['libsoup-3.0', 'libsoup3'], + }, + { + package: 'aylurs-gtk-shell', + required: true, + type: 'executable', + check: ['ags'], + }, +]; diff --git a/src/services/cli/commander/commands/system/dependencies/types.ts b/src/services/cli/commander/commands/system/dependencies/types.ts new file mode 100644 index 0000000..48b6776 --- /dev/null +++ b/src/services/cli/commander/commands/system/dependencies/types.ts @@ -0,0 +1,9 @@ +export type DependencyType = 'executable' | 'library' | 'service'; + +export type Dependency = { + package: string; + required: boolean; + type: DependencyType; + check: string[]; + description?: string; +}; diff --git a/src/services/cli/commander/commands/system/listSensors.ts b/src/services/cli/commander/commands/system/sensors/index.ts similarity index 100% rename from src/services/cli/commander/commands/system/listSensors.ts rename to src/services/cli/commander/commands/system/sensors/index.ts diff --git a/src/services/cli/commander/commands/system/index.ts b/src/services/cli/commander/commands/system/utility/index.ts similarity index 97% rename from src/services/cli/commander/commands/system/index.ts rename to src/services/cli/commander/commands/system/utility/index.ts index aea7d18..d266be8 100644 --- a/src/services/cli/commander/commands/system/index.ts +++ b/src/services/cli/commander/commands/system/utility/index.ts @@ -1,14 +1,14 @@ import AstalNotifd from 'gi://AstalNotifd?version=0.1'; import AstalWp from 'gi://AstalWp?version=0.1'; -import { Command } from '../../types'; +import { Command } from '../../../types'; import { execAsync, Gio, GLib } from 'astal'; -import { checkDependencies } from './checkDependencies'; +import { checkDependencies } from '../dependencies'; import { getSystrayItems } from 'src/services/cli/helpers/systray'; import { idleInhibit } from 'src/lib/window/visibility'; import { errorHandler } from 'src/core/errors/handler'; import { clearNotifications } from 'src/lib/shared/notifications'; import options from 'src/configuration'; -import { listCpuTempSensors } from './listSensors'; +import { listCpuTempSensors } from '../sensors'; const { clearDelay } = options.notifications; const notifdService = AstalNotifd.get_default();