feat(config): switch configuration parsing to TOML and add google_lens support
This commit is contained in:
5 files changed
+266
-80
No files matched your search
+47
-67
@@ -1,5 +1,4 @@
|
||||
from fabric.utils import logger
|
||||
import json
|
||||
|
||||
from fabric.utils import Gdk, GLib, get_relative_path, os
|
||||
|
||||
@@ -22,12 +21,12 @@ CURRENT_HEIGHT = screen.get_height()
|
||||
|
||||
|
||||
WALLPAPERS_DIR_DEFAULT = get_relative_path("../assets/wallpapers_example/")
|
||||
CONFIG_FILE = get_relative_path("../../config/config.json")
|
||||
CONFIG_FILE = get_relative_path("../../config/config.toml")
|
||||
MATUGEN_STATE_FILE = os.path.join(CONFIG_DIR, "matugen")
|
||||
|
||||
|
||||
def load_config():
|
||||
"""Load the configuration from config.json"""
|
||||
"""Load the configuration from config.toml"""
|
||||
try:
|
||||
from services.config import start_config_service
|
||||
|
||||
@@ -39,79 +38,60 @@ def load_config():
|
||||
|
||||
if os.path.exists(CONFIG_FILE):
|
||||
try:
|
||||
import tomlkit
|
||||
|
||||
with open(CONFIG_FILE, "r") as f:
|
||||
config = json.load(f)
|
||||
config = dict(tomlkit.load(f))
|
||||
except Exception as e:
|
||||
logger.error(f"Error loading config: {e}")
|
||||
|
||||
return config
|
||||
|
||||
|
||||
if os.path.exists(CONFIG_FILE):
|
||||
with open(CONFIG_FILE, "r") as f:
|
||||
config = json.load(f)
|
||||
wallpapers_dir_from_config = config.get("wallpapers_dir", WALLPAPERS_DIR_DEFAULT)
|
||||
WALLPAPERS_DIR = os.path.expanduser(wallpapers_dir_from_config)
|
||||
DOCK_POSITION = config.get("dock_position", "Bottom")
|
||||
DOCK_ENABLED = config.get("dock_enabled", True)
|
||||
DOCK_AUTO_HIDE = config.get("dock_auto_hide", True)
|
||||
DOCK_ALWAYS_OCCLUDED = config.get("dock_always_occluded", False)
|
||||
DOCK_ICON_SIZE = config.get("dock_icon_size", 60)
|
||||
WINDOW_SWITCHER_ITEMS_PER_ROW = config.get("window_switcher_items_per_row", 10)
|
||||
HIDE_SPECIAL_WORKSPACE = config.get("hide_special_workspace", True)
|
||||
DOCK_HIDE_SPECIAL_WORKSPACE_APPS = config.get(
|
||||
"dock_hide_special_workspace_apps", True
|
||||
)
|
||||
def _load_config_from_toml():
|
||||
"""Load config dict from config.toml (module-level helper)."""
|
||||
if os.path.exists(CONFIG_FILE):
|
||||
try:
|
||||
import tomlkit
|
||||
|
||||
NOTIFICATION_TIMEOUT_STR = config.get("notification_timeout", "5s")
|
||||
NOTIFICATION_TIMEOUT = parse_timeout_string(NOTIFICATION_TIMEOUT_STR)
|
||||
NOTIFICATION_IGNORED_APPS_HISTORY = config.get(
|
||||
"notification_ignored_apps_history", ["Hyprshot"]
|
||||
)
|
||||
NOTIFICATION_LIMITED_APPS_HISTORY = config.get(
|
||||
"notification_limited_apps_history", ["Spotify"]
|
||||
)
|
||||
with open(CONFIG_FILE, "r") as f:
|
||||
return dict(tomlkit.load(f))
|
||||
except Exception as e:
|
||||
logger.error(f"Error loading config: {e}")
|
||||
return {}
|
||||
|
||||
PANEL_COMPONENTS_VISIBILITY = {
|
||||
"imac_button": config.get("imac_button", True),
|
||||
"systray": config.get("systray", True),
|
||||
"control_center": config.get("control_center", True),
|
||||
"search": config.get("search", True),
|
||||
"global_menu": config.get("global_menu", True),
|
||||
"network": config.get("network", True),
|
||||
"battery": config.get("battery", True),
|
||||
"notification_center": config.get("notification_center", True),
|
||||
"workspace_indicator": config.get("workspace_indicator", True),
|
||||
"bluetooth": config.get("bluetooth", True),
|
||||
"date_time": config.get("date_time", True),
|
||||
}
|
||||
|
||||
else:
|
||||
WALLPAPERS_DIR = WALLPAPERS_DIR_DEFAULT
|
||||
DOCK_POSITION = "Bottom"
|
||||
DOCK_ENABLED = True
|
||||
DOCK_ALWAYS_OCCLUDED = False
|
||||
DOCK_AUTO_HIDE = True
|
||||
DOCK_ICON_SIZE = 52
|
||||
WINDOW_SWITCHER_ITEMS_PER_ROW = 10
|
||||
HIDE_SPECIAL_WORKSPACE = True
|
||||
DOCK_HIDE_SPECIAL_WORKSPACE_APPS = True
|
||||
config = _load_config_from_toml()
|
||||
wallpapers_dir_from_config = config.get("wallpapers_dir", WALLPAPERS_DIR_DEFAULT)
|
||||
WALLPAPERS_DIR = os.path.expanduser(wallpapers_dir_from_config)
|
||||
DOCK_POSITION = config.get("dock_position", "Bottom")
|
||||
DOCK_ENABLED = config.get("dock_enabled", True)
|
||||
DOCK_AUTO_HIDE = config.get("dock_auto_hide", True)
|
||||
DOCK_ALWAYS_OCCLUDED = config.get("dock_always_occluded", False)
|
||||
DOCK_ICON_SIZE = config.get("dock_icon_size", 60)
|
||||
WINDOW_SWITCHER_ITEMS_PER_ROW = config.get("window_switcher_items_per_row", 10)
|
||||
HIDE_SPECIAL_WORKSPACE = config.get("hide_special_workspace", True)
|
||||
DOCK_HIDE_SPECIAL_WORKSPACE_APPS = config.get("dock_hide_special_workspace_apps", True)
|
||||
|
||||
NOTIFICATION_TIMEOUT_STR = "5s"
|
||||
NOTIFICATION_TIMEOUT = parse_timeout_string(NOTIFICATION_TIMEOUT_STR)
|
||||
NOTIFICATION_IGNORED_APPS_HISTORY = ["Hyprshot"]
|
||||
NOTIFICATION_LIMITED_APPS_HISTORY = ["Spotify"]
|
||||
NOTIFICATION_TIMEOUT_STR = config.get("notification_timeout", "5s")
|
||||
NOTIFICATION_TIMEOUT = parse_timeout_string(NOTIFICATION_TIMEOUT_STR)
|
||||
NOTIFICATION_IGNORED_APPS_HISTORY = config.get(
|
||||
"notification_ignored_apps_history", ["Hyprshot"]
|
||||
)
|
||||
NOTIFICATION_LIMITED_APPS_HISTORY = config.get(
|
||||
"notification_limited_apps_history", ["Spotify"]
|
||||
)
|
||||
|
||||
PANEL_COMPONENTS_VISIBILITY = {
|
||||
"imac_button": True,
|
||||
"systray": True,
|
||||
"control_center": True,
|
||||
"search": True,
|
||||
"global_menu": True,
|
||||
"network": True,
|
||||
"battery": True,
|
||||
"notification_center": True,
|
||||
"workspace_indicator": True,
|
||||
"bluetooth": True,
|
||||
"date_time": True,
|
||||
}
|
||||
PANEL_COMPONENTS_VISIBILITY = {
|
||||
"imac_button": config.get("imac_button", True),
|
||||
"systray": config.get("systray", True),
|
||||
"control_center": config.get("control_center", True),
|
||||
"search": config.get("search", True),
|
||||
"global_menu": config.get("global_menu", True),
|
||||
"network": config.get("network", True),
|
||||
"battery": config.get("battery", True),
|
||||
"notification_center": config.get("notification_center", True),
|
||||
"workspace_indicator": config.get("workspace_indicator", True),
|
||||
"bluetooth": config.get("bluetooth", True),
|
||||
"date_time": config.get("date_time", True),
|
||||
}
|
||||
Reference in new issue
Block a user