Skip to content

Commit

Permalink
check if other tdp plugins are installed
Browse files Browse the repository at this point in the history
  • Loading branch information
antheas committed Mar 13, 2024
1 parent 108f59c commit dc49dd3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
36 changes: 28 additions & 8 deletions src/adjustor/hhd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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

Expand All @@ -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:
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/adjustor/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: >-
Expand Down

0 comments on commit dc49dd3

Please sign in to comment.