|
12 | 12 | import ms_toollib as ms |
13 | 13 | import ctypes |
14 | 14 | # from ctypes import wintypes |
15 | | -from mp_plugins.context import AppContext |
16 | | -from mp_plugins.events import * |
17 | | -from mp_plugins import PluginManager |
18 | 15 | from pathlib import Path |
19 | 16 | from utils import get_paths, patch_env |
20 | 17 |
|
21 | | -os.environ["QT_FONT_DPI"] = "96" |
22 | | - |
| 18 | +# 插件系统(新) |
| 19 | +from plugin_manager import GameServerBridge |
| 20 | +from plugin_manager.app_paths import get_env_for_subprocess |
| 21 | +import subprocess |
23 | 22 |
|
| 23 | +os.environ["QT_FONT_DPI"] = "96" |
24 | 24 |
|
25 | 25 |
|
26 | 26 | def on_new_connection(localServer: QLocalServer): |
@@ -150,31 +150,42 @@ def cli_check_file(file_path: str) -> int: |
150 | 150 | localServer.newConnection.connect( |
151 | 151 | lambda: on_new_connection(localServer=localServer) |
152 | 152 | ) |
153 | | - env = patch_env() |
154 | | - context = AppContext(name="Metasweeper", version="1.0.0", display_name="元扫雷", |
155 | | - plugin_dir=(Path(get_paths()) / |
156 | | - "plugins").as_posix(), |
157 | | - app_dir=get_paths() |
158 | | - ) |
159 | | - PluginManager.instance().context = context |
160 | | - |
161 | | - PluginManager.instance().start(Path(get_paths()) / "plugins", env) |
162 | 153 | mainWindow = mainWindowGUI.MainWindow() |
163 | 154 | ui = mineSweeperGUI.MineSweeperGUI(mainWindow, sys.argv) |
164 | 155 | ui.mainWindow.show() |
165 | | - # ui.mainWindow.game_setting = ui.game_setting |
| 156 | + |
| 157 | + # ── 启动 ZMQ Server + 插件管理器 ── |
| 158 | + game_server = GameServerBridge(ui) |
| 159 | + plugin_process = subprocess.Popen( |
| 160 | + [sys.executable, "-m", "plugin_manager", "--mode", "tray"], |
| 161 | + cwd=os.path.dirname(os.path.abspath(__file__)), |
| 162 | + env=get_env_for_subprocess(), |
| 163 | + ) |
| 164 | + ui._plugin_process = plugin_process # 保存引用,防止被 GC |
| 165 | + |
| 166 | + # 连接信号:插件发来的新游戏指令 → 主线程处理 |
| 167 | + game_server.signals.new_game_requested.connect(lambda r, c, m: None) # TODO: 接入游戏逻辑 |
| 168 | + |
| 169 | + game_server.start() |
166 | 170 |
|
167 | 171 | # _translate = QtCore.QCoreApplication.translate |
168 | 172 | hwnd = int(ui.mainWindow.winId()) |
169 | 173 |
|
170 | 174 | SetWindowDisplayAffinity = ctypes.windll.user32.SetWindowDisplayAffinity |
171 | 175 | ui.disable_screenshot = lambda: ... if SetWindowDisplayAffinity( |
172 | 176 | hwnd, 0x00000011) else 1/0 |
173 | | - ui.enable_screenshot = lambda: ... if SetWindowDisplayAffinity( |
174 | | - hwnd, 0x00000000) else 1/0 |
175 | | - app.aboutToQuit.connect(PluginManager.instance().stop) |
| 177 | + ui.enable_screenshot = lambda: ( |
| 178 | + ... if SetWindowDisplayAffinity(hwnd, 0x00000000) else 1 / 0 |
| 179 | + ) |
| 180 | + |
| 181 | + def _cleanup(): |
| 182 | + game_server.stop() |
| 183 | + if plugin_process.poll() is None: |
| 184 | + plugin_process.terminate() |
| 185 | + plugin_process.wait(timeout=5) |
| 186 | + |
| 187 | + app.aboutToQuit.connect(_cleanup) |
176 | 188 | sys.exit(app.exec_()) |
177 | | - ... |
178 | 189 | # except: |
179 | 190 | # pass |
180 | 191 |
|
|
0 commit comments