Skip to content

Commit 5a937a0

Browse files
authored
Windows build (#23)
Enable building the tool for windows.
2 parents b7695ae + 2079328 commit 5a937a0

File tree

8 files changed

+1245
-54
lines changed

8 files changed

+1245
-54
lines changed

.github/workflows/manual-build-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
python-version: 3.9
2020
- run: pip install -r requirements.txt
2121
- run: python scripts/download-tools.py
22-
- run: pyinstaller openandroidinstaller/openandroidinstaller.py --noconsole --noconfirm --onefile --icon "openandroidinstaller/assets/favicon.ico" --add-data "openandroidinstaller/assets;assets" --add-binary "openandroidinstaller/bin/adb.exe;bin" --add-binary "openandroidinstaller/bin/fastboot.exe;bin" --add-binary "openandroidinstaller/bin/heimdall.exe;bin"
22+
- run: pyinstaller openandroidinstaller/openandroidinstaller.py --noconsole --noconfirm --onefile --icon "openandroidinstaller\assets\favicon.ico" --add-data "openandroidinstaller\assets;assets" --add-binary "openandroidinstaller\bin\adb.exe;bin" --add-binary "openandroidinstaller\bin\AdbWinApi.dll;bin" --add-binary "openandroidinstaller\bin\fastboot.exe;bin" --add-binary "openandroidinstaller\bin\heimdall.exe;bin"
2323
# Optionally verify that it works (provided that it does not need user interaction)
2424
#- run: ./dist/your-code/your-code
2525
- uses: actions/upload-artifact@v3

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ Motorola | moto g7 power | ocean | | under development
4747

4848
## Usage
4949

50-
Currently, Linux (tested with Ubuntu 20.04 LTS) and MacOS are supported.
50+
Linux (tested with Ubuntu 20.04 LTS), Windows and MacOS are supported.
5151

5252
1. Download the AppImage, .exe or appropriate executable file for your OS. You might need to change permissions to run the executable.
53+
- On Windows also [install the Universal USB Drivers](https://adb.clockworkmod.com/) and other drivers needed for your device.
5354
2. Download the lineageOS image and the custom recovery image. A source for files can be found on https://lineageosroms.com or you can just search the web for an appropriate version for your device.
5455
3. Start the desktop app and follow the instructions.
5556

openandroidinstaller/openandroidinstaller.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
import os
1717
import sys
18-
import turtle
1918
import webbrowser
19+
import regex as re
2020
from pathlib import Path
2121
from time import sleep
2222
from typing import Callable, Optional
@@ -49,7 +49,7 @@
4949
colors,
5050
icons,
5151
)
52-
from installer_config import InstallerConfig, Step, _load_config
52+
from installer_config import Step, _load_config
5353
from loguru import logger
5454
from tool_utils import call_tool_with_command, search_device
5555
from utils import AppState, get_download_link, image_recovery_works_with_device
@@ -65,9 +65,6 @@
6565
CONFIG_PATH = (
6666
Path(__file__).parent.joinpath(Path(os.sep.join(["assets", "configs"]))).resolve()
6767
)
68-
IMAGE_PATH = (
69-
Path(__file__).parent.joinpath(Path(os.sep.join(["assets", "imgs"]))).resolve()
70-
)
7168
BIN_PATH = Path(__file__).parent.joinpath(Path("bin")).resolve()
7269

7370

@@ -77,7 +74,7 @@ def __init__(self, image: str = "placeholder.png"):
7774
self.right_view = Column(expand=True)
7875
self.left_view = Column(
7976
width=600,
80-
controls=[Image(src=IMAGE_PATH.joinpath(Path(image)))],
77+
controls=[Image(src=f"/assets/imgs/{image}")],
8178
expand=True,
8279
horizontal_alignment="center",
8380
)
@@ -364,7 +361,6 @@ def build(self):
364361

365362
def enable_button_if_ready(self, e):
366363
"""Enable the confirm button if both files have been selected."""
367-
368364
if (".zip" in self.selected_image.value) and (
369365
".img" in self.selected_recovery.value
370366
):
@@ -658,11 +654,10 @@ def main(page: Page):
658654
page.horizontal_alignment = "center"
659655

660656
# header
661-
image_path = Path(__file__).parent.joinpath(
662-
Path(os.sep.join(["assets", "logo-192x192.png"]))
663-
)
664657
page.appbar = AppBar(
665-
leading=Image(src=image_path, height=40, width=40, border_radius=40),
658+
leading=Image(
659+
src=f"/assets/logo-192x192.png", height=40, width=40, border_radius=40
660+
),
666661
leading_width=56,
667662
toolbar_height=72,
668663
elevation=0,

openandroidinstaller/tool_utils.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# If not, see <https://www.gnu.org/licenses/>."""
1414
# Author: Tobias Sterbak
1515

16+
import sys
1617
from pathlib import Path
1718
from subprocess import STDOUT, CalledProcessError, call, check_output
1819
from typing import Optional
@@ -21,11 +22,35 @@
2122
from loguru import logger
2223

2324

25+
PLATFORM = sys.platform
26+
27+
2428
def call_tool_with_command(command: str, bin_path: Path) -> bool:
2529
"""Call an executable with a specific command."""
26-
command = re.sub(r"^adb", str(bin_path.joinpath(Path("adb"))), command)
27-
command = re.sub(r"^fastboot", str(bin_path.joinpath(Path("fastboot"))), command)
28-
command = re.sub(r"^heimdall", str(bin_path.joinpath(Path("heimdall"))), command)
30+
if PLATFORM == "win32":
31+
command = re.sub(
32+
r"^adb", re.escape(str(bin_path.joinpath(Path("adb")))) + ".exe", command
33+
)
34+
command = re.sub(
35+
r"^fastboot",
36+
re.escape(str(bin_path.joinpath(Path("fastboot.exe")))) + ".exe",
37+
command,
38+
)
39+
command = re.sub(
40+
r"^heimdall",
41+
re.escape(str(bin_path.joinpath(Path("heimdall.exe")))) + ".exe",
42+
command,
43+
)
44+
else:
45+
command = re.sub(
46+
r"^adb", re.escape(str(bin_path.joinpath(Path("adb")))), command
47+
)
48+
command = re.sub(
49+
r"^fastboot", re.escape(str(bin_path.joinpath(Path("fastboot")))), command
50+
)
51+
command = re.sub(
52+
r"^heimdall", re.escape(str(bin_path.joinpath(Path("heimdall")))), command
53+
)
2954

3055
logger.info(f"Run command: {command}")
3156
res = call(f"{command}", shell=True)
@@ -65,10 +90,13 @@ def search_device(platform: str, bin_path: Path) -> Optional[str]:
6590
"ro.product.device",
6691
],
6792
stderr=STDOUT,
93+
shell=True,
6894
).decode()
6995
else:
7096
raise Exception(f"Unknown platform {platform}.")
71-
return output.split("[")[-1].strip()[:-1].strip()
97+
device_code = output.split("[")[-1].strip()[:-1].strip()
98+
logger.info(device_code)
99+
return device_code
72100
except CalledProcessError:
73101
logger.info(f"Did not detect a device.")
74102
return None

0 commit comments

Comments
 (0)