From 5fb455574751751649ec7648c2f81850d9f557b9 Mon Sep 17 00:00:00 2001 From: freeflyk <65976525+freeflyk@users.noreply.github.com> Date: Tue, 7 May 2024 22:59:06 +0200 Subject: [PATCH 1/3] Fix for re-establishing the websocket connection once it was lost and the thread upholding the connection was down. --- .../Services/NotificationWebsocketService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/polar/nextcloudservices/Services/NotificationWebsocketService.java b/app/src/main/java/com/polar/nextcloudservices/Services/NotificationWebsocketService.java index b3ab081..aa2fdef 100644 --- a/app/src/main/java/com/polar/nextcloudservices/Services/NotificationWebsocketService.java +++ b/app/src/main/java/com/polar/nextcloudservices/Services/NotificationWebsocketService.java @@ -134,8 +134,12 @@ public void onWebsocketConnected() { @Override public String getStatus() { - if(mNotificationWebsocket == null){ + if(mNotificationWebsocket == null && mWsThread.isAlive()){ return "Disconnected: can not connect to websocket. Are login details correct? Is notify_push installed on server?"; + }else if(mNotificationWebsocket == null && !mWsThread.isAlive()){ + mWsThread = new Thread(this::listenForever); + mWsThread.start(); + return "Disconnected: trying to reconnect to websocket."; } return mStatusController.getStatusString(); } From b64b71361eb020e4c8e9770254d06de3e41508f4 Mon Sep 17 00:00:00 2001 From: freeflyk <65976525+freeflyk@users.noreply.github.com> Date: Mon, 13 May 2024 22:05:10 +0200 Subject: [PATCH 2/3] Fix websocket service crashing when trying to reconnect while there is no connection. Fix for displaying the wrong status message when there is no connection while using websocket. --- .../Services/NotificationWebsocketService.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/polar/nextcloudservices/Services/NotificationWebsocketService.java b/app/src/main/java/com/polar/nextcloudservices/Services/NotificationWebsocketService.java index aa2fdef..6faf05b 100644 --- a/app/src/main/java/com/polar/nextcloudservices/Services/NotificationWebsocketService.java +++ b/app/src/main/java/com/polar/nextcloudservices/Services/NotificationWebsocketService.java @@ -1,7 +1,6 @@ package com.polar.nextcloudservices.Services; import android.app.Notification; -import android.app.NotificationManager; import android.app.Service; import android.content.Intent; import android.os.IBinder; @@ -134,7 +133,9 @@ public void onWebsocketConnected() { @Override public String getStatus() { - if(mNotificationWebsocket == null && mWsThread.isAlive()){ + if(!mConnectionController.checkConnection(this)){ + return "Disconnected: no suitable network found"; + }else if(mNotificationWebsocket == null && mWsThread.isAlive()){ return "Disconnected: can not connect to websocket. Are login details correct? Is notify_push installed on server?"; }else if(mNotificationWebsocket == null && !mWsThread.isAlive()){ mWsThread = new Thread(this::listenForever); @@ -152,15 +153,14 @@ private void safeCloseWebsocket(){ @Override public void onPreferencesChanged() { + safeCloseWebsocket(); if(!mServiceSettings.isWebsocketEnabled()){ Log.i(TAG, "Websocket is no more enabled. Disconnecting websocket and stopping service"); - safeCloseWebsocket(); stopForeground(true); + }else{ + Log.i(TAG, "Preferences changed. Re-connecting to websocket."); + mAPI = mServiceSettings.getAPIFromSettings(); } - Log.i(TAG, "Preferences changed. Re-connecting to websocket."); - safeCloseWebsocket(); - mAPI = mServiceSettings.getAPIFromSettings(); - startListening(); } @Override From 8c1a611afc19cdcef3b8095d2ea875f6fc091943 Mon Sep 17 00:00:00 2001 From: freeflyk <65976525+freeflyk@users.noreply.github.com> Date: Mon, 13 May 2024 23:17:21 +0200 Subject: [PATCH 3/3] Fixed login retry when credentials are wrong. --- .../Services/NotificationWebsocketService.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/main/java/com/polar/nextcloudservices/Services/NotificationWebsocketService.java b/app/src/main/java/com/polar/nextcloudservices/Services/NotificationWebsocketService.java index 6faf05b..b88e1de 100644 --- a/app/src/main/java/com/polar/nextcloudservices/Services/NotificationWebsocketService.java +++ b/app/src/main/java/com/polar/nextcloudservices/Services/NotificationWebsocketService.java @@ -135,12 +135,8 @@ public void onWebsocketConnected() { public String getStatus() { if(!mConnectionController.checkConnection(this)){ return "Disconnected: no suitable network found"; - }else if(mNotificationWebsocket == null && mWsThread.isAlive()){ + }else if(mNotificationWebsocket == null){ return "Disconnected: can not connect to websocket. Are login details correct? Is notify_push installed on server?"; - }else if(mNotificationWebsocket == null && !mWsThread.isAlive()){ - mWsThread = new Thread(this::listenForever); - mWsThread.start(); - return "Disconnected: trying to reconnect to websocket."; } return mStatusController.getStatusString(); }