自动启动配置的服务器列表
(self)
| 160 | return QRect(0, 0 if self.isFullScreen() else 9, 75, size.height()) |
| 161 | |
| 162 | def autoStartServers(self): |
| 163 | """自动启动配置的服务器列表""" |
| 164 | self.serverManagerInterface.refreshServers() |
| 165 | try: |
| 166 | import json |
| 167 | from MCSL2Lib.utils import readGlobalServerConfig |
| 168 | |
| 169 | # 读取需要自动启动的服务器列表 |
| 170 | auto_start_list = json.loads(cfg.get(cfg.autoStartServers) or "[]") |
| 171 | if not auto_start_list: |
| 172 | return |
| 173 | |
| 174 | # 读取全局服务器配置 |
| 175 | global_config = readGlobalServerConfig() |
| 176 | |
| 177 | # 为每个需要启动的服务器查找索引并触发开服按钮 |
| 178 | for server_name in auto_start_list: |
| 179 | # 在全局配置中查找服务器索引 |
| 180 | for index, server_cfg in enumerate(global_config): |
| 181 | if server_cfg.get("name") == server_name: |
| 182 | try: |
| 183 | # 查找对应的开服按钮并点击 |
| 184 | btn_name = f"startServer!{index}" |
| 185 | # 遍历 flowLayout 中的所有控件 |
| 186 | for i in range(self.serverManagerInterface.flowLayout.count()): |
| 187 | widget = self.serverManagerInterface.flowLayout.itemAt(i).widget() |
| 188 | if widget: |
| 189 | # 查找按钮 |
| 190 | run_btn = widget.findChild(object, btn_name) |
| 191 | if run_btn: |
| 192 | run_btn.click() |
| 193 | MCSL2Logger.info(f"自动启动服务器: {server_name}") |
| 194 | break |
| 195 | except Exception as e: |
| 196 | MCSL2Logger.error(f"自动启动服务器 {server_name} 失败: {e}") |
| 197 | break |
| 198 | except Exception as e: |
| 199 | MCSL2Logger.error(f"自动启动服务器 {server_name} 失败: {e}") |
| 200 | |
| 201 | def closeEvent(self, a0) -> None: |
| 202 | if self.consoleCenterInterface.isAnyServerRunning(): |
no test coverage detected