Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Jun 5, 2024
1 parent 2e757ee commit c53e789
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions app/src/main/java/io/legado/app/service/WebService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.net.wifi.WifiManager
import android.os.Build
import android.os.PowerManager
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import io.legado.app.R
import io.legado.app.base.BaseService
import io.legado.app.constant.AppConst
Expand All @@ -23,6 +22,7 @@ import io.legado.app.utils.postEvent
import io.legado.app.utils.printOnDebug
import io.legado.app.utils.sendToClip
import io.legado.app.utils.servicePendingIntent
import io.legado.app.utils.startForegroundServiceCompat
import io.legado.app.utils.startService
import io.legado.app.utils.stopService
import io.legado.app.utils.toastOnUi
Expand All @@ -45,7 +45,7 @@ class WebService : BaseService() {

fun startForeground(context: Context) {
val intent = Intent(context, WebService::class.java)
ContextCompat.startForegroundService(context, intent)
context.startForegroundServiceCompat(intent)
}

fun stop(context: Context) {
Expand Down Expand Up @@ -94,7 +94,13 @@ class WebService : BaseService() {
val addressList = NetworkUtils.getLocalIPAddress()
notificationList.clear()
if (addressList.any()) {
notificationList.addAll(addressList.map { address -> getString(R.string.http_ip, address.hostAddress, getPort()) })
notificationList.addAll(addressList.map { address ->
getString(
R.string.http_ip,
address.hostAddress,
getPort()
)
})
hostAddress = notificationList.first()
} else {
hostAddress = getString(R.string.network_connection_unavailable)
Expand Down Expand Up @@ -154,7 +160,13 @@ class WebService : BaseService() {
httpServer?.start()
webSocketServer?.start(1000 * 30) // 通信超时设置
notificationList.clear()
notificationList.addAll(addressList.map { address -> getString(R.string.http_ip, address.hostAddress, getPort()) })
notificationList.addAll(addressList.map { address ->
getString(
R.string.http_ip,
address.hostAddress,
getPort()
)
})
hostAddress = notificationList.first()
isRun = true
postEvent(EventBus.WEB_SERVICE, hostAddress)
Expand Down

0 comments on commit c53e789

Please sign in to comment.