Skip to content

Commit dac8c55

Browse files
committed
Optimize performance
Optimize core stability Update core Fix linux tun authority check error Fix some issues
1 parent 96328f6 commit dac8c55

File tree

129 files changed

+12739
-8657
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+12739
-8657
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@
66
path = plugins/flutter_distributor
77
url = git@github.com:chen08209/flutter_distributor.git
88
branch = FlClash
9+
[submodule "plugins/tray_manager"]
10+
path = plugins/tray_manager
11+
url = git@github.com:chen08209/tray_manager.git
12+
branch = main
13+
14+

analysis_options.yaml

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,8 @@
1-
# This file configures the analyzer, which statically analyzes Dart code to
2-
# check for errors, warnings, and lints.
3-
#
4-
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5-
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6-
# invoked from the command line by running `flutter analyze`.
7-
8-
# The following line activates a set of recommended lints for Flutter apps,
9-
# packages, and plugins designed to encourage good coding practices.
101
include: package:flutter_lints/flutter.yaml
112

123
linter:
13-
# The lint rules applied to this project can be customized in the
14-
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
15-
# included above or to enable additional rules. A list of all available lints
16-
# and their documentation is published at
17-
# https://dart-lang.github.io/linter/lints/index.html.
18-
#
19-
# Instead of disabling a lint rule for the entire project in the
20-
# section below, it can also be suppressed for a single line of code
21-
# or a specific dart file by using the `// ignore: name_of_lint` and
22-
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
23-
# producing the lint.
244
rules:
25-
# avoid_print: false # Uncomment to disable the `avoid_print` rule
26-
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
275

28-
# Additional information about this file can be found at
29-
# https://dart.dev/guides/language/analysis-options
6+
analyzer:
7+
plugins:
8+
- custom_lint

android/app/src/main/kotlin/com/follow/clash/models/Props.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ enum class AccessControlMode {
77
}
88

