Skip to content

Commit 5ab1fd7

Browse files
committed
add loader to handle userprofiles in vm-compact
ensure we reload user profiles into memory when rebuilding the config menu patch bump
1 parent d896193 commit 5ab1fd7

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "voicemeeter-compact"
3-
version = "1.7.0"
3+
version = "1.7.1"
44
description = "A Compact Voicemeeter Remote App"
55
authors = ["onyx-and-iris <code@onyxandiris.online>"]
66
license = "MIT"

vmcompact/app.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import tkinter as tk
2+
from functools import cached_property
23
from pathlib import Path
34
from tkinter import ttk
45
from typing import NamedTuple
56

67
from .builders import MainFrameBuilder
8+
from .configurations import loader
79
from .data import _base_values, _configuration, _kinds_all
810
from .errors import VMCompactError
911
from .menu import Menus
@@ -41,6 +43,7 @@ def __init__(self, vmr):
4143
self.iconbitmap(str(icon_path))
4244
self.minsize(275, False)
4345
self.subject = Subject()
46+
self._configs = None
4447
self["menu"] = Menus(self, vmr)
4548
self.styletable = ttk.Style()
4649
if _configuration.config:
@@ -130,6 +133,11 @@ def stop_drag(self):
130133
self.drag_id = ""
131134
_base_values.dragging = False
132135

136+
@cached_property
137+
def userconfigs(self):
138+
self._configs = loader(self.kind.name)
139+
return self._configs
140+
133141

134142
_apps = {kind.name: App.make(kind) for kind in _kinds_all}
135143

vmcompact/configurations.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
try:
2727
with open(filepath, "rb") as f:
2828
configs[filename] = tomllib.load(f)
29-
logger.info(f"{filename} loaded into memory")
29+
logger.info(f"configuration: {filename} loaded into memory")
3030
except tomllib.TOMLDecodeError:
3131
logger.error(f"Invalid TOML config: configs/{filename.stem}")
3232

@@ -66,3 +66,19 @@
6666
def get_configuration(key):
6767
if key in configuration:
6868
return configuration[key]
69+
70+
71+
def loader(kind_id):
72+
configs = {}
73+
userconfigpath = Path.home() / ".config" / "vm-compact" / "configs" / kind_id
74+
if userconfigpath.exists():
75+
filepaths = list(userconfigpath.glob("*.toml"))
76+
for filepath in filepaths:
77+
identifier = filepath.with_suffix("").stem
78+
try:
79+
with open(filepath, "rb") as f:
80+
configs[identifier] = tomllib.load(f)
81+
logger.info(f"loader: {identifier} loaded into memory")
82+
except tomllib.TOMLDecodeError:
83+
logger.error(f"Invalid TOML config: configs/{filename.stem}")
84+
return configs

vmcompact/menu.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ def __init__(self, parent, vmr):
9393
for profile in self.target.configs.keys()
9494
if profile not in self.config_defaults
9595
]
96+
elif self.parent.userconfigs:
97+
[
98+
self.menu_configs_load.add_command(
99+
label=name, command=partial(self.load_custom_profile, data)
100+
)
101+
for name, data in self.parent.userconfigs.items()
102+
if name not in self.config_defaults
103+
]
96104
else:
97105
self.menu_configs.entryconfig(0, state="disabled")
98106
self.menu_configs.add_command(
@@ -213,6 +221,10 @@ def action_set_voicemeeter(self, cmd, val=True):
213221
self._unlock.set(not self._lock.get())
214222
setattr(self.target.command, cmd, val)
215223

224+
def load_custom_profile(self, profile):
225+
self.logger.info(f"loading user profile {profile}")
226+
self.target.apply(profile)
227+
216228
def load_profile(self, profile):
217229
self.logger.info(f"loading user profile {profile}")
218230
self.target.apply_config(profile)
@@ -289,6 +301,11 @@ def menu_teardown(self, i):
289301
for key in self.target.configs.keys()
290302
if key not in self.config_defaults
291303
]
304+
[
305+
self.menu_configs_load.delete(key)
306+
for key in self.parent.userconfigs.keys()
307+
if key not in self.config_defaults
308+
]
292309

293310
[
294311
self.menu_vban.entryconfig(j, state="disabled")
@@ -307,6 +324,14 @@ def menu_setup(self):
307324
for profile in self.target.configs.keys()
308325
if profile not in self.config_defaults
309326
]
327+
elif self.parent.userconfigs:
328+
[
329+
self.menu_configs_load.add_command(
330+
label=name, command=partial(self.load_custom_profile, data)
331+
)
332+
for name, data in self.parent.userconfigs.items()
333+
if name not in self.config_defaults
334+
]
310335
else:
311336
self.menu_configs.entryconfig(0, state="disabled")
312337

@@ -346,6 +371,11 @@ def vban_connect(self, i):
346371
self.menu_layout.entryconfig(
347372
0, state=f"{'normal' if kind.name == 'potato' else 'disabled'}"
348373
)
374+
# ensure the configs are reloaded into memory
375+
if "config" in self.parent.target.__dict__:
376+
del self.parent.target.__dict__["config"]
377+
if "userconfigs" in self.parent.__dict__:
378+
del self.parent.__dict__["userconfigs"]
349379
self.menu_setup()
350380

351381
def vban_disconnect(self, i):
@@ -366,6 +396,11 @@ def vban_disconnect(self, i):
366396
self.menu_layout.entryconfig(
367397
0, state=f"{'normal' if kind.name == 'potato' else 'disabled'}"
368398
)
399+
# ensure the configs are reloaded into memory
400+
if "config" in self.parent.target.__dict__:
401+
del self.parent.target.__dict__["config"]
402+
if "userconfigs" in self.parent.__dict__:
403+
del self.parent.__dict__["userconfigs"]
369404
self.menu_setup()
370405

371406
self.after(15000, self.enable_vban_menus)

0 commit comments

Comments
 (0)