Skip to content

Commit f858cd0

Browse files
Add app's "assets" folder to sys.path
1 parent 0317f38 commit f858cd0

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

internal_filesystem/apps/com.lightningpiggy.displaywallet/assets/displaywallet.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import mpos.config
44
import mpos.ui
55

6+
from wallet import LNBitsWallet
7+
68
# screens:
79
main_screen = None
810
settings_screen = None
@@ -225,7 +227,7 @@ def janitor_cb(timer):
225227
try:
226228
wallet = LNBitsWallet(config.get_string("lnbits_url"), config.get_string("lnbits_readkey"))
227229
except Exception as e:
228-
print("Couldn't initialize LNBitsWallet because {e}")
230+
print(f"Couldn't initialize LNBitsWallet because {e}")
229231
elif wallet_type == "nwc":
230232
try:
231233
wallet = NWCWallet(config.get_string("nwc_url"))

internal_filesystem/lib/mpos/apps.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
import mpos.ui
1313

1414
# Run the script in the current thread:
15-
def execute_script(script_source, is_file):
15+
def execute_script(script_source, is_file, cwd=None):
1616
thread_id = _thread.get_ident()
1717
compile_name = 'script' if not is_file else script_source
18-
print(f"Thread {thread_id}: executing script")
18+
print(f"Thread {thread_id}: executing script with cwd: {cwd}")
1919
try:
2020
if is_file:
2121
print(f"Thread {thread_id}: reading script from file {script_source}")
@@ -26,6 +26,10 @@ def execute_script(script_source, is_file):
2626
'__name__': "__main__"
2727
}
2828
print(f"Thread {thread_id}: starting script")
29+
import sys
30+
path_before = sys.path
31+
if cwd:
32+
sys.path.append(cwd)
2933
try:
3034
compiled_script = compile(script_source, compile_name, 'exec')
3135
exec(compiled_script, script_globals)
@@ -35,7 +39,7 @@ def execute_script(script_source, is_file):
3539
tb = getattr(e, '__traceback__', None)
3640
traceback.print_exception(type(e), e, tb)
3741
print(f"Thread {thread_id}: script {compile_name} finished")
38-
# Note that newscreen isn't deleted, as it might still be foreground, or it might be mpos.ui.rootscreen
42+
sys.path = path_before
3943
except Exception as e:
4044
print(f"Thread {thread_id}: error:")
4145
tb = getattr(e, '__traceback__', None)
@@ -83,7 +87,7 @@ def start_app(app_dir, is_launcher=False):
8387
app = mpos.apps.parse_manifest(manifest_path)
8488
start_script_fullpath = f"{app_dir}/{app.entrypoint}"
8589
#execute_script_new_thread(start_script_fullpath, True, is_launcher, True) # Starting (GUI?) apps in a new thread can cause hangs (GIL lock?)
86-
execute_script(start_script_fullpath, True)
90+
execute_script(start_script_fullpath, True, app_dir + "/assets/")
8791
# Launchers have the bar, other apps don't have it
8892
if is_launcher:
8993
mpos.ui.open_bar()
@@ -158,12 +162,12 @@ def auto_connect():
158162
# Maybe start_app_by_name() and start_app_by_name() could be merged so the try-except logic is not duplicated...
159163
try:
160164
stat = uos.stat(custom_auto_connect)
161-
execute_script_new_thread(custom_auto_connect, True, False, False)
165+
execute_script_new_thread(custom_auto_connect, True)
162166
except Exception as e:
163167
try:
164168
print(f"Couldn't execute {custom_auto_connect} because exception {e}, trying {builtin_auto_connect}...")
165169
stat = uos.stat(builtin_auto_connect)
166-
execute_script_new_thread(builtin_auto_connect, True, False, False)
170+
execute_script_new_thread(builtin_auto_connect, True)
167171
except Exception as e:
168172
print("Couldn't execute {builtin_auto_connect} because exception {e}, continuing...")
169173

0 commit comments

Comments
 (0)