diff --git a/#README/README-cn.md b/#README/README-cn.md index 73e08de..9516fd0 100644 --- a/#README/README-cn.md +++ b/#README/README-cn.md @@ -1,6 +1,6 @@
diff --git a/#README/roadmap.md b/#README/roadmap.md index a338440..031f0a4 100644 --- a/#README/roadmap.md +++ b/#README/roadmap.md @@ -17,7 +17,7 @@ - 黑名单模式 - 控制权释放机制 - 提供HTTPS -- 自扫描可用端口,检验可用性 +- ~~自扫描可用端口,检验可用性~~ ## v0.6.x diff --git a/README.md b/README.md index 4a92ea9..8c4609a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ diff --git a/app.py b/app.py index 10b213e..e9939df 100644 --- a/app.py +++ b/app.py @@ -10,7 +10,7 @@ |_\____/\___/|_| |_|\__|_| \___/|_|_|\___|_| https://github.com/Mehver/iController -v0.4.2 +v0.4.3 """) diff --git a/modules/portchecker.py b/modules/portchecker.py index 0fb5134..861d060 100644 --- a/modules/portchecker.py +++ b/modules/portchecker.py @@ -1,20 +1,34 @@ -import psutil - +import socket +import platform def portchecker(port): """ - 使用psutil检查端口是否可用 + 检查端口是否可用。 - 如果端口是一个数字且在合法范围内(1-65534) - - 并且没有被别的程序使用,则返回True + - 并且没有被别的程序使用,则返回True。 """ - # 确保端口号是整数且在合法范围内 - if isinstance(port, int) and 0 < port < 65535: - # 获取当前所有的网络连接 - connections = psutil.net_connections() - # 遍历所有连接,检查端口是否被占用 - for conn in connections: - if conn.laddr.port == port: - return False # 端口已被占用 - return True # 端口未被占用,可用 + os_name = platform.system() + if os_name == 'Windows': + # Windows下使用psutil检查 + import psutil + if isinstance(port, int) and 0 < port < 65535: + connections = psutil.net_connections() + for conn in connections: + if conn.laddr.port == port: + return False # 端口已被占用 + return True # 端口未被占用,可用 + else: + return False # 端口号不合法 + elif os_name == 'Darwin': + # MacOS下使用socket尝试绑定端口检查 + if isinstance(port, int) and 0 < port < 65535: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + try: + s.bind(('localhost', port)) + return True # 端口未被占用,可用 + except socket.error: + return False # 端口已被占用 + else: + return False # 端口号不合法 else: - return False # 端口号不合法 + raise NotImplementedError("This OS is not supported for port checking") diff --git a/modules/server/keyboard.py b/modules/server/keyboard.py index 09df98e..7b7ec70 100644 --- a/modules/server/keyboard.py +++ b/modules/server/keyboard.py @@ -1,6 +1,7 @@ from flask import request, jsonify import pyautogui import pyperclip +import platform def keyboard_buttons(): @@ -29,11 +30,20 @@ def keyboard_typewriting(): def keyboard_pastetext(): text = request.data.decode('utf-8') # 获取请求体中的文本内容 - try: - pyperclip.copy(text) # 将文本复制到剪贴板 - pyautogui.hotkey('ctrl', 'v') # 模拟按下粘贴快捷键(Windows/Linux) - # 对于macOS,使用 pyautogui.hotkey('cmd', 'v') - return jsonify({"status": "success", "message": "Text has been pasted successfully."}) - except Exception as e: - print(f"Error: {e}") - return jsonify({"status": "error", "message": "An error occurred while pasting text."}), 500 + os_name = platform.system() + if os_name == 'Windows': + try: + pyperclip.copy(text) # 将文本复制到剪贴板 + pyautogui.hotkey('ctrl', 'v') # 模拟按下粘贴快捷键(Windows/Linux) + # 对于macOS,使用 pyautogui.hotkey('cmd', 'v') + return jsonify({"status": "success", "message": "Text has been pasted successfully."}) + except Exception as e: + print(f"Error: {e}") + return jsonify({"status": "error", "message": "An error occurred while pasting text."}), 500 + elif os_name == 'Darwin': + try: + pyautogui.write(text, interval=0.05) # 将文本输入到当前聚焦的位置 + return jsonify({"status": "success", "message": "Text has been sent successfully."}) + except Exception as e: + print(f"Error: {e}") + return jsonify({"status": "error", "message": "An error occurred while sending text."}), 500 diff --git a/modules/volume/__init__.py b/modules/volume/__init__.py index 47e6ab8..1e729f6 100644 --- a/modules/volume/__init__.py +++ b/modules/volume/__init__.py @@ -1,15 +1,15 @@ from modules.volume.base import BaseVolumeController -from modules.volume.windows import WindowsVolumeController -from modules.volume.mac import MacVolumeController import platform def get_volume_controller() -> BaseVolumeController: os_name = platform.system() if os_name == 'Windows': + from modules.volume.windows import WindowsVolumeController return WindowsVolumeController() - elif os_name == 'Darwin': # macOS的官方名称是Darwin + elif os_name == 'Darwin': + from modules.volume.mac import MacVolumeController return MacVolumeController() else: - raise NotImplementedError("This OS is not supported for volume control.") + raise NotImplementedError("This OS is not supported for volume control")