diff --git a/config/template.json b/config/template.json index 0030248cd..dca99cc0a 100644 --- a/config/template.json +++ b/config/template.json @@ -9,12 +9,6 @@ "ScreenshotDedithering": false, "AdbRestart": false }, - "RestartEmulator": { - "Enable": false, - "EmulatorData": "emulator:\nname:\npath:", - "ErrorRestart": false, - "DailyRestart": false - }, "Error": { "HandleError": true, "SaveError": true, @@ -75,6 +69,15 @@ "FailureInterval": 0, "ServerUpdate": "00:00" }, + "RestartEmulator": { + "Enable": false, + "DailyRestart": false + }, + "EmulatorInfo": { + "Emulator": "auto", + "name": null, + "path": null + }, "Storage": { "Storage": {} } diff --git a/module/config/argument/args.json b/module/config/argument/args.json index aace53a6d..2eb17f7cb 100644 --- a/module/config/argument/args.json +++ b/module/config/argument/args.json @@ -133,25 +133,6 @@ "value": false } }, - "RestartEmulator": { - "Enable": { - "type": "checkbox", - "value": false - }, - "EmulatorData": { - "type": "textarea", - "value": "emulator:\nname:\npath:", - "mode": "yaml" - }, - "ErrorRestart": { - "type": "checkbox", - "value": false - }, - "DailyRestart": { - "type": "checkbox", - "value": false - } - }, "Error": { "HandleError": { "type": "checkbox", @@ -394,6 +375,46 @@ "display": "hide" } }, + "RestartEmulator": { + "Enable": { + "type": "checkbox", + "value": false + }, + "DailyRestart": { + "type": "checkbox", + "value": false + } + }, + "EmulatorInfo": { + "Emulator": { + "type": "select", + "value": "auto", + "option": [ + "auto", + "NoxPlayer", + "NoxPlayer64", + "BlueStacks4", + "BlueStacks5", + "BlueStacks4HyperV", + "BlueStacks5HyperV", + "LDPlayer3", + "LDPlayer4", + "LDPlayer9", + "MumuPlayer", + "MumuPlayer9", + "MumuPlayer12", + "MemuPlayer" + ] + }, + "name": { + "type": "textarea", + "value": null + }, + "path": { + "type": "textarea", + "value": null + } + }, "Storage": { "Storage": { "type": "storage", diff --git a/module/config/argument/argument.yaml b/module/config/argument/argument.yaml index 632bbede2..605baa7ec 100644 --- a/module/config/argument/argument.yaml +++ b/module/config/argument/argument.yaml @@ -37,15 +37,32 @@ Emulator: AdbRestart: false RestartEmulator: Enable: false - EmulatorData: - type: textarea - mode: yaml - value: |- - emulator: - name: - path: - ErrorRestart: False DailyRestart: False +EmulatorInfo: + Emulator: + value: auto + option: [ + auto, + NoxPlayer, + NoxPlayer64, + BlueStacks4, + BlueStacks5, + BlueStacks4HyperV, + BlueStacks5HyperV, + LDPlayer3, + LDPlayer4, + LDPlayer9, + MumuPlayer, + MumuPlayer9, + MumuPlayer12, + MemuPlayer, + ] + name: + value: null + type: textarea + path: + value: null + type: textarea Error: HandleError: true SaveError: true diff --git a/module/config/argument/task.yaml b/module/config/argument/task.yaml index 7b7770e69..ac5496339 100644 --- a/module/config/argument/task.yaml +++ b/module/config/argument/task.yaml @@ -6,7 +6,6 @@ Alas: - Emulator - - RestartEmulator - Error - Optimization - DropRecord @@ -17,6 +16,8 @@ General: - OldRetire Restart: - Scheduler + - RestartEmulator + - EmulatorInfo # ==================== Farm ==================== diff --git a/module/config/config_generated.py b/module/config/config_generated.py index 13b204f57..02eaee9aa 100644 --- a/module/config/config_generated.py +++ b/module/config/config_generated.py @@ -28,10 +28,13 @@ class GeneratedConfig: # Group `RestartEmulator` RestartEmulator_Enable = False - RestartEmulator_EmulatorData = 'emulator:\nname:\npath:' - RestartEmulator_ErrorRestart = False RestartEmulator_DailyRestart = False + # Group `EmulatorInfo` + EmulatorInfo_Emulator = 'auto' # auto, NoxPlayer, NoxPlayer64, BlueStacks4, BlueStacks5, BlueStacks4HyperV, BlueStacks5HyperV, LDPlayer3, LDPlayer4, LDPlayer9, MumuPlayer, MumuPlayer9, MumuPlayer12, MemuPlayer + EmulatorInfo_name = None + EmulatorInfo_path = None + # Group `Error` Error_HandleError = True Error_SaveError = True diff --git a/module/config/i18n/en-US.json b/module/config/i18n/en-US.json index 038ba4fc1..01bf03a44 100644 --- a/module/config/i18n/en-US.json +++ b/module/config/i18n/en-US.json @@ -422,19 +422,43 @@ "name": "RestartEmulator.Enable.name", "help": "RestartEmulator.Enable.help" }, - "EmulatorData": { - "name": "RestartEmulator.EmulatorData.name", - "help": "RestartEmulator.EmulatorData.help" - }, - "ErrorRestart": { - "name": "Restart Emulator on Error", - "help": "Automatically restart the emulator when it cannot be connected" - }, "DailyRestart": { "name": "Restart Emulator when Server Refreshes", "help": "Restart emulator every day to solve the memory leak problem" } }, + "EmulatorInfo": { + "_info": { + "name": "EmulatorInfo._info.name", + "help": "EmulatorInfo._info.help" + }, + "Emulator": { + "name": "EmulatorInfo.Emulator.name", + "help": "EmulatorInfo.Emulator.help", + "auto": "auto", + "NoxPlayer": "NoxPlayer", + "NoxPlayer64": "NoxPlayer64", + "BlueStacks4": "BlueStacks4", + "BlueStacks5": "BlueStacks5", + "BlueStacks4HyperV": "BlueStacks4HyperV", + "BlueStacks5HyperV": "BlueStacks5HyperV", + "LDPlayer3": "LDPlayer3", + "LDPlayer4": "LDPlayer4", + "LDPlayer9": "LDPlayer9", + "MumuPlayer": "MumuPlayer", + "MumuPlayer9": "MumuPlayer9", + "MumuPlayer12": "MumuPlayer12", + "MemuPlayer": "MemuPlayer" + }, + "name": { + "name": "EmulatorInfo.name.name", + "help": "EmulatorInfo.name.help" + }, + "path": { + "name": "EmulatorInfo.path.name", + "help": "EmulatorInfo.path.help" + } + }, "Error": { "_info": { "name": "Debug Settings", diff --git a/module/config/i18n/ja-JP.json b/module/config/i18n/ja-JP.json index 9ef79a8ff..39ad2899c 100644 --- a/module/config/i18n/ja-JP.json +++ b/module/config/i18n/ja-JP.json @@ -422,19 +422,43 @@ "name": "RestartEmulator.Enable.name", "help": "RestartEmulator.Enable.help" }, - "EmulatorData": { - "name": "RestartEmulator.EmulatorData.name", - "help": "RestartEmulator.EmulatorData.help" - }, - "ErrorRestart": { - "name": "RestartEmulator.ErrorRestart.name", - "help": "RestartEmulator.ErrorRestart.help" - }, "DailyRestart": { "name": "RestartEmulator.DailyRestart.name", "help": "RestartEmulator.DailyRestart.help" } }, + "EmulatorInfo": { + "_info": { + "name": "EmulatorInfo._info.name", + "help": "EmulatorInfo._info.help" + }, + "Emulator": { + "name": "EmulatorInfo.Emulator.name", + "help": "EmulatorInfo.Emulator.help", + "auto": "auto", + "NoxPlayer": "NoxPlayer", + "NoxPlayer64": "NoxPlayer64", + "BlueStacks4": "BlueStacks4", + "BlueStacks5": "BlueStacks5", + "BlueStacks4HyperV": "BlueStacks4HyperV", + "BlueStacks5HyperV": "BlueStacks5HyperV", + "LDPlayer3": "LDPlayer3", + "LDPlayer4": "LDPlayer4", + "LDPlayer9": "LDPlayer9", + "MumuPlayer": "MumuPlayer", + "MumuPlayer9": "MumuPlayer9", + "MumuPlayer12": "MumuPlayer12", + "MemuPlayer": "MemuPlayer" + }, + "name": { + "name": "EmulatorInfo.name.name", + "help": "EmulatorInfo.name.help" + }, + "path": { + "name": "EmulatorInfo.path.name", + "help": "EmulatorInfo.path.help" + } + }, "Error": { "_info": { "name": "Error._info.name", diff --git a/module/config/i18n/zh-CN.json b/module/config/i18n/zh-CN.json index 80673e017..e8492bc49 100644 --- a/module/config/i18n/zh-CN.json +++ b/module/config/i18n/zh-CN.json @@ -419,20 +419,44 @@ "help": "" }, "Enable": { - "name": "RestartEmulator.Enable.name", - "help": "RestartEmulator.Enable.help" - }, - "EmulatorData": { - "name": "RestartEmulator.EmulatorData.name", - "help": "RestartEmulator.EmulatorData.help" - }, - "ErrorRestart": { - "name": "出错时重启模拟器", - "help": "在无法连接到模拟器时自动重启模拟器" + "name": "启用模拟器控制", + "help": "启用后 Alas 可以自动启动模拟器并登录游戏" }, "DailyRestart": { "name": "服务器刷新时重启模拟器", - "help": "每天主动重启模拟器以解决内存泄漏问题" + "help": "每天0点主动重启模拟器以解决内存泄漏问题" + } + }, + "EmulatorInfo": { + "_info": { + "name": "模拟器设置", + "help": "下列数值是根据Serial自动填充的,如果不懂请不要随意修改" + }, + "Emulator": { + "name": "模拟器类型", + "help": "", + "auto": "自动检测", + "NoxPlayer": "夜神模拟器", + "NoxPlayer64": "夜神模拟器64位", + "BlueStacks4": "蓝叠模拟器4", + "BlueStacks5": "蓝叠模拟器5", + "BlueStacks4HyperV": "蓝叠模拟器4 Hyper-V", + "BlueStacks5HyperV": "蓝叠模拟器5 Hyper-V", + "LDPlayer3": "雷电模拟器3", + "LDPlayer4": "雷电模拟器4", + "LDPlayer9": "雷电模拟器9", + "MumuPlayer": "MuMu模拟器", + "MumuPlayer9": "MuMu模拟器X", + "MumuPlayer12": "MuMu模拟器12", + "MemuPlayer": "逍遥模拟器" + }, + "name": { + "name": "模拟器实例名称", + "help": "" + }, + "path": { + "name": "模拟器安装路径", + "help": "" } }, "Error": { diff --git a/module/config/i18n/zh-TW.json b/module/config/i18n/zh-TW.json index 108562b71..8754132b0 100644 --- a/module/config/i18n/zh-TW.json +++ b/module/config/i18n/zh-TW.json @@ -422,19 +422,43 @@ "name": "RestartEmulator.Enable.name", "help": "RestartEmulator.Enable.help" }, - "EmulatorData": { - "name": "RestartEmulator.EmulatorData.name", - "help": "RestartEmulator.EmulatorData.help" - }, - "ErrorRestart": { - "name": "啟用重啓模擬器", - "help": "在模擬器被關閉的時候自動啟動模擬器" - }, "DailyRestart": { "name": "服務器重繪時重啓模擬器", "help": "每天主動重啓模擬器以解决記憶體洩漏問題" } }, + "EmulatorInfo": { + "_info": { + "name": "EmulatorInfo._info.name", + "help": "EmulatorInfo._info.help" + }, + "Emulator": { + "name": "EmulatorInfo.Emulator.name", + "help": "EmulatorInfo.Emulator.help", + "auto": "auto", + "NoxPlayer": "NoxPlayer", + "NoxPlayer64": "NoxPlayer64", + "BlueStacks4": "BlueStacks4", + "BlueStacks5": "BlueStacks5", + "BlueStacks4HyperV": "BlueStacks4HyperV", + "BlueStacks5HyperV": "BlueStacks5HyperV", + "LDPlayer3": "LDPlayer3", + "LDPlayer4": "LDPlayer4", + "LDPlayer9": "LDPlayer9", + "MumuPlayer": "MumuPlayer", + "MumuPlayer9": "MumuPlayer9", + "MumuPlayer12": "MumuPlayer12", + "MemuPlayer": "MemuPlayer" + }, + "name": { + "name": "EmulatorInfo.name.name", + "help": "EmulatorInfo.name.help" + }, + "path": { + "name": "EmulatorInfo.path.name", + "help": "EmulatorInfo.path.help" + } + }, "Error": { "_info": { "name": "除錯設定", diff --git a/module/device/platform/emulator_base.py b/module/device/platform/emulator_base.py index 61190cce0..bdc34e12b 100644 --- a/module/device/platform/emulator_base.py +++ b/module/device/platform/emulator_base.py @@ -59,6 +59,8 @@ class EmulatorBase: NoxPlayerFamily = [NoxPlayer, NoxPlayer64] BlueStacks4 = 'BlueStacks4' BlueStacks5 = 'BlueStacks5' + BlueStacks4HyperV = 'BlueStacks4HyperV' + BlueStacks5HyperV = 'BlueStacks5HyperV' BlueStacksFamily = [BlueStacks4, BlueStacks5] LDPlayer3 = 'LDPlayer3' LDPlayer4 = 'LDPlayer4' diff --git a/module/device/platform/platform_base.py b/module/device/platform/platform_base.py index daae6d02b..465f443f4 100644 --- a/module/device/platform/platform_base.py +++ b/module/device/platform/platform_base.py @@ -11,14 +11,14 @@ from module.logger import logger from module.map.map_grids import SelectedGrids -class EmulatorData(BaseModel): +class EmulatorInfo(BaseModel): emulator: str = '' name: str = '' path: str = '' # For APIs of chinac.com, a phone cloud platform. - access_key: SecretStr = '' - secret: SecretStr = '' + # access_key: SecretStr = '' + # secret: SecretStr = '' class PlatformBase(Connection, EmulatorManagerBase): @@ -46,14 +46,16 @@ class PlatformBase(Connection, EmulatorManagerBase): logger.info(f'Current platform {sys.platform} does not support emulator_stop, skip') @cached_property - def emulator_data(self) -> EmulatorData: - try: - data = yaml.safe_load(self.config.RestartEmulator_EmulatorData) - return EmulatorData(**data) - except Exception as e: - logger.error(e) - logger.error("Failed to load EmulatorData, no emulator_instance") - return EmulatorData() + def emulator_info(self) -> EmulatorInfo: + emulator = self.config.EmulatorInfo_Emulator + name = str(self.config.EmulatorInfo_name).strip().replace('\n', '') + path = str(self.config.EmulatorInfo_path).strip().replace('\n', '') + + return EmulatorInfo( + emulator=emulator, + name=name, + path=path, + ) @cached_property def emulator_instance(self) -> t.Optional[EmulatorInstanceBase]: @@ -61,7 +63,7 @@ class PlatformBase(Connection, EmulatorManagerBase): Returns: EmulatorInstanceBase: Emulator instance or None """ - data = self.emulator_data + data = self.emulator_info old_info = dict( emulator=data.emulator, path=data.path, @@ -75,14 +77,18 @@ class PlatformBase(Connection, EmulatorManagerBase): ) # Write complete emulator data - new_info = dict( - emulator=instance.type, - path=instance.path, - name=instance.name, - ) - if new_info != old_info: - self.config.RestartEmulator_EmulatorData = yaml.safe_dump(new_info).strip() - del_cached_property(self, 'emulator_data') + if instance is not None: + new_info = dict( + emulator=instance.type, + path=instance.path, + name=instance.name, + ) + if new_info != old_info: + with self.config.multi_set(): + self.config.EmulatorInfo_Emulator = instance.type + self.config.EmulatorInfo_name = instance.name + self.config.EmulatorInfo_path = instance.path + del_cached_property(self, 'emulator_info') return instance