From a6d6a34ea7c9d1f2400fab83c2717f397d6ccbaa Mon Sep 17 00:00:00 2001 From: matavach Date: Sun, 4 Aug 2024 00:01:38 -0500 Subject: [PATCH] validate profile image and create fallback (#67) * validate profile image and create fallback * Update modules/menus/dashboard/profile/index.ts Co-authored-by: Jas Singh * Update modules/menus/dashboard/profile/index.ts Co-authored-by: Jas Singh * Update options.ts Co-authored-by: Jas Singh * Update modules/menus/dashboard/profile/index.ts Co-authored-by: Jas Singh * Update modules/menus/dashboard/profile/index.ts --------- Co-authored-by: Jas Singh --- modules/menus/dashboard/profile/index.ts | 10 +++++++++- options.ts | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/menus/dashboard/profile/index.ts b/modules/menus/dashboard/profile/index.ts index e17e925..3627a72 100644 --- a/modules/menus/dashboard/profile/index.ts +++ b/modules/menus/dashboard/profile/index.ts @@ -1,6 +1,7 @@ import icons from "../../../icons/index.js"; import powermenu from "../../power/helpers/actions.js"; import { PowerOptions } from "lib/types/options.js"; +import GdkPixbuf from "types/@girs/gdkpixbuf-2.0/gdkpixbuf-2.0.js"; import options from "options"; const { image, name } = options.menus.dashboard.powermenu.avatar; @@ -24,7 +25,14 @@ const Profile = () => { Widget.Icon({ hpack: "center", class_name: "profile-picture", - icon: image.bind("value"), + icon: image.bind("value").as(i => { + try { + GdkPixbuf.Pixbuf.new_from_file(i); + return i; + } catch { + return "avatar-default-symbolic"; + } + }), }), Widget.Label({ hpack: "center", diff --git a/options.ts b/options.ts index 14992a6..aeee845 100644 --- a/options.ts +++ b/options.ts @@ -652,7 +652,7 @@ const options = mkOptions(OPTIONS, { logout: opt("pkill Hyprland"), shutdown: opt("shutdown now"), avatar: { - image: opt("/home/jaskir/Pictures/Icons/900-900-max_catppuccin-mocha_hald8_GaussianRBF_lum1_shape96_near16.png"), + image: opt("avatar-default-symbolic"), name: opt<"system" | string>("system"), }, },