|
53 | 53 |
|
54 | 54 | # Toggle to True for development purposes |
55 | 55 | DEVELOPMENT = False |
56 | | -DEVELOPMENT_CONFIG = "Xperia Z" # "Pixel 3a" |
| 56 | +DEVELOPMENT_CONFIG = "a3y17lte" # "sargo" |
57 | 57 |
|
58 | 58 |
|
59 | 59 | PLATFORM = sys.platform |
60 | 60 | logger.info(f"Running OpenAndroidInstaller on {PLATFORM}") |
61 | 61 | # Define asset paths |
62 | 62 | CONFIG_PATH = Path(__file__).parent.joinpath(Path("assets/configs")).resolve() |
63 | 63 | IMAGE_PATH = Path(__file__).parent.joinpath(Path("assets/imgs")).resolve() |
| 64 | +BIN_PATH = Path(__file__).parent.joinpath(Path("bin")).resolve() |
64 | 65 |
|
65 | 66 |
|
66 | 67 | class BaseView(UserControl): |
@@ -177,60 +178,58 @@ def close_developer_options_dlg(self, e): |
177 | 178 | self.page.update() |
178 | 179 |
|
179 | 180 | def search_devices(self, e): |
| 181 | + """Search the device when the button is clicked.""" |
| 182 | + logger.info("Search devices...") |
180 | 183 | try: |
181 | 184 | # read device properties |
182 | 185 | # TODO: This is not windows ready... |
183 | | - if PLATFORM in ("linux", "MacOS"): |
| 186 | + if PLATFORM in ("linux", "darwin"): |
184 | 187 | output = check_output( |
185 | 188 | [ |
186 | | - "adb", |
| 189 | + str(BIN_PATH.joinpath(Path("adb"))), |
187 | 190 | "shell", |
188 | | - "dumpsys", |
189 | | - "bluetooth_manager", |
| 191 | + "getprop", |
190 | 192 | "|", |
191 | 193 | "grep", |
192 | | - "'name:'", |
193 | | - "|", |
194 | | - "cut", |
195 | | - "-c9-", |
| 194 | + "ro.product.device" |
196 | 195 | ], |
197 | 196 | stderr=STDOUT, |
198 | 197 | ).decode() |
199 | 198 | elif PLATFORM == "windows": |
200 | 199 | output = check_output( |
201 | 200 | [ |
202 | | - "adb", |
| 201 | + str(BIN_PATH.joinpath(Path("adb"))), |
203 | 202 | "shell", |
204 | | - "dumpsys", |
205 | | - "bluetooth_manager", |
| 203 | + "getprop", |
206 | 204 | "|", |
207 | 205 | "findstr", |
208 | | - "'name:'", |
209 | | - "|", |
210 | | - "-split", |
211 | | - "-c9-", |
| 206 | + "ro.product.device" |
212 | 207 | ], |
213 | 208 | stderr=STDOUT, |
214 | 209 | ).decode() |
215 | 210 | else: |
216 | 211 | raise Exception(f"Unknown platform {PLATFORM}.") |
217 | 212 |
|
| 213 | + output = output.split("[")[-1][:-2] |
| 214 | + logger.info(f"Detected {output}") |
| 215 | + # write the device code to the text shown in the box |
218 | 216 | self.device_name.value = output.strip() |
219 | 217 | # load config from file |
220 | | - # path = f"{CONFIG_PATH}/{output.strip()}.yaml" |
221 | 218 | path = CONFIG_PATH.joinpath(Path(f"{output.strip()}.yaml")) |
222 | 219 | load_config_success = self.load_config(path) |
| 220 | + # display success in the application |
223 | 221 | if load_config_success: |
224 | 222 | self.config_found_box.value = True |
225 | 223 | self.continue_button.disabled = False |
| 224 | + # overwrite the text field with the real name from the config |
| 225 | + self.device_name.value = f"{load_config_success} (code: {output.strip()})" |
226 | 226 | else: |
227 | 227 | # show alternative configs here |
228 | 228 | # select a new path and load again |
229 | 229 | pass |
230 | 230 | except CalledProcessError: |
231 | 231 | if DEVELOPMENT: |
232 | 232 | path = CONFIG_PATH.joinpath(Path(f"{DEVELOPMENT_CONFIG}.yaml")) |
233 | | - # path = f"{CONFIG_PATH}/{DEVELOPMENT_CONFIG}.yaml" |
234 | 233 | load_config_success = self.load_config(path) |
235 | 234 | if load_config_success: |
236 | 235 | self.config_found_box.value = True |
@@ -428,7 +427,7 @@ def load_config(self, path: str): |
428 | 427 | try: |
429 | 428 | self.config = InstallerConfig.from_file(path) |
430 | 429 | self.num_total_steps = len(self.config.steps) |
431 | | - return True |
| 430 | + return self.config.metadata.get("devicename", "No device name in config.") |
432 | 431 | except FileNotFoundError: |
433 | 432 | return False |
434 | 433 |
|
@@ -501,6 +500,11 @@ def build(self): |
501 | 500 | return self.view |
502 | 501 |
|
503 | 502 | def call_to_phone(self, e, command: str): |
| 503 | + # TODO: use proper windows paths |
| 504 | + command = command.replace("adb", str(BIN_PATH.joinpath(Path("adb")))) |
| 505 | + command = command.replace("fastboot", str(BIN_PATH.joinpath(Path("fastboot")))) |
| 506 | + command = command.replace("heimdall", str(BIN_PATH.joinpath(Path("heimdall")))) |
| 507 | + |
504 | 508 | command = command.replace("<recovery>", self.recovery_path) |
505 | 509 | command = command.replace("<image>", self.image_path) |
506 | 510 | command = command.replace("<inputtext>", self.inputtext.value) |
|
0 commit comments