Bläddra i källkod

feat(script):桌面客户端独立配置组与多开账号隔离

- script.desktop 新组(enable/game_path/profile_dir/window_pos/window_title/
  launch_instance)替代 serial="desktop" 魔法字符串,handle 语义变为窗口标题
- 客户端 PID 改为运行时状态:不写配置,档案内 oas_instance.json 供下次启动
  认领;删除 handle 下拉注入与 PID 回退补丁
- 档案目录隔离启动:cwd 与 USERPROFILE 落在档案内(Documents 与 SDK 账号库
  独立),大目录 junction 共享
- 「启动实例」一次性按钮:主进程直接拉起客户端,值自动弹回 false
- 自定义窗口标题:绑定时改名,按标题找窗口的路径放行自定义标题
- 桌面模式强制 screenshot/control 方式为 window_background/window_message
LGG686 1 månad sedan
förälder
incheckning
1d990fce67

+ 12 - 2
assets/i18n/zh-CN.json

@@ -1,6 +1,16 @@
 {
-  "desktop_game_path": "桌面版安装目录",
-  "desktop_game_path_help": "本项:游戏安装目录(如D:\\yys)留空则自动查找。\n\n桌面版模式(Serial 填 \"desktop\" 启用;截图和控制方式只能选 window开头的,支持多开,不支持最小化):\n\n句柄Handle 填游戏窗口的进程 PID(多开时用于区分实例),PID 每次重启客户端都会变、需重新绑定(单开理论上只有第一次需要绑定);\n可以空启动一次脚本获取PID,使句柄Handle可展开进行选择\n或任务栏管理器查找直接填写;也可用管理员 cmd 在 OAS 目录下执行 【.\\toolkit\\python.exe -m dev_tools.bind_desktop_window --config 配置名 --pick】 一键绑定(配置名不带 .json;--pick 后把鼠标移到游戏窗口上回车,不用点击;多开改用 --list 选序号)\n\n游戏以管理员运行时 OAS 也需以管理员启动,否则 UIPI 会拦截点击(截图正常但无法点击点)。\n\n高分辨率设备请在游戏目录\\bin\\onmyoji.exe属性设置\\兼容性\\高DPI设置中勾选“替代高DPI缩放行为”,并选择“由应用程序执行”。",
+  "desktop": "桌面版设置",
+  "desktop_enable_help": "开启此项则控制电脑上的阴阳师桌面版,窗口可以互相遮挡,但不能最小化。\n游戏用管理员启动时,OAS 也需要用管理员启动,否则会点不动。\n高分辨率屏幕需在游戏目录 bin\\onmyoji.exe 的 属性-兼容性-高DPI设置 中勾选“替代高DPI缩放行为”,否则点击位置会偏。",
+  "game_path": "游戏安装目录",
+  "game_path_help": "游戏安装目录(如 D:\\yys),留空自动查找。",
+  "launch_instance": "启动客户端实例",
+  "launch_instance_help": "一次性按钮:点击后按上面的设置启动本配置对应的客户端,已在运行则跳过。\n它是按钮不是开关,点击后自动弹回,不会保存为开启。",
+  "profile_dir": "档案目录",
+  "profile_dir_help": "多开账号隔离:每个配置填一个不同目录(如 D:/yys-profiles/p1),无需手动创建,OAS 会自动准备好。\n填了之后每个实例拥有独立的游戏数据和账号。\n留空 = 和直接双击打开的游戏共享账号。",
+  "window_pos": "窗口位置",
+  "window_pos_help": "多开时自动把窗口移到指定位置,格式 横,竖(如 0,0 / 660,0);留空不移动。",
+  "window_title": "窗口标题",
+  "window_title_help": "多开时用来在任务栏区分实例:OAS 绑定该客户端时会把窗口标题改成它。\n留空 = 保持客户端默认标题,改动在下次启动或认领客户端时生效。识别和点击都不依赖标题,填不填都能正常跑。",
   "boss_limit_time": "单局Boss限制时间",
   "kirin_battle_config": "麒麟战斗配置",
   "netherworld_battle_config": "阴界之门战斗配置",

+ 8 - 0
config/template.json

@@ -15,6 +15,14 @@
       "emulator_window_minimize": false,
       "run_background_only": false
     },
