@@ -79,7 +79,7 @@ class HttpService : Service(), OnSimpleLife {
79
79
80
80
val scope = useScope()
81
81
82
- private val httpServerPortFlow = storeFlow.mapState(scope) { s -> s.httpServerPort }
82
+ val httpServerPortFlow = storeFlow.mapState(scope) { s -> s.httpServerPort }
83
83
84
84
init {
85
85
useLogLifecycle()
@@ -88,7 +88,9 @@ class HttpService : Service(), OnSimpleLife {
88
88
StopServiceReceiver .autoRegister()
89
89
onCreated {
90
90
scope.launchTry(Dispatchers .IO ) {
91
- localNetworkIpsFlow.value = getIpAddressInLocalNetwork()
91
+ httpServerPortFlow.collect {
92
+ localNetworkIpsFlow.value = getIpAddressInLocalNetwork()
93
+ }
92
94
}
93
95
}
94
96
onDestroyed {
@@ -98,13 +100,16 @@ class HttpService : Service(), OnSimpleLife {
98
100
httpServerFlow.value = null
99
101
}
100
102
onCreated {
101
- httpNotif.copy(text = " 端口- ${storeFlow.value.httpServerPort} " ). notifyService()
103
+ httpNotif.notifyService()
102
104
scope.launchTry(Dispatchers .IO ) {
103
105
httpServerPortFlow.collect { port ->
104
- httpServerFlow.value?.stop()
105
- httpServerFlow.value = null
106
+ val isReboot = httpServerFlow.value != null
107
+ httpServerFlow.apply {
108
+ value?.stop()
109
+ value = null
110
+ }
106
111
if (! isPortAvailable(port)) {
107
- toast(" 端口 $port 被占用, 请更换后重试" )
112
+ toast(" 端口 $port 被占用, 请更换后重试" )
108
113
stopSelf()
109
114
return @collect
110
115
}
@@ -117,8 +122,8 @@ class HttpService : Service(), OnSimpleLife {
117
122
}
118
123
if (httpServerFlow.value == null ) {
119
124
stopSelf()
120
- } else {
121
- httpNotif.copy(text = " 端口- $port " ).notifyService( )
125
+ } else if (isReboot) {
126
+ toast( " HTTP服务重启成功 " )
122
127
}
123
128
}
124
129
}
0 commit comments