Skip to content

Commit

Permalink
feat: no update w/ autohide option & add option to swap netstat icon … (
Browse files Browse the repository at this point in the history
#591)

* feat: no update w/ autohide option & add option to swap netstat icon for up/down links

* Update src/scss/style/bar/bar.scss

* Update src/components/bar/shared/Module.tsx

* Update src/components/bar/settings/config.tsx

* Update src/options.ts

* Apply suggestions from code review

* move visibilty to updatesIcon func

---------

Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com>
  • Loading branch information
ilikestreet and Jas-SinghFSU authored Dec 24, 2024
1 parent a3f348c commit e0917ff
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/components/bar/modules/netstat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const {
rateUnit,
dynamicIcon,
icon,
networkInLabel,
networkOutLabel,
round,
leftClick,
rightClick,
Expand Down Expand Up @@ -47,11 +49,11 @@ export const Netstat = (): BarBoxChild => {
const renderNetworkLabel = (lblType: NetstatLabelType, networkService: NetworkResourceData): string => {
switch (lblType) {
case 'in':
return ` ${networkService.in}`;
return `${networkInLabel.get()} ${networkService.in}`;
case 'out':
return ` ${networkService.out}`;
return `${networkOutLabel.get()} ${networkService.out}`;
default:
return ` ${networkService.in} ${networkService.out}`;
return `${networkInLabel.get()} ${networkService.in} ${networkOutLabel.get()} ${networkService.out}`;
}
};

Expand Down
4 changes: 4 additions & 0 deletions src/components/bar/modules/updates/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
updateCommand,
label,
padZero,
autoHide,
pollingInterval,
icon,
leftClick,
Expand All @@ -21,6 +22,7 @@ const {

const pendingUpdates: Variable<string> = Variable('0');
const postInputUpdater = Variable(true);
const isVis = Variable(!autoHide.get());

const processUpdateCount = (updateCount: string): string => {
if (!padZero.get()) return updateCount;
Expand All @@ -40,6 +42,7 @@ updatesPoller.initialize('updates');
const updatesIcon = Variable.derive(
[bind(icon.pending), bind(icon.updated), bind(pendingUpdates)],
(pendingIcon, updatedIcon, pUpdates) => {
isVis.set(!autoHide.get() || (autoHide.get() && parseFloat(pUpdates) > 0));
return parseFloat(pUpdates) === 0 ? updatedIcon : pendingIcon;
},
);
Expand All @@ -49,6 +52,7 @@ export const Updates = (): BarBoxChild => {
textIcon: updatesIcon(),
tooltipText: bind(pendingUpdates).as((v) => `${v} updates available`),
boxClass: 'updates',
isVis: isVis,
label: bind(pendingUpdates),
showLabelBinding: bind(label),
props: {
Expand Down
12 changes: 12 additions & 0 deletions src/components/bar/settings/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ export const CustomModuleSettings = (): JSX.Element => {
/>
<Option opt={options.bar.customModules.netstat.icon} title="Netstat Icon" type="string" />
<Option opt={options.bar.customModules.netstat.label} title="Show Label" type="boolean" />
<Option opt={options.bar.customModules.netstat.networkInLabel} title="Network In Label" type="string" />
<Option
opt={options.bar.customModules.netstat.networkOutLabel}
title="Network Out Label"
type="string"
/>
<Option
opt={options.bar.customModules.netstat.rateUnit}
title="Rate Unit"
Expand Down Expand Up @@ -221,6 +227,12 @@ export const CustomModuleSettings = (): JSX.Element => {
/>
<Option opt={options.bar.customModules.updates.icon.updated} title="No Updates Icon" type="string" />
<Option opt={options.bar.customModules.updates.label} title="Show Label" type="boolean" />
<Option
opt={options.bar.customModules.updates.autoHide}
title="Auto Hide"
subtitle="Hides module when no updates are available."
type="boolean"
/>
<Option opt={options.bar.customModules.updates.padZero} title="Pad with 0" type="boolean" />
<Option opt={options.theme.bar.buttons.modules.updates.spacing} title="Spacing" type="string" />
<Option
Expand Down
3 changes: 2 additions & 1 deletion src/components/bar/shared/Module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const Module = ({
label,
tooltipText,
boxClass,
isVis,
props = {},
showLabelBinding = bind(undefinedVar),
showLabel,
Expand Down Expand Up @@ -86,7 +87,7 @@ export const Module = ({
return {
component,
tooltip_text: tooltipText,
isVisible: true,
isVis: isVis,
boxClass,
props,
};
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/bar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type BarModule = {
boundLabel?: string;
tooltipText?: string | Binding<string>;
boxClass: string;
isVis?: Variable<boolean>;
props?: Widget.ButtonProps;
showLabel?: boolean;
showLabelBinding?: Binding;
Expand Down
3 changes: 3 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,8 @@ const options = mkOptions(CONFIG, {
networkInterface: opt(''),
dynamicIcon: opt(false),
icon: opt('󰖟'),
networkInLabel: opt('↓'),
networkOutLabel: opt('↑'),
round: opt(true),
labelType: opt<NetstatLabelType>('full'),
rateUnit: opt<RateUnit>('auto'),
Expand All @@ -1094,6 +1096,7 @@ const options = mkOptions(CONFIG, {
updateCommand: opt(`${SRC_DIR}/scripts/checkUpdates.sh -arch`),
label: opt(true),
padZero: opt(true),
autoHide: opt(false),
icon: {
pending: opt('󰏗'),
updated: opt('󰏖'),
Expand Down

0 comments on commit e0917ff

Please sign in to comment.