Skip to content

Commit 210aa55

Browse files
committed
Merge remote-tracking branch 'upstream/main' into main
2 parents b7b1e3e + 5768494 commit 210aa55

37 files changed

Lines changed: 277 additions & 135 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,24 @@
227227
<action android:name="android.intent.action.CREATE_SHORTCUT" />
228228
</intent-filter>
229229
</activity>
230+
<activity
231+
android:name="io.nekohasekai.sagernet.ui.QuickEnableShortcut"
232+
android:excludeFromRecents="true"
233+
android:exported="true"
234+
android:label="@string/quick_enable"
235+
android:launchMode="singleTask"
236+
android:process=":bg"
237+
android:taskAffinity=""
238+
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
239+
<activity
240+
android:name="io.nekohasekai.sagernet.ui.QuickDisableShortcut"
241+
android:excludeFromRecents="true"
242+
android:exported="true"
243+
android:label="@string/quick_disable"
244+
android:launchMode="singleTask"
245+
android:process=":bg"
246+
android:taskAffinity=""
247+
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
230248
<activity
231249
android:name="io.nekohasekai.sagernet.ui.AppManagerActivity"
232250
android:configChanges="uiMode"

app/src/main/java/io/nekohasekai/sagernet/fmt/AbstractBean.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,4 @@ public int hashCode() {
144144
public String toString() {
145145
return getClass().getSimpleName() + " " + JavaUtil.gson.toJson(this);
146146
}
147-
148-
public void applyFeatureSettings(AbstractBean other) {
149-
}
150-
151147
}

app/src/main/java/io/nekohasekai/sagernet/fmt/hysteria/HysteriaBean.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,6 @@ public void deserialize(ByteBufferInput input) {
150150
}
151151
}
152152

153-
@Override
154-
public void applyFeatureSettings(AbstractBean other) {
155-
if (!(other instanceof HysteriaBean)) return;
156-
HysteriaBean bean = ((HysteriaBean) other);
157-
bean.uploadMbps = uploadMbps;
158-
bean.downloadMbps = downloadMbps;
159-
bean.allowInsecure = allowInsecure;
160-
bean.disableMtuDiscovery = disableMtuDiscovery;
161-
bean.hopInterval = hopInterval;
162-
}
163-
164153
@Override
165154
public String displayAddress() {
166155
return NetsKt.wrapIPV6Host(serverAddress) + ":" + serverPorts;

app/src/main/java/io/nekohasekai/sagernet/fmt/shadowsocks/ShadowsocksBean.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,6 @@ public void deserialize(ByteBufferInput input) {
104104
}
105105
}
106106

107-
@Override
108-
public void applyFeatureSettings(AbstractBean other) {
109-
if (!(other instanceof ShadowsocksBean)) return;
110-
ShadowsocksBean bean = ((ShadowsocksBean) other);
111-
bean.sUoT = sUoT;
112-
bean.enableMux = enableMux;
113-
bean.muxPadding = muxPadding;
114-
bean.muxType = muxType;
115-
bean.muxConcurrency = muxConcurrency;
116-
bean.muxMode = muxMode;
117-
bean.muxMaxConnections = muxMaxConnections;
118-
bean.muxMinStreams = muxMinStreams;
119-
bean.muxBrutal = muxBrutal;
120-
bean.muxBrutalUpMbps = muxBrutalUpMbps;
121-
bean.muxBrutalDownMbps = muxBrutalDownMbps;
122-
}
123-
124107
@NotNull
125108
@Override
126109
public ShadowsocksBean clone() {

app/src/main/java/io/nekohasekai/sagernet/fmt/trojan_go/TrojanGoBean.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,6 @@ public void deserialize(ByteBufferInput input) {
146146
}
147147
}
148148

