Update On Sat Nov 29 19:37:09 CET 2025

This commit is contained in:
github-action[bot]
2025-11-29 19:37:10 +01:00
parent 0f0ec9e353
commit b010c64ed2
58 changed files with 619 additions and 169 deletions

View File

@@ -24,6 +24,8 @@ dependencies {
implementation(libs.androidx.coordinator)
implementation(libs.androidx.recyclerview)
implementation(libs.google.material)
implementation(libs.quickie.bundled)
implementation(libs.androidx.activity.ktx)
}
tasks.getByName("clean", type = Delete::class) {

View File

@@ -6,24 +6,35 @@ import android.content.Intent
import android.net.Uri
import android.provider.Settings
import androidx.activity.result.contract.ActivityResultContracts
import androidx.lifecycle.lifecycleScope
import com.github.kr328.clash.common.constants.Intents
import com.github.kr328.clash.common.util.intent
import com.github.kr328.clash.common.util.setUUID
import com.github.kr328.clash.design.NewProfileDesign
import com.github.kr328.clash.design.R
import com.github.kr328.clash.design.model.ProfileProvider
import com.github.kr328.clash.design.util.showExceptionToast
import com.github.kr328.clash.service.model.Profile
import com.github.kr328.clash.util.withProfile
import io.github.g00fy2.quickie.QRResult
import io.github.g00fy2.quickie.QRResult.QRError
import io.github.g00fy2.quickie.QRResult.QRMissingPermission
import io.github.g00fy2.quickie.QRResult.QRSuccess
import io.github.g00fy2.quickie.QRResult.QRUserCanceled
import io.github.g00fy2.quickie.ScanQRCode
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.selects.select
import kotlinx.coroutines.withContext
import java.util.*
import com.github.kr328.clash.design.R
class NewProfileActivity : BaseActivity<NewProfileDesign>() {
private val self: NewProfileActivity
get() = this
private val scanLauncher = registerForActivityResult(ScanQRCode(), ::scanResultHandler)
override suspend fun main() {
val design = NewProfileDesign(this)
@@ -45,8 +56,14 @@ class NewProfileActivity : BaseActivity<NewProfileDesign>() {
val uuid: UUID? = when (val p = it.provider) {
is ProfileProvider.File ->
create(Profile.Type.File, name)
is ProfileProvider.Url ->
create(Profile.Type.Url, name)
is ProfileProvider.QR -> {
null
}
is ProfileProvider.External -> {
val data = p.get()
@@ -68,9 +85,14 @@ class NewProfileActivity : BaseActivity<NewProfileDesign>() {
launchProperties(uuid)
}
}
is NewProfileDesign.Request.OpenDetail -> {
launchAppDetailed(it.provider)
}
is NewProfileDesign.Request.LaunchScanner -> {
scanLauncher.launch(null)
}
}
}
}
@@ -138,7 +160,41 @@ class NewProfileActivity : BaseActivity<NewProfileDesign>() {
ProfileProvider.External(name.toString(), summary.toString(), icon, intent)
}
listOf(ProfileProvider.File(self), ProfileProvider.Url(self)) + providers
listOf(
ProfileProvider.File(self),
ProfileProvider.Url(self),
ProfileProvider.QR(self)
) + providers
}
}
private fun scanResultHandler(result: QRResult) {
lifecycleScope.launch {
when (result) {
is QRSuccess -> {
val url = result.content.rawValue
?: result.content.rawBytes?.let { String(it) }.orEmpty()
createProfileByQrCode(url)
}
QRUserCanceled -> {}
QRMissingPermission -> design?.showExceptionToast(getString(R.string.import_from_qr_no_permission))
is QRError -> design?.showExceptionToast(getString(R.string.import_from_qr_exception))
}
}
}
private suspend fun createProfileByQrCode(url: String) {
withProfile {
launchProperties(
create(
type = Profile.Type.Url,
name = getString(R.string.new_profile),
url,
)
)
}
}
}

View File

