Skip to content

Commit 1ba9537

Browse files
committed
Updates
1 parent abc8666 commit 1ba9537

6 files changed

Lines changed: 48 additions & 108 deletions

File tree

client/buildozer.spec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ android.presplash_color = #000000
104104

105105
# (list) Permissions
106106
# (See https://python-for-android.readthedocs.io/en/latest/buildoptions.html for all the supported syntaxes and properties)
107-
android.permissions = android.permission.INTERNET, android.permission.ACCESS_NETWORK_STATE, android.permission.WAVE_LOCK, android.permission.MANAGE_EXTERNAL_STORAGE, android.permission.READ_EXTERNAL_STORAGE, android.permission.WRITE_EXTERNAL_STORAGE
107+
android.permissions = android.permission.INTERNET, android.permission.ACCESS_NETWORK_STATE, android.permission.WAVE_LOCK, android.permission.MANAGE_EXTERNAL_STORAGE, android.permission.READ_EXTERNAL_STORAGE, android.permission.WRITE_EXTERNAL_STORAGE, android.permission.CAMERA
108108

109109
# (list) features (adds uses-feature -tags to manifest)
110110
#android.features = android.hardware.usb.host
@@ -255,7 +255,7 @@ android.add_src = ./src
255255
#android.res_xml = PATH_TO_FILE,
256256

257257
# (str) launchMode to set for the main activity
258-
android.manifest.launch_mode = singleTask
258+
android.manifest.launch_mode = standard
259259

260260
# (str) screenOrientation to set for the main activity.
261261
# Valid values can be found at https://developer.android.com/guide/topics/manifest/activity-element
@@ -296,7 +296,7 @@ android.logcat_filters = *:S python:D
296296

297297
# (list) The Android archs to build for, choices: armeabi-v7a, arm64-v8a, x86, x86_64
298298
# In past, was `android.arch` as we weren't supporting builds for multiple archs at the same time.
299-
android.archs = arm64-v8a, armeabi-v7a
299+
android.archs = arm64-v8a
300300

301301
# (int) overrides automatic versionCode computation (used in build.gradle)
302302
# this is not the same as app version and should only be edited if you know what you're doing

client/libs/installer/__init__.py

Lines changed: 15 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
from kivy.app import App
66
from kivy.utils import platform
7-
import requests
87

98
if platform == "android":
109

1110
from jnius import autoclass
12-
from android.permissions import request_permissions, Permission # type: ignore
11+
from libs.utils import request_android_permissions, Permission
1312

1413
ApplicationActivity = autoclass("org.kvdeveloper.client.ApplicationActivity")
1514

@@ -25,108 +24,23 @@
2524
pre_installed_packages = [dist.project_name for dist in pkg_resources.working_set] + [dist.project_name for dist in list(pkg_resources.find_distributions(install_dir))]
2625

2726

28-
def request_android_permissions() -> None:
29-
"""
30-
Request Android runtime permissions.
31-
"""
3227

33-
def callback(permissions: Permission, results: bool) -> None:
34-
"""
35-
Callback function for permission results.
36-
"""
37-
if all([res for res in results]):
38-
print("callback. All permissions granted.")
39-
else:
40-
print("callback. Some permissions refused.")
28+
def install(package_name: str) -> None:
4129

