From b576785399bb86c5340ef8b1378af6569457074d Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Thu, 23 Nov 2023 17:21:49 +0100 Subject: [PATCH] Send and clear logs --- Linphone/Contacts/ContactsManager.swift | 3 ++ Linphone/Core/CoreContext.swift | 28 ++++++++---- Linphone/LinphoneApp.swift | 6 +-- Linphone/Localizable.xcstrings | 9 ++-- Linphone/Ressources/linphonerc-default | 1 + Linphone/SplashScreen.swift | 5 +-- Linphone/UI/Main/Fragments/SideMenu.swift | 53 ++++++++++++++++++++++- 7 files changed, 83 insertions(+), 22 deletions(-) diff --git a/Linphone/Contacts/ContactsManager.swift b/Linphone/Contacts/ContactsManager.swift index 717bc923e..44149bb49 100644 --- a/Linphone/Contacts/ContactsManager.swift +++ b/Linphone/Contacts/ContactsManager.swift @@ -67,6 +67,9 @@ final class ContactsManager { do { self.linphoneFriendList = try core.getFriendListByName(name: self.linphoneAddressBookFriendList) ?? core.createFriendList() + + //self.linphoneFriendList?.updateSubscriptions() + print("friendListfriendListfriendListfriendList \(self.linphoneFriendList!.rlsAddress)") } catch let error { print("\(#function) - Failed to enumerate contacts: \(error)") } diff --git a/Linphone/Core/CoreContext.swift b/Linphone/Core/CoreContext.swift index 5d025600b..ecb07e916 100644 --- a/Linphone/Core/CoreContext.swift +++ b/Linphone/Core/CoreContext.swift @@ -60,6 +60,10 @@ final class CoreContext: ObservableObject { coreQueue.async { let configDir = Factory.Instance.getConfigDir(context: nil) + + Factory.Instance.logCollectionPath = configDir + Factory.Instance.enableLogCollection(state: LogCollectionState.Enabled) + let url = NSURL(fileURLWithPath: configDir) if let pathComponent = url.appendingPathComponent("linphonerc") { let filePath = pathComponent.path @@ -71,25 +75,32 @@ final class CoreContext: ObservableObject { } } } - - let config: Config! = Config.newForSharedCore( - appGroupId: "group.org.linphone.phone.msgNotification", - configFilename: "linphonerc", - factoryConfigFilename: Bundle.main.path(forResource: "linphonerc-factory", ofType: nil) - ) - - self.mCore = try? Factory.Instance.createCoreWithConfig(config: config, systemContext: nil) + + let config = try? Factory.Instance.createConfigWithFactory( + path: "\(configDir)/linphonerc", + factoryPath: Bundle.main.path(forResource: "linphonerc-factory", ofType: nil) + ) + if config != nil { + self.mCore = try? Factory.Instance.createCoreWithConfig(config: config!, systemContext: nil) + } self.mCore.autoIterateEnabled = false self.mCore.friendsDatabasePath = "\(configDir)/friends.db" + //self.mCore.logCollectionUploadServerUrl = "https://www.linphone.org:444/lft.php" + //self.mCore.friendListSubscriptionEnabled = true + + print("configDirconfigDir \(configDir)") + self.mCore.publisher?.onGlobalStateChanged?.postOnMainQueue { (cbVal: (core: Core, state: GlobalState, message: String)) in if cbVal.state == GlobalState.On { self.defaultAccount = self.mCore.defaultAccount } else if cbVal.state == GlobalState.Off { self.defaultAccount = nil } + self.coreIsStarted = true } + try? self.mCore.start() // Create a Core listener to listen for the callback we need @@ -115,7 +126,6 @@ final class CoreContext: ObservableObject { if cbVal.state == .Ok { self.loggingInProgress = false self.loggedIn = true - self.coreIsStarted = true } else if cbVal.state == .Progress { self.loggingInProgress = true } else { diff --git a/Linphone/LinphoneApp.swift b/Linphone/LinphoneApp.swift index 1075bea5b..159abb97d 100644 --- a/Linphone/LinphoneApp.swift +++ b/Linphone/LinphoneApp.swift @@ -30,11 +30,9 @@ struct LinphoneApp: App { @State private var historyViewModel: HistoryViewModel? @State private var historyListViewModel: HistoryListViewModel? - @State private var isActive = true - var body: some Scene { WindowGroup { - if isActive && coreContext.coreIsStarted { + if coreContext.coreIsStarted { if !sharedMainViewModel.welcomeViewDisplayed { WelcomeView() } else if coreContext.defaultAccount == nil || sharedMainViewModel.displayProfileMode { @@ -52,7 +50,7 @@ struct LinphoneApp: App { ) } } else { - SplashScreen(isActive: $isActive) + SplashScreen() .onDisappear { contactViewModel = ContactViewModel() editContactViewModel = EditContactViewModel() diff --git a/Linphone/Localizable.xcstrings b/Linphone/Localizable.xcstrings index 8a1a3da17..d95a2a884 100644 --- a/Linphone/Localizable.xcstrings +++ b/Linphone/Localizable.xcstrings @@ -163,6 +163,9 @@ }, "Chiffrement de bout en bout de tous vos échanges, grâce au mode default vos communications sont à l’abri des regards." : { + }, + "Clear logs" : { + }, "Close" : { @@ -375,9 +378,6 @@ }, "Plus tard" : { - }, - "Posts" : { - }, "Pour vous permettre de vous profitez pleinement de Linphone nous avons besoin des autorisations suivantes :" : { @@ -408,6 +408,9 @@ }, "See Linphone contact" : { + }, + "Send logs" : { + }, "Share" : { diff --git a/Linphone/Ressources/linphonerc-default b/Linphone/Ressources/linphonerc-default index ea5356429..46ca19ac0 100644 --- a/Linphone/Ressources/linphonerc-default +++ b/Linphone/Ressources/linphonerc-default @@ -16,6 +16,7 @@ update_presence_model_timestamp_before_publish_expires_refresh=1 #Because dynamic bitrate adaption can increase bitrate, we must allow "no limit" download_bw=0 upload_bw=0 +friendlist_subscription_enabled=1 [video] size=vga diff --git a/Linphone/SplashScreen.swift b/Linphone/SplashScreen.swift index e8c11ef7c..e15c4aaac 100644 --- a/Linphone/SplashScreen.swift +++ b/Linphone/SplashScreen.swift @@ -21,9 +21,6 @@ import SwiftUI struct SplashScreen: View { - @ObservedObject private var coreContext = CoreContext.shared - @Binding var isActive: Bool - var body: some View { GeometryReader { _ in VStack { @@ -42,5 +39,5 @@ struct SplashScreen: View { } #Preview { - SplashScreen(isActive: .constant(true)) + SplashScreen() } diff --git a/Linphone/UI/Main/Fragments/SideMenu.swift b/Linphone/UI/Main/Fragments/SideMenu.swift index 317490553..8da7a0086 100644 --- a/Linphone/UI/Main/Fragments/SideMenu.swift +++ b/Linphone/UI/Main/Fragments/SideMenu.swift @@ -18,8 +18,15 @@ */ import SwiftUI +import linphonesw +import UniformTypeIdentifiers struct SideMenu: View { + + @ObservedObject private var coreContext = CoreContext.shared + + @State private var coreDelegate: CoreDelegate? + let width: CGFloat let isOpen: Bool let menuClose: () -> Void @@ -41,9 +48,13 @@ struct SideMenu: View { Text("My Profile").onTapGesture { print("My Profile") } - Text("Posts").onTapGesture { - print("Posts") + Text("Send logs").onTapGesture { + sendLogs() } + Text("Clear logs").onTapGesture { + print("Clear logs") + Core.resetLogCollection() + } Text("Logout").onTapGesture { print("Logout") } @@ -60,4 +71,42 @@ struct SideMenu: View { } .frame(maxWidth: .infinity, maxHeight: .infinity) } + + func sendLogs() { + coreContext.doOnCoreQueue { core in + core.uploadLogCollection() + + let newCoreDelegate = CoreDelegateStub( + onLogCollectionUploadStateChanged: { core, logCollectionUploadState, logString in + print("newCoreDelegatenewCoreDelegate \(logString)") + + if logString.starts(with: "https") { + UIPasteboard.general.setValue( + logString, + forPasteboardType: UTType.plainText.identifier + ) + + removeAllDelegate() + + ToastViewModel.shared.toastMessage = "Success_copied_into_clipboard" + ToastViewModel.shared.displayToast.toggle() + } + } + ) + + coreDelegate = newCoreDelegate + if coreDelegate != nil { + core.addDelegate(delegate: coreDelegate!) + } + } + } + + func removeAllDelegate() { + coreContext.doOnCoreQueue { core in + if coreDelegate != nil { + core.removeDelegate(delegate: coreDelegate!) + coreDelegate = nil + } + } + } }