Skip to content

Commit

Permalink
v0.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehver committed Apr 7, 2024
1 parent b638b89 commit c3f6a02
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 30 deletions.
2 changes: 1 addition & 1 deletion #README/README-cn.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">
<img src="https://github.com/Mehver/iController/raw/main/%23README/icon/256.png" width="20%"/>
<h1>iController <code>v0.4.2</code></h1>
<h1>iController <code>v0.4.3</code></h1>
<p><a href='https://github.com/Mehver/iController/blob/main/README.md'>English</a> | 简体中文</p>
</div>

Expand Down
2 changes: 1 addition & 1 deletion #README/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- 黑名单模式
- 控制权释放机制
- 提供HTTPS
- 自扫描可用端口,检验可用性
- ~~自扫描可用端口,检验可用性~~

## v0.6.x

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">
<img src="https://github.com/Mehver/iController/raw/main/%23README/icon/256.png" width="20%"/>
<h1>iController <code>v0.4.2</code></h1>
<h1>iController <code>v0.4.3</code></h1>
</tr>
<p>English | <a href='https://github.com/Mehver/iController/blob/main/%23README/README-cn.md'>简体中文</a></p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
|_\____/\___/|_| |_|\__|_| \___/|_|_|\___|_|
https://github.com/Mehver/iController
v0.4.2
v0.4.3
""")

Expand Down
42 changes: 28 additions & 14 deletions modules/portchecker.py
Original file line number Diff line number Diff line change
@@ -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")
26 changes: 18 additions & 8 deletions modules/server/keyboard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask import request, jsonify
import pyautogui
import pyperclip
import platform


def keyboard_buttons():
Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions modules/volume/__init__.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit c3f6a02

Please sign in to comment.