mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Hardcode the sliding sync proxy. (#502)
* Add support for migrating between versions. * Rename InfoPlistReader property. * Bump SDK version.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
import Combine
|
||||
import MatrixRustSDK
|
||||
import SwiftUI
|
||||
import Version
|
||||
|
||||
class AppCoordinator: AppCoordinatorProtocol {
|
||||
private let stateMachine: AppCoordinatorStateMachine
|
||||
@@ -66,13 +67,18 @@ class AppCoordinator: AppCoordinatorProtocol {
|
||||
|
||||
userSessionStore = UserSessionStore(backgroundTaskService: backgroundTaskService)
|
||||
|
||||
// Reset everything if the app has been deleted since the previous run
|
||||
if !ServiceLocator.shared.settings.hasAppLaunchedOnce {
|
||||
AppSettings.reset()
|
||||
userSessionStore.reset()
|
||||
ServiceLocator.shared.settings.hasAppLaunchedOnce = true
|
||||
guard let currentVersion = Version(InfoPlistReader(bundle: .main).bundleShortVersionString) else {
|
||||
fatalError("The app's version number **must** use semver for migration purposes.")
|
||||
}
|
||||
|
||||
if let previousVersion = ServiceLocator.shared.settings.lastVersionLaunched.flatMap(Version.init) {
|
||||
performMigrationsIfNecessary(from: previousVersion, to: currentVersion)
|
||||
} else {
|
||||
// The app has been deleted since the previous run. Reset everything.
|
||||
wipeUserData(includingSettings: true)
|
||||
}
|
||||
ServiceLocator.shared.settings.lastVersionLaunched = currentVersion.description
|
||||
|
||||
setupStateMachine()
|
||||
|
||||
Bundle.elementFallbackLanguage = "en"
|
||||
@@ -126,6 +132,27 @@ class AppCoordinator: AppCoordinatorProtocol {
|
||||
MXLog.configure(loggerConfiguration)
|
||||
}
|
||||
|
||||
/// Perform any required migrations for the app to function correctly.
|
||||
private func performMigrationsIfNecessary(from oldVersion: Version, to newVersion: Version) {
|
||||
guard oldVersion != newVersion else { return }
|
||||
|
||||
if oldVersion < Version(1, 0, 17) {
|
||||
// Version 1.0.17 hardcoded a new sliding sync proxy for matrix.org
|
||||
// Force a sign out for the user to log in with the new proxy.
|
||||
MXLog.warning("Clearing user data for hardcoded proxy.")
|
||||
wipeUserData()
|
||||
}
|
||||
}
|
||||
|
||||
/// Clears the keychain, app support directory etc ready for a fresh use.
|
||||
/// - Parameter includingSettings: Whether to additionally wipe the user's app settings too.
|
||||
private func wipeUserData(includingSettings: Bool = false) {
|
||||
if includingSettings {
|
||||
AppSettings.reset()
|
||||
}
|
||||
userSessionStore.reset()
|
||||
}
|
||||
|
||||
// swiftlint:disable:next cyclomatic_complexity
|
||||
private func setupStateMachine() {
|
||||
stateMachine.addTransitionHandler { [weak self] context in
|
||||
|
||||
@@ -20,7 +20,7 @@ import SwiftUI
|
||||
/// Store Element specific app settings.
|
||||
final class AppSettings: ObservableObject {
|
||||
private enum UserDefaultsKeys: String {
|
||||
case hasAppLaunchedOnce
|
||||
case lastVersionLaunched
|
||||
case timelineStyle
|
||||
case enableAnalytics
|
||||
case isIdentifiedForAnalytics
|
||||
@@ -29,7 +29,7 @@ final class AppSettings: ObservableObject {
|
||||
case pusherProfileTag
|
||||
}
|
||||
|
||||
private static var suiteName: String = InfoPlistReader.target.appGroupIdentifier
|
||||
private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier
|
||||
|
||||
/// UserDefaults to be used on reads and writes.
|
||||
private static var store: UserDefaults! = UserDefaults(suiteName: suiteName)
|
||||
@@ -50,20 +50,27 @@ final class AppSettings: ObservableObject {
|
||||
|
||||
// MARK: - Application
|
||||
|
||||
/// Simple flag to check if app has been deleted between runs.
|
||||
/// Used to clear data stored in the shared container and keychain
|
||||
@AppStorage(UserDefaultsKeys.hasAppLaunchedOnce.rawValue, store: store)
|
||||
var hasAppLaunchedOnce = false
|
||||
/// The last known version of the app that was launched on this device, which is
|
||||
/// used to detect when migrations should be run. When `nil` the app may have been
|
||||
/// deleted between runs so should clear data in the shared container and keychain.
|
||||
@AppStorage(UserDefaultsKeys.lastVersionLaunched.rawValue, store: store)
|
||||
var lastVersionLaunched: String?
|
||||
|
||||
/// The default homeserver address used. This is intentionally a string without a scheme
|
||||
/// so that it can be passed to Rust as a ServerName for well-known discovery.
|
||||
let defaultHomeserverAddress = "matrix.org"
|
||||
|
||||
/// An override of the homeserver's Sliding Sync proxy URL. This allows development against servers
|
||||
/// that don't yet have an officially trusted proxy configured in their well-known.
|
||||
let slidingSyncProxyURL = URL(staticString: "https://slidingsync.lab.matrix.org")
|
||||
|
||||
// MARK: - Notifications
|
||||
|
||||
var pusherAppId: String {
|
||||
#if DEBUG
|
||||
InfoPlistReader.target.baseBundleIdentifier + ".ios.dev"
|
||||
InfoPlistReader.main.baseBundleIdentifier + ".ios.dev"
|
||||
#else
|
||||
InfoPlistReader.target.baseBundleIdentifier + ".ios.prod"
|
||||
InfoPlistReader.main.baseBundleIdentifier + ".ios.prod"
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -84,14 +91,14 @@ final class AppSettings: ObservableObject {
|
||||
#if DEBUG
|
||||
/// The configuration to use for analytics during development. Set `isEnabled` to false to disable analytics in debug builds.
|
||||
/// **Note:** Analytics are disabled by default for forks. If you are maintaining a fork, set custom configurations.
|
||||
let analyticsConfiguration = AnalyticsConfiguration(isEnabled: InfoPlistReader.target.bundleIdentifier.starts(with: "io.element.elementx"),
|
||||
let analyticsConfiguration = AnalyticsConfiguration(isEnabled: InfoPlistReader.main.bundleIdentifier.starts(with: "io.element.elementx"),
|
||||
host: "https://posthog.element.dev",
|
||||
apiKey: "phc_VtA1L35nw3aeAtHIx1ayrGdzGkss7k1xINeXcoIQzXN",
|
||||
termsURL: URL(staticString: "https://element.io/cookie-policy"))
|
||||
#else
|
||||
/// The configuration to use for analytics. Set `isEnabled` to false to disable analytics.
|
||||
/// **Note:** Analytics are disabled by default for forks. If you are maintaining a fork, set custom configurations.
|
||||
let analyticsConfiguration = AnalyticsConfiguration(isEnabled: InfoPlistReader.target.bundleIdentifier.starts(with: "io.element.elementx"),
|
||||
let analyticsConfiguration = AnalyticsConfiguration(isEnabled: InfoPlistReader.main.bundleIdentifier.starts(with: "io.element.elementx"),
|
||||
host: "https://posthog.hss.element.io",
|
||||
apiKey: "phc_Jzsm6DTm6V2705zeU5dcNvQDlonOR68XvX2sh1sEOHO",
|
||||
termsURL: URL(staticString: "https://element.io/cookie-policy"))
|
||||
@@ -117,11 +124,6 @@ final class AppSettings: ObservableObject {
|
||||
@AppStorage(UserDefaultsKeys.timelineStyle.rawValue, store: store)
|
||||
var timelineStyle = TimelineStyle.bubbles
|
||||
|
||||
// MARK: - Client
|
||||
|
||||
@AppStorage(UserDefaultsKeys.slidingSyncProxyBaseURLString.rawValue, store: store)
|
||||
var slidingSyncProxyBaseURLString = "https://slidingsync.lab.element.dev"
|
||||
|
||||
// MARK: - Notifications
|
||||
|
||||
@AppStorage(UserDefaultsKeys.enableInAppNotifications.rawValue, store: store)
|
||||
|
||||
Reference in New Issue
Block a user