mirror of
https://github.com/gedoor/legado.git
synced 2024-07-04 23:36:56 +08:00
优化
This commit is contained in:
parent
2e757ee105
commit
c53e789762
|
@ -7,7 +7,6 @@ import android.net.wifi.WifiManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.BaseService
|
import io.legado.app.base.BaseService
|
||||||
import io.legado.app.constant.AppConst
|
import io.legado.app.constant.AppConst
|
||||||
|
@ -23,6 +22,7 @@ import io.legado.app.utils.postEvent
|
||||||
import io.legado.app.utils.printOnDebug
|
import io.legado.app.utils.printOnDebug
|
||||||
import io.legado.app.utils.sendToClip
|
import io.legado.app.utils.sendToClip
|
||||||
import io.legado.app.utils.servicePendingIntent
|
import io.legado.app.utils.servicePendingIntent
|
||||||
|
import io.legado.app.utils.startForegroundServiceCompat
|
||||||
import io.legado.app.utils.startService
|
import io.legado.app.utils.startService
|
||||||
import io.legado.app.utils.stopService
|
import io.legado.app.utils.stopService
|
||||||
import io.legado.app.utils.toastOnUi
|
import io.legado.app.utils.toastOnUi
|
||||||
|
@ -45,7 +45,7 @@ class WebService : BaseService() {
|
||||||
|
|
||||||
fun startForeground(context: Context) {
|
fun startForeground(context: Context) {
|
||||||
val intent = Intent(context, WebService::class.java)
|
val intent = Intent(context, WebService::class.java)
|
||||||
ContextCompat.startForegroundService(context, intent)
|
context.startForegroundServiceCompat(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stop(context: Context) {
|
fun stop(context: Context) {
|
||||||
|
@ -94,7 +94,13 @@ class WebService : BaseService() {
|
||||||
val addressList = NetworkUtils.getLocalIPAddress()
|
val addressList = NetworkUtils.getLocalIPAddress()
|
||||||
notificationList.clear()
|
notificationList.clear()
|
||||||
if (addressList.any()) {
|
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()
|
hostAddress = notificationList.first()
|
||||||
} else {
|
} else {
|
||||||
hostAddress = getString(R.string.network_connection_unavailable)
|
hostAddress = getString(R.string.network_connection_unavailable)
|
||||||
|
@ -154,7 +160,13 @@ class WebService : BaseService() {
|
||||||
httpServer?.start()
|
httpServer?.start()
|
||||||
webSocketServer?.start(1000 * 30) // 通信超时设置
|
webSocketServer?.start(1000 * 30) // 通信超时设置
|
||||||
notificationList.clear()
|
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()
|
hostAddress = notificationList.first()
|
||||||
isRun = true
|
isRun = true
|
||||||
postEvent(EventBus.WEB_SERVICE, hostAddress)
|
postEvent(EventBus.WEB_SERVICE, hostAddress)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user