From 30e0f24a86b74d24c86c104143d5825e3f00198a Mon Sep 17 00:00:00 2001 From: retrozinndev Date: Fri, 26 Sep 2025 14:12:29 -0300 Subject: [PATCH] :boom: fix: config being declared after its usage `generalConfig` and `userData` are now stored under src/config.ts --- src/app.ts | 75 ++----------------- src/config.ts | 70 +++++++++++++++++ src/modules/arg-handler.ts | 3 +- src/modules/bluetooth.ts | 4 +- src/modules/notifications.ts | 2 +- src/window/bar/widgets/Clock.tsx | 2 +- src/window/bar/widgets/Workspaces.tsx | 2 +- .../widgets/pages/Backlight.tsx | 2 +- src/window/floating-notifications/index.tsx | 2 +- src/window/logout-menu/index.tsx | 2 +- 10 files changed, 85 insertions(+), 79 deletions(-) create mode 100644 src/config.ts diff --git a/src/app.ts b/src/app.ts index a2ed9e5..88e5486 100644 --- a/src/app.ts +++ b/src/app.ts @@ -3,6 +3,7 @@ // fix can't convert non-null pointer to JS value (thanks Aylur!) import "ags/overrides"; +import "./config"; import { PluginApps, PluginClipboard, @@ -20,9 +21,8 @@ import { Notifications } from "./modules/notifications"; import { Wallpaper } from "./modules/wallpaper"; import { Stylesheet } from "./modules/stylesheet"; import { Clipboard } from "./modules/clipboard"; -import { Config } from "./modules/config"; import { Gdk, Gtk } from "ags/gtk4"; -import { createRoot, getScope } from "ags"; +import { createRoot, getScope, Scope } from "ags"; import { OSDModes, triggerOSD } from "./window/osd"; import { programArgs, programInvocationName } from "system"; import { setConsoleLogDomain } from "console"; @@ -51,11 +51,12 @@ const defaultWindows: Array = [ "bar" ]; GLib.unsetenv("LD_PRELOAD"); + @register({ GTypeName: "Shell" }) -export class Shell extends Adw.Application implements Gio.ActionMap { +export class Shell extends Adw.Application { private static instance: Shell; - #scope!: ReturnType; + #scope!: Scope; #connections = new Map | number>(); #providers: Array = []; #gresource: Gio.Resource|null = null; @@ -333,73 +334,7 @@ you should use the socket in the XDG_RUNTIME_DIR/colorshell.sock for a faster re quit(): void { this.release(); - super.quit(); } } - -const generalConfigDefaults = { - notifications: { - timeout_low: 4000, - timeout_normal: 6000, - timeout_critical: 0, - /** notification popup horizontal position. can be "left" or "right" - * @default "right" */ - position_h: "right", - /** vertical notification popup position. can be "top" or "bottom" - * @default "top" */ - position_v: "top" - }, - - night_light: { - /** whether to save night light values to disk */ - save_on_shutdown: true - }, - - workspaces: { - /** breaks `enable_helper`, makes all workspaces show their respective ID - * by default */ - always_show_id: false, - /** this is the function that shows the Workspace's IDs - * around the current workspace if one breaks the crescent order. - * It basically helps keyboard navigation between workspaces. - * --- - * Example: 1(empty, current, shows ID), 2(empty, does not appear(makes - * the previous not to be in a crescent order)), 3(not empty, shows ID) */ - enable_helper: true, - /** hide workspace indicator if there's only one active workspace */ - hide_if_single: false - }, - - clock: { - /** use the same format as gnu's `date` command */ - date_format: "%A %d, %H:%M" - }, - - misc: { - play_bell_on_volume_change: true - } -}; - -const userDataDefaults = { - control_center: { - default_backlight: undefined - }, - - bluetooth_default_adapter: undefined -}; - -export const userData = new Config< - keyof typeof userDataDefaults, - (typeof userDataDefaults)[keyof typeof userDataDefaults] ->( - `${GLib.get_user_data_dir()}/colorshell/data.json`, - userDataDefaults -); - -export const generalConfig = new Config( - `${GLib.get_user_config_dir()}/colorshell/config.json`, generalConfigDefaults -); - Shell.getDefault().runAsync([ programInvocationName, ...programArgs ]); diff --git a/src/config.ts b/src/config.ts new file mode 100644 index 0000000..7a32f76 --- /dev/null +++ b/src/config.ts @@ -0,0 +1,70 @@ +import { Config } from "./modules/config"; + +import GLib from "gi://GLib?version=2.0"; + + +const generalConfigDefaults = { + notifications: { + timeout_low: 4000, + timeout_normal: 6000, + timeout_critical: 0, + /** notification popup horizontal position. can be "left" or "right" + * @default "right" */ + position_h: "right", + /** vertical notification popup position. can be "top" or "bottom" + * @default "top" */ + position_v: "top" + }, + + night_light: { + /** whether to save night light values to disk */ + save_on_shutdown: true + }, + + workspaces: { + /** breaks `enable_helper`, makes all workspaces show their respective ID + * by default */ + always_show_id: false, + /** this is the function that shows the Workspace's IDs + * around the current workspace if one breaks the crescent order. + * It basically helps keyboard navigation between workspaces. + * --- + * Example: 1(empty, current, shows ID), 2(empty, does not appear(makes + * the previous not to be in a crescent order)), 3(not empty, shows ID) */ + enable_helper: true, + /** hide workspace indicator if there's only one active workspace */ + hide_if_single: false + }, + + clock: { + /** use the same format as gnu's `date` command */ + date_format: "%A %d, %H:%M" + }, + + misc: { + play_bell_on_volume_change: true + } +}; + +const userDataDefaults = { + control_center: { + /** last default backlight */ + default_backlight: undefined + }, + + /** last default adapter */ + bluetooth_default_adapter: undefined +}; + +export const userData = new Config< + keyof typeof userDataDefaults, + (typeof userDataDefaults)[keyof typeof userDataDefaults] +>( + `${GLib.get_user_data_dir()}/colorshell/data.json`, + userDataDefaults +); + +export const generalConfig = new Config( + `${GLib.get_user_config_dir()}/colorshell/config.json`, generalConfigDefaults +); diff --git a/src/modules/arg-handler.ts b/src/modules/arg-handler.ts index 7b7252a..2453c70 100644 --- a/src/modules/arg-handler.ts +++ b/src/modules/arg-handler.ts @@ -7,7 +7,8 @@ import { Runner } from "../runner/Runner"; import { showWorkspaceNumber } from "../window/bar/widgets/Workspaces"; import { playSystemBell } from "./utils"; import { player, setPlayer } from "./media"; -import { generalConfig, Shell } from "../app"; +import { Shell } from "../app"; +import { generalConfig } from "../config"; import AstalIO from "gi://AstalIO"; import AstalMpris from "gi://AstalMpris"; diff --git a/src/modules/bluetooth.ts b/src/modules/bluetooth.ts index 98c992b..98e5677 100644 --- a/src/modules/bluetooth.ts +++ b/src/modules/bluetooth.ts @@ -1,9 +1,9 @@ import { createRoot, getScope, Scope } from "ags"; -import GObject, { getter, gtype, property, register, setter } from "ags/gobject"; import { execAsync } from "ags/process"; +import { userData } from "../config"; +import GObject, { getter, gtype, property, register, setter } from "ags/gobject"; import AstalBluetooth from "gi://AstalBluetooth"; -import { userData } from "../app"; /** AstalBluetooth helper (implements the default adapter feature) */ diff --git a/src/modules/notifications.ts b/src/modules/notifications.ts index 4f71c20..e414e3e 100644 --- a/src/modules/notifications.ts +++ b/src/modules/notifications.ts @@ -1,5 +1,5 @@ import { execAsync } from "ags/process"; -import { generalConfig } from "../app"; +import { generalConfig } from "../config"; import { onCleanup } from "ags"; import GObject, { getter, ParamSpec, property, register, signal } from "ags/gobject"; diff --git a/src/window/bar/widgets/Clock.tsx b/src/window/bar/widgets/Clock.tsx index a90e273..34a128b 100644 --- a/src/window/bar/widgets/Clock.tsx +++ b/src/window/bar/widgets/Clock.tsx @@ -2,7 +2,7 @@ import { Gtk } from "ags/gtk4"; import { Windows } from "../../../windows"; import { createBinding } from "ags"; import { time } from "../../../modules/utils"; -import { generalConfig } from "../../../app"; +import { generalConfig } from "../../../config"; export const Clock = () => diff --git a/src/window/bar/widgets/Workspaces.tsx b/src/window/bar/widgets/Workspaces.tsx index e69aa74..4b2b859 100644 --- a/src/window/bar/widgets/Workspaces.tsx +++ b/src/window/bar/widgets/Workspaces.tsx @@ -1,7 +1,7 @@ import { Gtk } from "ags/gtk4"; import { getAppIcon, getSymbolicIcon } from "../../../modules/apps"; import { Separator } from "../../../widget/Separator"; -import { generalConfig } from "../../../app"; +import { generalConfig } from "../../../config"; import { createBinding, createComputed, createState, For, With } from "ags"; import { variableToBoolean } from "../../../modules/utils"; diff --git a/src/window/control-center/widgets/pages/Backlight.tsx b/src/window/control-center/widgets/pages/Backlight.tsx index 3135ed0..02f6175 100644 --- a/src/window/control-center/widgets/pages/Backlight.tsx +++ b/src/window/control-center/widgets/pages/Backlight.tsx @@ -4,7 +4,7 @@ import { Backlights } from "../../../../modules/backlight"; import { Page, PageButton } from "../Page"; import { createBinding, For, With } from "ags"; import { addSliderMarksFromMinMax } from "../../../../modules/utils"; -import { userData } from "../../../../app"; +import { userData } from "../../../../config"; export const PageBacklight = new Page({ diff --git a/src/window/floating-notifications/index.tsx b/src/window/floating-notifications/index.tsx index 5729ca1..8c7a995 100644 --- a/src/window/floating-notifications/index.tsx +++ b/src/window/floating-notifications/index.tsx @@ -2,7 +2,7 @@ import { Astal, Gtk } from "ags/gtk4"; import { createBinding, createComputed, For } from "ags"; import { Notifications } from "../../modules/notifications"; import { NotificationWidget } from "../../widget/Notification"; -import { generalConfig } from "../../app"; +import { generalConfig } from "../../config"; import AstalNotifd from "gi://AstalNotifd"; import Adw from "gi://Adw?version=1"; diff --git a/src/window/logout-menu/index.tsx b/src/window/logout-menu/index.tsx index bee0a92..6147078 100644 --- a/src/window/logout-menu/index.tsx +++ b/src/window/logout-menu/index.tsx @@ -1,6 +1,6 @@ import { Astal, Gdk, Gtk } from "ags/gtk4"; import { execAsync } from "ags/process"; -import { generalConfig } from "../../app"; +import { generalConfig } from "../../config"; import { AskPopup } from "../../widget/AskPopup"; import { Notifications } from "../../modules/notifications"; import { NightLight } from "../../modules/nightlight";