99
data class AccessControl(
10+
val enable: Boolean,
1011
val mode: AccessControlMode,
1112
val acceptList: List<String>,
1213
val rejectList: List<String>,
@@ -17,7 +18,7 @@ data class CIDR(val address: InetAddress, val prefixLength: Int)
1718
data class VpnOptions(
1819
val enable: Boolean,
1920
val port: Int,
20-
val accessControl: AccessControl?,
21+
val accessControl: AccessControl,
2122
val allowBypass: Boolean,
2223
val systemProxy: Boolean,
2324
val bypassDomain: List<String>,

android/app/src/main/kotlin/com/follow/clash/plugins/VpnPlugin.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import android.net.NetworkCapabilities
1010
import android.net.NetworkRequest
1111
import android.os.Build
1212
import android.os.IBinder
13+
import android.util.Log
1314
import androidx.core.content.getSystemService
1415
import com.follow.clash.FlClashApplication
1516
import com.follow.clash.GlobalState
@@ -92,11 +93,13 @@ data object VpnPlugin : FlutterPlugin, MethodChannel.MethodCallHandler {
9293

9394
"setProtect" -> {
9495
val fd = call.argument<Int>("fd")
95-
if (fd != null) {
96-
if (flClashService is FlClashVpnService) {
96+
if (fd != null && flClashService is FlClashVpnService) {
97+
try {
9798
(flClashService as FlClashVpnService).protect(fd)
99+
result.success(true)
100+
} catch (e: RuntimeException) {
101+
result.success(false)
98102
}
99-
result.success(true)
100103
} else {
101104
result.success(false)
102105
}

android/app/src/main/kotlin/com/follow/clash/services/FlClashVpnService.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,19 @@ class FlClashVpnService : VpnService(), BaseServiceInterface {
6868
}
6969
addDnsServer(options.dnsServerAddress)
7070
setMtu(9000)
71-
options.accessControl?.let { accessControl ->
72-
when (accessControl.mode) {
73-
AccessControlMode.acceptSelected -> {
74-
(accessControl.acceptList + packageName).forEach {
75-
addAllowedApplication(it)
71+
options.accessControl.let { accessControl ->
72+
if (accessControl.enable) {
73+
when (accessControl.mode) {
74+
AccessControlMode.acceptSelected -> {
75+
(accessControl.acceptList + packageName).forEach {
76+
addAllowedApplication(it)
77+
}
7678
}
77-
}
7879

79-
AccessControlMode.rejectSelected -> {
80-
(accessControl.rejectList - packageName).forEach {
81-
addDisallowedApplication(it)
80+
AccessControlMode.rejectSelected -> {
81+
(accessControl.rejectList - packageName).forEach {
82+
addDisallowedApplication(it)
83+
}
8284
}
8385
}
8486
}

build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ targets:
55
options:
66
build_extensions:
77
'^lib/models/{{}}.dart': 'lib/models/generated/{{}}.g.dart'
8+
'^lib/providers/{{}}.dart': 'lib/providers/generated/{{}}.g.dart'
89
freezed:
910
options:
1011
build_extensions:

core/Clash.Meta

Submodule Clash.Meta updated 93 files

core/action.go

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,146 +22,156 @@ func (result ActionResult) Json() ([]byte, error) {
2222
return data, err
2323
}
2424

25-
func (action Action) wrapMessage(data interface{}) []byte {
26-
sendAction := ActionResult{
25+
func (action Action) getResult(data interface{}) []byte {
26+
resultAction := ActionResult{
2727
Id: action.Id,
2828
Method: action.Method,
2929
Data: data,
3030
}
31-
res, _ := sendAction.Json()
31+
res, _ := resultAction.Json()
3232
return res
3333
}
3434

35-
func handleAction(action *Action, send func([]byte)) {
35+
func handleAction(action *Action, result func(data interface{})) {
3636
switch action.Method {
3737
case initClashMethod:
3838
data := action.Data.(string)
39-
send(action.wrapMessage(handleInitClash(data)))
39+
result(handleInitClash(data))
4040
return
4141
case getIsInitMethod:
42-
send(action.wrapMessage(handleGetIsInit()))
42+
result(handleGetIsInit())
4343
return
4444
case forceGcMethod:
4545
handleForceGc()
46-
send(action.wrapMessage(true))
46+
result(true)
4747
return
4848
case shutdownMethod:
49-
send(action.wrapMessage(handleShutdown()))
49+
result(handleShutdown())
5050
return
5151
case validateConfigMethod:
5252
data := []byte(action.Data.(string))
53-
send(action.wrapMessage(handleValidateConfig(data)))
53+
result(handleValidateConfig(data))
5454
return
5555
case updateConfigMethod:
5656
data := []byte(action.Data.(string))
57-
send(action.wrapMessage(handleUpdateConfig(data)))
57+
result(handleUpdateConfig(data))
5858
return
5959
case getProxiesMethod:
60-
send(action.wrapMessage(handleGetProxies()))
60+
result(handleGetProxies())
6161
return
6262
case changeProxyMethod:
6363
data := action.Data.(string)
6464
handleChangeProxy(data, func(value string) {
65-
send(action.wrapMessage(value))
65+
result(value)
6666
})
6767
return
6868
case getTrafficMethod:
69-
send(action.wrapMessage(handleGetTraffic()))
69+
result(handleGetTraffic())
7070
return
7171
case getTotalTrafficMethod:
72-
send(action.wrapMessage(handleGetTotalTraffic()))
72+
result(handleGetTotalTraffic())
7373
return
7474
case resetTrafficMethod:
7575
handleResetTraffic()
76-
send(action.wrapMessage(true))
76+
result(true)
7777
return
7878
case asyncTestDelayMethod:
7979
data := action.Data.(string)
8080
handleAsyncTestDelay(data, func(value string) {
81-
send(action.wrapMessage(value))
81+
result(value)
8282
})
8383
return
8484
case getConnectionsMethod:
85-
send(action.wrapMessage(handleGetConnections()))
85+
result(handleGetConnections())
8686
return
8787
case closeConnectionsMethod:
88-
send(action.wrapMessage(handleCloseConnections()))
88+
result(handleCloseConnections())
8989
return
9090
case closeConnectionMethod:
9191
id := action.Data.(string)
92-
send(action.wrapMessage(handleCloseConnection(id)))
92+
result(handleCloseConnection(id))
9393
return
9494
case getExternalProvidersMethod:
95-
send(action.wrapMessage(handleGetExternalProviders()))
95+
result(handleGetExternalProviders())
9696
return
9797
case getExternalProviderMethod:
9898
externalProviderName := action.Data.(string)
99-
send(action.wrapMessage(handleGetExternalProvider(externalProviderName)))
99+
result(handleGetExternalProvider(externalProviderName))
100100
case updateGeoDataMethod:
101101
paramsString := action.Data.(string)
102102
var params = map[string]string{}
103103
err := json.Unmarshal([]byte(paramsString), &params)
104104
if err != nil {
105-
send(action.wrapMessage(err.Error()))
105+
result(err.Error())
106106
return
107107
}
108108
geoType := params["geo-type"]
109109
geoName := params["geo-name"]
110110
handleUpdateGeoData(geoType, geoName, func(value string) {
111-
send(action.wrapMessage(value))
111+
result(value)
112112
})
113113
return
114114
case updateExternalProviderMethod:
115115
providerName := action.Data.(string)
116116
handleUpdateExternalProvider(providerName, func(value string) {
117-
send(action.wrapMessage(value))
117+
result(value)
118118
})
119119
return
120120
case sideLoadExternalProviderMethod:
121121
paramsString := action.Data.(string)
122122
var params = map[string]string{}
123123
err := json.Unmarshal([]byte(paramsString), &params)
124124
if err != nil {
125-
send(action.wrapMessage(err.Error()))
125+
result(err.Error())
126126
return
127127
}
128128
providerName := params["providerName"]
129129
data := params["data"]
130130
handleSideLoadExternalProvider(providerName, []byte(data), func(value string) {
131-
send(action.wrapMessage(value))
131+
result(value)
132132
})
133133
return
134134
case startLogMethod:
135135
handleStartLog()
136-
send(action.wrapMessage(true))
136+
result(true)
137137
return
138138
case stopLogMethod:
139139
handleStopLog()
140-
send(action.wrapMessage(true))
140+
result(true)
141141
return
142142
case startListenerMethod:
143-
send(action.wrapMessage(handleStartListener()))
143+
result(handleStartListener())
144144
return
145145
case stopListenerMethod:
146-
send(action.wrapMessage(handleStopListener()))
146+
result(handleStopListener())
147147
return
148148
case getCountryCodeMethod:
149149
ip := action.Data.(string)
150150
handleGetCountryCode(ip, func(value string) {
151-
send(action.wrapMessage(value))
151+
result(value)
152152
})
153153
return
154154
case getMemoryMethod:
155155
handleGetMemory(func(value string) {
156-
send(action.wrapMessage(value))
156+
result(value)
157157
})
158158
return
159+
case getProfileMethod:
160+
profileId := action.Data.(string)
161+
handleGetMemory(func(value string) {
162+
result(handleGetProfile(profileId))
163+
})
164+
return
165+
case setStateMethod:
166+
data := action.Data.(string)
167+
handleSetState(data)
168+
result(true)
159169
default:
160-
handle := nextHandle(action, send)
170+
handle := nextHandle(action, result)
161171
if handle {
162172
return
163173
} else {
164-
send(action.wrapMessage(action.DefaultValue))
174+
result(action.DefaultValue)
165175
}
166176
}
167177
}

core/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ func overwriteConfig(targetConfig *config.RawConfig, patchConfig config.RawConfi
215215
targetConfig.Tun.Device = patchConfig.Tun.Device
216216
targetConfig.Tun.DNSHijack = patchConfig.Tun.DNSHijack
217217
targetConfig.Tun.Stack = patchConfig.Tun.Stack
218+
targetConfig.Tun.RouteAddress = patchConfig.Tun.RouteAddress
218219
targetConfig.GeodataLoader = patchConfig.GeodataLoader
219220
targetConfig.Profile.StoreSelected = false
220221
targetConfig.GeoXUrl = patchConfig.GeoXUrl

core/constant.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import (
88
)
99

1010
type ConfigExtendedParams struct {
11-
IsPatch bool `json:"is-patch"`
12-
IsCompatible bool `json:"is-compatible"`
13-
SelectedMap map[string]string `json:"selected-map"`
14-
TestURL *string `json:"test-url"`
15-
OverrideDns bool `json:"override-dns"`
16-
OnlyStatisticsProxy bool `json:"only-statistics-proxy"`
11+
IsPatch bool `json:"is-patch"`
12+
IsCompatible bool `json:"is-compatible"`
13+
SelectedMap map[string]string `json:"selected-map"`
14+
TestURL *string `json:"test-url"`
15+
OverrideDns bool `json:"override-dns"`
1716
}
1817

1918
type GenerateConfigParams struct {
@@ -80,6 +79,7 @@ const (
8079
getAndroidVpnOptionsMethod Method = "getAndroidVpnOptions"
8180
getRunTimeMethod Method = "getRunTime"
8281
getCurrentProfileNameMethod Method = "getCurrentProfileName"
82+
getProfileMethod Method = "getProfile"
8383
)
8484

8585
type Method string

0 commit comments

Comments
 (0)