|
1 | 1 | import os |
2 | | -import sys |
| 2 | +import re |
3 | 3 | import subprocess |
| 4 | +import sys |
4 | 5 | import time |
5 | 6 | from pathlib import Path |
6 | 7 |
|
|
18 | 19 | # Add chrome.exe to environment variable |
19 | 20 | # Download chrome driver and add to environment variable |
20 | 21 |
|
| 22 | +def get_product_name(): |
| 23 | + """Get the product name from ProjectSettings.asset""" |
| 24 | + project_settings_path = Path(__file__).resolve().parent.parent.parent / 'ProjectSettings' / 'ProjectSettings.asset' |
| 25 | + |
| 26 | + if not project_settings_path.exists(): |
| 27 | + print(f"Warning: ProjectSettings.asset not found at {project_settings_path}") |
| 28 | + return "SampleApp" # Fallback to default |
| 29 | + |
| 30 | + with open(project_settings_path, 'r') as f: |
| 31 | + content = f.read() |
| 32 | + |
| 33 | + # Extract productName using regex |
| 34 | + match = re.search(r'productName: (.+)', content) |
| 35 | + if match: |
| 36 | + product_name = match.group(1).strip() |
| 37 | + return product_name |
| 38 | + |
| 39 | + # If regex fails, return default |
| 40 | + return "SampleApp" |
| 41 | + |
21 | 42 | def login(): |
22 | 43 | print("Connect to Chrome") |
23 | 44 | # Set up Chrome options to connect to the existing Chrome instance |
@@ -80,37 +101,40 @@ def login(): |
80 | 101 | driver.quit() |
81 | 102 |
|
82 | 103 | def open_sample_app(): |
83 | | - print("Opening Unity sample app...") |
84 | | - subprocess.Popen(["SampleApp.exe"], shell=True) |
| 104 | + product_name = get_product_name() |
| 105 | + print(f"Opening {product_name}...") |
| 106 | + subprocess.Popen([f"{product_name}.exe"], shell=True) |
85 | 107 | time.sleep(10) |
86 | | - print("Unity sample app opened successfully.") |
| 108 | + print(f"{product_name} opened successfully.") |
87 | 109 |
|
88 | 110 | def stop_sample_app(): |
89 | | - print("Stopping sample app...") |
90 | | - powershell_command = """ |
91 | | - $process = Get-Process -Name "SampleApp" -ErrorAction SilentlyContinue |
92 | | - if ($process) { |
| 111 | + product_name = get_product_name() |
| 112 | + print(f"Stopping {product_name}...") |
| 113 | + powershell_command = f""" |
| 114 | + $process = Get-Process -Name "{product_name}" -ErrorAction SilentlyContinue |
| 115 | + if ($process) {{ |
93 | 116 | Stop-Process -Id $process.Id |
94 | | - Write-Output "SampleApp.exe has been closed." |
95 | | - } else { |
96 | | - Write-Output "SampleApp.exe is not running." |
97 | | - } |
| 117 | + Write-Output "{product_name}.exe has been closed." |
| 118 | + }} else {{ |
| 119 | + Write-Output "{product_name}.exe is not running." |
| 120 | + }} |
98 | 121 | """ |
99 | 122 | subprocess.run(["powershell.exe", "-Command", powershell_command], check=True) |
100 | 123 | time.sleep(5) |
101 | | - print("Stopped sample app.") |
| 124 | + print(f"{product_name} stopped successfully.") |
102 | 125 |
|
103 | 126 | def bring_sample_app_to_foreground(): |
| 127 | + product_name = get_product_name() |
104 | 128 | powershell_script_path = "./switch-app.ps1" |
105 | | - |
106 | | - print("Bring Unity sample app to the foreground.") |
107 | | - |
| 129 | + |
| 130 | + print(f"Bring {product_name} to the foreground.") |
| 131 | + |
108 | 132 | command = [ |
109 | | - "powershell.exe", |
110 | | - "-Command", |
111 | | - f"Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process; & '{powershell_script_path}' -appName 'Immutable Sample'" |
| 133 | + "powershell.exe", |
| 134 | + "-Command", |
| 135 | + f"Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process; & '{powershell_script_path}' -appName '{product_name}'" |
112 | 136 | ] |
113 | | - |
| 137 | + |
114 | 138 | subprocess.run(command, check=True) |
115 | 139 | time.sleep(10) |
116 | 140 |
|
|
0 commit comments