Skip to content

Commit 7dd9bbf

Browse files
ACaiCatklxiaoniu
andauthored
feat(android): 新增一码通控制中心入口,修复iOS控制中心跳转 (#404)
* feat(android): 新增一码通控制中心入口 * style: 文件末尾补充空行 * chore: 简化标签,与APP保持一致 * chore: 改用`qr_action`图标 * fix: iOS改用scheme跳转 * refactor: Android改用scheme跳转 --------- Co-authored-by: klxiaoniu <klxiaoniu@proton.me>
1 parent a34f243 commit 7dd9bbf

6 files changed

Lines changed: 62 additions & 8 deletions

File tree

app/+native-intent.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export function redirectSystemPath({ path, initial }: { path: string; initial: b
1414
const target = encodeURIComponent(`/settings/friend/add?code=${code}`);
1515
// 在闪屏页做账户初始化相关工作并跳转
1616
return `/(guest)?target=${target}&cold_launch=${initial}`;
17+
} else if (hostname === 'qrcode') {
18+
// fzuhelper://qrcode
19+
const target = encodeURIComponent('/qrcode');
20+
return `/(guest)?target=${target}&cold_launch=${initial}`;
1721
} else if (hostname === null) {
1822
// 桌面启动
1923
return path;

modules/native-widget/android/src/main/AndroidManifest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@
4747
android:exported="false"
4848
android:permission="android.permission.BIND_REMOTEVIEWS" />
4949

50+
<service
51+
android:name="com.helper.west2ol.fzuhelper.QRCodeQSTileService"
52+
android:exported="true"
53+
android:label="@string/qrcode_qs_tile_label"
54+
android:icon="@drawable/ic_qrcode"
55+
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
56+
<intent-filter>
57+
<action android:name="android.service.quicksettings.action.QS_TILE" />
58+
</intent-filter>
59+
</service>
5060

5161
</application>
5262

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.helper.west2ol.fzuhelper
2+
3+
import android.annotation.SuppressLint
4+
import android.app.PendingIntent
5+
import android.content.Intent
6+
import android.os.Build
7+
import android.service.quicksettings.TileService
8+
import androidx.core.net.toUri
9+
10+
class QRCodeQSTileService : TileService() {
11+
override fun onClick() {
12+
super.onClick()
13+
14+
val intent = Intent().apply {
15+
data = "fzuhelper://qrcode".toUri()
16+
action = Intent.ACTION_VIEW
17+
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
18+
}
19+
20+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
21+
val pendingIntent = PendingIntent.getActivity(
22+
this, 0, intent,
23+
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
24+
)
25+
startActivityAndCollapse(pendingIntent)
26+
} else {
27+
@Suppress("DEPRECATION")
28+
@SuppressLint("StartActivityAndCollapseDeprecated")
29+
startActivityAndCollapse(intent)
30+
}
31+
}
32+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="160"
5+
android:viewportHeight="160">
6+
<path
7+
android:pathData="M11 24c0-6.6 6.4-13 13-13h50v63H11V24zm11-1v39h41V23H22zm64-11h51c6.6 0 12 5.4 12 12v50H86V12zm11 11v39h41V23H97zM31 32h22v22H31V32zm75 0h22v22h-22V32zM11 87h63v62H23c-6.6 0-12-6.4-12-12V87zm11 11v40h41V98H22zm9 9h22v22H31v-22zM86 87h40v11H86V87zm0 16h11v11H86v-11zm52-16h11v11h-11V87zm-35 16h46v12h-23v11h-11v-11h-12v-12zm-17 24h11v22H86v-22zm17 0h11v11h-11v-11zm12 22v-11h22v-11h12v10c0 6.6-5.4 12-12 12h-22z"
8+
android:fillColor="#1f1f1f" />
9+
</vector>

modules/native-widget/android/src/main/res/values/strings_widget.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
<item>自定义不透明度</item>
88
<item>跟随背景不透明度</item>
99
</string-array>
10-
</resources>
10+
11+
<string name="qrcode_qs_tile_label">一码通</string>
12+
</resources>

targets/iOS-widget/_shared/ControlWidget.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// Created by 黄骁 on 2025/3/22.
66
//
77

8-
// MARK: 这个文件涉及到 Universal Link,需要放在 _shared 文件夹下,否则无法自动关联 Target Membership,导致 Universal Link 无法打开(显示没有权限)
9-
108
import AppIntents
119
import SwiftUI
1210
import WidgetKit
@@ -33,11 +31,10 @@ struct OpenAppWithURLIntent: AppIntent {
3331
static var openAppWhenRun = true
3432
static var isDiscoverable = true
3533

34+
@MainActor
3635
func perform() async throws -> some IntentResult & OpensIntent {
37-
// 使用 Universal Link
38-
// MARK: 这个 Universal Link 需要 fzuhelper-web,也就是我们官网的 AASA 文件配合,以及 app 内的配合,这个 /qrcode 路径不要修改,直接对应 App 内的 Expo-Router 设置的 /qrcode 页面,即一码通
39-
// let url = URL(string: "https://fzuhelperapp.west2.online/(guest)/?method=qrcode")! // 这个设计保留,但暂时不使用
40-
let url = URL(string: "https://fzuhelperapp.west2.online/qrcode")!
41-
return .result(opensIntent: OpenURLIntent(url))
36+
let url = URL(string: "fzuhelper://qrcode")!
37+
EnvironmentValues().openURL(url)
38+
return .result()
4239
}
4340
}

0 commit comments

Comments
 (0)