Refactor QR scan and share and add QRS support

This commit is contained in:
世界
2026-01-02 16:27:26 +08:00
parent 313cb5d213
commit 52db9bbb39
23 changed files with 1115 additions and 1411 deletions
@@ -231,8 +231,17 @@ public struct NewProfileMenuView: View {
#if !os(tvOS)
private func handleQRScanResult(_ result: QRScanResult) {
switch result {
case let .qrCode(string, _):
handleQRCodeString(string)
case let .qrsData(data):
handleQRSData(data)
}
}
private func handleQRCodeString(_ string: String) {
var error: NSError?
let remoteProfile = LibboxParseRemoteProfileImportLink(result.string, &error)
let remoteProfile = LibboxParseRemoteProfileImportLink(string, &error)
if let error {
alert = AlertState(
title: String(localized: "Invalid QR Code"),
@@ -249,5 +258,30 @@ public struct NewProfileMenuView: View {
}
importRequest = NewProfileView.ImportRequest(name: remoteProfile.name, url: remoteProfile.url)
}
private func handleQRSData(_ data: Data) {
do {
let (actualData, _, _) = try BinaryMeta.readFileHeaderMeta(buffer: data)
let content = try LibboxProfileContent.from(actualData)
alert = AlertState(
title: String(localized: "Import Profile"),
message: String(localized: "Are you sure to import profile \(content.name)?"),
primaryButton: .default(String(localized: "Import")) {
Task {
do {
try await content.importProfile()
environments.profileUpdate.send()
dismiss()
} catch {
alert = AlertState(error: error)
}
}
},
secondaryButton: .cancel()
)
} catch {
alert = AlertState(error: error)
}
}
#endif
}