Skip to content

Commit 4091d7e

Browse files
committed
Improve path handling and basic windows commands
1 parent c2a19da commit 4091d7e

File tree

2 files changed

+49
-27
lines changed

2 files changed

+49
-27
lines changed

openandroidinstaller/openandroidinstaller.py

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

16+
import sys
1617
import webbrowser
1718
from loguru import logger
18-
from os import path
1919
from subprocess import STDOUT, CalledProcessError, call, check_output
2020
from time import sleep
2121
from typing import Callable
22+
from pathlib import Path
2223

2324
import flet
2425
from flet import (
@@ -55,8 +56,11 @@
5556
DEVELOPMENT_CONFIG = "Xperia Z" # "Pixel 3a"
5657

5758

58-
CONFIG_PATH = path.abspath(path.join(path.dirname(__file__), "assets/configs/"))
59-
IMAGE_PATH = path.abspath(path.join(path.dirname(__file__), "assets/imgs/"))
59+
PLATFORM = sys.platform
60+
logger.info(f"Running OpenAndroidInstaller on {PLATFORM}")
61+
# Define asset paths
62+
CONFIG_PATH = Path(__file__).parent.joinpath(Path("assets/configs")).resolve()
63+
IMAGE_PATH = Path(__file__).parent.joinpath(Path("assets/imgs")).resolve()
6064

6165

6266
class BaseView(UserControl):
@@ -65,7 +69,7 @@ def __init__(self, image: str = "placeholder.png"):
6569
self.right_view = Column(expand=True)
6670
self.left_view = Column(
6771
width=480,
68-
controls=[Image(src=IMAGE_PATH + "/" + image)],
72+
controls=[Image(src=IMAGE_PATH.joinpath(Path(image)))],
6973
expand=True,
7074
horizontal_alignment="center",
7175
)
@@ -175,24 +179,46 @@ def close_developer_options_dlg(self, e):
175179
def search_devices(self, e):
176180
try:
177181
# read device properties
178-
output = check_output(
179-
[
180-
"adb",
181-
"shell",
182-
"dumpsys",
183-
"bluetooth_manager",
184-
"|",
185-
"grep",
186-
"'name:'",
187-
"|",
188-
"cut",
189-
"-c9-",
190-
],
191-
stderr=STDOUT,
192-
).decode()
182+
# TODO: This is not windows ready...
183+
if PLATFORM in ("linux", "MacOS"):
184+
output = check_output(
185+
[
186+
"adb",
187+
"shell",
188+
"dumpsys",
189+
"bluetooth_manager",
190+
"|",
191+
"grep",
192+
"'name:'",
193+
"|",
194+
"cut",
195+
"-c9-",
196+
],
197+
stderr=STDOUT,
198+
).decode()
199+
elif PLATFORM == "windows":
200+
output = check_output(
201+
[
202+
"adb",
203+
"shell",
204+
"dumpsys",
205+
"bluetooth_manager",
206+
"|",
207+
"findstr",
208+
"'name:'",
209+
"|",
210+
"-split",
211+
"-c9-",
212+
],
213+
stderr=STDOUT,
214+
).decode()
215+
else:
216+
raise Exception(f"Unknown platform {PLATFORM}.")
217+
193218
self.device_name.value = output.strip()
194219
# load config from file
195-
path = f"{CONFIG_PATH}/{output.strip()}.yaml"
220+
# path = f"{CONFIG_PATH}/{output.strip()}.yaml"
221+
path = CONFIG_PATH.joinpath(Path(f"{output.strip()}.yaml"))
196222
load_config_success = self.load_config(path)
197223
if load_config_success:
198224
self.config_found_box.value = True
@@ -203,7 +229,8 @@ def search_devices(self, e):
203229
pass
204230
except CalledProcessError:
205231
if DEVELOPMENT:
206-
path = f"{CONFIG_PATH}/{DEVELOPMENT_CONFIG}.yaml"
232+
path = CONFIG_PATH.joinpath(Path(f"{DEVELOPMENT_CONFIG}.yaml"))
233+
# path = f"{CONFIG_PATH}/{DEVELOPMENT_CONFIG}.yaml"
207234
load_config_success = self.load_config(path)
208235
if load_config_success:
209236
self.config_found_box.value = True
@@ -509,9 +536,7 @@ def main(page: Page):
509536
page.horizontal_alignment = "center"
510537

511538
# header
512-
image_path = path.abspath(
513-
path.join(path.dirname(__file__), "assets/logo-192x192.png")
514-
)
539+
image_path = Path(__file__).parent.joinpath(Path("assets/logo-192x192.png"))
515540
page.appbar = AppBar(
516541
leading=Image(src=image_path, height=40, width=40, border_radius=40),
517542
leading_width=56,

openandroidinstaller/widgets.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121

2222

2323
def get_title(title: str):
24-
image_path = path.abspath(
25-
path.join(path.dirname(__file__), "assets/logo-192x192.png")
26-
)
2724
return Container(
2825
content=Row(
2926
[

0 commit comments

Comments
 (0)