149-
@Override
150-
public void applyFeatureSettings(AbstractBean other) {
151-
if (!(other instanceof TrojanGoBean)) return;
152-
TrojanGoBean bean = ((TrojanGoBean) other);
153-
if (allowInsecure) {
154-
bean.allowInsecure = true;
155-
}
156-
}
157-
158149
@NotNull
159150
@Override
160151
public TrojanGoBean clone() {

app/src/main/java/io/nekohasekai/sagernet/fmt/tuic/TuicFmt.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,21 @@ fun parseTuic(url: String): TuicBean {
1717
protocolVersion = 5
1818

1919
name = link.fragment
20-
uuid = link.username
21-
token = link.password
2220
serverAddress = link.host
2321
serverPort = link.port
2422

23+
val rawUser = link.username
24+
val rawPass = link.password
25+
26+
if (rawUser.contains(":")) {
27+
val parts = rawUser.split(":", limit = 2)
28+
uuid = parts[0]
29+
token = parts.getOrElse(1) { "" }
30+
} else {
31+
uuid = rawUser
32+
token = rawPass
33+
}
34+
2535
link.queryParameter("sni")?.let {
2636
sni = it
2737
}

app/src/main/java/io/nekohasekai/sagernet/fmt/v2ray/StandardV2RayBean.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -355,27 +355,6 @@ public void deserialize(ByteBufferInput input) {
355355
// Note: kcp fields are read in the switch case above when version >= 6
356356
}
357357

358-
@Override
359-
public void applyFeatureSettings(AbstractBean other) {
360-
if (!(other instanceof StandardV2RayBean)) return;
361-
StandardV2RayBean bean = ((StandardV2RayBean) other);
362-
bean.allowInsecure = allowInsecure;
363-
bean.utlsFingerprint = utlsFingerprint;
364-
bean.packetEncoding = packetEncoding;
365-
bean.enableECH = enableECH;
366-
bean.echConfig = echConfig;
367-
bean.enableMux = enableMux;
368-
bean.muxPadding = muxPadding;
369-
bean.muxType = muxType;
370-
bean.muxConcurrency = muxConcurrency;
371-
bean.muxMode = muxMode;
372-
bean.muxMaxConnections = muxMaxConnections;
373-
bean.muxMinStreams = muxMinStreams;
374-
bean.muxBrutal = muxBrutal;
375-
bean.muxBrutalUpMbps = muxBrutalUpMbps;
376-
bean.muxBrutalDownMbps = muxBrutalDownMbps;
377-
}
378-
379358
public boolean isVLESS() {
380359
if (this instanceof VMessBean) {
381360
Integer aid = ((VMessBean) this).alterId;

app/src/main/java/io/nekohasekai/sagernet/group/RawUpdater.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ object RawUpdater : GroupUpdater() {
176176
if (toReplace.contains(name)) {
177177
val entity = toReplace[name]!!
178178
val existsBean = entity.requireBean()
179-
existsBean.applyFeatureSettings(bean)
179+
// 更新订阅,保留自定义覆写设置
180+
bean.customOutboundJson = existsBean.customOutboundJson
181+
bean.customConfigJson = existsBean.customConfigJson
180182
when {
181183
existsBean != bean -> {
182184
changed++
@@ -509,6 +511,15 @@ object RawUpdater : GroupUpdater() {
509511
}
510512
}
511513
}
514+
515+
"ech-opts" -> (opt.value as? Map<String, Any?>)?.also {
516+
for (echOpt in it) {
517+
when (echOpt.key) {
518+
"enable" -> bean.enableECH =
519+
echOpt.value.toString() == "true"
520+
}
521+
}
522+
}
512523
}
513524
}
514525
proxies.add(bean)

app/src/main/java/io/nekohasekai/sagernet/ui/AssetsActivity.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,12 @@ class AssetsActivity : ThemedActivity() {
211211

212212
val localVersion = if (file.isFile) {
213213
if (versionFile.isFile) {
214-
versionFile.readText().trim()
214+
try {
215+
versionFile.readText().trim()
216+
} catch (e: Throwable) {
217+
snackbar(e.readableMessage)
218+
"<unknown>"
219+
}
215220
} else {
216221
"Unknown-" + DateFormat.getDateFormat(app).format(Date(file.lastModified()))
217222
}

app/src/main/java/io/nekohasekai/sagernet/ui/GroupFragment.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,17 @@ class GroupFragment : ToolbarFragment(R.layout.layout_group),
476476
used += toLong()
477477
}
478478
val total = get("total=([0-9]+)")?.toLong() ?: 0
479+
val remain = total - used
479480
if (used > 0 || total > 0) {
480-
text += getString(
481-
R.string.subscription_traffic,
482-
used.toBytesString(),
483-
(total - used).toBytesString()
484-
)
481+
text += if (remain > 0) {
482+
getString(
483+
R.string.subscription_traffic,
484+
used.toBytesString(),
485+
remain.toBytesString()
486+
)
487+
} else {
488+
getString(R.string.subscription_used, used.toBytesString())
489+
}
485490
}
486491
get("expire=([0-9]+)")?.apply {
487492
text += "\n"

0 commit comments

Comments
 (0)