From 90231749c4ca7cb3a52251571ced16791bff36c5 Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Thu, 24 Apr 2025 10:03:54 +0200 Subject: [PATCH] Fix provisioning click URI handler --- Linphone/Core/CoreContext.swift | 12 ++++-------- Linphone/LinphoneApp.swift | 8 ++++++-- Linphone/UI/Assistant/Viewmodel/QRScanner.swift | 2 ++ Linphone/Utils/URIHandler.swift | 11 ++++++++--- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Linphone/Core/CoreContext.swift b/Linphone/Core/CoreContext.swift index 16b81ea87..61bbb8900 100644 --- a/Linphone/Core/CoreContext.swift +++ b/Linphone/Core/CoreContext.swift @@ -255,16 +255,12 @@ final class CoreContext: ObservableObject { } }, onConfiguringStatus: { (_: Core, status: ConfiguringState, message: String) in Log.info("New configuration state is \(status) = \(message)\n") - var accountModels: [AccountModel] = [] - for account in self.mCore.accountList { - accountModels.append(AccountModel(account: account, core: self.mCore)) - } DispatchQueue.main.async { if status == ConfiguringState.Successful { - /* - ToastViewModel.shared.toastMessage = "Success_qr_code_validated" - ToastViewModel.shared.displayToast = true - */ + var accountModels: [AccountModel] = [] + for account in self.mCore.accountList { + accountModels.append(AccountModel(account: account, core: self.mCore)) + } self.accounts = accountModels } } diff --git a/Linphone/LinphoneApp.swift b/Linphone/LinphoneApp.swift index 1d8899dcd..22a1c8eb6 100644 --- a/Linphone/LinphoneApp.swift +++ b/Linphone/LinphoneApp.swift @@ -158,6 +158,9 @@ struct LinphoneApp: App { ToastView() .zIndex(3) } + .onOpenURL { url in + URIHandler.handleURL(url: url) + } } else if coreContext.accounts.isEmpty || sharedMainViewModel.displayProfileMode { ZStack { AssistantView() @@ -165,6 +168,9 @@ struct LinphoneApp: App { ToastView() .zIndex(3) } + .onOpenURL { url in + URIHandler.handleURL(url: url) + } } else if !coreContext.accounts.isEmpty && contactViewModel != nil && editContactViewModel != nil @@ -236,8 +242,6 @@ struct LinphoneApp: App { meetingViewModel = MeetingViewModel() conversationForwardMessageViewModel = ConversationForwardMessageViewModel() accountProfileViewModel = AccountProfileViewModel() - }.onOpenURL { url in - URIHandler.handleURL(url: url) } } }.onChange(of: scenePhase) { newPhase in diff --git a/Linphone/UI/Assistant/Viewmodel/QRScanner.swift b/Linphone/UI/Assistant/Viewmodel/QRScanner.swift index 014cf08f3..ccf371084 100644 --- a/Linphone/UI/Assistant/Viewmodel/QRScanner.swift +++ b/Linphone/UI/Assistant/Viewmodel/QRScanner.swift @@ -76,6 +76,8 @@ class Coordinator: NSObject, AVCaptureMetadataOutputObjectsDelegate { core.stop() try? core.start() } + ToastViewModel.shared.toastMessage = "Success_qr_code_validated" + ToastViewModel.shared.displayToast = true } else { ToastViewModel.shared.toastMessage = "Invalide URI" ToastViewModel.shared.displayToast.toggle() diff --git a/Linphone/Utils/URIHandler.swift b/Linphone/Utils/URIHandler.swift index 7706dc530..d478f896b 100644 --- a/Linphone/Utils/URIHandler.swift +++ b/Linphone/Utils/URIHandler.swift @@ -90,12 +90,17 @@ class URIHandler { private static func initiateConfiguration(url: URL) { if autoRemoteProvisioningOnConfigUriHandler() { - CoreContext.shared.performActionOnCoreQueueWhenCoreIsStarted { core in + CoreContext.shared.doOnCoreQueue { core in Log.info("[URIHandler] provisioning app with URI: \(url.resourceSpecifier)") do { addCoreDelegate() - core.config?.setString(section: "misc", key: "config-uri", value: url.resourceSpecifier) - try core.setProvisioninguri(newValue: url.resourceSpecifier) + var urlString = url.resourceSpecifier + if urlString.starts(with: "//") { + urlString = String(urlString.dropFirst(2)) + } + + core.config?.setString(section: "misc", key: "config-uri", value: urlString) + try core.setProvisioninguri(newValue: urlString) core.stop() try core.start() } catch {