Skip to content

Commit ef25b23

Browse files
committed
Add a button type to open a website
1 parent 170269a commit ef25b23

5 files changed

Lines changed: 34 additions & 11 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ Every step in the config file corresponds to one view in the application. These
7676
- `confirm_button`: Display the content, as well as a button to allow the user to go to the next step.
7777
- `call_button`: Display the content text and a button that runs a given command. After the command is run, a confirm button is displayed to allow the user to move to the next step.
7878
- `call_button_with_input`: Display the content text, an input field and a button that runs a given command. The inputtext, can be used in the command by using the `<inputtext>` placeholder in the command field. After the command is run, a confirm button is displayed to allow the user to move to the next step.
79+
- `link_button_with_confirm`: Display a button that opens a browser with a given link, confirm afterwards. Link is given in `link`.
7980
- `content`: str; The content text displayed alongside the action of the step. Used to inform the user about whats going on.
8081
- `command`: [ONLY for call_button* steps] str; This is a terminal command run in a shell. (For example fastboot or adb). There are three types of placeholders supported, that will be filled by the tool as soon as information is given.
81-
- `<image>`: The path of the image file.
82+
- `<image>`: The path of the ROM image file.
8283
- `<recovery>`: The path of the recovery file.
8384
- `<inputtext>`: Text from the user input from `call_button_with_input` views.
8485
- `img`: [OPTIONAL] Display an image on the left pane of the step view. Images are loaded from `openandroidinstaller/assets/imgs/`.
8586
- `allow_skip`: [OPTIONAL] boolean; If a skip button should be displayed to allow skipping this step. Can be useful when the bootloader is already unlocked.
87+
- `link`: [OPTIONAL] Link to use for the link button if type is `link_button_with_confirm`.
8688

8789
The file should be named after device name output by `adb shell getprop | grep ro.poroduct.device` when the devices is connected to the computer. You can also get the device code by connecting the device to the computer and run OpenAndroidInstaller to detect the device.
8890

openandroidinstaller/assets/configs/yuga.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,28 @@ steps:
1818
content: Press the button to reboot into the bootloader now. Then confirm to continue.
1919
command: "adb reboot bootloader"
2020
- title: "Unlock the bootloader"
21-
type: confirm_button
21+
type: link_button_with_confirm
2222
content: >
23-
Follow the instructions on Sonys official unlocking website to generate an unlock code for your bootloader:
24-
https://developer.sonymobile.com/unlockbootloader/unlock-yourboot-loader/"
23+
Click on the button to open the instructions on Sonys official unlocking website to generate an unlock code for your bootloader.
24+
Once you got the code, continue to input the code.
25+
link: https://developer.sonymobile.com/unlockbootloader/unlock-yourboot-loader/
2526
- title: "Unlock the bootloader"
2627
type: call_button_with_input
2728
content: >
2829
Use your code to unlock the bootloader of your device. Type in the full 18 character code starting with 0x (Example: 0x3EC4F7AD6E0B32B6).
2930
If you already did that, you can skip this step.
3031
command: "fastboot oem unlock <inputtext>"
3132
allow_skip: True
32-
flash_recovery:
33-
- title: "Flash temporary recovery"
33+
- title: "Unlock the bootloader"
3434
type: call_button
3535
content: >
3636
Press the button to reboot. Since the device resets completely, you will need to re-enable USB debugging to continue.
3737
Connect your device to your PC via USB. Then confirm here to continue.
3838
command: "fastboot reboot"
39+
flash_recovery:
3940
- title: "Flash temporary recovery"
4041
type: call_button
41-
content: Now you have to reboot into bootloader again. Press the button to do it and continue once it is done.
42+
content: Now you have to reboot into bootloader again. With your phone turned on, press the button to do so and continue once it is done.
4243
command: "adb reboot bootloader"
4344
allow_skip: True
4445
- title: "Flash temporary recovery"

openandroidinstaller/installer_config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ def __init__(
3131
command: str = None,
3232
img: str = "placeholder.png",
3333
allow_skip: bool = False,
34+
link: str = None,
3435
):
3536
self.title = title
3637
self.type = type
3738
self.content = content
3839
self.command = command
3940
self.img = img
4041
self.allow_skip = allow_skip
42+
self.link = link
4143

4244

4345
class InstallerConfig:
@@ -112,11 +114,12 @@ def validate_config(config: str) -> bool:
112114

113115
step_schema = {
114116
"title": str,
115-
"type": Regex(r"text|confirm_button|call_button|call_button_with_input"),
117+
"type": Regex(r"text|confirm_button|call_button|call_button_with_input|link_button_with_confirm"),
116118
"content": str,
117119
schema.Optional("command"): Regex(r"^adb\s|^fastboot\s|^heimdall\s"),
118120
schema.Optional("allow_skip"): bool,
119121
schema.Optional("img"): str,
122+
schema.Optional("link"): str,
120123
}
121124

122125
config_schema = Schema({

openandroidinstaller/openandroidinstaller.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import os
1717
import sys
18+
import turtle
1819
import webbrowser
1920
from pathlib import Path
2021
from time import sleep
@@ -30,11 +31,11 @@
3031
from loguru import logger
3132
from tool_utils import call_tool_with_command, search_device
3233
from utils import AppState, get_download_link
33-
from widgets import call_button, confirm_button, get_title
34+
from widgets import call_button, confirm_button, get_title, link_button
3435

3536
# Toggle to True for development purposes
36-
DEVELOPMENT = False
37-
DEVELOPMENT_CONFIG = "sargo" # "a3y17lte" # "sargo"
37+
DEVELOPMENT = True
38+
DEVELOPMENT_CONFIG = "yuga" # "a3y17lte" # "sargo"
3839

3940

4041
PLATFORM = sys.platform
@@ -523,6 +524,12 @@ def build(self):
523524
self.right_view.controls.extend(
524525
[self.inputtext, Row([self.call_button, self.confirm_button])]
525526
)
527+
elif self.step.type == "link_button_with_confirm":
528+
self.confirm_button = confirm_button(self.on_confirm)
529+
self.right_view.controls.extend(
530+
[Row([link_button(self.step.link, "Open Link"), self.confirm_button])]
531+
)
532+
526533
elif self.step.type != "text":
527534
raise Exception(f"Unknown step type: {self.step.type}")
528535

openandroidinstaller/widgets.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from functools import partial
1717
from typing import Callable
18+
import webbrowser
1819

1920
from flet import Container, ElevatedButton, Row, Text, alignment, icons
2021

@@ -57,3 +58,12 @@ def call_button(
5758
expand=True,
5859
icon=icons.DIRECTIONS_RUN_OUTLINED,
5960
)
61+
62+
63+
def link_button(link: str, text: str) -> ElevatedButton:
64+
"""Get a button that opens a link in a browser."""
65+
return ElevatedButton(
66+
f"{text}",
67+
on_click=lambda _: webbrowser.open(link),
68+
expand=True,
69+
)

0 commit comments

Comments
 (0)