diff --git a/src/adjustor/hhd.py b/src/adjustor/hhd.py index f36eb67..09e0e7c 100644 --- a/src/adjustor/hhd.py +++ b/src/adjustor/hhd.py @@ -3,6 +3,7 @@ from threading import Event as TEvent, Thread from typing import Sequence +from hhd.utils import expanduser from hhd.plugins import Context, HHDPlugin, HHDSettings, load_relative_yaml from hhd.plugins.conf import Config from hhd.plugins.plugin import Emitter @@ -14,6 +15,11 @@ logger = logging.getLogger(__name__) +CONFLICTING_PLUGINS = { + "SimpleDeckyTDP": "~/homebrew/plugins/SimpleDeckyTDP", + "PowerControl": "~/homebrew/plugins/PowerControl", +} + class AdjustorInitPlugin(HHDPlugin): def __init__(self) -> None: @@ -27,6 +33,7 @@ def __init__(self) -> None: self.action_enabled = False def open(self, emit: Emitter, context: Context): + self.context = context if exists_sentinel() or not install_sentinel(): self.safe_mode = True @@ -42,6 +49,7 @@ def update(self, conf: Config): conf["tdp.tdp.tdp_enable"] = False conf["hhd.settings.tdp_enable"] = True + old_enabled = conf["hhd.settings.tdp_enable"].to(bool) if self.failed: conf["hhd.settings.tdp_enable"] = False if self.safe_mode: @@ -54,24 +62,36 @@ def update(self, conf: Config): self.enabled = conf["hhd.settings.tdp_enable"].to(bool) - if self.init: - return - - if not conf["hhd.settings.tdp_enable"].to(bool): + if self.init or not old_enabled: return - initialize() - if not check_perms(): + for name, path in CONFLICTING_PLUGINS.items(): + if os.path.exists(expanduser(path, self.context)): + err = ( + f'Found plugin "{name}" at the following path:\n{path}\n' + + "TDP Controls can not be enabled while other TDP plugins are installed." + ) + conf["tdp.tdp.tdp_error"] = err + conf["hhd.settings.tdp_enable"] = False + logger.error(err) + self.failed = True + self.enabled = False + return + + if not check_perms() or not initialize(): conf["hhd.settings.tdp_enable"] = False conf["tdp.tdp.tdp_error"] = ( "Can not write to 'acpi_call'. It is required for TDP." ) self.failed = True self.enabled = False - else: - conf["tdp.tdp.tdp_error"] = "" + return + self.failed = False + self.enabled = True self.init = True + conf["hhd.settings.tdp_enable"] = True + conf["tdp.tdp.tdp_error"] = "" def close(self): remove_sentinel() diff --git a/src/adjustor/settings.yml b/src/adjustor/settings.yml index 369eea6..9c09c1a 100644 --- a/src/adjustor/settings.yml +++ b/src/adjustor/settings.yml @@ -3,7 +3,7 @@ tdp: type: container children: tdp_enable: - title: Enable TDP Controls + title: Enable TDP Controls [BETA] type: action tags: [ non-essential ] hint: >-