Skip to content

Commit

Permalink
Clean up and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tsterbak committed Jan 17, 2023
1 parent f2ae4a6 commit 0462a30
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 20 deletions.
3 changes: 2 additions & 1 deletion openandroidinstaller/installer_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def __init__(
self.metadata = metadata
self.requirements = requirements
self.device_code = metadata.get("devicecode")
self.alternative_device_code = self.device_code_mapping.get(
inverted_mapping = dict(map(reversed, self.device_code_mapping.items()))
self.alternative_device_code = inverted_mapping.get(
self.device_code, self.device_code
)

Expand Down
16 changes: 1 addition & 15 deletions openandroidinstaller/tooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,6 @@ def heimdall_flash_recovery(bin_path: Path, recovery: str) -> bool:
def search_device(platform: str, bin_path: Path) -> Optional[str]:
"""Search for a connected device."""
logger.info(f"Search devices on {platform} with {bin_path}...")
# map some detected device codes to their real code.
device_code_mapping = {
# Sony issues
"C6603": "yuga",
# OnePlus issues
"OnePlus6": "enchilada",
"OnePlus6T": "fajita",
"OnePlus7": "guacamoleb",
"OnePlus7Pro": "guacamole",
"OnePlus7T": "hotdogb",
"OnePlus7TPro": "hotdog",
"Nord": "avicii",
"NordN200": "dre",
}
try:
# read device properties
if platform in ("linux", "darwin"):
Expand Down Expand Up @@ -348,7 +334,7 @@ def search_device(platform: str, bin_path: Path) -> Optional[str]:
raise Exception(f"Unknown platform {platform}.")
device_code = output.split("[")[-1].strip()[:-1].strip()
logger.info(device_code)
return device_code_mapping.get(device_code, device_code)
return device_code
except CalledProcessError:
logger.error("Failed to detect a device.")
return None
6 changes: 3 additions & 3 deletions openandroidinstaller/views/select_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def build(self):
"Download TWRP recovery",
icon=icons.DOWNLOAD_OUTLINED,
on_click=lambda _: webbrowser.open(
f"https://dl.twrp.me/{self.state.config.metadata.get('devicecode')}"
f"https://dl.twrp.me/{self.state.config.device_code}"
),
expand=True,
),
Expand All @@ -164,7 +164,7 @@ def build(self):
Text("Select an OS image:", style="titleSmall"),
Markdown(
f"""
The image file should look something like `lineage-19.1-20221101-nightly-{self.state.config.metadata.get('devicecode')}-signed.zip`."""
The image file should look something like `lineage-19.1-20221101-nightly-{self.state.config.device_code}-signed.zip`."""
),
Row(
[
Expand All @@ -185,7 +185,7 @@ def build(self):
Text("Select a TWRP recovery image:", style="titleSmall"),
Markdown(
f"""
The recovery image should look something like `twrp-3.6.2_9-0-{self.state.config.metadata.get('devicecode')}.img`.
The recovery image should look something like `twrp-3.7.0_12-0-{self.state.config.device_code}.img`.
**Note:** This tool **only supports TWRP recoveries**.""",
extension_set="gitHubFlavored",
Expand Down
3 changes: 2 additions & 1 deletion openandroidinstaller/views/start_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from app_state import AppState
from widgets import get_title
from tooling import search_device
from installer_config import InstallerConfig


class StartView(BaseView):
Expand Down Expand Up @@ -224,7 +225,7 @@ def search_devices(self, e):
self.continue_button.disabled = False
self.bootloader_switch.disabled = False
# overwrite the text field with the real name from the config
self.device_name.value = f"{device_name} (code: {device_code})"
self.device_name.value = f"{device_name} (code: {InstallerConfig.device_code_mapping.get(device_code, device_code)})"
self.device_name.color = colors.GREEN
else:
# failed to load config
Expand Down

0 comments on commit 0462a30

Please sign in to comment.