From 3cc3fa5d42b69354a26f9b15b63c0e51280a1f19 Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Fri, 8 Nov 2024 15:16:21 +0545 Subject: [PATCH] feat: launcher icon auto detect from os name (#413) * feat: launcher icon auto detect from os name * feat: add more * fix: revamp distro icon * feat: on hover only show actions if available on notifications (#396) * feat: on hover only show actions if available on notifications * feat: on hover only show actions if available on notifications * fix: make the change configurable * fix: remove unneeded op * Added the ability to scale a popover. (#443) * Added the ability to scale a popover. * Removed redundant code * Provide a cli command to clear notifications. (#444) * Added a cpu temperature custom module. (#446) * Added a CPU Temperature module. * Update defauls and add wiki link. * Move celsius to fahr conversion to method. * fix: move distoicons , use capitalizeLetter func * fix: lint * Rename dissto.ts to distro.ts * Update lib/utils.ts --------- Co-authored-by: Jas Singh --- lib/constants/distro.ts | 31 +++++++++++++++++++++++ lib/utils.ts | 7 +++++ modules/bar/menu/index.ts | 19 ++++++++------ modules/bar/window_title/index.ts | 15 ++++++----- modules/menus/network/ethernet/index.ts | 5 ++-- modules/menus/powerDropdown/button.ts | 5 ++-- options.ts | 1 + widget/settings/pages/config/bar/index.ts | 5 ++++ 8 files changed, 68 insertions(+), 20 deletions(-) create mode 100644 lib/constants/distro.ts diff --git a/lib/constants/distro.ts b/lib/constants/distro.ts new file mode 100644 index 0000000..f8f6223 --- /dev/null +++ b/lib/constants/distro.ts @@ -0,0 +1,31 @@ +export const distroIcons = [ + ['deepin', ''], + ['fedora', ''], + ['arch', ''], + ['nixos', ''], + ['debian', ''], + ['opensuse-tumbleweed', ''], + ['ubuntu', ''], + ['endeavouros', ''], + ['manjaro', ''], + ['popos', ''], + ['garuda', ''], + ['zorin', ''], + ['mxlinux', ''], + ['arcolinux', ''], + ['gentoo', ''], + ['artix', ''], + ['centos', ''], + ['hyperbola', ''], + ['kubuntu', ''], + ['mandriva', ''], + ['xerolinux', ''], + ['parabola', ''], + ['void', ''], + ['linuxmint', ''], + ['archlabs', ''], + ['devuan', ''], + ['freebsd', ''], + ['openbsd', ''], + ['slackware', ''], +]; diff --git a/lib/utils.ts b/lib/utils.ts index 8b8fd04..198ab4b 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -11,6 +11,8 @@ import { NotificationArgs } from 'types/utils/notify'; import { SubstituteKeys } from './types/utils'; import { Window } from 'types/@girs/gtk-3.0/gtk-3.0.cjs'; import { namedColors } from './constants/colors'; +import { distroIcons } from './constants/distro'; +import { distro } from './variables'; export type Binding = import('types/service').Binding; @@ -193,3 +195,8 @@ export const isValidGjsColor = (color: string): boolean => { export const capitalizeFirstLetter = (str: string): string => { return str.charAt(0).toUpperCase() + str.slice(1); }; + +export function getDistroIcon(): string { + const icon = distroIcons.find(([id]) => id === distro.id); + return icon ? icon[1] : ''; // default icon if not found +} diff --git a/modules/bar/menu/index.ts b/modules/bar/menu/index.ts index 5c55bfb..00ad72f 100644 --- a/modules/bar/menu/index.ts +++ b/modules/bar/menu/index.ts @@ -1,12 +1,13 @@ -import Gdk from 'gi://Gdk?version=3.0'; -import { openMenu } from '../utils.js'; -import options from 'options'; -import { BarBoxChild } from 'lib/types/bar.js'; -import Button from 'types/widgets/button.js'; -import { Attribute, Child } from 'lib/types/widget.js'; import { runAsyncCommand, throttledScrollHandler } from 'customModules/utils.js'; +import Gdk from 'gi://Gdk?version=3.0'; +import { BarBoxChild } from 'lib/types/bar.js'; +import { Attribute, Child } from 'lib/types/widget.js'; +import options from 'options'; +import Button from 'types/widgets/button.js'; +import { openMenu } from '../utils.js'; +import { getDistroIcon } from 'lib/utils.js'; -const { rightClick, middleClick, scrollUp, scrollDown } = options.bar.launcher; +const { rightClick, middleClick, scrollUp, scrollDown, autoDetectIcon, icon } = options.bar.launcher; const Menu = (): BarBoxChild => { return { @@ -22,7 +23,9 @@ const Menu = (): BarBoxChild => { }), child: Widget.Label({ class_name: 'bar-menu_label bar-button_icon txt-icon bar', - label: options.bar.launcher.icon.bind('value'), + label: Utils.merge([autoDetectIcon.bind('value'), icon.bind('value')], (autoDetect, icon): string => { + return autoDetect ? getDistroIcon() : icon; + }), }), }), isVisible: true, diff --git a/modules/bar/window_title/index.ts b/modules/bar/window_title/index.ts index ddfd44b..19cf239 100644 --- a/modules/bar/window_title/index.ts +++ b/modules/bar/window_title/index.ts @@ -1,12 +1,13 @@ const hyprland = await Service.import('hyprland'); -import { BarBoxChild } from 'lib/types/bar'; -import options from 'options'; -import { Attribute, Child } from 'lib/types/widget'; -import { ActiveClient } from 'types/service/hyprland'; -import Label from 'types/widgets/label'; import { runAsyncCommand, throttledScrollHandler } from 'customModules/utils'; -import Button from 'types/widgets/button'; +import { BarBoxChild } from 'lib/types/bar'; +import { Attribute, Child } from 'lib/types/widget'; +import { capitalizeFirstLetter } from 'lib/utils'; +import options from 'options'; import Gdk from 'types/@girs/gdk-3.0/gdk-3.0'; +import { ActiveClient } from 'types/service/hyprland'; +import Button from 'types/widgets/button'; +import Label from 'types/widgets/label'; const { leftClick, rightClick, middleClick, scrollDown, scrollUp } = options.bar.windowtitle; @@ -117,7 +118,7 @@ const filterTitle = (windowtitle: ActiveClient): Record => { ['^$', '󰇄', 'Desktop'], // Fallback icon - ['(.+)', '󰣆', `${windowtitle.class.charAt(0).toUpperCase() + windowtitle.class.slice(1)}`], + ['(.+)', '󰣆', `${capitalizeFirstLetter(windowtitle.class)}}`], ]; const foundMatch = windowTitleMap.find((wt) => RegExp(wt[0]).test(windowtitle.class.toLowerCase())); diff --git a/modules/menus/network/ethernet/index.ts b/modules/menus/network/ethernet/index.ts index e1bf0d0..5fdbf97 100644 --- a/modules/menus/network/ethernet/index.ts +++ b/modules/menus/network/ethernet/index.ts @@ -1,4 +1,5 @@ import { BoxWidget } from 'lib/types/widget'; +import { capitalizeFirstLetter } from 'lib/utils'; const network = await Service.import('network'); @@ -49,9 +50,7 @@ const Ethernet = (): BoxWidget => { Widget.Label({ hpack: 'start', class_name: 'connection-status dim', - label: - network.wired.internet.charAt(0).toUpperCase() + - network.wired.internet.slice(1), + label: capitalizeFirstLetter(network.wired.internet), }), ], }), diff --git a/modules/menus/powerDropdown/button.ts b/modules/menus/powerDropdown/button.ts index f2ae20f..4b0d017 100644 --- a/modules/menus/powerDropdown/button.ts +++ b/modules/menus/powerDropdown/button.ts @@ -1,7 +1,8 @@ import { PowerOptions } from 'lib/types/options'; +import { GButton } from 'lib/types/widget'; +import { capitalizeFirstLetter } from 'lib/utils'; import options from 'options'; import powermenu from '../power/helpers/actions'; -import { GButton } from 'lib/types/widget'; const { confirmation, shutdown, logout, sleep, reboot, showLabel } = options.menus.power; @@ -48,7 +49,7 @@ export const PowerButton = (action: PowerOptions): GButton => { Widget.Label({ hpack: 'center', hexpand: true, - label: action.charAt(0).toUpperCase() + action.slice(1), + label: capitalizeFirstLetter(action), className: `power-button-label ${action}-label show-label`, }), ]; diff --git a/options.ts b/options.ts index 98fd40c..4db05e9 100644 --- a/options.ts +++ b/options.ts @@ -870,6 +870,7 @@ const options = mkOptions(OPTIONS, { }), launcher: { icon: opt('󰣇'), + autoDetectIcon: opt(false), rightClick: opt(''), middleClick: opt(''), scrollUp: opt(''), diff --git a/widget/settings/pages/config/bar/index.ts b/widget/settings/pages/config/bar/index.ts index 1af4f68..c844398 100644 --- a/widget/settings/pages/config/bar/index.ts +++ b/widget/settings/pages/config/bar/index.ts @@ -164,6 +164,11 @@ export const BarSettings = (): Scrollable => { title: 'Dashboard Menu Icon', type: 'string', }), + Option({ + opt: options.bar.launcher.autoDetectIcon, + title: 'Auto Detect Icon', + type: 'boolean', + }), Option({ opt: options.theme.bar.buttons.dashboard.enableBorder, title: 'Button Border',