+    "desktop": {
+      "enable": false,
+      "game_path": "",
+      "profile_dir": "",
+      "window_pos": "",
+      "window_title": "",
+      "launch_instance": false
+    },
     "error": {
       "handle_error": true,
       "error_repeated": false,

+ 42 - 92
dev_tools/bind_desktop_window.py

@@ -1,117 +1,67 @@
 # -*- coding: utf-8 -*-
-"""
-桌面客户端窗口 PID 绑定工具
+"""桌面客户端模式配置工具
 ============================
-把"阴阳师-网易游戏"桌面客户端窗口的 PID 写入指定 OAS 配置,并切到桌面模式
-(serial='desktop'、handle=PID、screenshot_method='window_background'、control_method='window_message')。
+把指定 OAS 配置切到桌面客户端模式(script.desktop.enable=True、
+screenshot_method='window_background'、control_method='window_message'),
+并可顺带启动一个实例验证安装目录与档案配置是否可用。
+
+PID 不再写进配置:客户端进程 PID 每次重启都会变,OAS 启动/认领时自动绑定,
+档案目录内会写 oas_instance.json 运行时状态供下次认领(多开账号隔离)。
 
 用法:
-    ./toolkit/python.exe -m dev_tools.bind_desktop_window --config oas1 --pick
-    ./toolkit/python.exe -m dev_tools.bind_desktop_window --config oas1 --list
-    ./toolkit/python.exe -m dev_tools.bind_desktop_window --config oas1 --pid 4242
+    ./toolkit/python.exe -m dev_tools.bind_desktop_window --config oas1
+    ./toolkit/python.exe -m dev_tools.bind_desktop_window --config oas1 --path D:\\yys
+    ./toolkit/python.exe -m dev_tools.bind_desktop_window --config oas1 --profile D:\\yys-profiles\\p1 --launch
 """
 import argparse
-import ctypes
-import sys
-from ctypes import wintypes
-
-import win32gui
-import win32process
 
 from module.config.config import Config
 from module.logger import logger
 
-DESKTOP_WINDOW_TITLES = ('阴阳师-网易游戏', '阴阳师-MuMu模拟器专版')
-
-
-def list_desktop_windows() -> list:
-    """枚举所有桌面客户端窗口,返回 [(title, hwnd, pid)]。"""
-    def enum_cb(hwnd, param):
-        param.append(hwnd)
-        return True
-
-    windows = []
-    win32gui.EnumWindows(enum_cb, windows)
-    result = []
-    for hwnd in windows:
-        title = win32gui.GetWindowText(hwnd)
-        if title in DESKTOP_WINDOW_TITLES:
-            pid = win32process.GetWindowThreadProcessId(hwnd)[1]
-            result.append((title, hwnd, pid))
-    return result
-
-
-def pick_window_under_cursor() -> int:
-    """返回鼠标光标所指窗口的句柄;无窗口返回 0。"""
-    user32 = ctypes.WinDLL('user32', use_last_error=True)
-
-    class POINT(ctypes.Structure):
-        _fields_ = [('x', ctypes.c_long), ('y', ctypes.c_long)]
-
-    point = POINT()
-    user32.GetCursorPos.argtypes = [ctypes.POINTER(POINT)]
-    user32.GetCursorPos.restype = wintypes.BOOL
-    if not user32.GetCursorPos(ctypes.byref(point)):
-        return 0
-    user32.WindowFromPoint.argtypes = [POINT]
-    user32.WindowFromPoint.restype = wintypes.HWND
-    return int(user32.WindowFromPoint(point)) or 0
 
-
-def bind_pid_to_config(config_name: str, pid: int) -> None:
-    """把 PID 写入指定配置,并切到桌面模式。"""
+def bind_desktop_mode(config_name: str, game_path: str = '', profile_dir: str = '') -> None:
+    """把配置切到桌面客户端模式(幂等,可重复执行)。"""
     config = Config(config_name)
-    config.script.device.serial = 'desktop'
-    config.script.device.handle = str(pid)
+    config.script.desktop.enable = True
+    if game_path:
+        config.script.desktop.game_path = game_path
+    if profile_dir:
+        config.script.desktop.profile_dir = profile_dir
     # PrintWindow 对客户端的 DirectX 渲染窗口返回纯黑,桌面模式统一用 BitBlt
     config.script.device.screenshot_method = 'window_background'
     config.script.device.control_method = 'window_message'
     config.save()
-    logger.info(f'Config [{config_name}] bound to desktop client PID={pid}')
-    # 绑定后检测并调整窗口客户区到 1280x720,保证识别 1:1
-    from module.device.handle import Handle
-    h = Handle(config)
-    h.desktop_window_set_size()
+    logger.info(f'Config [{config_name}] switched to desktop client mode '
+                f'(game_path={config.script.desktop.game_path or "auto"}, '
+                f'profile_dir={config.script.desktop.profile_dir or "-"})')
 
 
-def main():
-    parser = argparse.ArgumentParser(description='绑定桌面客户端窗口 PID 到 OAS 配置')
-    parser.add_argument('--config', required=True, help='配置实例名,如 oas1')
-    group = parser.add_mutually_exclusive_group(required=True)
-    group.add_argument('--pick', action='store_true', help='鼠标点选窗口(光标所指)')
-    group.add_argument('--list', action='store_true', help='从窗口列表按序号选择')
-    group.add_argument('--pid', type=int, help='直接指定 PID')
-    args = parser.parse_args()
+def launch_and_check(config_name: str) -> None:
+    """按当前 desktop 配置启动一个实例并校准窗口尺寸,验证配置可用。"""
+    from module.device.device import Device
+    from module.device.method.desktop_impl import desktop_launch_instance
 
-    if args.pid:
-        bind_pid_to_config(args.config, args.pid)
+    config = Config(config_name)
+    if not desktop_launch_instance(config):
+        logger.error('启动失败,请检查 游戏安装目录 / 档案目录 配置')
         return
+    device = Device(config)
+    device.desktop_window_set_size()
+    logger.info('桌面客户端已启动并完成窗口校准,可以启动脚本了')
 
-    if args.pick:
-        input('请把鼠标移到目标游戏窗口上,然后按回车…')
-        hwnd = pick_window_under_cursor()
-        if not hwnd:
-            logger.error('未获取到光标下的窗口')
-            sys.exit(1)
-        title = win32gui.GetWindowText(hwnd)
-        if title not in DESKTOP_WINDOW_TITLES:
-            logger.error(f'光标下的窗口不是桌面客户端(标题: "{title}"),'
-                         f'请把鼠标移到游戏画面实体区域上重试')
-            sys.exit(1)
-        pid = win32process.GetWindowThreadProcessId(hwnd)[1]
-        bind_pid_to_config(args.config, pid)
-        return
 
-    windows = list_desktop_windows()
-    if not windows:
-        logger.error('未找到桌面客户端窗口,请先启动游戏')
-        sys.exit(1)
-    for i, (title, hwnd, pid) in enumerate(windows):
-        print(f'[{i}] {title}  PID={pid}  HWND=0x{hwnd:X}')
-    choice = input('请输入方括号内的序号: ')
-    idx = int(choice)
-    _, _, pid = windows[idx]
-    bind_pid_to_config(args.config, pid)
+def main():
+    parser = argparse.ArgumentParser(description='把 OAS 配置切换到桌面客户端模式')
+    parser.add_argument('--config', required=True, help='配置实例名,如 oas1')
+    parser.add_argument('--path', default='', help='游戏安装目录(含 bin\\onmyoji.exe 的根目录)')
+    parser.add_argument('--profile', default='', help='多开档案目录(每个配置一个,实现账号隔离)')
+    parser.add_argument('--launch', action='store_true',
+                        help='切换后立即启动一个客户端实例并校准窗口尺寸')
+    args = parser.parse_args()
+
+    bind_desktop_mode(args.config, args.path, args.profile)
+    if args.launch:
+        launch_and_check(args.config)
 
 
 if __name__ == '__main__':

+ 8 - 60
module/config/config_model.py

@@ -356,58 +356,8 @@ class ConfigModel(ConfigBase):
                         groups_value[key] = groups[group_name]
             result[key] = merge_value(groups_value[key], value, schema["$defs"])
 
-        self._inject_desktop_handle_options(result)
-
         return result
 
-    def _inject_desktop_handle_options(self, result: dict) -> None:
-        """桌面模式下把 handle 改成"已开客户端窗口"下拉,供界面选择而非手填 PID。
-
-        仅 serial == 'desktop' 时注入:handle 是桌面与模拟器共用字段,模拟器模式
-        需要保留窗口标题/HWND 的自由输入。字段类型仍是 str,只是补上候选项。
-        """
-        device_items = result.get('device')
-        if not device_items:
-            return
-        if getattr(self.script.device, 'serial', '') != 'desktop':
-            return
-        try:
-            from module.device.method.desktop_impl import desktop_window_option, list_desktop_windows
-            windows = list_desktop_windows()
-        except Exception as e:
-            # 枚举依赖 win32 且只服务于界面展示,失败时退回手填输入框
-            logger.warning(f'list desktop windows failed, handle stays a text input: {e}')
-            return
-
-        options = [desktop_window_option(w) for w in windows]
-        current = ''
-        for item in device_items:
-            if item['name'] == 'handle':
-                current = str(item.get('value') or '')
-                break
-        # 落盘的 handle 是纯 PID,候选项却是带标题坐标的展示串;界面靠"值等于候选项"
-        # 来选中,所以要把当前值换成同款展示串,否则下拉显示为空白
-        display = ''
-        for window, option in zip(windows, options):
-            if str(window['pid']) == current:
-                display = option
-                break
-        # 已绑定的 PID 此刻可能不在枚举结果里(客户端未启动/换了 PID),
-        # 原值仍作候选保留,让界面能看出配置里存的是谁
-        if current and not display:
-            display = current
-            options.append(current)
-        # 空串候选用于解除绑定
-        options.insert(0, '')
-
-        for item in device_items:
-            if item['name'] != 'handle':
-                continue
-            item['type'] = 'enum'
-            item['enumEnum'] = options
-            item['value'] = display
-            break
-
     def script_set_arg(self, task: str, group: str, argument: str, value) -> bool:
         # 验证参数
         task = convert_to_underscore(task)
@@ -436,16 +386,6 @@ class ConfigModel(ConfigBase):
         if isinstance(value, str) and value == 'false':
             value = False
 
-        # 桌面模式下 handle 在界面上是下拉项,回传的是 "PID (x,y)" 展示串,落盘前剥回
-        # 纯 PID;必须限定 desktop 模式,模拟器的 handle 允许填窗口标题等非数字文本
-        if (task == 'script' and group == 'device' and argument == 'handle'
-                and isinstance(value, str) and self.script.device.serial == 'desktop'):
-            from module.device.method.desktop_impl import desktop_option2pid
-            resolved = desktop_option2pid(value)
-            if resolved != value:
-                logger.info(f'Desktop handle option resolved to PID: {resolved}')
-            value = resolved
-
         task_object = getattr(self, task, None)
         group_object = getattr(task_object, group, None)
         if group_object is None:  # deal list
@@ -468,6 +408,14 @@ class ConfigModel(ConfigBase):
             logger.info(f"reset_task_datetime={date_time}")
             self.reset_datetime_for_all_enabled_tasks(date_time)
 
+        # 桌面客户端「启动实例」按钮:点击置 True → 主进程直接拉起该配置的客户端
+        # 实例,完成后改写 False 再走通用保存
+        if (task == 'script' and group == 'desktop' and argument == 'launch_instance'
+                and value is True):
+            from module.device.method.desktop_impl import desktop_launch_instance
+            desktop_launch_instance(self)
+            value = False
+
         # 设置参数
         try:
             setattr(group_object, argument, value)

+ 5 - 0
module/config/utils.py

@@ -273,6 +273,11 @@ def parse_tomorrow_server(server_update: time, delay_date: int = 1, float_second
     
     return next_run
 
+def desktop_mode_enabled(config) -> bool:
+    """是否启用桌面客户端模式(script.desktop.enable)。"""
+    return bool(config.script.desktop.enable)
+
+
 def deep_get(d, keys, default=None):
     """
     Get values in dictionary safely.

+ 5 - 5
module/device/connection_attr.py

@@ -9,7 +9,7 @@ from adbutils import AdbClient, AdbDevice
 
 from module.base.decorator import cached_property
 from module.config.config import Config
-from module.config.utils import deep_iter
+from module.config.utils import deep_iter, desktop_mode_enabled
 from module.exception import RequestHumanTakeover
 from module.logger import logger
 
@@ -131,12 +131,12 @@ class ConnectionAttr:
 
     @cached_property
     def is_desktop(self):
-        """桌面客户端模式:serial 配置为 'desktop'。
+        """桌面客户端模式:script.desktop.enable 显式开关。
 
-        不做异常兜底:读不到配置说明 Device 构造链没走到 ConnectionAttr,
-        此时静默返回 False 会把桌面模式当成模拟器模式继续跑,报错指向完全无关的地方。
+        刻意不兜底:读不到配置时抛 AttributeError 比静默 False 好——后者会把
+        桌面模式当成模拟器模式继续跑,报错指向完全无关的地方。
         """
-        return str(self.config.script.device.serial) == 'desktop'
+        return desktop_mode_enabled(self.config)
 
     @cached_property
     def is_network_device(self):

+ 29 - 7
module/device/desktop_device.py

@@ -1,9 +1,11 @@
 # This Python file uses the following encoding: utf-8
-"""桌面客户端(serial='desktop')在 Device 层的生命周期策略。
+"""桌面客户端(script.desktop.enable)在 Device 层的生命周期策略。
 
 窗口/进程的实现细节在 module/device/method/desktop_impl.py 的 DesktopWindow,
 这里只管「什么时候把客户端拉起来、什么时候算它在运行」。
 """
+from module.device.method.desktop_impl import (
+    desktop_pid_alive, desktop_window_titles, find_desktop_window_by_pid)
 from module.logger import logger
 
 
@@ -16,15 +18,28 @@ class DesktopDevice:
         """确保客户端可用:进程已死才拉起,进程活着只等窗口就绪。
 
         判定顺序是关键——先看进程再看窗口。把「窗口不在」当成「客户端没在运行」
-        会拉起多余实例,并把配置里的 handle 覆盖成新实例的 PID,从此再也绑不回
-        原来那个。窗口被最小化不算没运行,截图方法会先还原再取帧。
+        会拉起多余实例,从此再也绑不回原来那个。窗口被最小化不算没运行,
+        截图方法会先还原再取帧。
+
+        本会话没有存活 PID 时(刚启动、或上一个客户端已退出),先按「档案状态
+        文件 → 唯一窗口枚举」认领已在运行的实例——按钮手动启动的实例就是这样
+        被接上的;认领不到才拉起新的。
         """
         pid = self.desktop_pid()
-        if pid is None or not self._desktop_pid_alive(pid):
-            return self.launch_desktop_client()
-        if self.desktop_window_exists():
+        if pid is not None and desktop_pid_alive(pid):
+            if self.desktop_window_exists():
+                return True
+            return self._desktop_wait_window_ready(pid)
+        located_pid, hwnd = self._desktop_locate_window()
+        if located_pid:
+            if not hwnd and not self._desktop_wait_window_ready(located_pid):
+                return False
+            if not hwnd:
+                hwnd = find_desktop_window_by_pid(
+                    located_pid, desktop_window_titles(self.config))
+            self.desktop_bind_pid(located_pid, hwnd)
             return True
-        return self._desktop_wait_window_ready(pid)
+        return self.launch_desktop_client()
 
     def app_lost_login(self) -> bool:
         """客户端是否掉回了未登录态。
@@ -50,6 +65,13 @@ class DesktopDevice:
         """桌面客户端模式初始化:跳过模拟器健康检查/full_recovery。"""
         logger.info('Desktop client mode: skip emulator health check and full recovery')
         if self.config.script.device.screenshot_method == 'auto':
+            # auto 是「自动选择」的语义,桌面模式自动落到后台截图,无需告警
+            self.config.script.device.screenshot_method = 'window_background'
+        elif self.config.script.device.screenshot_method != 'window_background':
+            logger.warning(
+                f'Desktop mode requires screenshot_method=window_background, '
+                f'current={self.config.script.device.screenshot_method}, overriding'
+            )
             self.config.script.device.screenshot_method = 'window_background'
         if self.config.script.device.control_method != 'window_message':
             logger.warning(

+ 1 - 1
module/device/device.py

@@ -250,7 +250,7 @@ class Device(DesktopDevice, Platform, Screenshot, Control, AppControl):
         if self.is_desktop:
             if not self._desktop_ensure_launched():
                 logger.error('Desktop client not running and auto-launch failed, '
-                             'please start the game manually or check desktop_game_path')
+                             'please start the game manually or check game_path')
                 raise GameNotRunningError('Desktop client auto-launch failed')
             # 这里必然早于 app_handle_login,且是拉起客户端的唯一入口:客户区没校准到
             # 1280x720 的话登录 OCR 与点击坐标全错。运行期重拉时 Device 对象是复用的,

+ 19 - 14
module/device/handle.py

@@ -18,7 +18,9 @@ from win32con import (SRCCOPY, DESKTOPHORZRES, DESKTOPVERTRES, WM_LBUTTONUP,
                       WM_LBUTTONDOWN, WM_ACTIVATE, WA_ACTIVE, MK_LBUTTON,
                       WM_NCHITTEST, WM_SETCURSOR, HTCLIENT, WM_MOUSEMOVE)
 from module.config.config import Config
-from module.device.method.desktop_impl import DesktopWindow, DESKTOP_WINDOW_TITLES
+from module.config.utils import desktop_mode_enabled
+from module.device.method.desktop_impl import DesktopWindow
+from module.exception import EmulatorNotRunningError
 from module.logger import logger
 
 
@@ -159,7 +161,7 @@ class Handle(DesktopWindow):
     }
     config: Config = None
     is_desktop_window: bool = False
-    """是否为桌面客户端模式(serial='desktop'),桌面分支统一用此标志隔离"""
+    """是否为桌面客户端模式(script.desktop.enable),桌面分支统一用此标志隔离"""
 
     def __init__(self, config) -> None:
         """
@@ -172,20 +174,23 @@ class Handle(DesktopWindow):
                 self.config = Config(config, task=None)
             else:
                 self.config = config
-        if not self.config.script.device.handle or self.config.script.device.handle == '':
-            logger.info('Handle is empty, oas not use handle')
-            return
-
-        # 桌面客户端模式:按 PID 定位窗口,跳过模拟器窗口树逻辑
-        if self.config.script.device.serial == 'desktop':
+        # 桌面模式:PID 只在运行时存在(不落配置),按「档案状态文件 → 窗口枚举」定位,
+        # 找不到抛错交给 Device.__init__ 自动拉起。须排在 handle 空判之前(桌面模式留空是常态)
+        if desktop_mode_enabled(self.config):
             self.root_handle_title = ''
             self.root_handle_num = 0
-            self.root_handle = self.config.script.device.handle
-            logger.info(f'Desktop handle PID is {self.root_handle}')
-            self.root_handle_num = self.find_desktop_window_by_pid(self.root_handle)
-            self.root_handle_title = DESKTOP_WINDOW_TITLES[0]
-            self.is_desktop_window = True
-            logger.info(f'Desktop client window found: title={self.root_handle_title}, hwnd={self.root_handle_num}')
+            self.root_handle = ''
+            pid, hwnd = self._desktop_locate_window()
+            if pid and hwnd:
+                self.desktop_bind_pid(pid, hwnd)
+                logger.info(f'Desktop client window bound: PID={pid}, hwnd={hwnd}')
+                return
+            if pid:
+                logger.info(f'Desktop client process alive (PID={pid}) but window not ready yet')
+            raise EmulatorNotRunningError('Desktop client window not found')
+
+        if not self.config.script.device.handle or self.config.script.device.handle == '':
+            logger.info('Handle is empty, oas not use handle')
             return
 
         # 获取根的句柄

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 670 - 184
module/device/method/desktop_impl.py


+ 2 - 0
module/device/method/windows_impl.py

@@ -95,6 +95,8 @@ class Window(Handle):
         与资产 1:1,客户区 DC 原点即画面左上角、不含标题栏,故无偏移、无缩放。
         """
         self.desktop_window_restore_if_minimized()
+        # 多开摆位重断言:客户端启动后会自行挪回屏幕中央,只在启动时摆一次压不住
+        self._desktop_assert_window_pos(self.root_handle_num)
         with dpi_awareness():
             client_rect = GetClientRect(self.screenshot_handle_num)
             widthScreen = client_rect[2] - client_rect[0]

+ 3 - 1
tasks/Script/config.py

@@ -4,6 +4,7 @@
 from pydantic import BaseModel, Field
 
 from tasks.Script.config_device import Device
+from tasks.Script.config_desktop import Desktop
 from tasks.Script.config_error import Error
 from tasks.Script.config_optimization import Optimization
 from tasks.Script.config_antiban import AntiBan
@@ -11,6 +12,7 @@ from tasks.Script.config_antiban import AntiBan
 
 class Script(BaseModel):
     device: Device = Field(default_factory=Device)
+    desktop: Desktop = Field(default_factory=Desktop)
     error: Error = Field(default_factory=Error)
     optimization: Optimization = Field(default_factory=Optimization)
-    anti_ban: AntiBan = Field(default_factory=AntiBan)
+    anti_ban: AntiBan = Field(default_factory=AntiBan)

+ 26 - 0
tasks/Script/config_desktop.py

@@ -0,0 +1,26 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from pydantic import BaseModel, Field
+
+
+class Desktop(BaseModel):
+    """桌面客户端(阴阳师 PC 版)模式开关与专属参数,与 device 组并列。
+
+    enable 为 True 时 OAS 不走 adb,直接控制本机 Windows 上的客户端窗口;
+    多开账号隔离见 profile_dir。
+    """
+
+    # 启用后 device 组的模拟器参数退场,handle 改作客户端窗口标题(留空自动识别)
+    enable: bool = Field(default=False, description='desktop_enable_help')
+    # 游戏安装目录(含 bin\onmyoji.exe 或 Launch.exe 的根目录),留空自动查找
+    game_path: str = Field(default='', description='game_path_help')
+    # 多开账号隔离:实例档案目录,每个配置一个
+    profile_dir: str = Field(default='', description='profile_dir_help')
+    # 多开时自动摆放窗口位置,格式 "x,y"(如 0,0 / 660,0);留空 = 不移动
+    window_pos: str = Field(default='', description='window_pos_help')
+    # 自定义窗口标题:绑定时改窗口标题,仅用于多开时在任务栏区分实例。
+    # 留空 = 不改;识别与点击不依赖标题
+    window_title: str = Field(default='', description='window_title_help')
+    # 一次性按钮:点击后启动本配置对应的客户端实例;执行后自动弹回 false
+    launch_instance: bool = Field(default=False, description='launch_instance_help')

+ 2 - 4
tasks/Script/config_device.py

@@ -50,14 +50,12 @@ class EmulatorInfoType(str, Enum):
     MEmuPlayer = 'MEmuPlayer'
 
 class Device(BaseModel):
+    # adb 序列号;桌面客户端模式(见 desktop 组)下本字段退场
     serial: str = Field(default="auto",
                         description='serial_help')
+    # 模拟器模式:窗口标题或句柄编号;桌面客户端模式:客户端窗口标题(留空自动识别)
     handle: str = Field(default='',
                         description='handle_help')
-    # 桌面客户端自动启动用:游戏安装目录(含 bin\onmyoji.exe 或 Launch.exe 的根目录),
-    # 留空时按 %ProgramFiles%\Onmyoji 与注册表 InstallLocation 自动发现;仅桌面模式使用
-    desktop_game_path: str = Field(default='',
-                                   description='desktop_game_path_help')
     package_name: PackageName = Field(title='Package Name',
                                       default=PackageName.AUTO,
                                       description='package_name_help')

Vissa filer visades inte eftersom för många filer har ändrats