From c147f154a40c9007b3cf1734bd0d727a9e2f5706 Mon Sep 17 00:00:00 2001 From: Mara Date: Fri, 28 Mar 2025 07:19:55 +0100 Subject: [PATCH] Feat: Add optional extended tooltip for updates module (#866) * added optional extended tooltip for updates module * Apply suggestions from code review Linter fixes * Update scripts/checkUpdates.sh Co-authored-by: Jas Singh * Update scripts/checkUpdates.sh Co-authored-by: Jas Singh --------- Co-authored-by: Mara Co-authored-by: Jas Singh --- scripts/checkUpdates.sh | 109 +++++++++++++------ src/components/bar/modules/updates/index.tsx | 23 +++- src/components/bar/settings/config.tsx | 11 ++ src/options.ts | 2 + 4 files changed, 111 insertions(+), 34 deletions(-) diff --git a/scripts/checkUpdates.sh b/scripts/checkUpdates.sh index ab36d3c..cff43db 100755 --- a/scripts/checkUpdates.sh +++ b/scripts/checkUpdates.sh @@ -1,49 +1,94 @@ #!/bin/bash -check_arch_updates() { - official_updates=0 - aur_updates=0 - if command -v paru &> /dev/null; then - aur_helper="paru" - else - aur_helper="yay" - fi +has_param() { + local term="$1" + shift + for arg; do + if [[ $arg == "$term" ]]; then + return 0 + fi + done + return 1 +} - if [ "$1" = "-y" ]; then - aur_updates=$($aur_helper -Qum 2>/dev/null | wc -l) - elif [ "$1" = "-p" ]; then - official_updates=$(checkupdates 2>/dev/null | wc -l) +wait_for_process_to_finish() { + local process_name="$1" + while pgrep -a "$process_name" >/dev/null; do + sleep 0.1 + done +} + +check_arch_updates() { + if command -v paru &> /dev/null; then + aur_helper="paru" else - official_updates=$(checkupdates 2>/dev/null | wc -l) - aur_updates=$($aur_helper -Qum 2>/dev/null | wc -l) + aur_helper="yay" + fi + + if has_param "-tooltip" "$@"; then + command=" | head -n 50" + official_updates="" + aur_updates="" + wait_for_process_to_finish "checkupdates" + else + command="2>/dev/null | wc -l" + official_updates=0 + aur_updates=0 + fi + + aur_command="$aur_helper -Qum $command" + official_command="checkupdates $command" + + if has_param "-y" "$@"; then + aur_updates=$(eval "$aur_command") + elif has_param "-p" "$@"; then + official_updates=$(eval "$official_command") + else + aur_updates=$(eval "$aur_command") + official_updates=$(eval "$official_command") + fi + + if has_param "-tooltip" "$@"; then + if [ "$official_updates" ];then + echo "pacman:" + echo "$official_updates" + fi + if [ "$official_updates" ] && [ "$aur_updates" ];then + echo "" + fi + if [ "$aur_updates" ];then + echo "AUR:" + echo "$aur_updates" + fi + else + total_updates=$((official_updates + aur_updates)) + echo $total_updates fi - total_updates=$((official_updates + aur_updates)) - echo $total_updates } check_ubuntu_updates() { - result=$(apt-get -s -o Debug::NoLocking=true upgrade | grep -c ^Inst) - echo "$result" + result=$(apt-get -s -o Debug::NoLocking=true upgrade | grep -c ^Inst) + echo "$result" } check_fedora_updates() { - result=$(dnf check-update -q | grep -v '^Loaded plugins' | grep -v '^No match for' | wc -l) - echo "$result" + result=$(dnf check-update -q | grep -v '^Loaded plugins' | grep -v '^No match for' | wc -l) + echo "$result" } case "$1" in --arch) - check_arch_updates "$2" - ;; --ubuntu) - check_ubuntu_updates - ;; --fedora) - check_fedora_updates - ;; -*) - echo "0" - ;; + -arch) + check_arch_updates "$2" "$3" + ;; + -ubuntu) + check_ubuntu_updates + ;; + -fedora) + check_fedora_updates + ;; + *) + echo "0" + ;; esac diff --git a/src/components/bar/modules/updates/index.tsx b/src/components/bar/modules/updates/index.tsx index c2460bf..a367150 100644 --- a/src/components/bar/modules/updates/index.tsx +++ b/src/components/bar/modules/updates/index.tsx @@ -8,6 +8,8 @@ import { Astal } from 'astal/gtk3'; const { updateCommand, + updateTooltipCommand, + extendedTooltip, label, padZero, autoHide, @@ -21,6 +23,7 @@ const { } = options.bar.customModules.updates; const pendingUpdates: Variable = Variable('0'); +const pendingUpdatesTooltip: Variable = Variable(''); const postInputUpdater = Variable(true); const isVis = Variable(!autoHide.get()); @@ -29,15 +32,31 @@ const processUpdateCount = (updateCount: string): string => { return `${updateCount.padStart(2, '0')}`; }; +const processUpdateTooltip = (updateTooltip: string, updateCount: Variable): string => { + const defaultTooltip = updateCount.get() + ' updates available'; + if (!extendedTooltip.get()) return defaultTooltip; + return defaultTooltip + '\n\n' + updateTooltip; +}; + const updatesPoller = new BashPoller( pendingUpdates, - [bind(padZero), bind(postInputUpdater)], + [bind(padZero), bind(postInputUpdater), bind(updateCommand)], bind(pollingInterval), updateCommand.get(), processUpdateCount, ); +const tooltipPoller = new BashPoller]>( + pendingUpdatesTooltip, + [bind(extendedTooltip), bind(postInputUpdater), bind(updateTooltipCommand)], + bind(pollingInterval), + updateTooltipCommand.get(), + processUpdateTooltip, + pendingUpdates, +); + updatesPoller.initialize('updates'); +tooltipPoller.initialize('updates'); Variable.derive([bind(autoHide)], (autoHideModule) => { isVis.set(!autoHideModule || (autoHideModule && parseFloat(pendingUpdates.get()) > 0)); @@ -54,7 +73,7 @@ const updatesIcon = Variable.derive( export const Updates = (): BarBoxChild => { const updatesModule = Module({ textIcon: updatesIcon(), - tooltipText: bind(pendingUpdates).as((v) => `${v} updates available`), + tooltipText: bind(pendingUpdatesTooltip), boxClass: 'updates', isVis: isVis, label: bind(pendingUpdates), diff --git a/src/components/bar/settings/config.tsx b/src/components/bar/settings/config.tsx index 363255a..70e2802 100644 --- a/src/components/bar/settings/config.tsx +++ b/src/components/bar/settings/config.tsx @@ -237,6 +237,17 @@ export const CustomModuleSettings = (): JSX.Element => { title="Check Updates Command" type="string" /> +