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
|
#!/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() {
|
check_arch_updates() {
|
||||||
official_updates=0
|
|
||||||
aur_updates=0
|
|
||||||
if command -v paru &> /dev/null; then
|
if command -v paru &> /dev/null; then
|
||||||
aur_helper="paru"
|
aur_helper="paru"
|
||||||
else
|
else
|
||||||
aur_helper="yay"
|
aur_helper="yay"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" = "-y" ]; then
|
if has_param "-tooltip" "$@"; then
|
||||||
aur_updates=$($aur_helper -Qum 2>/dev/null | wc -l)
|
command=" | head -n 50"
|
||||||
elif [ "$1" = "-p" ]; then
|
official_updates=""
|
||||||
official_updates=$(checkupdates 2>/dev/null | wc -l)
|
aur_updates=""
|
||||||
|
wait_for_process_to_finish "checkupdates"
|
||||||
else
|
else
|
||||||
official_updates=$(checkupdates 2>/dev/null | wc -l)
|
command="2>/dev/null | wc -l"
|
||||||
aur_updates=$($aur_helper -Qum 2>/dev/null | wc -l)
|
official_updates=0
|
||||||
|
aur_updates=0
|
||||||
fi
|
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
|
echo $total_updates
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check_ubuntu_updates() {
|
check_ubuntu_updates() {
|
||||||
@@ -34,16 +79,16 @@ check_fedora_updates() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-arch)
|
-arch)
|
||||||
check_arch_updates "$2"
|
check_arch_updates "$2" "$3"
|
||||||
;;
|
;;
|
||||||
-ubuntu)
|
-ubuntu)
|
||||||
check_ubuntu_updates
|
check_ubuntu_updates
|
||||||
;;
|
;;
|
||||||
-fedora)
|
-fedora)
|
||||||
check_fedora_updates
|
check_fedora_updates
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "0"
|
echo "0"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import { Astal } from 'astal/gtk3';
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
updateCommand,
|
updateCommand,
|
||||||
|
updateTooltipCommand,
|
||||||
|
extendedTooltip,
|
||||||
label,
|
label,
|
||||||
padZero,
|
padZero,
|
||||||
autoHide,
|
autoHide,
|
||||||
@@ -21,6 +23,7 @@ const {
|
|||||||
} = options.bar.customModules.updates;
|
} = options.bar.customModules.updates;
|
||||||
|
|
||||||
const pendingUpdates: Variable<string> = Variable('0');
|
const pendingUpdates: Variable<string> = Variable('0');
|
||||||
|
const pendingUpdatesTooltip: Variable<string> = Variable('');
|
||||||
const postInputUpdater = Variable(true);
|
const postInputUpdater = Variable(true);
|
||||||
const isVis = Variable(!autoHide.get());
|
const isVis = Variable(!autoHide.get());
|
||||||
|
|
||||||
@@ -29,15 +32,31 @@ const processUpdateCount = (updateCount: string): string => {
|
|||||||
return `${updateCount.padStart(2, '0')}`;
|
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, []>(
|
const updatesPoller = new BashPoller<string, []>(
|
||||||
pendingUpdates,
|
pendingUpdates,
|
||||||
[bind(padZero), bind(postInputUpdater)],
|
[bind(padZero), bind(postInputUpdater), bind(updateCommand)],
|
||||||
bind(pollingInterval),
|
bind(pollingInterval),
|
||||||
updateCommand.get(),
|
updateCommand.get(),
|
||||||
processUpdateCount,
|
processUpdateCount,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const tooltipPoller = new BashPoller<string, [Variable<string>]>(
|
||||||
|
pendingUpdatesTooltip,
|
||||||
|
[bind(extendedTooltip), bind(postInputUpdater), bind(updateTooltipCommand)],
|
||||||
|
bind(pollingInterval),
|
||||||
|
updateTooltipCommand.get(),
|
||||||
|
processUpdateTooltip,
|
||||||
|
pendingUpdates,
|
||||||
|
);
|
||||||
|
|
||||||
updatesPoller.initialize('updates');
|
updatesPoller.initialize('updates');
|
||||||
|
tooltipPoller.initialize('updates');
|
||||||
|
|
||||||
Variable.derive([bind(autoHide)], (autoHideModule) => {
|
Variable.derive([bind(autoHide)], (autoHideModule) => {
|
||||||
isVis.set(!autoHideModule || (autoHideModule && parseFloat(pendingUpdates.get()) > 0));
|
isVis.set(!autoHideModule || (autoHideModule && parseFloat(pendingUpdates.get()) > 0));
|
||||||
@@ -54,7 +73,7 @@ const updatesIcon = Variable.derive(
|
|||||||
export const Updates = (): BarBoxChild => {
|
export const Updates = (): BarBoxChild => {
|
||||||
const updatesModule = Module({
|
const updatesModule = Module({
|
||||||
textIcon: updatesIcon(),
|
textIcon: updatesIcon(),
|
||||||
tooltipText: bind(pendingUpdates).as((v) => `${v} updates available`),
|
tooltipText: bind(pendingUpdatesTooltip),
|
||||||
boxClass: 'updates',
|
boxClass: 'updates',
|
||||||
isVis: isVis,
|
isVis: isVis,
|
||||||
label: bind(pendingUpdates),
|
label: bind(pendingUpdates),
|
||||||
|
|||||||
@@ -237,6 +237,17 @@ export const CustomModuleSettings = (): JSX.Element => {
|
|||||||
title="Check Updates Command"
|
title="Check Updates Command"
|
||||||
type="string"
|
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
|
<Option
|
||||||
opt={options.bar.customModules.updates.icon.pending}
|
opt={options.bar.customModules.updates.icon.pending}
|
||||||
title="Updates Available Icon"
|
title="Updates Available Icon"
|
||||||
|
|||||||
@@ -1142,6 +1142,8 @@ const options = mkOptions({
|
|||||||
},
|
},
|
||||||
updates: {
|
updates: {
|
||||||
updateCommand: opt(`${SRC_DIR}/scripts/checkUpdates.sh -arch`),
|
updateCommand: opt(`${SRC_DIR}/scripts/checkUpdates.sh -arch`),
|
||||||
|
updateTooltipCommand: opt(`${SRC_DIR}/scripts/checkUpdates.sh -arch -tooltip`),
|
||||||
|
extendedTooltip: opt(false),
|
||||||
label: opt(true),
|
label: opt(true),
|
||||||
padZero: opt(true),
|
padZero: opt(true),
|
||||||
autoHide: opt(false),
|
autoHide: opt(false),
|
||||||
|
|||||||
Reference in New Issue
Block a user