@@ -11,6 +11,7 @@ class NewProfileDesign(context: Context) : Design<NewProfileDesign.Request>(cont
sealed class Request {
data class Create(val provider: ProfileProvider) : Request()
data class OpenDetail(val provider: ProfileProvider.External) : Request()
data class LaunchScanner(val provider: ProfileProvider.QR) : Request()
}
private val binding = DesignNewProfileBinding
@@ -38,7 +39,12 @@ class NewProfileDesign(context: Context) : Design<NewProfileDesign.Request>(cont
}
private fun requestCreate(provider: ProfileProvider) {
requests.trySend(Request.Create(provider))
if (provider is ProfileProvider.QR) {
requests.trySend(Request.LaunchScanner(provider))
} else {
requests.trySend(Request.Create(provider))
}
}
private fun requestDetail(provider: ProfileProvider): Boolean {

View File

@@ -14,6 +14,8 @@ sealed class ProfileProvider {
get() = context.getString(R.string.import_from_file)
override val icon: Drawable?
get() = context.getDrawableCompat(R.drawable.ic_baseline_attach_file)
}
class Url(private val context: Context) : ProfileProvider() {
@@ -25,6 +27,14 @@ sealed class ProfileProvider {
get() = context.getDrawableCompat(R.drawable.ic_baseline_cloud_download)
}
class QR(private val context: Context) : ProfileProvider() {
override val name: String
get() = context.getString(R.string.qr)
override val summary: String
get() = context.getString(R.string.import_from_qr)
override val icon: Drawable?
get() = context.getDrawableCompat(R.drawable.baseline_qr_code_scanner)
}
class External(
override val name: String,
override val summary: String,

View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="@android:color/white" android:pathData="M9.5,6.5v3h-3v-3H9.5M11,5H5v6h6V5L11,5zM9.5,14.5v3h-3v-3H9.5M11,13H5v6h6V13L11,13zM17.5,6.5v3h-3v-3H17.5M19,5h-6v6h6V5L19,5zM13,13h1.5v1.5H13V13zM14.5,14.5H16V16h-1.5V14.5zM16,13h1.5v1.5H16V13zM13,16h1.5v1.5H13V16zM14.5,17.5H16V19h-1.5V17.5zM16,16h1.5v1.5H16V16zM17.5,14.5H19V16h-1.5V14.5zM17.5,17.5H19V19h-1.5V17.5zM22,7h-2V4h-3V2h5V7zM22,22v-5h-2v3h-3v2H22zM2,22h5v-2H4v-3H2V22zM2,2v5h2V4h3V2H2z"/>
</vector>

View File

@@ -30,6 +30,7 @@
<string name="import_from_file">ファイルからインポート</string>
<string name="url">URL</string>
<string name="import_from_url">URLからインポート</string>
<string name="import_from_qr">QRコードからインポート</string>
<string name="external">外部入力</string>
<string name="format_type_unsaved">%s (未保存)</string>
<string name="application_broken">アプリが破損しています</string>
@@ -250,4 +251,6 @@
<string name="force_dns_mapping">Force DNS Mapping</string>
<string name="parse_pure_ip">Parse Pure IP</string>
<string name="override_destination">Override Destination</string>
<string name="import_from_qr_no_permission">カメラのアクセスが制限されています。設定から有効にしてください。</string>
<string name="import_from_qr_exception">システムで予期しない例外が発生しました。</string>
</resources>

View File

@@ -31,6 +31,7 @@
<string name="url">URL</string>
<string name="import_from_url">URL에서 가져오기</string>
<string name="external">외부</string>
<string name="import_from_qr">QR코드에서 가져오기</string>
<string name="format_type_unsaved">%s (저장되지 않음)</string>
<string name="application_broken">앱 오류</string>
<string name="application_crashed">앱 중지</string>
@@ -250,4 +251,6 @@
<string name="force_dns_mapping">Force DNS Mapping</string>
<string name="parse_pure_ip">Parse Pure IP</string>
<string name="override_destination">Override Destination</string>
<string name="import_from_qr_no_permission">카메라 접근이 제한되었습니다. 설정에서 허용해 주세요.</string>
<string name="import_from_qr_exception">처리되지 않은 시스템 예외가 발생했습니다.</string>
</resources>

View File

@@ -38,6 +38,7 @@
<string name="url">URL</string>
<string name="import_from_url">Импорт из URL</string>
<string name="external">Внешний</string>
<string name="import_from_qr">Импорт из QR-кода</string>
<string name="format_type_unsaved">%s (не сохранён)</string>
<string name="application_broken">Приложение сломано</string>
@@ -314,4 +315,6 @@
<string name="force_dns_mapping">Force DNS Mapping</string>
<string name="parse_pure_ip">Parse Pure IP</string>
<string name="override_destination">Override Destination</string>
<string name="import_from_qr_no_permission">Доступ к камере ограничен. Разрешите его в настройках.</string>
<string name="import_from_qr_exception">Произошла не обрабатываемая системная ошибка.</string>
</resources>

View File

@@ -236,4 +236,7 @@
<string name="version_updated_tips">Các cài đặt đã được đặt lại và các cấu hình cũ cần được lưu lại.</string>
<string name="vpn_service_options">Tuỳ chọn VpnService</string>
<string name="warning">Cảnh báo</string>
<string name="import_from_qr">Nhập từ Mã QR</string>
<string name="import_from_qr_no_permission">Quyền truy cập camera bị hạn chế. Vui lòng bật trong Cài đặt.</string>
<string name="import_from_qr_exception">Đã xảy ra ngoại lệ hệ thống không xử lý được.</string>
</resources>

View File

@@ -41,6 +41,7 @@
<string name="import_from_file">從文件導入</string>
<string name="import_from_url">從 URL 導入</string>
<string name="interface_">界面</string>
<string name="import_from_qr">從二維碼導入</string>
<string name="invalid_url">無效的 URL</string>
<string name="logcat">Logcat</string>
<string name="logs">日誌</string>
@@ -247,4 +248,6 @@
<string name="force_dns_mapping">Force DNS Mapping</string>
<string name="parse_pure_ip">Parse Pure IP</string>
<string name="override_destination">Override Destination</string>
<string name="import_from_qr_no_permission">相機權限受限,請前往設定開啟。</string>
<string name="import_from_qr_exception">發生系統未知異常,操作失敗。</string>
</resources>

View File

@@ -40,6 +40,7 @@
<string name="history">歷史</string>
<string name="import_from_file">從檔案匯入</string>
<string name="import_from_url">從 URL 匯入</string>
<string name="import_from_qr">從二維碼導入</string>
<string name="interface_">介面</string>
<string name="invalid_url">無效 URL</string>
<string name="logcat">Logcat</string>
@@ -247,4 +248,6 @@
<string name="force_dns_mapping">Force DNS Mapping</string>
<string name="parse_pure_ip">Parse Pure IP</string>
<string name="override_destination">Override Destination</string>
<string name="import_from_qr_no_permission">相機權限受限,請前往設定開啟。</string>
<string name="import_from_qr_exception">發生系統未知異常,操作失敗。</string>
</resources>

View File

@@ -42,6 +42,7 @@
<string name="history">历史</string>
<string name="import_from_file">从文件导入</string>
<string name="import_from_url">从 URL 导入</string>
<string name="import_from_qr">从二维码导入</string>
<string name="interface_">界面</string>
<string name="invalid_url">无效的 URL</string>
<string name="logcat">Logcat</string>
@@ -257,4 +258,6 @@
<string name="external_control_activity">外部控制</string>
<string name="external_control_started">Clash.Meta 服务已启动</string>
<string name="external_control_stopped">Clash.Meta 服务已停止</string>
<string name="import_from_qr_no_permission">相机权限受限,请前往设置开启。</string>
<string name="import_from_qr_exception">发生系统未知异常,操作失败。</string>
</resources>

View File

@@ -41,7 +41,9 @@
<string name="file">File</string>
<string name="import_from_file">Import from File</string>
<string name="url">URL</string>
<string name="qr" translatable="false">QR Code</string>
<string name="import_from_url">Import from URL</string>
<string name="import_from_qr">Import from QR Code</string>
<string name="external">External</string>
<string name="format_type_unsaved">%s (Unsaved)</string>
@@ -344,4 +346,6 @@
<string name="hide_app_icon_title">Hide App Icon</string>
<string name="hide_app_icon_desc">You can dial *#*#252746382#*#* to open this App</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>
</resources>

View File

@@ -16,6 +16,8 @@ serialization = "1.3.3"
kaidl = "1.15"
room = "2.4.2"
multiprocess = "1.0.0"
quickie = "1.11.0"
androidx-activity-ktx = "1.9.0"
[libraries]
build-android = { module = "com.android.tools.build:gradle", version.ref = "agp" }
@@ -39,5 +41,7 @@ google-material = { module = "com.google.android.material:material", version.ref
kaidl-compiler = { module = "com.github.kr328.kaidl:kaidl", version.ref = "kaidl" }
kaidl-runtime = { module = "com.github.kr328.kaidl:kaidl-runtime", version.ref = "kaidl" }
rikkax-multiprocess = { module = "dev.rikka.rikkax.preference:multiprocess", version.ref = "multiprocess" }
quickie-bundled = { group = "io.github.g00fy2.quickie", name = "quickie-bundled", version.ref = "quickie" }
androidx-activity-ktx = { group = "androidx.activity", name = "activity-ktx", version.ref = "androidx-activity-ktx" }
[plugins]