From dd931f493d8844b0401d874bfaf7d9b7373c504c Mon Sep 17 00:00:00 2001 From: Jas Singh Date: Thu, 26 Dec 2024 16:33:43 -0800 Subject: [PATCH 1/2] Hyprpanel config no longer resets if there is a parsing error. (#640) --- src/lib/option.ts | 31 ++++++++++++++++++------------- src/lib/session.ts | 4 +++- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/lib/option.ts b/src/lib/option.ts index e8af15655..c0a309738 100644 --- a/src/lib/option.ts +++ b/src/lib/option.ts @@ -4,6 +4,7 @@ import { ensureDirectory } from './session'; import Variable from 'astal/variable'; import { monitorFile, readFile, writeFile } from 'astal/file'; import GLib from 'gi://GLib?version=2.0'; +import { errorHandler } from './utils'; type OptProps = { persistent?: boolean; @@ -88,8 +89,8 @@ export class Opt extends Variable { if (rawData && rawData.trim() !== '') { try { cacheData = JSON.parse(rawData) as Record; - } catch { - // do nuffin + } catch (error) { + errorHandler(error); } } @@ -178,19 +179,23 @@ export function opt(initial: T, props?: OptProps): Opt { * @returns An array of all found `Opt` instances. */ function getOptions(object: Record, path = '', arr: Opt[] = []): Opt[] { - for (const key in object) { - const value = object[key]; - const id = path ? `${path}.${key}` : key; - - if (value instanceof Variable) { - const optValue = value as Opt; - optValue.id = id; - arr.push(optValue); - } else if (typeof value === 'object' && value !== null) { - getOptions(value as Record, id, arr); + try { + for (const key in object) { + const value = object[key]; + const id = path ? `${path}.${key}` : key; + + if (value instanceof Variable) { + const optValue = value as Opt; + optValue.id = id; + arr.push(optValue); + } else if (typeof value === 'object' && value !== null) { + getOptions(value as Record, id, arr); + } } + return arr; + } catch (error) { + errorHandler(error); } - return arr; } /** diff --git a/src/lib/session.ts b/src/lib/session.ts index 713c70b0a..8b89f9f87 100644 --- a/src/lib/session.ts +++ b/src/lib/session.ts @@ -10,7 +10,9 @@ declare global { } export function ensureDirectory(path: string): void { - if (!GLib.file_test(path, GLib.FileTest.EXISTS)) Gio.File.new_for_path(path).make_directory_with_parents(null); + if (!GLib.file_test(path, GLib.FileTest.EXISTS)) { + Gio.File.new_for_path(path).make_directory_with_parents(null); + } } export function ensureFile(path: string): void { From 516309570195b8b324e565d613ca0fb07cc46d04 Mon Sep 17 00:00:00 2001 From: Jas Singh Date: Thu, 26 Dec 2024 16:53:02 -0800 Subject: [PATCH 2/2] Fixed an issue that would prevent the volume menu border color from being set. (#641) --- src/scss/style/menus/audiomenu.scss | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/scss/style/menus/audiomenu.scss b/src/scss/style/menus/audiomenu.scss index 462dda7f0..5eef58fed 100644 --- a/src/scss/style/menus/audiomenu.scss +++ b/src/scss/style/menus/audiomenu.scss @@ -1,3 +1,8 @@ +.menu-items.audio { + border-color: if($bar-menus-monochrome, $bar-menus-border-color, $bar-menus-menu-volume-border-color); + opacity: $bar-menus-opacity * 0.01; +} + .menu-items-container.audio { min-width: 18em * $bar-menus-menu-volume-scaling * 0.01; @@ -9,11 +14,6 @@ background: if($bar-menus-monochrome, $bar-menus-background, $bar-menus-menu-volume-background-color); - .menu-items { - border-color: if($bar-menus-monochrome, $bar-menus-border-color, $bar-menus-menu-volume-border-color); - opacity: $bar-menus-opacity * 0.01; - } - .menu-dropdown-label.audio { color: if($bar-menus-monochrome, $bar-menus-label, $bar-menus-menu-volume-label-color); }