Skip to content

Commit 5e4c9f7

Browse files
committed
Support better window position memory
Add windows arm64 and linux arm64 build script Optimize some details
1 parent ece8a48 commit 5e4c9f7

File tree

25 files changed

+318
-157
lines changed

25 files changed

+318
-157
lines changed

.github/release_template.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131
</td>
3232
</tr>
3333
<tr>
34-
<td>macOS (v10.15+)</td>
34+
<td>macOS</td>
3535
<td>
36-
<a href="https://github.com/chen08209/FlClash/releases/download/vVERSION/FlClash-VERSION-macos-amd64.dmg"><img src="https://img.shields.io/badge/DMG-Universal-ea005e.svg?logo=apple"></a><br>
36+
<a href="https://github.com/chen08209/FlClash/releases/download/vVERSION/FlClash-VERSION-macos-arm64.dmg"><img src="https://img.shields.io/badge/DMG-Apple%20Silicon-%23000000.svg?logo=apple"></a><br>
37+
<a href="https://github.com/chen08209/FlClash/releases/download/vVERSION/FlClash-VERSION-macos-amd64.dmg"><img src="https://img.shields.io/badge/DMG-Intel%20X64-%2300A9E0.svg?logo=apple"></a><br>
3738
</td>
3839
</tr>
3940
<tr>

.github/workflows/build.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,71 @@ on:
66
- 'v*'
77

