Skip to content

Commit

Permalink
#4064 move gstreamer configuration to new gui
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Jan 30, 2024
1 parent 34bedd5 commit d94a170
Show file tree
Hide file tree
Showing 4 changed files with 341 additions and 190 deletions.
32 changes: 30 additions & 2 deletions xpra/gtk/configure/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_user_config_file() -> str:
return osexpand(os.path.join(get_user_conf_dirs()[0], "conf.d", "99_configure_tool.conf"))


def parse_user_config_file() -> dict[str, str | list[str]]:
def parse_user_config_file() -> dict[str, str | list[str] | dict[str, str]]:
filename = get_user_config_file()
if not os.path.exists(filename):
return {}
Expand All @@ -59,7 +59,14 @@ def save_user_config_file(options: dict) -> None:
with open(filename, "w", encoding="utf8") as f:
f.write("# generated on " + datetime.now().strftime("%c")+"\n\n")
for k, v in options.items():
f.write(f"{k} = {v}\n")
if isinstance(v, dict):
for dk, dv in v.items():
f.write(f"{k} = {dk}={dv}\n")
continue
if not isinstance(v, (list, tuple)):
v = [v]
for item in v:
f.write(f"{k} = {item}\n")


def update_config_attribute(attribute: str, value) -> None:
Expand All @@ -69,6 +76,27 @@ def update_config_attribute(attribute: str, value) -> None:
save_user_config_file(config)


def update_config_env(attribute: str, value) -> None:
# there can be many env attributes
log(f"update config env: {attribute}={value}")
config = parse_user_config_file()
env = config.get("env")
if not isinstance(env, dict):
log.warn(f"Warning: env option was using invalid type {type(env)}")
config["env"] = env = {}
env[attribute] = str(value)
save_user_config_file(config)


def get_config_env(var_name: str) -> str:
config = parse_user_config_file()
env = config.get("env", {})
if not isinstance(env, dict):
log.warn(f"Warning: env option was using invalid type {type(env)}")
return ""
return env.get(var_name, "")


def with_config(cb: Callable) -> None:
# load config in a thread as this involves IO,
# then run the callback in the UI thread
Expand Down
Loading

0 comments on commit d94a170

Please sign in to comment.