Skip to content

Commit

Permalink
fix : unable to open emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
pur1fying committed Sep 15, 2024
1 parent 8ad668d commit 655b55f
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions device_operation/process_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,35 @@ def match_lists(target_args: list[str], process_cmdline: list[str]):
return False
return True


def extract_args(emulator_path: str) -> tuple[str, list[str]]:
# Resolve the emulator's actual executable path from a shortcut if provided
if emulator_path.endswith('.lnk'):
shell = win32com.client.Dispatch("WScript.Shell")
shortcut = shell.CreateShortCut(emulator_path)
emulator_path = os.path.abspath(shortcut.Targetpath)

# Extract command line arguments from the shortcut
arguments = shortcut.Arguments
arguments = arguments.split(" ")
if arguments == [""]:
arguments = None
else:
# No .lnk file, so there are no additional arguments
arguments = None
arguments = [""]

return emulator_path, arguments



def start(emulator_path: str):
if os.path.isfile(emulator_path):
directory = os.path.dirname(emulator_path)
path, args = extract_args(emulator_path)
subprocess.Popen([path] + args, shell=True, cwd=directory)


def is_running(emulator_path) -> Union[psutil.Process, None]:
# Initialize the COM library
pythoncom.CoInitialize()

emulator_path, target_args = extract_args(emulator_path)

# Iterate over all running processes
Expand All @@ -57,11 +58,12 @@ def is_running(emulator_path) -> Union[psutil.Process, None]:
if (os.path.normcase(process_exe) == os.path.normcase(emulator_path)):
if target_args is None or (process_cmdline and match_lists(target_args, process_cmdline)):
p = psutil.Process(process_info['pid'])
return p # Emulator process is running
return p # Emulator process is running
except Exception as e:
print(e)
return None


def terminate(emulator_path: str) -> bool:
p = is_running(emulator_path)
try:
Expand All @@ -70,5 +72,5 @@ def terminate(emulator_path: str) -> bool:
return True # Emulator process terminated successfully
except Exception as e:
print(e)

return False # Emulator process not found or termination failed

0 comments on commit 655b55f

Please sign in to comment.