From c0a16e62be9a718149f31cbc45dfd2f4af078f2e Mon Sep 17 00:00:00 2001 From: QuentinArguillere Date: Mon, 26 Feb 2024 18:06:29 +0100 Subject: [PATCH] Switch app Core to SharedCore, which will be required to have a working AppExtension --- Linphone/Core/CoreContext.swift | 39 +++++++++---------- Linphone/Linphone.entitlements | 1 - .../Utils/Extensions/ConfigExtension.swift | 5 ++- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/Linphone/Core/CoreContext.swift b/Linphone/Core/CoreContext.swift index 1cadfdcbd..3746a3f2c 100644 --- a/Linphone/Core/CoreContext.swift +++ b/Linphone/Core/CoreContext.swift @@ -70,38 +70,35 @@ final class CoreContext: ObservableObject { } func initialiseCore() throws { - #if USE_CRASHLYTICS FirebaseApp.configure() #endif coreQueue.async { - LoggingService.Instance.logLevel = LogLevel.Debug - let configDir = Factory.Instance.getConfigDir(context: nil) - - Factory.Instance.logCollectionPath = configDir + Factory.Instance.logCollectionPath = Factory.Instance.getConfigDir(context: nil) Factory.Instance.enableLogCollection(state: LogCollectionState.Enabled) - Log.info("Initialising core") - let url = NSURL(fileURLWithPath: configDir) - if let pathComponent = url.appendingPathComponent("linphonerc") { - let filePath = pathComponent.path - let fileManager = FileManager.default - if !fileManager.fileExists(atPath: filePath) { - let path = Bundle.main.path(forResource: "linphonerc-default", ofType: nil) - if path != nil { - try? FileManager.default.copyItem(at: NSURL(fileURLWithPath: path!) as URL, to: pathComponent) + Log.info("Checking if linphonerc file exists already. If not, creating one as a copy of linphonerc-default") + if let rcDir = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: Config.appGroupName)? + .appendingPathComponent("Library/Preferences/linphone") { + let rcFileUrl = rcDir.appendingPathComponent("linphonerc") + if !FileManager.default.fileExists(atPath: rcFileUrl.path) { + do { + try FileManager.default.createDirectory(at: rcDir, withIntermediateDirectories: true) + if let pathToDefaultConfig = Bundle.main.path(forResource: "linphonerc-default", ofType: nil) { + try FileManager.default.copyItem(at: URL(fileURLWithPath: pathToDefaultConfig), to: rcFileUrl) + Log.info("Successfully copied linphonerc-default configuration") + } + } catch let error { + Log.error("Failed to copy default linphonerc file: \(error.localizedDescription)") } + } else { + Log.info("Found existing linphonerc file, skip copying of linphonerc-default configuration") } } - 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) - } + Log.info("Initialising core") + self.mCore = try? Factory.Instance.createSharedCoreWithConfig(config: Config.get(), systemContext: nil, appGroupId: Config.appGroupName, mainCore: true) linphone_core_set_push_registry_dispatch_queue(self.mCore.getCobject, Unmanaged.passUnretained(coreQueue).toOpaque()) self.mCore.autoIterateEnabled = false diff --git a/Linphone/Linphone.entitlements b/Linphone/Linphone.entitlements index 6a0769bbd..5ac776606 100644 --- a/Linphone/Linphone.entitlements +++ b/Linphone/Linphone.entitlements @@ -13,7 +13,6 @@ group.belledonne-communications.linphone group.org.linphone.phone.linphoneExtension group.org.linphone.phone.msgNotification - group.org.linphone.phone.logs com.apple.security.files.user-selected.read-only diff --git a/Linphone/Utils/Extensions/ConfigExtension.swift b/Linphone/Utils/Extensions/ConfigExtension.swift index 9d83cd891..b7b308c0a 100644 --- a/Linphone/Utils/Extensions/ConfigExtension.swift +++ b/Linphone/Utils/Extensions/ConfigExtension.swift @@ -36,7 +36,8 @@ extension Config { public static func get() -> Config { if _instance == nil { - let factoryPath = FileUtil.bundleFilePath(Core.runsInsideExtension() ? "linphonerc-factory-appex" : "linphonerc-factory-app")! + let factoryPath = FileUtil.bundleFilePath("linphonerc-factory")! + let configDir = Factory.Instance.getConfigDir(context: nil) _instance = Config.newForSharedCore(appGroupId: Config.appGroupName, configFilename: "linphonerc", factoryConfigFilename: factoryPath)! } return _instance! @@ -46,7 +47,7 @@ extension Config { return hasEntry(section: section, key: key) == 1 ? getString(section: section, key: key, defaultString: "") : nil } - static let appGroupName = "group.org.linphone.phone.logs" + static let appGroupName = "group.org.linphone.phone.msgNotification" // Needs to be the same name in App Group (capabilities in ALL targets - app & extensions - content + service), can't be stored in the Config itself the Config needs this value to get created static let teamID = Config.get().getString(section: "app", key: "team_id", defaultString: "") static let earlymediaContentExtCatIdentifier = Config.get().getString(section: "app", key: "extension_category", defaultString: "")