mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-25 10:01:10 +00:00
Chore: [ALAS] Abstract platform condition
(cherry picked from commit 6064457620b202da7442884b45f9e21556df88b8)
This commit is contained in:
parent
df22d61aaa
commit
599579aee6
@ -3,7 +3,6 @@ import logging
|
|||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
import time
|
import time
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
@ -12,10 +11,10 @@ from adbutils import AdbClient, AdbDevice, AdbTimeout, ForwardItem, ReverseItem
|
|||||||
from adbutils.errors import AdbError
|
from adbutils.errors import AdbError
|
||||||
|
|
||||||
import module.config.server as server_
|
import module.config.server as server_
|
||||||
import platform
|
|
||||||
from module.base.decorator import Config, cached_property, del_cached_property, run_once
|
from module.base.decorator import Config, cached_property, del_cached_property, run_once
|
||||||
from module.base.utils import SelectedGrids, ensure_time
|
from module.base.utils import SelectedGrids, ensure_time
|
||||||
from module.device.connection_attr import ConnectionAttr
|
from module.device.connection_attr import ConnectionAttr
|
||||||
|
from module.device.env import IS_LINUX, IS_MACINTOSH, IS_WINDOWS
|
||||||
from module.device.method.utils import (
|
from module.device.method.utils import (
|
||||||
PackageNotInstalled, RETRY_TRIES, get_serial_pair, handle_adb_error,
|
PackageNotInstalled, RETRY_TRIES, get_serial_pair, handle_adb_error,
|
||||||
possible_reasons, random_port, recv_all, remove_shell_warning, retry_sleep)
|
possible_reasons, random_port, recv_all, remove_shell_warning, retry_sleep)
|
||||||
@ -337,7 +336,7 @@ class Connection(ConnectionAttr):
|
|||||||
logger.error(e)
|
logger.error(e)
|
||||||
logger.error(f'Unknown host name: {socket.gethostname()}')
|
logger.error(f'Unknown host name: {socket.gethostname()}')
|
||||||
host = '127.0.0.1'
|
host = '127.0.0.1'
|
||||||
if platform.system() == 'Linux' and host == '127.0.1.1':
|
if IS_LINUX and host == '127.0.1.1':
|
||||||
host = '127.0.0.1'
|
host = '127.0.0.1'
|
||||||
logger.info(f'Connecting to local emulator, using host {host}')
|
logger.info(f'Connecting to local emulator, using host {host}')
|
||||||
port = random_port(self.config.FORWARD_PORT_RANGE)
|
port = random_port(self.config.FORWARD_PORT_RANGE)
|
||||||
@ -841,7 +840,7 @@ class Connection(ConnectionAttr):
|
|||||||
# brute_force_connect
|
# brute_force_connect
|
||||||
if self.config.Emulator_Serial == 'auto' and available.count == 0:
|
if self.config.Emulator_Serial == 'auto' and available.count == 0:
|
||||||
logger.warning(f'No available device found')
|
logger.warning(f'No available device found')
|
||||||
if sys.platform == 'win32':
|
if IS_WINDOWS:
|
||||||
brute_force_connect()
|
brute_force_connect()
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
@ -903,7 +902,10 @@ class Connection(ConnectionAttr):
|
|||||||
self.serial = emu_serial
|
self.serial = emu_serial
|
||||||
|
|
||||||
# Redirect MuMu12 from 127.0.0.1:7555 to 127.0.0.1:16xxx
|
# Redirect MuMu12 from 127.0.0.1:7555 to 127.0.0.1:16xxx
|
||||||
if self.serial == '127.0.0.1:7555':
|
if (
|
||||||
|
(IS_WINDOWS and self.serial == '127.0.0.1:7555')
|
||||||
|
or (IS_MACINTOSH and self.serial == '127.0.0.1:5555')
|
||||||
|
):
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
mumu12 = available.select(may_mumu12_family=True)
|
mumu12 = available.select(may_mumu12_family=True)
|
||||||
if mumu12.count == 1:
|
if mumu12.count == 1:
|
||||||
@ -920,7 +922,8 @@ class Connection(ConnectionAttr):
|
|||||||
# is_mumu_over_version_356 and nemud_app_keep_alive was cached
|
# is_mumu_over_version_356 and nemud_app_keep_alive was cached
|
||||||
# Acceptable since it's the same device
|
# Acceptable since it's the same device
|
||||||
logger.warning(f'Device {self.serial} is MuMu12 but corresponding port not found')
|
logger.warning(f'Device {self.serial} is MuMu12 but corresponding port not found')
|
||||||
brute_force_connect()
|
if IS_WINDOWS:
|
||||||
|
brute_force_connect()
|
||||||
devices = self.list_device()
|
devices = self.list_device()
|
||||||
# Show available devices
|
# Show available devices
|
||||||
available = devices.select(status='device')
|
available = devices.select(status='device')
|
||||||
|
5
module/device/env.py
Normal file
5
module/device/env.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
IS_WINDOWS = sys.platform == 'win32'
|
||||||
|
IS_MACINTOSH = sys.platform == 'darwin'
|
||||||
|
IS_LINUX = sys.platform == 'linux'
|
@ -1,6 +1,6 @@
|
|||||||
import sys
|
from module.device.env import IS_WINDOWS
|
||||||
|
|
||||||
if sys.platform == 'win32':
|
if IS_WINDOWS:
|
||||||
from module.device.platform.platform_windows import PlatformWindows as Platform
|
from module.device.platform.platform_windows import PlatformWindows as Platform
|
||||||
else:
|
else:
|
||||||
from module.device.platform.platform_base import PlatformBase as Platform
|
from module.device.platform.platform_base import PlatformBase as Platform
|
||||||
|
Loading…
Reference in New Issue
Block a user