Feature/3811 appconfig

This commit is contained in:
Frank Rotermund
2023-09-19 11:21:12 +00:00
parent e3cfb301a9
commit 5dd5dc2db7
13 changed files with 205 additions and 145 deletions
@@ -18,6 +18,7 @@
import Foundation
import UIKit
import MatrixSDK
import SwiftUI
fileprivate let BWI_ServerDowntimes = "BWI_ServerDowntimes"
@@ -150,6 +151,80 @@ fileprivate let maintenanceURL = "/_matrix/cmaintenance"
extension ServerDowntimeDefaultService : ServerDowntimeService {
func alert(alertType: ServerMaintenanceAlertType, completion: @escaping () -> Void) -> Alert {
switch alertType {
case .showInvalidAppVersionAlert:
return Alert(title: Text(BWIL10n.bwiOutdatedVersionWarningTitle),
message: Text(BWIL10n.bwiOutdatedVersionWarningMessage(AppInfo.current.displayName)),
dismissButton: .destructive(Text(BWIL10n.bwiOutdatedVersionAppstoreButton), action: {
let iTunesLink = BWIBuildSettings.shared.itunesAppLink
UIApplication.shared.open(URL(string: iTunesLink)!, options: [:], completionHandler: nil)
}))
case .showDowntimeTimeAlert:
if BWIBuildSettings.shared.ignoreBlockingMaintenance && isBlocking() {
return Alert( title: Text(""),
message: Text(ServerDowntimeDefaultService().downtimeText()),
primaryButton: .cancel(Text(BWIL10n.blockingDowntimeAlertIgnoreButton)) {
UserDefaults.standard.set(false, forKey: "ServerDownTimeBlockingKey")
self.setManuallyIgnored()
completion()
},
secondaryButton: .destructive(Text(BWIL10n.blockingDowntimeAlertDismissButton))
)
} else {
return Alert(title: Text(BWIL10n.downtimeTitle),
message: Text(ServerDowntimeDefaultService().downtimeText() != "" ? BWIL10n.downtimeDefaultMessage + "\n\n" + ServerDowntimeDefaultService().downtimeText() : BWIL10n.downtimeDefaultMessage),
dismissButton: .destructive(Text(isBlocking() ? BWIL10n.blockingDowntimeAlertDismissButton : BWIL10n.downtimeAlertDismissButton)) {
if self.isBlocking() {
return
} else {
completion()
}
})
}
case .showServerMaintenanceInfoMessageAlert:
if BWIBuildSettings.shared.ignoreBlockingMaintenance && isBlocking() {
return Alert( title: Text(""),
message: Text(ServerDowntimeDefaultService().downtimeText()),
primaryButton: .cancel(Text(BWIL10n.blockingDowntimeAlertIgnoreButton)) {
completion()
},
secondaryButton: .destructive(Text(BWIL10n.blockingDowntimeAlertDismissButton))
)
} else {
return Alert(title: Text(""),
message: Text(ServerDowntimeDefaultService().downtimeText()),
dismissButton: .destructive(Text(isBlocking() ? BWIL10n.blockingDowntimeAlertDismissButton : BWIL10n.downtimeAlertDismissButton)) {
if self.isBlocking() {
return
} else {
completion()
}
})
}
case .showServerMaintenanceDefaultAlert:
return Alert(title: Text(BWIL10n.downtimeTitle),
message: Text(BWIL10n.downtimeDefaultMessage),
dismissButton: .destructive(Text(BWIL10n.downtimeAlertDismissButton)) {
completion()
})
}
}
func showAlert() -> Bool {
return nextDowntimeStatus() == .ongoing
}
func alertType() -> ServerMaintenanceAlertType {
if downtimeType() == .adhocMessage {
return .showServerMaintenanceInfoMessageAlert
} else {
return .showDowntimeTimeAlert
}
}
func fetchDowntimes(session: MXSession, completion: @escaping () -> Void) {
session.matrixRestClient.getDowntime(completion: { (jsonResponse, error) in
do {