This commit is contained in:
Finnley Somdahl 2023-12-04 22:15:48 -06:00
parent c728eae2ba
commit 8c957007ab
2 changed files with 7 additions and 12 deletions

View file

@ -105,17 +105,14 @@ class DiscordService : Service() {
if (intent != null) { if (intent != null) {
if (intent.hasExtra("presence")) { if (intent.hasExtra("presence")) {
log("Service onStartCommand() setPresence") log("Service onStartCommand() setPresence")
var lPresence = intent.getStringExtra("presence") val lPresence = intent.getStringExtra("presence")
if (this::webSocket.isInitialized) webSocket.send(lPresence!!) if (this::webSocket.isInitialized) webSocket.send(lPresence!!)
presenceStore = lPresence!! presenceStore = lPresence!!
} else { } else {
log("Service onStartCommand() no presence") log("Service onStartCommand() no presence")
DiscordServiceRunningSingleton.running = false DiscordServiceRunningSingleton.running = false
client.dispatcher.executorService.shutdown() //kill the client
stopSelf() client = OkHttpClient()
}
if (intent.hasExtra(ACTION_STOP_SERVICE)) {
log("Service onStartCommand() stopService")
stopSelf() stopSelf()
} }
} }
@ -145,6 +142,7 @@ class DiscordService : Service() {
wakeLock.release() wakeLock.release()
} }
SERVICE_RUNNING = false SERVICE_RUNNING = false
client = OkHttpClient()
if (this::webSocket.isInitialized) webSocket.close(1000, "Closed by user") if (this::webSocket.isInitialized) webSocket.close(1000, "Closed by user")
super.onDestroy() super.onDestroy()
//saveLogToFile() //saveLogToFile()
@ -468,7 +466,6 @@ class DiscordService : Service() {
companion object { companion object {
var SERVICE_RUNNING = false var SERVICE_RUNNING = false
const val ACTION_STOP_SERVICE = "ACTION_STOP_SERVICE"
} }
} }

View file

@ -124,12 +124,10 @@ class MangaReaderActivity : AppCompatActivity() {
override fun onDestroy() { override fun onDestroy() {
mangaCache.clear() mangaCache.clear()
val stopIntent = Intent(this, DiscordService::class.java).apply { if (isOnline(baseContext)) { //TODO:
putExtra(DiscordService.ACTION_STOP_SERVICE, true)
}
if (!isOnline(this)) { //TODO:
DiscordServiceRunningSingleton.running = false DiscordServiceRunningSingleton.running = false
startService(stopIntent) val stopIntent = Intent(this, DiscordService::class.java)
stopService(stopIntent)
} }
super.onDestroy() super.onDestroy()
} }