Skip to content

Commit 9df2ede

Browse files
yqx1110hamjin
authored andcommitted
fix broadcast receiver not registered when application started with no ui, e.g. from settings tile or external control
Signed-off-by: hamjin <jinham@qq.com>
1 parent 51486a3 commit 9df2ede

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

app/src/main/java/com/github/kr328/clash/remote/Broadcasts.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class Broadcasts(private val context: Application) {
100100
})
101101

102102
clashRunning = StatusClient(context).currentProfile() != null
103+
registered = true
103104
} catch (e: Exception) {
104105
Log.w("Register global receiver: $e", e)
105106
}
@@ -113,6 +114,7 @@ class Broadcasts(private val context: Application) {
113114
context.unregisterReceiver(broadcastReceiver)
114115

115116
clashRunning = false
117+
registered = false
116118
} catch (e: Exception) {
117119
Log.w("Unregister global receiver: $e", e)
118120
}

app/src/main/java/com/github/kr328/clash/remote/Remote.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ object Remote {
3030
fun launch() {
3131
ApplicationObserver.attach(Global.application)
3232

33+
broadcasts.register()
34+
3335
ApplicationObserver.onVisibleChanged {
3436
if(it) {
3537
Log.d("App becomes visible")
3638
service.bind()
37-
broadcasts.register()
3839
}
3940
else {
4041
Log.d("App becomes invisible")
4142
service.unbind()
42-
broadcasts.unregister()
4343
}
4444
}
4545

0 commit comments

Comments
 (0)