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] 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