mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 09:32:52 +02:00
Feature/3811 appconfig
This commit is contained in:
@@ -35,7 +35,7 @@ extension UserDefaults
|
||||
@objcMembers class AppConfigService : NSObject {
|
||||
static let shared = AppConfigService()
|
||||
|
||||
private let serverUrlKey = "serverUrl"
|
||||
private let serverUrlKey = "home_server_url"
|
||||
private let contentScannerKey = "contentScanner"
|
||||
private let pusherUrlKey = "pusherUrl"
|
||||
private let permalinkUrlKey = "permalinkUrl"
|
||||
@@ -50,10 +50,14 @@ extension UserDefaults
|
||||
|
||||
var session: MXSession?
|
||||
|
||||
var isAppConfig: Bool
|
||||
|
||||
private func loadAppConfig() {
|
||||
isAppConfig = false
|
||||
do {
|
||||
if let dataIn = UserDefaults.standard.value(forKey: savedConfig) as? Data {
|
||||
appConfig = try JSONDecoder().decode(AppConfig.self, from: dataIn)
|
||||
isAppConfig = true
|
||||
}
|
||||
} catch {
|
||||
|
||||
@@ -70,17 +74,18 @@ extension UserDefaults
|
||||
}
|
||||
|
||||
private func checkUrlSavety(_ serverUrl: String) -> Bool {
|
||||
if serverUrl.hasSuffix("bwi.de")
|
||||
|| serverUrl.hasSuffix("example.com")
|
||||
|| serverUrl.hasSuffix("example.com")
|
||||
|| serverUrl.hasSuffix("example.com") {
|
||||
return true
|
||||
if BWIBuildSettings.shared.bwiEnableLoginProtection {
|
||||
let protectionService = LoginProtectionService()
|
||||
protectionService.hashes = BWIBuildSettings.shared.bwiHashes
|
||||
|
||||
return protectionService.isValid(serverUrl)
|
||||
} else {
|
||||
return false
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
override init() {
|
||||
isAppConfig = false
|
||||
super.init()
|
||||
self.loadAppConfig()
|
||||
}
|
||||
@@ -93,12 +98,13 @@ extension UserDefaults
|
||||
}
|
||||
|
||||
func handleAppConfig() {
|
||||
|
||||
if let dict = UserDefaults.standard.dictionary(forKey: configKey) {
|
||||
var config = AppConfig()
|
||||
|
||||
if let serverUrl = dict[serverUrlKey] as? String {
|
||||
if checkUrlSavety(serverUrl) {
|
||||
if serverUrl.count == 0 {
|
||||
config.serverUrl = nil
|
||||
} else if checkUrlSavety(serverUrl) {
|
||||
config.serverUrl = serverUrl
|
||||
}
|
||||
}
|
||||
@@ -118,6 +124,9 @@ extension UserDefaults
|
||||
}
|
||||
}
|
||||
|
||||
// app config needs at least a valid server url
|
||||
isAppConfig = (config.serverUrl != nil)
|
||||
|
||||
if config != appConfig {
|
||||
appConfig = config
|
||||
self.saveAppConfig()
|
||||
@@ -125,6 +134,8 @@ extension UserDefaults
|
||||
completion(true)
|
||||
}
|
||||
}
|
||||
|
||||
UserDefaults.standard.removeObject(forKey: configKey)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user