mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-03-30 20:45:49 +00:00
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:
@@ -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")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user