Skip to content

Commit 9e6a913

Browse files
committed
Update
1 parent fd7ea6d commit 9e6a913

5 files changed

Lines changed: 36 additions & 26 deletions

File tree

client/buildozer.spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ version = 0.1
4242

4343
# (list) Application requirements
4444
# comma separated e.g. requirements = sqlite3,kivy
45-
requirements = python3, kivy==2.3.0, https://github.com/CarbonKivy/CarbonKivy/archive/master.zip, android, requests, pyjnius
45+
requirements = python3, kivy==2.3.0, https://github.com/CarbonKivy/CarbonKivy/archive/master.zip, android, requests, pyjnius, kaki, watchdog
4646

4747
# (str) Custom source folders for requirements
4848
# Sets custom source for any requirements with recipes
@@ -251,7 +251,7 @@ android.add_src = ./src
251251
#android.res_xml = PATH_TO_FILE,
252252

253253
# (str) launchMode to set for the main activity
254-
android.manifest.launch_mode = standard
254+
android.manifest.launch_mode = singleTask
255255

256256
# (str) screenOrientation to set for the main activity.
257257
# Valid values can be found at https://developer.android.com/guide/topics/manifest/activity-element

client/libs/launcher/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def download_file_from_server(self, filename: str) -> None:
8787
r.raise_for_status()
8888
with open(local_path, "wb") as f:
8989
f.write(r.content)
90-
print(f"[SYNC] Downloaded: {filename}")
90+
print(f"[SYNC] Downloaded {filename} at {local_path}")
9191
except Exception as e:
9292
print(f"[ERROR] Failed to download {filename}: {e}")
9393
self.start_auto_sync()
@@ -109,15 +109,14 @@ def sync_loop(self) -> None:
109109
except Exception as e:
110110
print(f"[SYNC ERROR] {e}")
111111
time.sleep(3.0) # Poll interval
112-
if (self.process and (self.process.poll() != None)) or (self.running == False):
112+
if (self.process and (self.process.poll() != None)) or (self.app.running == False):
113113
break
114114

115115
def run_entrypoint(self) -> None:
116116
entrypoint_path = os.path.abspath(os.path.join(self.target_dir, self.entrypoint))
117117
self.display_indicator(False)
118118
if platform == "android":
119119
launch_client_activity(entrypoint_path)
120-
self.running = False
121120
else:
122121
self.process = subprocess.Popen([sys.executable, entrypoint_path], cwd=self.target_dir) # nosec
123122
print(f"[RUN] {self.entrypoint} launched...")

client/libs/launcher/android/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from jnius import autoclass
3+
from android.runnable import run_on_ui_thread # type: ignore
34

45
PythonActivity = autoclass("org.kivy.android.PythonActivity")
56
ClientActivity = autoclass("org.kvdeveloper.client.ClientActivity")
@@ -9,14 +10,13 @@
910
activity = PythonActivity.mActivity
1011
AppStorageDir = os.path.join(activity.getFilesDir().getAbsolutePath(), "Applications")
1112

13+
@run_on_ui_thread
1214
def launch_client_activity(entrypoint_path: str) -> None:
1315
app_dir = os.path.dirname(entrypoint_path)
1416
uri = Uri.parse("file://" + app_dir)
1517

16-
intent = Intent(Intent.ACTION_MAIN)
17-
intent.setClass(activity, ClientActivity)
18+
intent = Intent(activity.getApplicationContext(), ClientActivity)
1819
intent.setData(uri)
19-
intent.setAction("org.kivy.LAUNCH")
2020
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
2121
activity.startActivity(intent)
2222

client/main.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def set_softinput(*args) -> None:
1212

1313
Window.on_restore(Clock.schedule_once(set_softinput, 0.1))
1414

15-
from kivy.properties import StringProperty
15+
from kivy.properties import StringProperty, BooleanProperty
1616

1717
from carbonkivy.app import CarbonApp
1818
from carbonkivy.uix.screenmanager import CScreenManager
@@ -29,6 +29,8 @@ class KvDeveloperClient(CarbonApp):
2929

3030
status = StringProperty()
3131

32+
running = BooleanProperty(None, allownone=True)
33+
3234
def __init__(self, *args, **kwargs) -> None:
3335
super(KvDeveloperClient, self).__init__(*args, **kwargs)
3436
self.load_all_kv_files(os.path.join(self.directory, "View"))
@@ -54,30 +56,18 @@ def referrer(self, destination: str = None) -> None:
5456
if self.manager_screens.current != destination:
5557
self.manager_screens.current = destination
5658

59+
def on_resume(self):
60+
self.running = False
61+
return super().on_resume()
62+
5763
def launch(self, server_url: str, *args) -> None:
5864
self.launcher = ApplicationLauncher(server_url=server_url, entrypoint="main.py", app_name="Demo")
5965
self.launcher.launch_app()
66+
self.running = True
6067
self.launcher = None
6168

6269

6370
if __name__ == "__main__":
6471
app = KvDeveloperClient()
6572
app.run()
66-
import sys
67-
from kivy.utils import platform
68-
69-
if platform == "android":
70-
from jnius import autoclass
71-
activity = autoclass("org.kivy.android.PythonActivity").mActivity
72-
log_dir = activity.getExternalFilesDir(None).getAbsolutePath()
73-
else:
74-
log_dir = os.path.expanduser("~/AppLogs")
75-
76-
os.makedirs(log_dir, exist_ok=True)
77-
78-
log_file_path = os.path.join(log_dir, "app_log.txt")
79-
sys.stdout = open(log_file_path, "a")
80-
sys.stderr = sys.stdout
81-
82-
print("[LOG] Logging started.")
8373

client/src/org/kvdeveloper/client/ClientActivity.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.kvdeveloper.client;
22

3+
import android.net.Uri;
4+
import android.os.Bundle;
35
import android.util.Log;
46
import android.view.KeyEvent;
57

@@ -8,6 +10,25 @@
810
public class ClientActivity extends PythonActivity {
911
private static final String TAG = "ClientActivity";
1012

13+
@Override
14+
protected String getEntryPoint() {
15+
Uri uri = getIntent().getData();
16+
if (uri != null) {
17+
String path = uri.getPath();
18+
Log.i(TAG, "Launching entrypoint from URI: " + path);
19+
return path;
20+
} else {
21+
Log.w(TAG, "No entrypoint URI passed.");
22+
finish();
23+
}
24+
}
25+
26+
@Override
27+
protected void onCreate(Bundle savedInstanceState) {
28+
Log.i(TAG, "ClientActivity started");
29+
super.onCreate(savedInstanceState);
30+
}
31+
1132
@Override
1233
public boolean dispatchKeyEvent(KeyEvent event) {
1334
int keyCode = event.getKeyCode();

0 commit comments

Comments
 (0)