Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions app/src/main/java/com/github/kr328/clash/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -30,11 +36,49 @@ class MainApplication : Application() {

if (processName == packageName) {
Remote.launch()
setupShortcuts()
} else {
sendServiceRecreated()
}
}

private fun setupShortcuts() {
val toggle = ShortcutInfoCompat.Builder(this, "toggle_clash")
.setShortLabel(getString(DesignR.string.shortcut_toggle_short))
.setLongLabel(getString(DesignR.string.shortcut_toggle_long))
.setIcon(IconCompat.createWithResource(this, DesignR.drawable.ic_baseline_swap_vertical_circle))
.setIntent(
Intent(Intents.ACTION_TOGGLE_CLASH)
.setClassName(this, ExternalControlActivity::class.java.name)
)
.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(IconCompat.createWithResource(this, DesignR.drawable.ic_baseline_flash_on))
.setIntent(
Intent(Intents.ACTION_START_CLASH)
.setClassName(this, ExternalControlActivity::class.java.name)
)
.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(IconCompat.createWithResource(this, DesignR.drawable.ic_baseline_stop))
.setIntent(
Intent(Intents.ACTION_STOP_CLASH)
.setClassName(this, ExternalControlActivity::class.java.name)
)
.setRank(2)
.build()

ShortcutManagerCompat.setDynamicShortcuts(this, listOf(toggle, start, stop))
}

private fun extractGeoFiles() {
clashDir.mkdirs()

Expand Down
7 changes: 7 additions & 0 deletions design/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
7 changes: 7 additions & 0 deletions design/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>