ios: fix showing connection alert when fresh app is opened via link (before onboarding) (#6332)

* ios: fix showing connection alert when fresh app is opened via link (before onboarding)

* remove logs

* revert lib
This commit is contained in:
spaced4ndy
2025-10-04 12:08:23 +00:00
committed by GitHub
parent fa0103c7f5
commit 84dd294983
3 changed files with 27 additions and 19 deletions

View File

@@ -430,19 +430,27 @@ struct ContentView: View {
let m = ChatModel.shared
if let url = m.appOpenUrl {
m.appOpenUrl = nil
dismissAllSheets() {
var path = url.path
if (path == "/contact" || path == "/invitation" || path == "/a" || path == "/c" || path == "/g" || path == "/i") {
path.removeFirst()
let link = url.absoluteString.replacingOccurrences(of: "///\(path)", with: "/\(path)")
planAndConnect(
link,
theme: theme,
dismiss: false
)
} else {
AlertManager.shared.showAlert(Alert(title: Text("Error: URL is invalid")))
}
connectViaUrl_(url)
} else if let url = m.appOpenUrlLater, AppChatState.shared.value == .active, scenePhase == .active {
// correcting branch in case .onChange(of: scenePhase) in SimpleXApp doesn't trigger and transfer appOpenUrlLater into appOpenUrl
m.appOpenUrlLater = nil
connectViaUrl_(url)
}
}
func connectViaUrl_(_ url: URL) {
dismissAllSheets() {
var path = url.path
if (path == "/contact" || path == "/invitation" || path == "/a" || path == "/c" || path == "/g" || path == "/i") {
path.removeFirst()
let link = url.absoluteString.replacingOccurrences(of: "///\(path)", with: "/\(path)")
planAndConnect(
link,
theme: theme,
dismiss: false
)
} else {
AlertManager.shared.showAlert(Alert(title: Text("Error: URL is invalid")))
}
}
}

View File

@@ -385,6 +385,7 @@ final class ChatModel: ObservableObject {
@Published var userAddress: UserContactLink?
@Published var chatItemTTL: ChatItemTTL = .none
@Published var appOpenUrl: URL?
@Published var appOpenUrlLater: URL?
@Published var deviceToken: DeviceToken?
@Published var savedToken: DeviceToken?
@Published var tokenRegistered = false

View File

@@ -19,7 +19,6 @@ struct SimpleXApp: App {
@Environment(\.scenePhase) var scenePhase
@State private var enteredBackgroundAuthenticated: TimeInterval? = nil
@State private var appOpenUrlLater: URL?
init() {
DispatchQueue.global(qos: .background).sync {
@@ -46,7 +45,7 @@ struct SimpleXApp: App {
if AppChatState.shared.value == .active {
chatModel.appOpenUrl = url
} else {
appOpenUrlLater = url
chatModel.appOpenUrlLater = url
}
}
.onAppear() {
@@ -98,15 +97,15 @@ struct SimpleXApp: App {
if !chatModel.showCallView && !CallController.shared.hasActiveCalls() {
await updateCallInvitations()
}
if let url = appOpenUrlLater {
if let url = chatModel.appOpenUrlLater {
await MainActor.run {
appOpenUrlLater = nil
chatModel.appOpenUrlLater = nil
chatModel.appOpenUrl = url
}
}
}
} else if let url = appOpenUrlLater {
appOpenUrlLater = nil
} else if let url = chatModel.appOpenUrlLater {
chatModel.appOpenUrlLater = nil
chatModel.appOpenUrl = url
}
}