最新 Android 客户端源代码以及教程,完全免费开源最新版本
free all
This commit is contained in:
+5
@@ -7,6 +7,7 @@ import com.github.kr328.clash.common.log.Log
|
||||
import com.github.kr328.clash.service.clash.clashRuntime
|
||||
import com.github.kr328.clash.service.clash.module.*
|
||||
import com.github.kr328.clash.service.store.ServiceStore
|
||||
import com.github.kr328.clash.service.util.PreferenceManagerServer
|
||||
import com.github.kr328.clash.service.util.cancelAndJoinBlocking
|
||||
import com.github.kr328.clash.service.util.sendClashStarted
|
||||
import com.github.kr328.clash.service.util.sendClashStopped
|
||||
@@ -69,11 +70,15 @@ class ClashService : BaseService() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
//PreferenceManagerServer.init(this)
|
||||
|
||||
if (StatusProvider.serviceRunning)
|
||||
return stopSelf()
|
||||
|
||||
StatusProvider.serviceRunning = true
|
||||
|
||||
|
||||
|
||||
StaticNotificationModule.createNotificationChannel(this)
|
||||
StaticNotificationModule.notifyLoadingNotification(this)
|
||||
|
||||
|
||||
+4
-1
@@ -163,7 +163,7 @@ class ProfileWorker : BaseService() {
|
||||
.setColor(getColorCompat(R.color.color_clash))
|
||||
.setSmallIcon(R.drawable.ic_logo_service)
|
||||
.setOnlyAlertOnce(true)
|
||||
.setContentIntent(intent)
|
||||
// .setContentIntent(intent) //点击更新通知后跳转进入订阅地址编辑中心处理
|
||||
.setAutoCancel(true)
|
||||
.setGroup(RESULT_CHANNEL)
|
||||
}
|
||||
@@ -183,6 +183,7 @@ class ProfileWorker : BaseService() {
|
||||
}
|
||||
|
||||
private fun failed(uuid: UUID, name: String, reason: String) {
|
||||
/* 更新失败不提醒
|
||||
val id = UndefinedIds.next()
|
||||
|
||||
val content = getString(R.string.format_update_failure, name, reason)
|
||||
@@ -197,6 +198,8 @@ class ProfileWorker : BaseService() {
|
||||
.notify(id, notification)
|
||||
|
||||
sendProfileUpdateFailed(uuid, reason)
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@ import com.github.kr328.clash.service.clash.clashRuntime
|
||||
import com.github.kr328.clash.service.clash.module.*
|
||||
import com.github.kr328.clash.service.model.AccessControlMode
|
||||
import com.github.kr328.clash.service.store.ServiceStore
|
||||
import com.github.kr328.clash.service.util.PreferenceManagerServer
|
||||
import com.github.kr328.clash.service.util.cancelAndJoinBlocking
|
||||
import com.github.kr328.clash.service.util.parseCIDR
|
||||
import com.github.kr328.clash.service.util.sendClashStarted
|
||||
@@ -82,7 +83,7 @@ class TunService : VpnService(), CoroutineScope by CoroutineScope(Dispatchers.De
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
//PreferenceManagerServer.init(this)
|
||||
if (StatusProvider.serviceRunning)
|
||||
return stopSelf()
|
||||
|
||||
|
||||
+9
-3
@@ -1,6 +1,7 @@
|
||||
package com.github.kr328.clash.service.clash.module
|
||||
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import com.github.kr328.clash.common.constants.Intents
|
||||
import com.github.kr328.clash.common.log.Log
|
||||
import com.github.kr328.clash.core.Clash
|
||||
@@ -8,6 +9,7 @@ import com.github.kr328.clash.service.StatusProvider
|
||||
import com.github.kr328.clash.service.data.ImportedDao
|
||||
import com.github.kr328.clash.service.data.SelectionDao
|
||||
import com.github.kr328.clash.service.store.ServiceStore
|
||||
import com.github.kr328.clash.service.util.PreferenceManagerServer
|
||||
import com.github.kr328.clash.service.util.importedDir
|
||||
import com.github.kr328.clash.service.util.sendProfileLoaded
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
@@ -45,7 +47,7 @@ class ConfigurationModule(service: Service) : Module<ConfigurationModule.LoadExc
|
||||
|
||||
try {
|
||||
val current = store.activeProfile
|
||||
?: throw NullPointerException("No profile selected")
|
||||
?: throw NullPointerException("刷新节点数据成功,请重新点击连接VPN")
|
||||
|
||||
if (current == loaded && changed != null && changed != loaded)
|
||||
continue
|
||||
@@ -53,7 +55,7 @@ class ConfigurationModule(service: Service) : Module<ConfigurationModule.LoadExc
|
||||
loaded = current
|
||||
|
||||
val active = ImportedDao().queryByUUID(current)
|
||||
?: throw NullPointerException("No profile selected")
|
||||
?: throw NullPointerException("刷新节点数据成功,请重新点击连接VPN")
|
||||
|
||||
Clash.load(service.importedDir.resolve(active.uuid.toString())).await()
|
||||
|
||||
@@ -63,7 +65,11 @@ class ConfigurationModule(service: Service) : Module<ConfigurationModule.LoadExc
|
||||
|
||||
SelectionDao().removeSelections(active.uuid, remove)
|
||||
|
||||
StatusProvider.currentProfile = active.name
|
||||
StatusProvider.currentProfile = active.name //之前的是按照 Profile 文件名展示通知栏
|
||||
//StatusProvider.currentProfile = PreferenceManagerServer.selectnodeName
|
||||
|
||||
//val nodeName = PreferenceManagerServer.selectnodeName
|
||||
//println("Selected node name>>>>>>>>>:${PreferenceManagerServer.modeName} $nodeName")
|
||||
|
||||
service.sendProfileLoaded(current)
|
||||
|
||||
|
||||
+10
-3
@@ -17,6 +17,7 @@ import com.github.kr328.clash.core.util.trafficDownload
|
||||
import com.github.kr328.clash.core.util.trafficUpload
|
||||
import com.github.kr328.clash.service.R
|
||||
import com.github.kr328.clash.service.StatusProvider
|
||||
import com.github.kr328.clash.service.util.PreferenceManagerServer
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.selects.select
|
||||
@@ -29,7 +30,7 @@ class DynamicNotificationModule(service: Service) : Module<Unit>(service) {
|
||||
.setColor(service.getColorCompat(R.color.color_clash))
|
||||
.setOnlyAlertOnce(true)
|
||||
.setShowWhen(false)
|
||||
.setContentTitle("Not Selected")
|
||||
.setContentTitle("")//Not Selected
|
||||
.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE)
|
||||
.setContentIntent(
|
||||
PendingIntent.getActivity(
|
||||
@@ -67,6 +68,11 @@ class DynamicNotificationModule(service: Service) : Module<Unit>(service) {
|
||||
)
|
||||
.build()
|
||||
|
||||
PreferenceManagerServer.init(service.application)
|
||||
val nodeName = PreferenceManagerServer.selectnodeName
|
||||
val modeNamech = if (PreferenceManagerServer.modeName == "Rule") "智能模式" else "全局模式"
|
||||
var contentitle = "${modeNamech}(${nodeName})"
|
||||
builder.setContentTitle(contentitle)
|
||||
notificationManager.notify(R.id.nf_clash_status, notification)
|
||||
}
|
||||
|
||||
@@ -82,7 +88,7 @@ class DynamicNotificationModule(service: Service) : Module<Unit>(service) {
|
||||
addAction(Intents.ACTION_PROFILE_LOADED)
|
||||
}
|
||||
|
||||
val ticker = ticker(TimeUnit.SECONDS.toMillis(1))
|
||||
val ticker = ticker(TimeUnit.SECONDS.toMillis(2))
|
||||
|
||||
while (true) {
|
||||
select<Unit> {
|
||||
@@ -95,7 +101,8 @@ class DynamicNotificationModule(service: Service) : Module<Unit>(service) {
|
||||
}
|
||||
}
|
||||
profileLoaded.onReceive {
|
||||
builder.setContentTitle(StatusProvider.currentProfile ?: "Not selected")
|
||||
//builder.setContentTitle(StatusProvider.currentProfile ?: "Not selected 1")
|
||||
//builder.setContentTitle(PreferenceManagerServer.selectnodeName)
|
||||
}
|
||||
if (shouldUpdate) {
|
||||
ticker.onReceive {
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@ class StaticNotificationModule(service: Service) : Module<Unit>(service) {
|
||||
private val builder = NotificationCompat.Builder(service, CHANNEL_ID)
|
||||
.setSmallIcon(R.drawable.ic_logo_service)
|
||||
.setOngoing(true)
|
||||
.setColor(service.getColorCompat(R.color.color_clash))
|
||||
//.setColor(service.getColorCompat(R.color.color_clash))
|
||||
.setOnlyAlertOnce(true)
|
||||
.setShowWhen(false)
|
||||
.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE)
|
||||
@@ -40,10 +40,10 @@ class StaticNotificationModule(service: Service) : Module<Unit>(service) {
|
||||
while (true) {
|
||||
loaded.receive()
|
||||
|
||||
val profileName = StatusProvider.currentProfile ?: "Not selected"
|
||||
val profileName = StatusProvider.currentProfile+ " 2" ?: "Not selected 2"
|
||||
|
||||
val notification = builder
|
||||
.setContentTitle(profileName)
|
||||
.setContentTitle(profileName)
|
||||
.setContentText(service.getText(R.string.running))
|
||||
.build()
|
||||
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.github.kr328.clash.service.util
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
|
||||
|
||||
|
||||
object PreferenceManagerServer {
|
||||
private const val PREF_NAME = "app_preferences"
|
||||
|
||||
private lateinit var prefs: SharedPreferences
|
||||
|
||||
fun init(context: Context) {
|
||||
prefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE or Context.MODE_MULTI_PROCESS)
|
||||
|
||||
}
|
||||
|
||||
var modeName: String
|
||||
get() = prefs.getString("modeName", "Rule") ?: "Rule"
|
||||
set(value) {
|
||||
prefs.edit().putString("modeName", value).apply()
|
||||
}
|
||||
|
||||
var selectnodeName: String
|
||||
get() = prefs.getString("selectnodeName", "自动选择") ?: "自动选择"
|
||||
set(value) {
|
||||
prefs.edit().putString("selectnodeName", value).apply()
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
@@ -1,11 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:width="205dp"
|
||||
android:height="205dp"
|
||||
android:viewportWidth="205"
|
||||
android:viewportHeight="200"
|
||||
android:tint="@color/color_clash">
|
||||
<path
|
||||
android:pathData="M 31.55 16.82 C 32.47 16.76 33.46 16.72 34.27 17.21 C 35.55 17.98 36.58 19.09 37.68 20.07 C 54.09 35.08 70.55 50.02 86.96 65.03 C 88.06 66.02 89.1 67.14 90.46 67.79 C 91.53 68.3 92.75 68.05 93.88 67.89 C 96.89 67.38 99.95 67.35 102.99 67.35 C 105.92 67.4 108.87 67.49 111.76 67.97 C 112.92 68.11 114.31 68.48 115.19 67.47 C 133.27 50.95 151.41 34.47 169.52 17.94 C 171.05 16.35 173.4 16.7 175.4 16.94 C 180.44 17.69 185.53 18.04 190.6 18.61 C 191.44 18.77 192.63 18.83 192.92 19.84 C 193.32 21.57 193.1 23.36 193.14 25.12 C 193.12 60.85 193.12 96.58 193.1 132.31 C 193.08 134.12 193.2 135.94 193.02 137.73 C 192.94 138.38 192.86 139.13 192.33 139.58 C 191.21 140.08 189.96 140.25 188.78 140.55 C 183.71 141.73 178.57 142.58 173.52 143.87 C 170.99 144.53 168.37 144.28 165.79 144.32 C 164.47 144.3 163.11 144.41 161.79 144.2 C 161.02 144.14 160.47 143.45 160.41 142.7 C 160.13 140.92 160.29 139.13 160.27 137.34 C 160.25 119.75 160.23 102.16 160.25 84.57 C 160.23 82.83 160.35 81.08 160.11 79.34 C 159.79 77.35 157.71 75.95 155.75 76.19 C 154.67 76.21 153.74 76.88 152.95 77.57 C 144.22 85.61 135.39 93.52 126.67 101.55 C 125.66 102.42 124.52 103.42 123.1 103.28 C 121.23 103.12 119.47 102.45 117.66 102.04 C 110.4 100.22 102.83 100.01 95.42 100.64 C 91.81 101.13 88.16 101.55 84.69 102.69 C 83.57 103 82.44 103.36 81.28 103.3 C 80.1 103.22 79.17 102.43 78.32 101.7 C 69.66 93.74 60.91 85.91 52.25 77.94 C 51.41 77.21 50.5 76.41 49.35 76.23 C 47.92 76.05 46.44 76.64 45.45 77.69 C 44.6 78.65 44.56 79.99 44.52 81.22 C 44.56 101.19 44.5 121.15 44.54 141.12 C 44.5 141.89 44.5 142.68 44.21 143.41 C 43.75 144.24 42.69 144.28 41.86 144.32 C 39.61 144.35 37.38 144.3 35.14 144.32 C 32.61 144.35 30.17 143.62 27.72 143.11 C 23.25 142.13 18.77 141.12 14.28 140.18 C 13.33 139.94 12.01 139.66 11.83 138.5 C 11.55 136.45 11.75 134.38 11.71 132.31 C 11.67 96.72 11.69 61.12 11.69 25.53 C 11.69 23.85 11.59 22.18 11.75 20.52 C 11.81 19.91 11.99 19.2 12.58 18.89 C 13.21 18.61 13.92 18.57 14.59 18.47 C 20.27 18.08 25.91 17.39 31.55 16.82 Z M 98.96 148.02 C 101.51 147.81 104.07 147.89 106.6 148.02 C 108.57 148.01 109.79 150.39 108.88 152.07 C 107.78 154.27 106.63 156.44 105.33 158.55 C 104.51 160.07 102.1 160.37 101.02 158.97 C 99.97 157.69 99.36 156.15 98.53 154.73 C 97.9 153.54 97.09 152.42 96.79 151.08 C 96.5 149.68 97.56 148.22 98.96 148.02 Z M 13.54 152.62 C 14.04 152.56 14.53 152.52 15.04 152.52 C 29.14 152.56 43.24 152.54 57.36 152.54 C 58.62 152.52 60.06 152.83 60.81 153.98 C 61.58 155.26 61.42 157.25 60.08 158.1 C 59.17 158.73 58.01 158.73 56.94 158.77 C 42.98 158.73 29 158.75 15.04 158.77 C 14.26 158.73 13.47 158.73 12.74 158.48 C 11.53 158.02 10.73 156.7 10.9 155.42 C 11 154.04 12.11 152.74 13.54 152.62 Z M 146.68 152.62 C 148.57 152.42 150.49 152.58 152.4 152.54 C 164.96 152.52 177.54 152.58 190.1 152.52 C 190.91 152.56 191.76 152.54 192.51 152.87 C 193.63 153.37 194.26 154.59 194.26 155.79 C 194.28 157.19 193.12 158.51 191.72 158.65 C 189.92 158.87 188.11 158.73 186.31 158.75 L 151.55 158.75 C 149.78 158.73 147.98 158.89 146.23 158.59 C 144.91 158.36 143.82 157.15 143.92 155.77 C 143.74 154.15 145.12 152.73 146.68 152.62 Z M 56.69 167.7 C 57.62 167.45 58.66 167.31 59.55 167.76 C 61.4 168.61 61.84 171.57 60.18 172.85 C 59.19 173.54 58.01 173.81 56.91 174.21 C 52.73 175.51 48.66 177.15 44.48 178.45 C 39.67 179.97 34.96 181.76 30.17 183.38 C 26.68 184.5 23.21 185.68 19.74 186.89 C 18.3 187.38 16.9 188.01 15.42 188.33 C 14.51 188.52 13.5 188.35 12.79 187.74 C 11.61 186.81 11.39 185.02 12.07 183.73 C 12.62 182.81 13.72 182.47 14.67 182.1 C 17.67 181.05 20.62 179.97 23.64 179.02 C 31.19 176.57 38.62 173.74 46.2 171.35 C 49.73 170.21 53.16 168.81 56.69 167.7 Z M 146.25 167.55 C 147.33 167.29 148.4 167.7 149.42 168 C 152.72 169.12 155.95 170.38 159.26 171.45 C 167.05 173.91 174.68 176.85 182.49 179.32 C 185.05 180.14 187.59 181.09 190.16 181.98 C 191.13 182.35 192.19 182.67 192.9 183.48 C 194.02 185.02 193.35 187.52 191.56 188.21 C 190.4 188.66 189.17 188.21 188.05 187.86 C 183.41 186.14 178.72 184.6 174.03 183.06 C 169.46 181.49 164.92 179.81 160.33 178.35 C 156.15 177.03 152.1 175.39 147.92 174.11 C 146.82 173.72 145.64 173.44 144.75 172.65 C 143.15 171.09 144.02 167.94 146.25 167.55 Z"
|
||||
android:fillColor="#FFFFFFFF" />
|
||||
</vector>
|
||||
@@ -10,7 +10,7 @@
|
||||
<string name="format_update_failure">更新 %1$s: %2$s </string>
|
||||
<string name="running">実行中</string>
|
||||
<string name="loading">読み込み中</string>
|
||||
<string name="clash_meta_for_android">LiteVPN</string>
|
||||
<string name="clash_meta_for_android">UUVPN</string>
|
||||
<string name="profiles_and_providers">プロファイルと外部リソース</string>
|
||||
<string name="configuration_yaml">コンフィグ.yaml</string>
|
||||
<string name="provider_files">外部リソースファイル</string>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<string name="format_update_failure">업데이트 %1$s: %2$s</string>
|
||||
<string name="running">연결됨</string>
|
||||
<string name="loading">로딩중</string>
|
||||
<string name="clash_meta_for_android">LiteVPN</string>
|
||||
<string name="clash_meta_for_android">UUVPN</string>
|
||||
<string name="profiles_and_providers">구성 파일과 외부 리소스</string>
|
||||
<string name="configuration_yaml">구성 파일.yaml</string>
|
||||
<string name="provider_files">외부 리소스 파일</string>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<string name="running">正在運行</string>
|
||||
<string name="format_update_complete">更新 %s 成功</string>
|
||||
<string name="format_update_failure">"更新 %1$s: %2$s "</string>
|
||||
<string name="clash_meta_for_android">LiteVPN</string>
|
||||
<string name="clash_meta_for_android">UUVPN</string>
|
||||
<string name="profiles_and_providers">配置文件和外部資源</string>
|
||||
<string name="configuration_yaml">配置文件.yaml</string>
|
||||
<string name="provider_files">外部資源文件列表</string>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<string name="running">正在運作</string>
|
||||
<string name="format_update_complete">更新 %s 成功</string>
|
||||
<string name="format_update_failure">"更新 %1$s: %2$s "</string>
|
||||
<string name="clash_meta_for_android">LiteVPN</string>
|
||||
<string name="clash_meta_for_android">UUVPN</string>
|
||||
<string name="profiles_and_providers">設定檔和外部資源</string>
|
||||
<string name="configuration_yaml">設定檔.yaml</string>
|
||||
<string name="provider_files">外部資源文件列表</string>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<string name="running">正在运行</string>
|
||||
<string name="format_update_complete">更新 %s 成功</string>
|
||||
<string name="format_update_failure">"更新 %1$s: %2$s "</string>
|
||||
<string name="clash_meta_for_android">LiteVPN</string>
|
||||
<string name="clash_meta_for_android">UUVPN</string>
|
||||
<string name="profiles_and_providers">配置文件和外部资源</string>
|
||||
<string name="configuration_yaml">配置文件.yaml</string>
|
||||
<string name="provider_files">外部资源文件列表</string>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="color_clash">#1E4376</color>
|
||||
</resources>
|
||||
</resources>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<string name="format_update_failure">Update %1$s: %2$s</string>
|
||||
<string name="running">Running</string>
|
||||
<string name="loading">Loading</string>
|
||||
<string name="clash_meta_for_android">LiteVPN</string>
|
||||
<string name="clash_meta_for_android">UUVPN</string>
|
||||
<string name="profiles_and_providers">Profiles and Providers</string>
|
||||
<string name="configuration_yaml">Configuration.yaml</string>
|
||||
<string name="provider_files">Provider Files</string>
|
||||
|
||||
Reference in New Issue
Block a user