mirror of
https://github.com/bolucat/Archive.git
synced 2026-04-22 16:07:49 +08:00
Update On Fri Mar 6 20:05:19 CET 2026
This commit is contained in:
@@ -42,7 +42,7 @@
|
||||
android:configChanges="uiMode"
|
||||
android:exported="true"
|
||||
android:label="@string/launch_name"
|
||||
android:launchMode="singleTop">
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
@@ -65,8 +65,10 @@
|
||||
|
||||
<activity
|
||||
android:name=".ExternalControlActivity"
|
||||
android:excludeFromRecents="true"
|
||||
android:exported="true"
|
||||
android:label="@string/external_control_activity"
|
||||
android:noHistory="true"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
||||
@@ -25,6 +25,8 @@ import com.github.kr328.clash.design.R
|
||||
class ExternalControlActivity : Activity(), CoroutineScope by MainScope() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@Suppress("DEPRECATION")
|
||||
overridePendingTransition(0, 0)
|
||||
|
||||
when(intent.action) {
|
||||
Intent.ACTION_VIEW -> {
|
||||
@@ -90,4 +92,10 @@ class ExternalControlActivity : Activity(), CoroutineScope by MainScope() {
|
||||
stopClashService()
|
||||
Toast.makeText(this, R.string.external_control_stopped, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
override fun finish() {
|
||||
super.finish()
|
||||
@Suppress("DEPRECATION")
|
||||
overridePendingTransition(0, 0)
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,20 @@ package com.github.kr328.clash
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.core.content.pm.ShortcutInfoCompat
|
||||
import androidx.core.content.pm.ShortcutManagerCompat
|
||||
import androidx.core.graphics.drawable.IconCompat
|
||||
import com.github.kr328.clash.common.Global
|
||||
import com.github.kr328.clash.common.compat.currentProcessName
|
||||
import com.github.kr328.clash.common.constants.Intents
|
||||
import com.github.kr328.clash.common.log.Log
|
||||
import com.github.kr328.clash.remote.Remote
|
||||
import com.github.kr328.clash.service.util.sendServiceRecreated
|
||||
import com.github.kr328.clash.util.clashDir
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import com.github.kr328.clash.design.R as DesignR
|
||||
|
||||
|
||||
@Suppress("unused")
|
||||
@@ -30,11 +36,57 @@ class MainApplication : Application() {
|
||||
|
||||
if (processName == packageName) {
|
||||
Remote.launch()
|
||||
setupShortcuts()
|
||||
} else {
|
||||
sendServiceRecreated()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupShortcuts() {
|
||||
val icon = IconCompat.createWithResource(this, R.mipmap.ic_launcher)
|
||||
val flags = Intent.FLAG_ACTIVITY_NEW_TASK or
|
||||
Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS or
|
||||
Intent.FLAG_ACTIVITY_NO_ANIMATION
|
||||
|
||||
val toggle = ShortcutInfoCompat.Builder(this, "toggle_clash")
|
||||
.setShortLabel(getString(DesignR.string.shortcut_toggle_short))
|
||||
.setLongLabel(getString(DesignR.string.shortcut_toggle_long))
|
||||
.setIcon(icon)
|
||||
.setIntent(
|
||||
Intent(Intents.ACTION_TOGGLE_CLASH)
|
||||
.setClassName(this, ExternalControlActivity::class.java.name)
|
||||
.addFlags(flags)
|
||||
)
|
||||
.setRank(0)
|
||||
.build()
|
||||
|
||||
val start = ShortcutInfoCompat.Builder(this, "start_clash")
|
||||
.setShortLabel(getString(DesignR.string.shortcut_start_short))
|
||||
.setLongLabel(getString(DesignR.string.shortcut_start_long))
|
||||
.setIcon(icon)
|
||||
.setIntent(
|
||||
Intent(Intents.ACTION_START_CLASH)
|
||||
.setClassName(this, ExternalControlActivity::class.java.name)
|
||||
.addFlags(flags)
|
||||
)
|
||||
.setRank(1)
|
||||
.build()
|
||||
|
||||
val stop = ShortcutInfoCompat.Builder(this, "stop_clash")
|
||||
.setShortLabel(getString(DesignR.string.shortcut_stop_short))
|
||||
.setLongLabel(getString(DesignR.string.shortcut_stop_long))
|
||||
.setIcon(icon)
|
||||
.setIntent(
|
||||
Intent(Intents.ACTION_STOP_CLASH)
|
||||
.setClassName(this, ExternalControlActivity::class.java.name)
|
||||
.addFlags(flags)
|
||||
)
|
||||
.setRank(2)
|
||||
.build()
|
||||
|
||||
ShortcutManagerCompat.setDynamicShortcuts(this, listOf(toggle, start, stop))
|
||||
}
|
||||
|
||||
private fun extractGeoFiles() {
|
||||
clashDir.mkdirs()
|
||||
|
||||
|
||||
@@ -262,4 +262,11 @@
|
||||
<string name="external_control_stopped">Clash.Meta 服务已停止</string>
|
||||
<string name="import_from_qr_no_permission">相机权限受限,请前往设置开启。</string>
|
||||
<string name="import_from_qr_exception">发生系统未知异常,操作失败。</string>
|
||||
|
||||
<string name="shortcut_toggle_short">切换 Clash</string>
|
||||
<string name="shortcut_toggle_long">切换 Clash 服务启停</string>
|
||||
<string name="shortcut_start_short">启动 Clash</string>
|
||||
<string name="shortcut_start_long">启动 Clash 服务</string>
|
||||
<string name="shortcut_stop_short">停止 Clash</string>
|
||||
<string name="shortcut_stop_long">停止 Clash 服务</string>
|
||||
</resources>
|
||||
|
||||
@@ -350,4 +350,11 @@
|
||||
<string name="hide_from_recents_desc">Hide app from the Recent apps screen</string>
|
||||
<string name="import_from_qr_no_permission">Camera access is restricted. Please enable it in Settings.</string>
|
||||
<string name="import_from_qr_exception">An unhandled system exception occurred.</string>
|
||||
|
||||
<string name="shortcut_toggle_short">Toggle Clash</string>
|
||||
<string name="shortcut_toggle_long">Toggle Clash service on/off</string>
|
||||
<string name="shortcut_start_short">Start Clash</string>
|
||||
<string name="shortcut_start_long">Start Clash service</string>
|
||||
<string name="shortcut_stop_short">Stop Clash</string>
|
||||
<string name="shortcut_stop_long">Stop Clash service</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user