Skip to content

Commit

Permalink
Add a request device button if no config for the device code is found…
Browse files Browse the repository at this point in the history
…; improve logging in this case
  • Loading branch information
tsterbak committed Jun 28, 2023
1 parent 1ac4e7a commit 3e24422
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
6 changes: 3 additions & 3 deletions openandroidinstaller/installer_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ def from_file(cls, path):
metadata = config["metadata"]
requirements = config.get("requirements", None)
else:
logger.info("Validation of config failed.")
logger.error(f"Validation of config at {path} failed.")
return None
except yaml.YAMLError as exc:
logger.info(exc)
logger.error(f"Loading the config from {path} failed with {exc}")
return None

if raw_steps.get("unlock_bootloader") is not None:
Expand Down Expand Up @@ -137,7 +137,7 @@ def _load_config(device_code: str, config_path: Path) -> Optional[InstallerConfi
logger.info(f"Config metadata: {config.metadata}.")
return config
else:
logger.info(f"No device config found for {path}.")
logger.info(f"No device config found for device code '{device_code}'.")
return None


Expand Down
2 changes: 1 addition & 1 deletion openandroidinstaller/tooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def search_device(platform: str, bin_path: Path) -> Optional[str]:
else:
raise Exception(f"Unknown platform {platform}.")
device_code = output.split("[")[-1].strip()[:-1].strip()
logger.info(device_code)
logger.info(f"Found device code '{device_code}'")
return device_code
except CalledProcessError:
logger.error("Failed to detect a device.")
Expand Down
36 changes: 26 additions & 10 deletions openandroidinstaller/views/start_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# Author: Tobias Sterbak

import copy
import webbrowser
from loguru import logger
from typing import Callable

Expand Down Expand Up @@ -122,6 +123,13 @@ def check_bootloader_unlocked(e):
self.device_detection_infobox = Row(
[Text("Detected device:"), self.device_name]
)
self.device_request_row = Row([], alignment="center")
self.device_infobox = Column(
[
self.device_detection_infobox,
self.device_request_row,
]
)

def build(self):
self.clear()
Expand Down Expand Up @@ -176,17 +184,13 @@ def build(self):
),
Row([self.bootloader_switch]),
Divider(),
Column(
[
self.device_detection_infobox,
]
),
self.device_infobox,
Row(
[
self.back_button,
FilledButton(
"Search for device",
on_click=self.search_devices,
on_click=self.search_devices_clicked,
icon=icons.DEVICES_OTHER_OUTLINED,
expand=True,
tooltip="Search for a connected device.",
Expand All @@ -210,8 +214,9 @@ def close_developer_options_dlg(self, e):
self.dlg_help_developer_options.open = False
self.page.update()

def search_devices(self, e):
def search_devices_clicked(self, e):
"""Search the device when the button is clicked."""
self.device_request_row.controls.clear()
# search the device
if self.state.test:
# this only happens for testing
Expand Down Expand Up @@ -258,10 +263,21 @@ def search_devices(self, e):
if len(self.state.config.unlock_bootloader) == 0:
self.bootloader_switch.value = True
else:
# failed to load config
logger.error(f"Failed to load config for {device_code}.")
# failed to load config or device is not supported
logger.error(
f"Device with code '{device_code}' is not supported or the config is corrupted. Please check the logs for more information."
)
self.device_name.value = (
f"Failed to load config for device with code {device_code}."
f"Device with code '{device_code}' is not supported yet."
)
# add request support for device button
request_url = f"https://github.com/openandroidinstaller-dev/openandroidinstaller/issues/new?assignees=&labels=device&projects=&template=device-support-request.md&title=Add support for {device_code}"
self.device_request_row.controls.append(
ElevatedButton(
"Request support for this device",
icon=icons.PHONELINK_SETUP_OUTLINED,
on_click=lambda _: webbrowser.open(request_url),
)
)
self.device_name.color = colors.RED
self.view.update()

0 comments on commit 3e24422

Please sign in to comment.