From b87c2d57333a2db234b45556b94814d2533d0dd8 Mon Sep 17 00:00:00 2001 From: 1812z <61372168+1812z@users.noreply.github.com> Date: Fri, 20 Sep 2024 14:32:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=98=BE=E7=A4=BA=E5=99=A8?= =?UTF-8?q?=E8=B0=83=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- command.py | 14 +++++++++++--- gui.py | 9 +++++++-- readme.md | 4 ++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/command.py b/command.py index fe23e71..3db32e6 100644 --- a/command.py +++ b/command.py @@ -77,15 +77,20 @@ def on_connect(client, userdata, flags, reason_code, properties): print("成功连接到:", broker) subcribe(client) + +# 运行命令 def run_command(command, data): + path = json_data.get("user_directory") + "\\AppData\\Local\\Programs\\twinkle-tray\\Twinkle Tray.exe" + print(path) key = command.split('/')[2] - if key == device_name + "screen": # 显示器亮度调节 + if key == device_name + "screen": # 显示器控制 if data == "OFF": - run = r' "C:\Program Files\WindowsApps\38002AlexanderFrangos.TwinkleTray_1.15.4.0_x64__m7qx9dzpwqaze\app\Twinkle Tray.exe" --MonitorNum=1 --VCP=0xD6:0x04 ' + run = 'start /b cmd /c "'+ path + '" --MonitorNum=1 --VCP=0xD6:0x04' os.system(run) else: brightness = str(int(data) * 100 // 255) - run = 'start /b cmd /c '+r' "C:\Program Files\WindowsApps\38002AlexanderFrangos.TwinkleTray_1.15.4.0_x64__m7qx9dzpwqaze\app\Twinkle Tray.exe" --MonitorNum=1 --Set=' + brightness + run = 'start /b cmd /c "'+ path + '" --MonitorNum=1 --Set=' + brightness + print(run) os.system(run) print("显示器亮度:", brightness) elif key == device_name + "volume": @@ -96,6 +101,7 @@ def run_command(command, data): run = current_directory + '\\' + run_file os.system(f'start "" "{run}"') + # 初始化 def init_data(): global current_directory @@ -115,12 +121,14 @@ def init_data(): global device_name global device_name global broker + global user_directory json_data = json.load(file) username = json_data.get("username") password = json_data.get("password") broker = json_data.get("HA_MQTT") port = json_data.get("HA_MQTT_port") device_name = json_data.get("device_name") + user_directory = json_data.get("user_directory") global mqttc mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2) diff --git a/gui.py b/gui.py index 8eee28e..b35a80a 100644 --- a/gui.py +++ b/gui.py @@ -1,3 +1,4 @@ +import os import threading import time from PIL import Image @@ -358,10 +359,14 @@ def icon_task(): icon.run() +def user_directory(): + save_json_data("user_directory",os.path.expanduser("~")) + + show_menu_flag = False icon_flag = True if __name__ == "__main__": - + threading.Thread(target=icon_task).start() with open('config.json', 'r') as file: json_data = json.load(file) @@ -375,7 +380,7 @@ def icon_task(): read_ha_broker = json_data.get("HA_MQTT") read_port = json_data.get("HA_MQTT_port") read_device_name = json_data.get("device_name") - + user_directory() if fun4: run_flag = True start() diff --git a/readme.md b/readme.md index 9c30749..1ae9cef 100644 --- a/readme.md +++ b/readme.md @@ -16,8 +16,8 @@ Homeassistant远程运行可执行文件 - 必选: pyhon 相关库, Homeassistant MQTT加载项 通过如下命令安装环境 `pip install -r .\requirements.txt` -- 监控反馈: Aida64(读取数据并共享给程序) -- 远程命令: Twinkle tray(控制显示器亮度) +- 电脑信息监控: 依赖Aida64(读取数据并共享给程序) +- 显示器亮度调节: 依赖[Twinkle tray](https://github.com/xanderfrangos/twinkle-tray/releases) ## 二.启动程序