Fix provisioning click URI handler (after core has started)

This commit is contained in:
Benoit Martins 2025-05-12 15:57:11 +02:00
parent 4f1fcbbcf6
commit 0da7f36619
2 changed files with 89 additions and 73 deletions

View file

@ -40,6 +40,7 @@ final class CoreContext: ObservableObject {
var coreVersion: String = Core.getVersion
@Published var loggedIn: Bool = false
@Published var loggingInProgress: Bool = false
@Published var coreHasStartedOnce: Bool = false
@Published var coreIsStarted: Bool = false
@Published var accounts: [AccountModel] = []
@Published var shortcuts: [ShortcutModel] = []
@ -81,7 +82,7 @@ final class CoreContext: ObservableObject {
}
func initialiseCore() throws {
Log.info("Initialising core 0000")
Log.info("Initialising core")
#if USE_CRASHLYTICS
FirebaseApp.configure()
#endif
@ -128,11 +129,9 @@ final class CoreContext: ObservableObject {
}
}
Log.info("Initialising core")
self.mCore = try? Factory.Instance.createSharedCoreWithConfig(config: Config.get(), systemContext: nil, appGroupId: Config.appGroupName, mainCore: true)
linphone_core_set_push_and_app_delegate_dispatch_queue(self.mCore.getCobject, Unmanaged.passUnretained(coreQueue).toOpaque())
self.mCore.autoIterateEnabled = false
self.mCore.callkitEnabled = true
self.mCore.pushNotificationEnabled = true
@ -221,9 +220,14 @@ final class CoreContext: ObservableObject {
accountModels.append(AccountModel(account: account, core: self.mCore))
}
DispatchQueue.main.async {
self.coreHasStartedOnce = true
self.coreIsStarted = true
self.accounts = accountModels
}
} else {
DispatchQueue.main.async {
self.coreIsStarted = state == GlobalState.On
}
}
}, onCallStateChanged: { (core: Core, call: Call, cstate: Call.State, message: String) in
TelecomManager.shared.onCallStateChanged(core: core, call: call, state: cstate, message: message)
@ -411,7 +415,7 @@ final class CoreContext: ObservableObject {
}
func performActionOnCoreQueueWhenCoreIsStarted(action: @escaping (_ core: Core) -> Void ) {
if coreIsStarted {
if coreHasStartedOnce {
CoreContext.shared.doOnCoreQueue { core in
action(core)
}

View file

@ -148,81 +148,93 @@ struct LinphoneApp: App {
@State private var conversationForwardMessageViewModel: ConversationForwardMessageViewModel?
@State private var accountProfileViewModel: AccountProfileViewModel?
@State private var pendingURL: URL?
var body: some Scene {
WindowGroup {
if coreContext.coreIsStarted {
if !sharedMainViewModel.welcomeViewDisplayed {
ZStack {
WelcomeView()
ToastView()
.zIndex(3)
}
.onOpenURL { url in
URIHandler.handleURL(url: url)
}
} else if coreContext.accounts.isEmpty || sharedMainViewModel.displayProfileMode {
ZStack {
AssistantView()
ToastView()
.zIndex(3)
}
.onOpenURL { url in
URIHandler.handleURL(url: url)
}
} else if !coreContext.accounts.isEmpty
&& contactViewModel != nil
&& editContactViewModel != nil
&& historyViewModel != nil
&& historyListViewModel != nil
&& startCallViewModel != nil
&& startConversationViewModel != nil
&& callViewModel != nil
&& meetingWaitingRoomViewModel != nil
&& conversationsListViewModel != nil
&& conversationViewModel != nil
&& meetingsListViewModel != nil
&& meetingViewModel != nil
&& conversationForwardMessageViewModel != nil
&& accountProfileViewModel != nil {
ContentView(
contactViewModel: contactViewModel!,
editContactViewModel: editContactViewModel!,
historyViewModel: historyViewModel!,
historyListViewModel: historyListViewModel!,
startCallViewModel: startCallViewModel!,
startConversationViewModel: startConversationViewModel!,
callViewModel: callViewModel!,
meetingWaitingRoomViewModel: meetingWaitingRoomViewModel!,
conversationsListViewModel: conversationsListViewModel!,
conversationViewModel: conversationViewModel!,
meetingsListViewModel: meetingsListViewModel!,
meetingViewModel: meetingViewModel!,
conversationForwardMessageViewModel: conversationForwardMessageViewModel!,
accountProfileViewModel: accountProfileViewModel!,
index: $index
)
.environmentObject(navigationManager)
.onAppear {
index = sharedMainViewModel.indexView
// Link the navigation manager to the AppDelegate
delegate.navigationManager = navigationManager
// Check if the app was launched with a notification payload
if let callId = delegate.launchNotificationCallId, let peerAddr = delegate.launchNotificationPeerAddr, let localAddr = delegate.launchNotificationLocalAddr {
// Notify the app to navigate to the chat room
navigationManager.openChatRoom(callId: callId, peerAddr: peerAddr, localAddr: localAddr)
if coreContext.coreHasStartedOnce {
ZStack {
if !sharedMainViewModel.welcomeViewDisplayed {
ZStack {
WelcomeView()
ToastView()
.zIndex(3)
}
accountProfileViewModel!.setAvatarModel()
} else if coreContext.accounts.isEmpty || sharedMainViewModel.displayProfileMode {
ZStack {
AssistantView()
ToastView()
.zIndex(3)
}
} else if !coreContext.accounts.isEmpty
&& contactViewModel != nil
&& editContactViewModel != nil
&& historyViewModel != nil
&& historyListViewModel != nil
&& startCallViewModel != nil
&& startConversationViewModel != nil
&& callViewModel != nil
&& meetingWaitingRoomViewModel != nil
&& conversationsListViewModel != nil
&& conversationViewModel != nil
&& meetingsListViewModel != nil
&& meetingViewModel != nil
&& conversationForwardMessageViewModel != nil
&& accountProfileViewModel != nil {
ContentView(
contactViewModel: contactViewModel!,
editContactViewModel: editContactViewModel!,
historyViewModel: historyViewModel!,
historyListViewModel: historyListViewModel!,
startCallViewModel: startCallViewModel!,
startConversationViewModel: startConversationViewModel!,
callViewModel: callViewModel!,
meetingWaitingRoomViewModel: meetingWaitingRoomViewModel!,
conversationsListViewModel: conversationsListViewModel!,
conversationViewModel: conversationViewModel!,
meetingsListViewModel: meetingsListViewModel!,
meetingViewModel: meetingViewModel!,
conversationForwardMessageViewModel: conversationForwardMessageViewModel!,
accountProfileViewModel: accountProfileViewModel!,
index: $index
)
.environmentObject(navigationManager)
.onAppear {
index = sharedMainViewModel.indexView
// Link the navigation manager to the AppDelegate
delegate.navigationManager = navigationManager
// Check if the app was launched with a notification payload
if let callId = delegate.launchNotificationCallId, let peerAddr = delegate.launchNotificationPeerAddr, let localAddr = delegate.launchNotificationLocalAddr {
// Notify the app to navigate to the chat room
navigationManager.openChatRoom(callId: callId, peerAddr: peerAddr, localAddr: localAddr)
}
accountProfileViewModel!.setAvatarModel()
}
} else {
SplashScreen()
}
.onOpenURL { url in
URIHandler.handleURL(url: url)
if coreContext.coreIsStarted {
VStack {
}
.onAppear {
if let url = pendingURL {
URIHandler.handleURL(url: url)
pendingURL = nil
}
}
}
} else {
SplashScreen().onOpenURL { url in
}
.onOpenURL { url in
if coreContext.coreIsStarted {
URIHandler.handleURL(url: url)
} else {
pendingURL = url
}
}
} else {