Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed May 11, 2024
1 parent 06d486c commit 2aed021
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
5 changes: 2 additions & 3 deletions app/src/main/java/io/legado/app/service/WebService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,11 @@ class WebService : BaseService() {
if (addressList.any()) {
notificationList.addAll(addressList.map { address -> getString(R.string.http_ip, address.hostAddress, getPort()) })
hostAddress = notificationList.first()
startForegroundNotification()
} else {
hostAddress = getString(R.string.network_connection_unavailable)
notificationList.add(hostAddress)
startForegroundNotification()
}
startForegroundNotification()
postEvent(EventBus.WEB_SERVICE, hostAddress)
}
}
Expand Down Expand Up @@ -184,6 +183,7 @@ class WebService : BaseService() {
*/
override fun startForegroundNotification() {
val builder = NotificationCompat.Builder(this, AppConst.channelIdWeb)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setSmallIcon(R.drawable.ic_web_service_noti)
.setOngoing(true)
.setContentTitle(getString(R.string.web_service))
Expand All @@ -196,7 +196,6 @@ class WebService : BaseService() {
getString(R.string.cancel),
servicePendingIntent<WebService>(IntentAction.stop)
)
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
val notification = builder.build()
startForeground(NotificationId.WebService, notification)
}
Expand Down
10 changes: 4 additions & 6 deletions app/src/main/java/io/legado/app/utils/NetworkUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -194,24 +194,22 @@ object NetworkUtils {
enumeration = NetworkInterface.getNetworkInterfaces()
} catch (e: SocketException) {
e.printOnDebug()
return mutableListOf()
return emptyList()
}

var fallbackAddress: MutableList<InetAddress> = mutableListOf()
val addressList = mutableListOf<InetAddress>()

while (enumeration.hasMoreElements()) {
val nif = enumeration.nextElement()
val addresses = nif.inetAddresses ?: continue
while (addresses.hasMoreElements()) {
val address = addresses.nextElement()
if (!address.isLoopbackAddress && isIPv4Address(address.hostAddress)) {
if (nif.name?.startsWith("wlan") == true) {
fallbackAddress.add(address)
}
addressList.add(address)
}
}
}
return fallbackAddress
return addressList
}

/**
Expand Down

0 comments on commit 2aed021

Please sign in to comment.