forked from Shinonome/caelestia-cli
refactor: add get_config func
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import json
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
@@ -9,7 +8,7 @@ from pathlib import Path
|
||||
|
||||
from caelestia.utils import hypr
|
||||
from caelestia.utils.notify import close_notification, notify
|
||||
from caelestia.utils.paths import recording_notif_path, recording_path, recordings_dir, user_config_path
|
||||
from caelestia.utils.paths import get_config, recording_notif_path, recording_path, recordings_dir
|
||||
|
||||
RECORDER = "gpu-screen-recorder"
|
||||
|
||||
@@ -65,12 +64,10 @@ class Command:
|
||||
if self.args.sound:
|
||||
args += ["-a", "default_output"]
|
||||
|
||||
config = get_config()
|
||||
try:
|
||||
config = json.loads(user_config_path.read_text())
|
||||
if "record" in config and "extraArgs" in config["record"]:
|
||||
args += config["record"]["extraArgs"]
|
||||
except (json.JSONDecodeError, FileNotFoundError):
|
||||
pass
|
||||
except TypeError as e:
|
||||
raise ValueError(f"Config option 'record.extraArgs' should be an array: {e}")
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from typing import Any, Dict, Optional
|
||||
|
||||
from caelestia.utils import hypr
|
||||
from caelestia.utils.io import log_message
|
||||
from caelestia.utils.paths import user_config_path
|
||||
from caelestia.utils.paths import get_config
|
||||
|
||||
|
||||
class WindowRule:
|
||||
@@ -52,8 +52,8 @@ class Command:
|
||||
WindowRule("^[Pp]icture(-| )in(-| )[Pp]icture$", "titleRegex", "", "", ["pip"]),
|
||||
]
|
||||
|
||||
config = get_config()
|
||||
try:
|
||||
config = json.loads(user_config_path.read_text())
|
||||
if "resizer" in config and "rules" in config["resizer"]:
|
||||
rules = []
|
||||
for rule_config in config["resizer"]["rules"]:
|
||||
@@ -67,7 +67,7 @@ class Command:
|
||||
)
|
||||
)
|
||||
return rules
|
||||
except (json.JSONDecodeError, KeyError):
|
||||
except KeyError:
|
||||
log_message("ERROR: invalid config")
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
@@ -6,7 +6,7 @@ from collections import ChainMap
|
||||
from typing import Any, Callable, cast
|
||||
|
||||
from caelestia.utils import hypr
|
||||
from caelestia.utils.paths import user_config_path
|
||||
from caelestia.utils.paths import get_config
|
||||
|
||||
|
||||
def is_subset(superset, subset):
|
||||
@@ -103,8 +103,8 @@ class Command:
|
||||
},
|
||||
}
|
||||
try:
|
||||
self.cfg = DeepChainMap(json.loads(user_config_path.read_text())["toggles"], self.cfg)
|
||||
except (FileNotFoundError, json.JSONDecodeError, KeyError):
|
||||
self.cfg = DeepChainMap(get_config()["toggles"], self.cfg)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
def run(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user