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 <jaskiratpal.singh@outlook.com> * Update scripts/checkUpdates.sh Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com> --------- Co-authored-by: Mara <mara.dawn69@gmail.com> Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com>
This commit is contained in:
@@ -1,26 +1,71 @@
|
||||
#!/bin/bash
|
||||
|
||||
has_param() {
|
||||
local term="$1"
|
||||
shift
|
||||
for arg; do
|
||||
if [[ $arg == "$term" ]]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
wait_for_process_to_finish() {
|
||||
local process_name="$1"
|
||||
while pgrep -a "$process_name" >/dev/null; do
|
||||
sleep 0.1
|
||||
done
|
||||
}
|
||||
|
||||
check_arch_updates() {
|
||||
official_updates=0
|
||||
aur_updates=0
|
||||
if command -v paru &> /dev/null; then
|
||||
aur_helper="paru"
|
||||
else
|
||||
aur_helper="yay"
|
||||
fi
|
||||
|
||||
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)
|
||||
if has_param "-tooltip" "$@"; then
|
||||
command=" | head -n 50"
|
||||
official_updates=""
|
||||
aur_updates=""
|
||||
wait_for_process_to_finish "checkupdates"
|
||||
else
|
||||
official_updates=$(checkupdates 2>/dev/null | wc -l)
|
||||
aur_updates=$($aur_helper -Qum 2>/dev/null | wc -l)
|
||||
command="2>/dev/null | wc -l"
|
||||
official_updates=0
|
||||
aur_updates=0
|
||||
fi
|
||||
|
||||
total_updates=$((official_updates + aur_updates))
|
||||
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
|
||||
|
||||
|
||||
}
|
||||
|
||||
check_ubuntu_updates() {
|
||||
@@ -35,7 +80,7 @@ check_fedora_updates() {
|
||||
|
||||
case "$1" in
|
||||
-arch)
|
||||
check_arch_updates "$2"
|
||||
check_arch_updates "$2" "$3"
|
||||
;;
|
||||
-ubuntu)
|
||||
check_ubuntu_updates
|
||||
|
||||
@@ -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<string> = Variable('0');
|
||||
const pendingUpdatesTooltip: Variable<string> = 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>): string => {
|
||||
const defaultTooltip = updateCount.get() + ' updates available';
|
||||
if (!extendedTooltip.get()) return defaultTooltip;
|
||||
return defaultTooltip + '\n\n' + updateTooltip;
|
||||
};
|
||||
|
||||
const updatesPoller = new BashPoller<string, []>(
|
||||
pendingUpdates,
|
||||
[bind(padZero), bind(postInputUpdater)],
|
||||
[bind(padZero), bind(postInputUpdater), bind(updateCommand)],
|
||||
bind(pollingInterval),
|
||||
updateCommand.get(),
|
||||
processUpdateCount,
|
||||
);
|
||||
|
||||
const tooltipPoller = new BashPoller<string, [Variable<string>]>(
|
||||
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),
|
||||
|
||||
@@ -237,6 +237,17 @@ export const CustomModuleSettings = (): JSX.Element => {
|
||||
title="Check Updates Command"
|
||||
type="string"
|
||||
/>
|
||||
<Option
|
||||
opt={options.bar.customModules.updates.updateTooltipCommand}
|
||||
title="Check Updates Tooltip Command"
|
||||
type="string"
|
||||
/>
|
||||
<Option
|
||||
opt={options.bar.customModules.updates.extendedTooltip}
|
||||
title="Show Extended Tooltip"
|
||||
subtitle="Lists packages with updates. Arch only."
|
||||
type="boolean"
|
||||
/>
|
||||
<Option
|
||||
opt={options.bar.customModules.updates.icon.pending}
|
||||
title="Updates Available Icon"
|
||||
|
||||
@@ -1142,6 +1142,8 @@ const options = mkOptions({
|
||||
},
|
||||
updates: {
|
||||
updateCommand: opt(`${SRC_DIR}/scripts/checkUpdates.sh -arch`),
|
||||
updateTooltipCommand: opt(`${SRC_DIR}/scripts/checkUpdates.sh -arch -tooltip`),
|
||||
extendedTooltip: opt(false),
|
||||
label: opt(true),
|
||||
padZero: opt(true),
|
||||
autoHide: opt(false),
|
||||
|
||||
Reference in New Issue
Block a user