changeset 417:4dcc071e1feb

monitor failure should not kill the TE
author Carl Byington <carl@five-ten-sg.com>
date Wed, 29 Oct 2014 12:12:48 -0700
parents 07c1da90deab
children 39533be5cbe9
files src/com/five_ten_sg/connectbot/TerminalView.java src/com/five_ten_sg/connectbot/service/TerminalMonitor.java
diffstat 2 files changed, 21 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/five_ten_sg/connectbot/TerminalView.java	Mon Oct 27 13:58:42 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/TerminalView.java	Wed Oct 29 12:12:48 2014 -0700
@@ -72,7 +72,6 @@
     private Matrix scaleMatrix;
     private static final Matrix.ScaleToFit scaleType = Matrix.ScaleToFit.FILL;
 
-    private Toast notification = null;
     private String lastNotification = null;
     private volatile boolean notifications = true;
 
@@ -242,22 +241,11 @@
     }
 
     public void notifyUser(String message) {
-        if (!notifications)
-            return;
-
-        if (notification != null) {
-            // Don't keep telling the user the same thing.
-            if (lastNotification != null && lastNotification.equals(message))
-                return;
-
-            notification.setText(message);
-            notification.show();
-        }
-        else {
-            notification = Toast.makeText(context, message, Toast.LENGTH_SHORT);
-            notification.show();
-        }
-
+        if (!notifications) return;
+        // Don't keep telling the user the same thing.
+        if (lastNotification != null && lastNotification.equals(message)) return;
+        Toast notification = Toast.makeText(context, message, Toast.LENGTH_SHORT);
+        notification.show();
         lastNotification = message;
     }
 
--- a/src/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Mon Oct 27 13:58:42 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Wed Oct 29 12:12:48 2014 -0700
@@ -181,25 +181,28 @@
                         monitor_socket = new Socket(serverAddr, MONITORPORT);
                     }
                     catch (Exception e) {
+                        monitor_socket = null;
                         Log.e(TAG, "exception connecting to monitor socket", e);
                         tries = tries + 1;
                     }
                 }
-                Log.i(TAG, "connected to monitor socket, send init " + init);
-                monitor_in     = monitor_socket.getInputStream();
-                monitor_out    = monitor_socket.getOutputStream();
-                monitor_reader = new MyReader(monitor_in);
-                monitor_reader.start();
-                String x = "  " + init;
-                monitorWrite(MONITOR_CMD_INIT, x.toCharArray());
-                char [] c;
+                if (monitor_socket != null) {
+                    Log.i(TAG, "connected to monitor socket, send init " + init);
+                    monitor_in     = monitor_socket.getInputStream();
+                    monitor_out    = monitor_socket.getOutputStream();
+                    monitor_reader = new MyReader(monitor_in);
+                    monitor_reader.start();
+                    String x = "  " + init;
+                    monitorWrite(MONITOR_CMD_INIT, x.toCharArray());
+                    char [] c;
 
-                while (true) {
-                    c = pending_commands.poll();
+                    while (true) {
+                        c = pending_commands.poll();
 
-                    if (c == null) break;
+                        if (c == null) break;
 
-                    monitorWrite(c[1], c);
+                        monitorWrite(c[1], c);
+                   }
                 }
             }
             catch (IOException e) {
@@ -331,7 +334,7 @@
             }
             else {
                 c[1] = cmd;
-                pending_commands.put(c);
+                pending_commands.offer(c);
             }
         }
         catch (InterruptedException e) {