diff --git a/service/src/main/java/com/github/kr328/clash/service/ProfileManager.kt b/service/src/main/java/com/github/kr328/clash/service/ProfileManager.kt index fa10fd9ab..90184f8cf 100644 --- a/service/src/main/java/com/github/kr328/clash/service/ProfileManager.kt +++ b/service/src/main/java/com/github/kr328/clash/service/ProfileManager.kt @@ -1,6 +1,7 @@ package com.github.kr328.clash.service import android.content.Context +import com.github.kr328.clash.common.log.Log import com.github.kr328.clash.service.data.Database import com.github.kr328.clash.service.data.Imported import com.github.kr328.clash.service.data.ImportedDao @@ -24,6 +25,7 @@ import okhttp3.Request import java.io.FileNotFoundException import java.math.BigDecimal import java.util.* +import java.util.concurrent.TimeUnit class ProfileManager(private val context: Context) : IProfileManager, CoroutineScope by CoroutineScope(Dispatchers.IO) { @@ -151,10 +153,21 @@ class ProfileManager(private val context: Context) : IProfileManager, var download: Long = 0 var total: Long = 0 var expire: Long = 0 + var interval: Long = old.interval val userinfo = response.headers["subscription-userinfo"] - if (response.isSuccessful && userinfo != null) { + val updateInterval = response.headers["profile-update-interval"] + + if (updateInterval != null) { + try { + val minutes = updateInterval.toInt() * 60 // Convert hours to minutes + interval = TimeUnit.MINUTES.toMillis(minutes.toLong()) + } catch (e: NumberFormatException) { + Log.w("Invalid profile update interval value: $updateInterval", e) + } + } + if (response.isSuccessful && userinfo != null) { val flags = userinfo.split(";") for (flag in flags) { val info = flag.split("=") @@ -182,7 +195,7 @@ class ProfileManager(private val context: Context) : IProfileManager, old.name, old.type, old.source, - old.interval, + interval, upload, download, total, diff --git a/service/src/main/java/com/github/kr328/clash/service/ProfileProcessor.kt b/service/src/main/java/com/github/kr328/clash/service/ProfileProcessor.kt index 360db1f9a..e711871f9 100644 --- a/service/src/main/java/com/github/kr328/clash/service/ProfileProcessor.kt +++ b/service/src/main/java/com/github/kr328/clash/service/ProfileProcessor.kt @@ -72,6 +72,8 @@ object ProfileProcessor { var download: Long = 0 var total: Long = 0 var expire: Long = 0 + var interval = snapshot.interval + if (snapshot?.type == Profile.Type.Url) { if (snapshot.source.startsWith("https://", true)) { val client = OkHttpClient() @@ -82,6 +84,17 @@ object ProfileProcessor { client.newCall(request).execute().use { response -> val userinfo = response.headers["subscription-userinfo"] + val updateInterval = response.headers["profile-update-interval"] + + if (updateInterval != null) { + try { + val minutes = updateInterval.toInt() * 60 // Convert hours to minutes + interval = TimeUnit.MINUTES.toMillis(minutes.toLong()) + } catch (e: NumberFormatException) { + Log.w("Invalid profile update interval value: $updateInterval", e) + } + } + if (response.isSuccessful && userinfo != null) { val flags = userinfo.split(";") for (flag in flags) { @@ -108,7 +121,7 @@ object ProfileProcessor { snapshot.name, snapshot.type, snapshot.source, - snapshot.interval, + interval, upload, download, total,