Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .p4a
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
--fileprovider-paths src/fileprovider_paths.xml
--add-asset assets/_load.html:_load.html
--add-asset assets/loadingScreen:loadingScreen
--add-source src/java/
--whitelist ./allowlist.txt
--blacklist ./blocklist.txt
21 changes: 21 additions & 0 deletions src/java/WelcomeScreenInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.endlessos.Key;
import android.webkit.JavascriptInterface;
import android.util.Log;

public class WelcomeScreenInterface {

private static final String TAG = "WelcomeScreen";

public void test() {
Log.d(TAG, "test called!");
}

@JavascriptInterface
public void load() {
Log.d(TAG, "load called!");
}
@JavascriptInterface
public void loadWithUSB() {
Log.d(TAG, "loadWithUSB called!");
}
}
41 changes: 30 additions & 11 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time

import initialization # noqa: F401 keep this first, to ensure we're set up for other imports
from android.runnable import run_on_ui_thread
from android_utils import ask_all_files_access
from android_utils import get_endless_key_paths
from android_utils import provision_endless_key_database
Expand Down Expand Up @@ -87,22 +88,40 @@ def _enable_kolibri_plugin(plugin_name: str, optional=False) -> bool:
except FileNotFoundError:
pass

# we need to initialize Kolibri to allow us to access the app key
initialize()

# start kolibri server
logging.info("Starting kolibri server via Android service...")
start_service("server")
def start_kolibri():
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this was needed :)

# we need to initialize Kolibri to allow us to access the app key
initialize()

# Tie up this thread until the server is running
wait_for_status(STATUS_RUNNING, timeout=120)
# start kolibri server
logging.info("Starting kolibri server via Android service...")
start_service("server")

_, port, _, _ = _read_pid_file(PID_FILE)
# Tie up this thread until the server is running
wait_for_status(STATUS_RUNNING, timeout=120)

start_url = "http://127.0.0.1:{port}".format(port=port) + interface.get_initialize_url()
loadUrl(start_url)
_, port, _, _ = _read_pid_file(PID_FILE)

start_service("remoteshell")
start_url = (
"http://127.0.0.1:{port}".format(port=port) + interface.get_initialize_url()
)
loadUrl(start_url)

start_service("remoteshell")
Copy link
Copy Markdown

@dylanmccall dylanmccall Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit (the remoteshell service) is unrelated to Kolibri itself. We should start this service earlier, and ideally somewhere else just so it's clearer.



@run_on_ui_thread
def hook():
WelcomeScreenInterface = autoclass("org.endlessos.Key.WelcomeScreenInterface")
welcomeScreenInterface = WelcomeScreenInterface()
welcomeScreenInterface.test()
PythonActivity.mWebView.addJavascriptInterface(welcomeScreenInterface, "EndlessAPI")
PythonActivity.mWebView.loadUrl(
"file:///android_asset/loadingScreen/index.html#/welcome"
)


hook()

while True:
time.sleep(0.05)