From 060f1980f58f5c59f407fdc5a5dc19cfc05576a8 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Fri, 25 Aug 2023 18:27:19 +0000 Subject: [PATCH] A little more paranoia around the file watcher. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4427 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- .../com/unprompted/tildefriends/MainActivity.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/android/com/unprompted/tildefriends/MainActivity.java b/src/android/com/unprompted/tildefriends/MainActivity.java index bda9dc73..e7eac61c 100644 --- a/src/android/com/unprompted/tildefriends/MainActivity.java +++ b/src/android/com/unprompted/tildefriends/MainActivity.java @@ -105,10 +105,13 @@ public class MainActivity extends Activity { for (WatchEvent event : key.pollEvents()) { if (event.context().toString().equals("port.txt")) { Log.w("tildefriends", "Observed file write: " + event.context().toString()); - base_url = "http://127.0.0.1:" + String.valueOf(read_port(port_file_path)) + "/"; - activity.runOnUiThread(() -> { - web_view.loadUrl(base_url); - }); + int port = read_port(port_file_path); + if (port >= 0) { + base_url = "http://127.0.0.1:" + String.valueOf(port) + "/"; + activity.runOnUiThread(() -> { + web_view.loadUrl(base_url); + }); + } break; } }