mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 14:50:45 +00:00
被控端 - 修复 MTU 问题:夹 MSS + 路径 MTU 探测(公网可用率 48% -> 100%) - 复用 HTTP 连接(免掉每次新建 TLS 的 30% 握手失败) - 每分钟回头找局域网,自动切回快 400 倍的路径 - 画面心跳帧:静止时省流量,客户端仍知道流是活的 - 锁屏时给出可操作的提示 手表端 - 内置 GTS Root R4 / GlobalSign Root CA,修 SSLHandshakeException - 连接错误翻译成人话(证书/时间/解析/超时分别提示) - 经中转连上后用服务器报的地址刷新已配对记录 - 新增局域网连接页面、服务器延迟检测 服务器端 - 支持 chunked 请求体(修每 16 秒一次的连接错乱与大面积 502) - 网络调优脚本 net-tune.sh(开机自动应用) - 管理页:批量删除、网络体检、下载区 - 隧道改 HTTP/2 + 双连接 文档 - 许可协议 / 安装前必读 / 安装后须知(作者:小麦子)
330 lines
12 KiB
Python
330 lines
12 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""按用户反馈调整桌面表现:
|
|
|
|
1. 去掉右上角悬浮状态条 —— 关掉主窗口后桌面完全干净
|
|
(连接信息、临时消息一律不再往桌面上弹)
|
|
2. 投图改成**屏幕正中间的普通 Windows 窗口**(带标题栏,不再全屏无边框)
|
|
3. 远程「弹通知」也改成屏幕正中间的普通窗口
|
|
|
|
保留:屏幕共享期间右下角的一条小提示(共享一停立刻消失)。
|
|
理由写在 ui.py 的注释里 —— 没有任何提示的"能看你的屏幕"和木马没区别。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote")
|
|
UI = ROOT / "windows" / "lanremote" / "ui.py"
|
|
ACTIONS = ROOT / "windows" / "lanremote" / "actions.py"
|
|
|
|
NEW_UI_BLOCK = ''' # ---- 提示:一律显示在主窗口里,桌面上不留任何东西 ----
|
|
|
|
def notify(self, title: str, text: str) -> None:
|
|
"""远程「弹通知」:在屏幕正中间弹一个普通 Windows 窗口。"""
|
|
self.show_text_window(title or "局域网遥控", text or "")
|
|
|
|
def show_text_window(self, title: str, text: str) -> None:
|
|
def do():
|
|
try:
|
|
win = tk.Toplevel(self.root)
|
|
except tk.TclError:
|
|
return
|
|
win.title(title)
|
|
win.configure(bg=CARD)
|
|
win.resizable(False, False)
|
|
|
|
tk.Label(win, text=title, bg=CARD, fg=FG,
|
|
font=("Microsoft YaHei UI", 13, "bold"),
|
|
anchor="w").pack(fill="x", padx=20, pady=(18, 6))
|
|
|
|
tk.Label(win, text=text or "(空消息)", bg=CARD, fg=FG,
|
|
font=FONT_UI, wraplength=430, justify="left",
|
|
anchor="w").pack(fill="x", padx=20, pady=(0, 16))
|
|
|
|
tk.Button(win, text="知道了", command=win.destroy,
|
|
bg=ACCENT, fg="#ffffff", relief="flat",
|
|
font=FONT_UI, padx=20, pady=5,
|
|
cursor="hand2").pack(pady=(0, 18))
|
|
|
|
self.center_window(win)
|
|
try:
|
|
self.ui_call(do, timeout=3.0)
|
|
except Exception:
|
|
pass
|
|
|
|
def center_window(self, win) -> None:
|
|
"""把窗口摆到屏幕正中间(普通窗口,保留标题栏)。"""
|
|
try:
|
|
win.update_idletasks()
|
|
width = win.winfo_reqwidth()
|
|
height = win.winfo_reqheight()
|
|
x = max(0, (win.winfo_screenwidth() - width) // 2)
|
|
y = max(0, (win.winfo_screenheight() - height) // 2)
|
|
win.geometry(f"{width}x{height}+{x}+{y}")
|
|
win.lift()
|
|
win.focus_force()
|
|
except tk.TclError:
|
|
pass
|
|
|
|
def show_message(self, text: str, seconds: float = 3.5) -> None:
|
|
"""短暂提示:显示在主窗口里,不在桌面上弹任何东西。"""
|
|
def do():
|
|
self._message_text = text
|
|
self._message_until = time.time() + seconds
|
|
self.refresh()
|
|
try:
|
|
self.ui_call(do, timeout=2.0)
|
|
except Exception:
|
|
pass
|
|
|
|
def on_state_changed(self) -> None:
|
|
try:
|
|
self.root.after(0, self.refresh)
|
|
except (tk.TclError, RuntimeError):
|
|
pass
|
|
|
|
def refresh(self) -> None:
|
|
if not self.server:
|
|
return
|
|
status = self.server.status()
|
|
self.lbl_code.configure(text=status["pairing_code"] or "------")
|
|
|
|
connected = status["connected"]
|
|
sharing = bool(status.get("screen_sharing"))
|
|
now = time.time()
|
|
|
|
# 连接状态和临时消息都只在主窗口里出现,桌面不留任何东西
|
|
if self._message_until > now and self._message_text:
|
|
self.lbl_conn.configure(text=self._message_text, fg=ACCENT)
|
|
elif connected:
|
|
names = "、".join(d["name"] for d in connected[:3])
|
|
self.lbl_conn.configure(text=f"● 已连接:{names}", fg=OK)
|
|
else:
|
|
self.lbl_conn.configure(text="等待手表连接…", fg=DIM)
|
|
|
|
if sharing:
|
|
self.lbl_state.configure(text="屏幕共享中", fg=DANGER)
|
|
elif connected:
|
|
self.lbl_state.configure(text="已连接", fg=OK)
|
|
else:
|
|
self.lbl_state.configure(text="运行中", fg=OK)
|
|
|
|
self.refresh_sharing_notice(status, sharing)
|
|
|
|
# ---- 屏幕共享提示:只在「正在共享」时出现,共享一停立刻消失 ----
|
|
#
|
|
# 这是唯一保留的桌面提示,且只在共享进行中出现。
|
|
# 原因:一个能实时看到你屏幕、却没有任何提示的工具,
|
|
# 和木马在功能上就没有区别了。这条提示只在主动共享时存在,
|
|
# 不共享时桌面完全干净。位置放在右下角,不占用户看的地方。
|
|
|
|
def set_screen_sharing(self, active: bool) -> None:
|
|
def do():
|
|
self._screen_sharing = bool(active)
|
|
self.refresh()
|
|
try:
|
|
self.ui_call(do, timeout=3.0)
|
|
except Exception:
|
|
pass
|
|
|
|
def flash_screen_indicator(self, seconds: float = 2.5) -> None:
|
|
# 一次性截屏不再往桌面弹东西,只记日志
|
|
self.log(f"远程截屏一次")
|
|
|
|
def refresh_sharing_notice(self, status: dict, sharing: bool) -> None:
|
|
if not sharing:
|
|
self._hide_notice()
|
|
return
|
|
viewers = status.get("screen_viewers", 0)
|
|
fps = status.get("screen_fps", 0)
|
|
self._show_notice(
|
|
f"▲ 屏幕正在被共享 {viewers} 台观看 · {fps} fps",
|
|
DANGER, ("停止共享", self.stop_screen_sharing))
|
|
|
|
def _show_notice(self, text: str, color: str, button) -> None:
|
|
if self._bar is None:
|
|
try:
|
|
win = tk.Toplevel(self.root)
|
|
win.overrideredirect(True)
|
|
win.attributes("-topmost", True)
|
|
outer = tk.Frame(win, padx=10, pady=5)
|
|
outer.pack()
|
|
label = tk.Label(outer, text="", fg="#ffffff",
|
|
font=("Microsoft YaHei UI", 9, "bold"))
|
|
label.pack(side="left")
|
|
self._bar, self._bar_inner, self._bar_label = win, outer, label
|
|
except tk.TclError:
|
|
return
|
|
try:
|
|
self._bar_inner.configure(bg=color)
|
|
self._bar_label.configure(bg=color, text=text)
|
|
if self._bar_button is not None:
|
|
self._bar_button.destroy()
|
|
self._bar_button = None
|
|
if button is not None:
|
|
caption, command = button
|
|
self._bar_button = tk.Button(
|
|
self._bar_inner, text=caption, command=command,
|
|
bg="white", fg=color, relief="flat",
|
|
font=("Microsoft YaHei UI", 9, "bold"), padx=8, pady=1,
|
|
cursor="hand2")
|
|
self._bar_button.pack(side="left", padx=(10, 0))
|
|
self._bar.deiconify()
|
|
self._bar.lift()
|
|
self._bar.update_idletasks()
|
|
width = self._bar.winfo_width()
|
|
height = self._bar.winfo_height()
|
|
screen_w = self._bar.winfo_screenwidth()
|
|
screen_h = self._bar.winfo_screenheight()
|
|
# 右下角(用户明确不要右上角有东西)
|
|
self._bar.geometry(f"+{max(0, screen_w - width - 16)}"
|
|
f"+{max(0, screen_h - height - 64)}")
|
|
except tk.TclError:
|
|
self._bar = None
|
|
|
|
def _hide_notice(self) -> None:
|
|
if self._bar is None:
|
|
return
|
|
try:
|
|
self._bar.destroy()
|
|
except tk.TclError:
|
|
pass
|
|
self._bar = None
|
|
self._bar_button = None
|
|
self._bar_label = None
|
|
'''
|
|
|
|
NEW_IMAGE_FUNC = ''' def show_image(self, path: str) -> str:
|
|
"""在**屏幕正中间**弹一个普通 Windows 窗口显示图片。"""
|
|
p = Path(path)
|
|
if not p.is_file():
|
|
raise ActionError(f"图片不存在: {path}")
|
|
|
|
from PIL import Image, ImageTk
|
|
|
|
try:
|
|
img = Image.open(p)
|
|
img.load()
|
|
except Exception as exc:
|
|
raise ActionError(f"无法读取图片: {exc}") from exc
|
|
|
|
screen_w, screen_h = self.ui.screen_size()
|
|
# 留出标题栏和按钮的位置,最多占屏幕 78%
|
|
img = img.convert("RGB")
|
|
img.thumbnail((int(screen_w * 0.78), int(screen_h * 0.78)), Image.LANCZOS)
|
|
|
|
def build():
|
|
import tkinter as tk
|
|
if self._image_window is not None:
|
|
try:
|
|
self._image_window.destroy()
|
|
except Exception:
|
|
pass
|
|
|
|
win = tk.Toplevel(self.ui.root)
|
|
win.title(f"图片 - {p.name}")
|
|
win.configure(bg=CARD)
|
|
win.resizable(False, False)
|
|
|
|
def close(_event=None):
|
|
with self._lock:
|
|
self._image_window = None
|
|
try:
|
|
win.destroy()
|
|
except Exception:
|
|
pass
|
|
|
|
photo = ImageTk.PhotoImage(img)
|
|
label = tk.Label(win, image=photo, bg=CARD, bd=0,
|
|
highlightthickness=0)
|
|
label.image = photo # 防止被 GC
|
|
label.pack(fill="both", expand=True)
|
|
|
|
foot = tk.Frame(win, bg=CARD)
|
|
foot.pack(fill="x")
|
|
tk.Button(foot, text="关闭", command=close,
|
|
bg="#eaeef2", fg=FG, relief="flat",
|
|
font=("Microsoft YaHei UI", 9), padx=14, pady=2,
|
|
cursor="hand2").pack(side="right", padx=10, pady=8)
|
|
|
|
# 摆到屏幕正中间 —— 普通窗口,有标题栏和关闭按钮
|
|
win.update_idletasks()
|
|
width = win.winfo_reqwidth()
|
|
height = win.winfo_reqheight()
|
|
x = max(0, (win.winfo_screenwidth() - width) // 2)
|
|
y = max(0, (win.winfo_screenheight() - height) // 2)
|
|
win.geometry(f"{width}x{height}+{x}+{y}")
|
|
win.lift()
|
|
win.focus_force()
|
|
|
|
win.bind("<Escape>", close)
|
|
win.bind("<Button-1>", close)
|
|
win.protocol("WM_DELETE_WINDOW", close)
|
|
self._image_window = win
|
|
|
|
timeout = int(self.store.get("image_timeout", 0) or 0)
|
|
if timeout > 0:
|
|
win.after(timeout * 1000, close)
|
|
|
|
self.ui.ui_call(build)
|
|
return f"已在屏幕中间显示 {p.name}"
|
|
'''
|
|
|
|
|
|
def patch_ui() -> bool:
|
|
text = UI.read_text(encoding="utf-8")
|
|
start = text.index(" def notify(self, title: str, text: str) -> None:")
|
|
end_marker = " self._bar_label = None\n"
|
|
end = text.index(end_marker, start) + len(end_marker)
|
|
text = text[:start] + NEW_UI_BLOCK + text[end:]
|
|
|
|
# stop_screen_sharing 里还引用了已删除的 _update_bar
|
|
text = text.replace(
|
|
" self._screen_sharing = False\n self._update_bar()",
|
|
" self._screen_sharing = False\n self.refresh()")
|
|
|
|
if "_update_bar" in text:
|
|
print(" [失败] ui.py 里仍有 _update_bar 残留")
|
|
return False
|
|
UI.write_text(text, encoding="utf-8")
|
|
print(" ui.py: 已改(去悬浮条 / 通知改居中窗口 / 共享提示移右下角)")
|
|
return True
|
|
|
|
|
|
def patch_actions() -> bool:
|
|
text = ACTIONS.read_text(encoding="utf-8")
|
|
start = text.index(" def show_image(self, path: str) -> str:")
|
|
end_marker = ' return f"已全屏显示 {p.name}"\n'
|
|
end = text.index(end_marker, start) + len(end_marker)
|
|
text = text[:start] + NEW_IMAGE_FUNC + text[end:]
|
|
if "已全屏显示" in text:
|
|
print(" [失败] actions.py 里仍有全屏显示残留")
|
|
return False
|
|
ACTIONS.write_text(text, encoding="utf-8")
|
|
print(" actions.py: 已改(投图改屏幕正中间的普通窗口)")
|
|
return True
|
|
|
|
|
|
def main() -> int:
|
|
ok = True
|
|
print("修改文件:")
|
|
ok &= patch_ui()
|
|
ok &= patch_actions()
|
|
|
|
print("\n语法检查:")
|
|
import ast
|
|
for name, path in (("ui.py", UI), ("actions.py", ACTIONS)):
|
|
try:
|
|
ast.parse(path.read_text(encoding="utf-8"))
|
|
print(f" {name}: OK")
|
|
except SyntaxError as exc:
|
|
print(f" {name}: 语法错误 {exc}")
|
|
ok = False
|
|
return 0 if ok else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|