42-
request_permissions(
43-
[
30+
if platform == "android":
31+
request_android_permissions([
4432
Permission.MANAGE_EXTERNAL_STORAGE,
4533
Permission.READ_EXTERNAL_STORAGE,
4634
Permission.WRITE_EXTERNAL_STORAGE,
47-
],
48-
callback,
49-
)
50-
51-
52-
def get_dependencies(package_name: str) -> list[str]:
53-
import requests
54-
55-
# Split version from spec if present
56-
for op in ['==', '>=', '<=', '~=', '>', '<']:
57-
if op in package_name:
58-
name, version = package_name.split(op, 1)
59-
name = name.strip()
60-
version = version.strip()
61-
url = f"https://pypi.org/pypi/{name}/{version}/json"
62-
break
35+
])
36+
37+
if not package_name in pre_installed_packages:
38+
try:
39+
print(f"Installing deps: {package_name}")
40+
process = subprocess.Popen( # nosec
41+
f"{sys.executable} -m pip install {package_name} --target {install_dir} --no-deps",
42+
)
43+
except Exception as e:
44+
print(e)
6345
else:
64-
url = f"https://pypi.org/pypi/{package_name.strip()}/json"
65-
66-
try:
67-
response = requests.get(url, timeout=10)
68-
response.raise_for_status()
69-
data = response.json()
70-
return data.get("info", {}).get("requires_dist", []) or []
71-
except Exception as e:
72-
print(f"[ERROR] Failed to fetch {package_name}: {e}")
73-
return []
74-
75-
76-
def filter_dependencies(deps: list[str], to_exclude: list[str]) -> list[str]:
77-
return [
78-
dep for dep in deps
79-
if dep.split()[0].split(";")[0].split("(")[0].strip() not in to_exclude
80-
]
81-
def clean_dependency_list(deps: list[str]) -> list[str]:
82-
"""
83-
Cleans a list of dependency strings, removing extras, env markers, and malformed suffixes.
84-
"""
85-
cleaned = []
86-
for dep in deps:
87-
# Drop markers like ' ; python_version < "3.11"'
88-
dep = dep.split(";")[0].strip()
89-
90-
# Drop extras like '[watchmedo]' or '(extra)'
91-
dep = dep.split("[")[0].strip()
92-
dep = dep.split("(")[0].strip()
93-
94-
# Fix malformed '==\\all\\' or '== extra'
95-
if "==" in dep:
96-
parts = dep.split("==")
97-
if len(parts) >= 2:
98-
left, right = parts[0].strip(), parts[1].strip()
99-
# Ignore if right looks like an extra token
100-
if right.lower() in {"extra", "extras", "\\all\\", "optional"}:
101-
dep = left
102-
else:
103-
dep = f"{left}=={right}"
104-
else:
105-
dep = parts[0].strip()
106-
cleaned.append(dep)
107-
return cleaned
108-
109-
110-
def install(package_name: str) -> None:
111-
112-
if platform == "android":
113-
request_android_permissions()
114-
115-
dependencies = get_dependencies(package_name=package_name)
116-
dependencies = clean_dependency_list(dependencies)
117-
118-
if dependencies != False:
119-
120-
installable_deps = filter_dependencies(dependencies, pre_installed_packages)
121-
122-
package_install_string = " ".join(installable_deps)
123-
124-
125-
if installable_deps:=installable_deps:
126-
try:
127-
print(f"Installing deps: {package_install_string}")
128-
process = subprocess.Popen( # nosec
129-
f"{sys.executable} -m pip install {package_install_string} --target {install_dir} --no-deps",
130-
)
131-
except Exception as e:
132-
print(e)
46+
print(f"[INSTALL] {package_name} already installed.")

client/libs/launcher/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from libs.launcher.android import (
2020
AppStorageDir,
2121
launch_client_activity,
22-
finish_client_activity,
2322
)
2423

2524

@@ -146,8 +145,8 @@ def restart_entrypoint(self) -> None:
146145
print("[RESTART] Killing previous process...")
147146
self.process.terminate()
148147
self.process.wait()
149-
print(f"[RESTART] Restarting {self.entrypoint}")
150-
self.run_entrypoint()
148+
print(f"[RESTART] Restarting {self.entrypoint}")
149+
self.run_entrypoint()
151150

152151
@mainthread
153152
def display_indicator(self, val: bool = True, *args) -> None:

client/libs/scanner/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from jnius import autoclass

client/libs/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from kivy.utils import platform
2+
13
try:
24
import tomllib # type: ignore
35

@@ -7,7 +9,30 @@
79

810
toml_loader = toml
911

12+
if platform == "android":
13+
14+
from android.permissions import request_permissions, Permission # type: ignore
1015

1116
def toml_parser(source_config: str) -> dict:
1217
parsed_config = toml_loader.load(source_config)
1318
return parsed_config
19+
20+
21+
def request_android_permissions(permissions: list) -> None:
22+
"""
23+
Request Android runtime permissions.
24+
"""
25+
26+
def callback(permissions: Permission, results: bool) -> None:
27+
"""
28+
Callback function for permission results.
29+
"""
30+
if all([res for res in results]):
31+
print("callback. All permissions granted.")
32+
else:
33+
print("callback. Some permissions refused.")
34+
35+
request_permissions(
36+
permissions,
37+
callback,
38+
)

client/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ def referrer(self, destination: str = None) -> None:
6060

6161
def on_resume(self):
6262
self.running = False
63+
self.status = ""
6364
return super().on_resume()
6465

65-
def fetch_config(self, server_url: str, *args) -> None:
66+
def fetch_config(self, server_url: str, *args) -> dict | bool:
6667
url = f"{server_url}/config.toml"
6768
try:
6869
r = requests.get(url, timeout=3)

0 commit comments

Comments
 (0)