88
jobs:
9+
changelog:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
if: ${{ !contains(github.ref, '+') }}
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
ref: refs/heads/main
18+
19+
- name: Generate
20+
if: ${{ !contains(github.ref, '+') }}
21+
run: |
22+
tags=($(git tag --merged $(git rev-parse HEAD) --sort=-creatordate))
23+
preTag=$(grep -oP '^## \K.*' CHANGELOG.md | head -n 1)
24+
currentTag=""
25+
for ((i = 0; i <= ${#tags[@]}; i++)); do
26+
if (( i < ${#tags[@]} )); then
27+
tag=${tags[$i]}
28+
else
29+
tag=""
30+
fi
31+
if [ -n "$currentTag" ]; then
32+
if [ "$(echo -e "$currentTag\n$preTag" | sort -V | head -n 1)" == "$currentTag" ]; then
33+
break
34+
fi
35+
fi
36+
if [ -n "$currentTag" ]; then
37+
echo "## $currentTag" >> NEW_CHANGELOG.md
38+
echo "" >> NEW_CHANGELOG.md
39+
if [ -n "$tag" ]; then
40+
git log --pretty=format:"%B" "$tag..$currentTag" | awk 'NF {print "- " $0} !NF {print ""}' >> NEW_CHANGELOG.md
41+
else
42+
git log --pretty=format:"%B" "$currentTag" | awk 'NF {print "- " $0} !NF {print ""}' >> NEW_CHANGELOG.md
43+
fi
44+
echo "" >> NEW_CHANGELOG.md
45+
fi
46+
currentTag=$tag
47+
done
48+
cat CHANGELOG.md >> NEW_CHANGELOG.md
49+
cat NEW_CHANGELOG.md > CHANGELOG.md
50+
51+
- name: Commit
52+
if: ${{ !contains(github.ref, '+') }}
53+
run: |
54+
git add CHANGELOG.md
55+
if ! git diff --cached --quiet; then
56+
echo "Commit pushing"
57+
git config --local user.email "[email protected]"
58+
git config --local user.name "chen08209"
59+
git commit -m "Update changelog"
60+
git push
61+
if [ $? -eq 0 ]; then
62+
echo "Push succeeded"
63+
else
64+
echo "Push failed"
65+
exit 1
66+
fi
67+
fi
68+
69+
env:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
972
build:
73+
needs: [ changelog ]
1074
runs-on: ${{ matrix.os }}
1175
strategy:
1276
matrix:

.github/workflows/change.yaml

Lines changed: 0 additions & 66 deletions
This file was deleted.

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,29 @@ on Mobile:
3434

3535
✨ Support subscription link, Dark mode
3636

37+
## Use
38+
39+
### Linux
40+
41+
⚠️ Make sure to install the following dependencies before using them
42+
43+
```bash
44+
sudo apt-get install appindicator3-0.1 libappindicator3-dev
45+
sudo apt-get install keybinder-3.0
46+
```
47+
48+
### Android
49+
50+
Support the following actions
51+
52+
```bash
53+
com.follow.clash.action.START
54+
55+
com.follow.clash.action.STOP
56+
57+
com.follow.clash.action.CHANGE
58+
```
59+
3760
## Download
3861

3962
<a href="https://chen08209.github.io/FlClash-fdroid-repo/repo?fingerprint=789D6D32668712EF7672F9E58DEEB15FBD6DCEEC5AE7A4371EA72F2AAE8A12FD"><img alt="Get it on F-Droid" src="snapshots/get-it-on-fdroid.svg" width="200px"/></a> <a href="https://github.com/chen08209/FlClash/releases"><img alt="Get it on GitHub" src="snapshots/get-it-on-github.svg" width="200px"/></a>
@@ -70,7 +93,7 @@ on Mobile:
7093
3. Run build script
7194

7295
```bash
73-
dart .\setup.dart
96+
dart .\setup.dart windows --arch <arm64 | amd64>
7497
```
7598

7699
- linux
@@ -80,7 +103,7 @@ on Mobile:
80103
2. Run build script
81104

82105
```bash
83-
dart .\setup.dart
106+
dart .\setup.dart linux --arch <arm64 | amd64>
84107
```
85108

86109
- macOS
@@ -90,7 +113,7 @@ on Mobile:
90113
2. Run build script
91114

92115
```bash
93-
dart .\setup.dart
116+
dart .\setup.dart macos --arch <arm64 | amd64>
94117
```
95118

96119
## Star

README_zh_CN.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
[![Channel](https://img.shields.io/badge/Telegram-Channel-blue?style=flat-square&logo=telegram)](https://t.me/FlClash)
1212

13-
1413
基于ClashMeta的多平台代理客户端,简单易用,开源无广告。
1514

1615
on Desktop:
@@ -35,6 +34,29 @@ on Mobile:
3534

3635
✨ 支持一键导入订阅, 深色模式
3736

37+
## Use
38+
39+
### Linux
40+
41+
⚠️ 使用前请确保安装以下依赖
42+
43+
```bash
44+
sudo apt-get install appindicator3-0.1 libappindicator3-dev
45+
sudo apt-get install keybinder-3.0
46+
```
47+
48+
### Android
49+
50+
支持下列操作
51+
52+
```bash
53+
com.follow.clash.action.START
54+
55+
com.follow.clash.action.STOP
56+
57+
com.follow.clash.action.CHANGE
58+
```
59+
3860
## Download
3961

4062
<a href="https://chen08209.github.io/FlClash-fdroid-repo/repo?fingerprint=789D6D32668712EF7672F9E58DEEB15FBD6DCEEC5AE7A4371EA72F2AAE8A12FD"><img alt="Get it on F-Droid" src="snapshots/get-it-on-fdroid.svg" width="200px"/></a> <a href="https://github.com/chen08209/FlClash/releases"><img alt="Get it on GitHub" src="snapshots/get-it-on-github.svg" width="200px"/></a>
@@ -71,7 +93,7 @@ on Mobile:
7193
3. 运行构建脚本
7294

7395
```bash
74-
dart .\setup.dart
96+
dart .\setup.dart windows --arch <arm64 | amd64>
7597
```
7698

7799
- linux
@@ -81,7 +103,7 @@ on Mobile:
81103
2. 运行构建脚本
82104

83105
```bash
84-
dart .\setup.dart
106+
dart .\setup.dart linux --arch <arm64 | amd64>
85107
```
86108

87109
- macOS
@@ -91,7 +113,7 @@ on Mobile:
91113
2. 运行构建脚本
92114

93115
```bash
94-
dart .\setup.dart
116+
dart .\setup.dart macos --arch <arm64 | amd64>
95117
```
96118

97119
## Star History

android/app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
android:name=".TempActivity"
7373
android:exported="true"
7474
android:theme="@style/TransparentTheme">
75+
<intent-filter>
76+
<category android:name="android.intent.category.DEFAULT" />
77+
<action android:name="${applicationId}.action.START" />
78+
</intent-filter>
7579
<intent-filter>
7680
<category android:name="android.intent.category.DEFAULT" />
7781
<action android:name="${applicationId}.action.STOP" />
@@ -88,7 +92,8 @@
8892
android:foregroundServiceType="specialUse"
8993
android:icon="@drawable/ic_stat_name"
9094
android:label="FlClash"
91-
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
95+
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
96+
tools:targetApi="n">
9297
<intent-filter>
9398
<action android:name="android.service.quicksettings.action.QS_TILE" />
9499
</intent-filter>

android/app/src/main/kotlin/com/follow/clash/GlobalState.kt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ enum class RunState {
2020

2121

2222
object GlobalState {
23-
24-
private val lock = ReentrantLock()
2523
val runLock = ReentrantLock()
2624

2725
val runState: MutableLiveData<RunState> = MutableLiveData<RunState>(RunState.STOP)
@@ -47,35 +45,46 @@ object GlobalState {
4745
}
4846

4947
fun handleToggle(context: Context) {
48+
val starting = handleStart(context)
49+
if (!starting) {
50+
handleStop()
51+
}
52+
}
53+
54+
fun handleStart(context: Context): Boolean {
5055
if (runState.value == RunState.STOP) {
5156
runState.value = RunState.PENDING
57+
runLock.lock()
5258
val tilePlugin = getCurrentTilePlugin()
5359
if (tilePlugin != null) {
5460
tilePlugin.handleStart()
5561
} else {
5662
initServiceEngine(context)
5763
}
58-
} else {
59-
handleStop()
64+
return true
6065
}
66+
return false
6167
}
6268

6369
fun handleStop() {
6470
if (runState.value == RunState.START) {
6571
runState.value = RunState.PENDING
72+
runLock.lock()
6673
getCurrentTilePlugin()?.handleStop()
6774
}
6875
}
6976

7077
fun destroyServiceEngine() {
71-
serviceEngine?.destroy()
72-
serviceEngine = null
78+
runLock.withLock {
79+
serviceEngine?.destroy()
80+
serviceEngine = null
81+
}
7382
}
7483

7584
fun initServiceEngine(context: Context) {
7685
if (serviceEngine != null) return
77-
lock.withLock {
78-
destroyServiceEngine()
86+
destroyServiceEngine()
87+
runLock.withLock {
7988
serviceEngine = FlutterEngine(context)
8089
serviceEngine?.plugins?.add(VpnPlugin())
8190
serviceEngine?.plugins?.add(AppPlugin())

android/app/src/main/kotlin/com/follow/clash/TempActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ class TempActivity : Activity() {
88
override fun onCreate(savedInstanceState: Bundle?) {
99
super.onCreate(savedInstanceState)
1010
when (intent.action) {
11+
wrapAction("START") -> {
12+
GlobalState.handleStart(applicationContext)
13+
}
14+
1115
wrapAction("STOP") -> {
1216
GlobalState.handleStop()
1317
}

android/app/src/main/kotlin/com/follow/clash/extensions/Ext.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import java.io.ByteArrayOutputStream
2323
import java.net.Inet4Address
2424
import java.net.Inet6Address
2525
import java.net.InetAddress
26+
import java.util.concurrent.locks.ReentrantLock
2627
import kotlin.coroutines.resume
2728
import kotlin.coroutines.suspendCoroutine
2829

@@ -179,4 +180,19 @@ suspend fun <T> MethodChannel.awaitResult(
179180
}
180181
})
181182
}
183+
}
184+
185+
fun ReentrantLock.safeLock() {
186+
if (this.isLocked) {
187+
return
188+
}
189+
this.lock()
190+
}
191+
192+
fun ReentrantLock.safeUnlock() {
193+
if (!this.isLocked) {
194+
return
195+
}
196+
197+
this.unlock()
182198
}

0 commit comments

Comments
 (0)