Switch app Core to SharedCore, which will be required to have a working AppExtension

This commit is contained in:
QuentinArguillere 2024-02-26 18:06:29 +01:00
parent ea1420356d
commit c0a16e62be
3 changed files with 21 additions and 24 deletions

View file

@ -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

View file

@ -13,7 +13,6 @@
<string>group.belledonne-communications.linphone</string>
<string>group.org.linphone.phone.linphoneExtension</string>
<string>group.org.linphone.phone.msgNotification</string>
<string>group.org.linphone.phone.logs</string>
</array>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>

View file

@ -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: "")