mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-17 15:09:31 +02:00
Merge branch 'feature/5556_fix_maintenance_sync' into 'develop'
Feature/5556 fix maintenance sync See merge request bwmessenger/bundesmessenger/bundesmessenger-ios!341
This commit is contained in:
@@ -59,6 +59,9 @@
|
||||
"bwi_settings_developer_well_known" = "Well-Known";
|
||||
"bwi_settings_developer_capabilities" = "Capabilities";
|
||||
"bwi_settings_developer_maintenance" = "Maintenance";
|
||||
"bwi_settings_developer_maintenance_reload" = "Aktualisieren";
|
||||
"bwi_settings_developer_maintenance_server_data" = "Daten vom Server";
|
||||
"bwi_settings_developer_maintenance_local_data" = "UserDefaults / lokale Daten";
|
||||
"bwi_settings_developer_user_account_data" = "Account Data";
|
||||
"bwi_settings_developer_user_account_data_type" = "Type";
|
||||
"bwi_settings_developer_key_backup" = "Key Backup";
|
||||
|
||||
@@ -60,7 +60,10 @@
|
||||
"bwi_settings_developer_well_known" = "Well-Known";
|
||||
"bwi_settings_developer_capabilities" = "Capabilities";
|
||||
"bwi_settings_developer_maintenance" = "Maintenance";
|
||||
"bwi_settings_developer_maintenance_reload" = "Reload";
|
||||
"bwi_settings_developer_user_account_data" = "Account Data";
|
||||
"bwi_settings_developer_maintenance_server_data" = "Data from Server";
|
||||
"bwi_settings_developer_maintenance_local_data" = "UserDefaults / local data";
|
||||
"bwi_settings_developer_user_account_data_type" = "Type";
|
||||
"bwi_settings_developer_key_backup" = "Key Backup";
|
||||
"bwi_settings_developer_key_backup_algorithm" = "Algorithm";
|
||||
|
||||
@@ -599,6 +599,18 @@ public class BWIL10n: NSObject {
|
||||
public static var bwiSettingsDeveloperMaintenance: String {
|
||||
return BWIL10n.tr("Bwi", "bwi_settings_developer_maintenance")
|
||||
}
|
||||
/// UserDefaults / lokale Daten
|
||||
public static var bwiSettingsDeveloperMaintenanceLocalData: String {
|
||||
return BWIL10n.tr("Bwi", "bwi_settings_developer_maintenance_local_data")
|
||||
}
|
||||
/// Aktualisieren
|
||||
public static var bwiSettingsDeveloperMaintenanceReload: String {
|
||||
return BWIL10n.tr("Bwi", "bwi_settings_developer_maintenance_reload")
|
||||
}
|
||||
/// Daten vom Server
|
||||
public static var bwiSettingsDeveloperMaintenanceServerData: String {
|
||||
return BWIL10n.tr("Bwi", "bwi_settings_developer_maintenance_server_data")
|
||||
}
|
||||
/// Der alte Notizen-Raum Raum wurde durch einen neuen ersetzt.
|
||||
public static var bwiSettingsDeveloperNewPersonalNotesRoomCreated: String {
|
||||
return BWIL10n.tr("Bwi", "bwi_settings_developer_new_personal_notes_room_created")
|
||||
|
||||
@@ -2281,8 +2281,7 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
|
||||
|
||||
// bwi reset outdated Alert for next login
|
||||
if (BWIBuildSettings.shared.bwiCheckAppVersion) {
|
||||
ValidAppVersionsDefaultService *service = [[ValidAppVersionsDefaultService alloc] init];
|
||||
[service setOutdatedAlertShown:false];
|
||||
[ValidAppVersionsDefaultService.shared setOutdatedAlertShown:false];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2475,8 +2475,7 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewContro
|
||||
#pragma mark - Bwi Check App version
|
||||
|
||||
- (void)checkAppVersionDeprecated {
|
||||
ValidAppVersionsDefaultService *appVersionsService = [[ValidAppVersionsDefaultService alloc] init];
|
||||
if( BWIBuildSettings.shared.bwiCheckAppVersion && appVersionsService.isCurrentAppVersionDeprecated ) {
|
||||
if( BWIBuildSettings.shared.bwiCheckAppVersion && ValidAppVersionsDefaultService.shared.isCurrentAppVersionDeprecated ) {
|
||||
|
||||
MXWeakify(self);
|
||||
UIAlertController *errorAlert = [UIAlertController alertControllerWithTitle:[BWIL10n bwiOutdatedVersionWarningTitle]
|
||||
@@ -2498,8 +2497,7 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewContro
|
||||
}
|
||||
|
||||
- (void)checkAppVersionOutdated {
|
||||
ValidAppVersionsDefaultService *appVersionsService = [[ValidAppVersionsDefaultService alloc] init];
|
||||
if (BWIBuildSettings.shared.bwiCheckAppVersion && appVersionsService.isCurrentAppVersionOutdated && !appVersionsService.wasOutdatedAlertShown) {
|
||||
if (BWIBuildSettings.shared.bwiCheckAppVersion && ValidAppVersionsDefaultService.shared.isCurrentAppVersionOutdated && !ValidAppVersionsDefaultService.shared.wasOutdatedAlertShown) {
|
||||
MXWeakify(self);
|
||||
UIAlertController *errorAlert = [UIAlertController alertControllerWithTitle:[BWIL10n bwiOutdatedVersionWarningTitle]
|
||||
message:[BWIL10n bwiOutdatedVersionWarningMessage:AppInfo.current.displayName]
|
||||
@@ -2510,7 +2508,7 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewContro
|
||||
handler:^(UIAlertAction * action) {
|
||||
|
||||
[self gotoAppStore];
|
||||
[appVersionsService setOutdatedAlertShown:true];
|
||||
[ValidAppVersionsDefaultService.shared setOutdatedAlertShown:true];
|
||||
|
||||
MXStrongifyAndReturnIfNil(self);
|
||||
self->currentAlert = nil;
|
||||
@@ -2519,15 +2517,15 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewContro
|
||||
[errorAlert addAction:[UIAlertAction actionWithTitle:[BWIL10n bwiOutdatedVersionLogoutButton]
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction * action) {
|
||||
[appVersionsService setOutdatedAlertShown:true];
|
||||
[ValidAppVersionsDefaultService.shared setOutdatedAlertShown:true];
|
||||
}]];
|
||||
|
||||
[self presentViewController:errorAlert animated:YES completion:nil];
|
||||
}
|
||||
|
||||
// bwi #5276: if outdated was shown but our app version is valid that means we have updated and have to reset outdated shown
|
||||
if (BWIBuildSettings.shared.bwiCheckAppVersion && !appVersionsService.isCurrentAppVersionOutdated && appVersionsService.wasOutdatedAlertShown) {
|
||||
[appVersionsService setOutdatedAlertShown:false];
|
||||
if (BWIBuildSettings.shared.bwiCheckAppVersion && !ValidAppVersionsDefaultService.shared.isCurrentAppVersionOutdated && ValidAppVersionsDefaultService.shared.wasOutdatedAlertShown) {
|
||||
[ValidAppVersionsDefaultService.shared setOutdatedAlertShown:false];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -395,10 +395,9 @@ class AllChatsCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {
|
||||
button.autoresizingMask = [.flexibleHeight, .flexibleWidth]
|
||||
button.accessibilityLabel = VectorL10n.allChatsUserMenuAccessibilityLabel
|
||||
|
||||
let serverDownTime = ServerDowntimeDefaultService()
|
||||
if serverDownTime.isDowntimePresentable() {
|
||||
button = ServerDowntimeBadge().applyBadgeToButton(button: button, color: serverDownTime.downtimeColor())
|
||||
} else if BWIBuildSettings.shared.bwiCheckAppVersion && ValidAppVersionsDefaultService().isCurrentAppVersionOutdated() {
|
||||
if ServerDowntimeDefaultService.shared.isDowntimePresentable() {
|
||||
button = ServerDowntimeBadge().applyBadgeToButton(button: button, color: ServerDowntimeDefaultService.shared.downtimeColor())
|
||||
} else if BWIBuildSettings.shared.bwiCheckAppVersion && ValidAppVersionsDefaultService.shared.isCurrentAppVersionOutdated() {
|
||||
button = ServerDowntimeBadge().applyBadgeToButton(button: button, color: .yellow)
|
||||
}
|
||||
|
||||
@@ -722,13 +721,12 @@ class AllChatsCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {
|
||||
|
||||
// bwi: check if there are changes in maintenance status
|
||||
@objc private func checkMaintenanceStatus() {
|
||||
let serverDownTime = ServerDowntimeDefaultService()
|
||||
// bwi: bwi specific
|
||||
if BWIBuildSettings.shared.useTestDataForDowntime {
|
||||
serverDownTime.fetchDowntimes(completion: {
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimes(completion: {
|
||||
self.createLeftButtonItem(for: self.allChatsViewController)
|
||||
|
||||
if serverDownTime.isBlocking() && serverDownTime.isDowntimeNow() && !serverDownTime.isManuallyIgnored() {
|
||||
if ServerDowntimeDefaultService.shared.isBlocking() && ServerDowntimeDefaultService.shared.isDowntimeNow() && !ServerDowntimeDefaultService.shared.isManuallyIgnored() {
|
||||
UserDefaults.standard.set(true, forKey: "ServerDownTimeBlockingKey")
|
||||
} else {
|
||||
UserDefaults.standard.set(false, forKey: "ServerDownTimeBlockingKey")
|
||||
@@ -739,10 +737,10 @@ class AllChatsCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
serverDownTime.fetchDowntimesWithDirectRequest { success in
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimesWithDirectRequest(completion: { success, _, _, _ in
|
||||
self.createLeftButtonItem(for: self.allChatsViewController)
|
||||
|
||||
if serverDownTime.isBlocking() && serverDownTime.isDowntimeNow() && !serverDownTime.isManuallyIgnored() {
|
||||
|
||||
if ServerDowntimeDefaultService.shared.isBlocking() && ServerDowntimeDefaultService.shared.isDowntimeNow() && !ServerDowntimeDefaultService.shared.isManuallyIgnored() {
|
||||
UserDefaults.standard.set(true, forKey: "ServerDownTimeBlockingKey")
|
||||
} else {
|
||||
UserDefaults.standard.set(false, forKey: "ServerDownTimeBlockingKey")
|
||||
@@ -752,7 +750,7 @@ class AllChatsCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {
|
||||
self.allChatsViewController.checkAppVersionDeprecated()
|
||||
self.allChatsViewController.checkAppVersionOutdated()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -437,7 +437,7 @@ SSOAuthenticationPresenterDelegate>
|
||||
[tmpSections addObject:sectionDowntime];
|
||||
}
|
||||
|
||||
if (BWIBuildSettings.shared.bwiCheckAppVersion && [[[ValidAppVersionsDefaultService alloc] init] isCurrentAppVersionOutdated]) {
|
||||
if (BWIBuildSettings.shared.bwiCheckAppVersion && [ValidAppVersionsDefaultService.shared isCurrentAppVersionOutdated]) {
|
||||
Section *sectionOutdated = [Section sectionWithTag:SECTION_TAG_OUTDATED_WARNING];
|
||||
[sectionOutdated addRowWithTag:OUTDATED_WARNING];
|
||||
sectionOutdated.headerTitle = [BWIL10n bwiOutdatedSettingsHeader];
|
||||
|
||||
@@ -199,15 +199,14 @@ final class TabBarCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {
|
||||
}
|
||||
|
||||
func pinUnlocked() {
|
||||
let serverDownTime = ServerDowntimeDefaultService()
|
||||
|
||||
if BWIBuildSettings.shared.useTestDataForDowntime {
|
||||
serverDownTime.fetchDowntimes {
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimes {
|
||||
self.createSettingsButton(self.masterTabBarController)
|
||||
}
|
||||
} else {
|
||||
if let session = self.currentMatrixSession {
|
||||
serverDownTime.fetchDowntimes(session: session, completion: {
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimes(session: session, completion: {
|
||||
self.createSettingsButton(self.masterTabBarController)
|
||||
})
|
||||
}
|
||||
@@ -779,10 +778,9 @@ final class TabBarCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {
|
||||
private func createSettingsButton(_ controller: MasterTabBarController) {
|
||||
var settingsBarButtonItem: UIBarButtonItem
|
||||
|
||||
let serverDownTime = ServerDowntimeDefaultService()
|
||||
if serverDownTime.isDowntimePresentable() {
|
||||
settingsBarButtonItem = ServerDowntimeBadge().createBadgeBarButton(color: serverDownTime.downtimeColor(), target: self, selector: #selector(showSettings))
|
||||
} else if BWIBuildSettings.shared.bwiCheckAppVersion && ValidAppVersionsDefaultService().isCurrentAppVersionOutdated() {
|
||||
if ServerDowntimeDefaultService.shared.isDowntimePresentable() {
|
||||
settingsBarButtonItem = ServerDowntimeBadge().createBadgeBarButton(color: ServerDowntimeDefaultService.shared.downtimeColor(), target: self, selector: #selector(showSettings))
|
||||
} else if BWIBuildSettings.shared.bwiCheckAppVersion && ValidAppVersionsDefaultService.shared.isCurrentAppVersionOutdated() {
|
||||
settingsBarButtonItem = ServerDowntimeBadge().createBadgeBarButton(color: .yellow, target: self, selector: #selector(showSettings))
|
||||
} else {
|
||||
settingsBarButtonItem = MXKBarButtonItem(image: Asset.Images.settingsIcon.image, style: .plain) { [weak self] in
|
||||
|
||||
@@ -130,7 +130,7 @@ final class AuthenticationLoginCoordinator: Coordinator, Presentable {
|
||||
self.showForgotPasswordScreen()
|
||||
}
|
||||
case .login(let username, let password):
|
||||
if BWIBuildSettings.shared.bwiCheckAppVersion && ValidAppVersionsDefaultService().isCurrentAppVersionDeprecated() {
|
||||
if BWIBuildSettings.shared.bwiCheckAppVersion && ValidAppVersionsDefaultService.shared.isCurrentAppVersionDeprecated() {
|
||||
self.authenticationLoginViewModel.displayError(.appVersion)
|
||||
} else {
|
||||
self.login(username: username, password: password)
|
||||
|
||||
@@ -24,7 +24,6 @@ struct AuthenticationServerSelectionScreen: View {
|
||||
|
||||
@Environment(\.theme) private var theme
|
||||
|
||||
private let service = ServerDowntimeDefaultService()
|
||||
|
||||
@State private var showAlertForMissingCameraAuthorization = false
|
||||
@State private var showAlertForInvalidServer = false
|
||||
@@ -98,7 +97,7 @@ struct AuthenticationServerSelectionScreen: View {
|
||||
if isInvalidServerAlert {
|
||||
return self.invalidServerAlert()
|
||||
} else {
|
||||
return service.alert(alertType: activeAlert) {
|
||||
return ServerDowntimeDefaultService.shared.alert(alertType: activeAlert) {
|
||||
self.submit()
|
||||
}
|
||||
}
|
||||
@@ -281,12 +280,12 @@ struct AuthenticationServerSelectionScreen: View {
|
||||
isFetchingDowntime = true // show progresview
|
||||
|
||||
if BWIBuildSettings.shared.useTestDataForDowntime {
|
||||
service.fetchDowntimes {
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimes {
|
||||
self.isFetchingDowntime = false // hide progressview
|
||||
self.showAlertIfNeeded()
|
||||
}
|
||||
} else {
|
||||
service.fetchDowntimesWithDirectRequest(localUrlString:viewModel.homeserverAddress) { success in
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimesWithDirectRequest(localUrlString:viewModel.homeserverAddress) { success, _, _, _ in
|
||||
DispatchQueue.main.async {
|
||||
self.isFetchingDowntime = false // hide progressview
|
||||
if success {
|
||||
@@ -304,8 +303,8 @@ struct AuthenticationServerSelectionScreen: View {
|
||||
}
|
||||
|
||||
private func showAlertIfNeeded() {
|
||||
if service.showAlert() {
|
||||
activeAlert = service.alertType()
|
||||
if ServerDowntimeDefaultService.shared.showAlert() {
|
||||
activeAlert = ServerDowntimeDefaultService.shared.alertType()
|
||||
showAlert = true
|
||||
} else {
|
||||
self.submit()
|
||||
|
||||
@@ -18,52 +18,148 @@
|
||||
import SwiftUI
|
||||
|
||||
struct MaintenanceView: View {
|
||||
@State var jsonString = ""
|
||||
@State var jsonStringFromServer = ""
|
||||
@State var jsonStringFromUserDefaults = ""
|
||||
@State var isFetching: Bool = false
|
||||
var session: MXSession?
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading) {
|
||||
HStack {
|
||||
Text(jsonString)
|
||||
.font(.caption)
|
||||
.padding()
|
||||
Spacer()
|
||||
}
|
||||
ServerDataView
|
||||
|
||||
Divider()
|
||||
|
||||
UserDefaultDataView
|
||||
}
|
||||
}
|
||||
.navigationTitle(BWIL10n.bwiSettingsDeveloperMaintenance)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.onAppear {
|
||||
Task {
|
||||
await fetchData()
|
||||
await fetchDataFromServer()
|
||||
}
|
||||
fetchDataFromUserDefaults()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private var ServerDataView: some View {
|
||||
return VStack(alignment: .leading) {
|
||||
Text(BWIL10n.bwiSettingsDeveloperMaintenanceServerData)
|
||||
.font(.title3)
|
||||
.padding()
|
||||
|
||||
if isFetching {
|
||||
HStack {
|
||||
Spacer()
|
||||
ProgressView()
|
||||
.progressViewStyle(CircularProgressViewStyle())
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
|
||||
HStack {
|
||||
Text(jsonStringFromServer)
|
||||
.font(.caption)
|
||||
.padding()
|
||||
Spacer()
|
||||
}
|
||||
|
||||
HStack {
|
||||
Spacer()
|
||||
Button {
|
||||
Task {
|
||||
await fetchDataFromServer()
|
||||
}
|
||||
} label: {
|
||||
Text(BWIL10n.bwiSettingsDeveloperMaintenanceReload)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func fetchData() async {
|
||||
guard let restClient = session?.matrixRestClient else {
|
||||
return
|
||||
}
|
||||
|
||||
let responseDict = await withCheckedContinuation { continuation in
|
||||
restClient.getDowntime { jsonResponse, error in
|
||||
continuation.resume(returning: jsonResponse)
|
||||
private var UserDefaultDataView: some View {
|
||||
return VStack(alignment: .leading) {
|
||||
Text(BWIL10n.bwiSettingsDeveloperMaintenanceLocalData)
|
||||
.font(.title3)
|
||||
.padding()
|
||||
HStack {
|
||||
Text(jsonStringFromUserDefaults)
|
||||
.font(.caption)
|
||||
.padding()
|
||||
Spacer()
|
||||
}
|
||||
HStack {
|
||||
Spacer()
|
||||
Button {
|
||||
fetchDataFromUserDefaults()
|
||||
} label: {
|
||||
Text(BWIL10n.bwiSettingsDeveloperMaintenanceReload)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
await MainActor.run {
|
||||
do {
|
||||
if let responseDict = responseDict {
|
||||
let data = try JSONSerialization.data(withJSONObject: responseDict as Any, options: [.prettyPrinted])
|
||||
jsonString = String(data: data, encoding: .utf8) ?? ""
|
||||
}
|
||||
|
||||
|
||||
// MARK: sync functions
|
||||
private func fetchDataFromServer() async {
|
||||
isFetching = true
|
||||
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimesWithDirectRequest(localUrlString: nil) { _, response, data, error in
|
||||
isFetching = false
|
||||
guard let response = response, response.statusCode == 200 else {
|
||||
if let error = error {
|
||||
jsonStringFromServer = error.localizedDescription
|
||||
} else {
|
||||
jsonString = ""
|
||||
jsonStringFromServer = ""
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
do {
|
||||
if let data = data, let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
|
||||
let jsonData = try JSONSerialization.data(withJSONObject: jsonObject as Any, options: [.prettyPrinted])
|
||||
jsonStringFromServer = String(data: jsonData, encoding: .utf8) ?? ""
|
||||
} else {
|
||||
jsonStringFromServer = ""
|
||||
}
|
||||
} catch {
|
||||
jsonString = ""
|
||||
jsonStringFromServer = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func fetchDataFromUserDefaults() {
|
||||
jsonStringFromUserDefaults = ""
|
||||
let encodedDowntimes = UserDefaults.standard.object(forKey: "BWI_ServerDowntimes") as? [Data] ?? [Data]()
|
||||
let encodedValidAppVersions = UserDefaults.standard.data(forKey: "BWI_ValidAppVersions") ?? Data()
|
||||
|
||||
var jsonString = ""
|
||||
|
||||
let serverDowntimes = encodedDowntimes
|
||||
.compactMap { try? JSONDecoder().decode(ServerDowntime.self, from: $0) }
|
||||
|
||||
for serverDowntime in serverDowntimes {
|
||||
do {
|
||||
let data = try JSONEncoder().encode(serverDowntime)
|
||||
let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
|
||||
let newJsonData = try JSONSerialization.data(withJSONObject: jsonObject as Any, options: [.prettyPrinted])
|
||||
jsonString.append(contentsOf: String(data: newJsonData, encoding: .utf8) ?? "")
|
||||
jsonString.append(contentsOf: !jsonString.isEmpty ? ",\n" : "")
|
||||
} catch {}
|
||||
}
|
||||
do {
|
||||
let jsonObjectAppVersion = try JSONSerialization.jsonObject(with: encodedValidAppVersions, options: []) as? [String: Any]
|
||||
let jsonDataAppVersion = try JSONSerialization.data(withJSONObject: jsonObjectAppVersion as Any, options: [.prettyPrinted])
|
||||
jsonString.append(contentsOf: String(data: jsonDataAppVersion, encoding: .utf8) ?? "")
|
||||
} catch {}
|
||||
|
||||
jsonStringFromUserDefaults = jsonString
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
struct MaintenanceView_Previews: PreviewProvider {
|
||||
|
||||
@@ -28,6 +28,7 @@ fileprivate let exampleFile = "exampleDowntime"
|
||||
fileprivate let maintenanceURL = "/_matrix/cmaintenance"
|
||||
|
||||
@objcMembers class ServerDowntimeDefaultService : NSObject {
|
||||
static let shared = ServerDowntimeDefaultService()
|
||||
var isCurrentDowntime: ServerDowntimeStatus = .none
|
||||
|
||||
static var manuallyIgnored: Bool = false
|
||||
@@ -186,16 +187,16 @@ 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: {
|
||||
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.vc_open(URL(string: iTunesLink)!, completionHandler: nil)
|
||||
}))
|
||||
case .showDowntimeTimeAlert:
|
||||
if BWIBuildSettings.shared.ignoreBlockingMaintenance && isBlocking() {
|
||||
return Alert( title: Text(""),
|
||||
message: Text(ServerDowntimeDefaultService().downtimeText()),
|
||||
message: Text(downtimeText()),
|
||||
primaryButton: .cancel(Text(BWIL10n.blockingDowntimeAlertIgnoreButton)) {
|
||||
UserDefaults.standard.set(false, forKey: "ServerDownTimeBlockingKey")
|
||||
self.setManuallyIgnored()
|
||||
@@ -205,8 +206,8 @@ extension ServerDowntimeDefaultService : ServerDowntimeService {
|
||||
)
|
||||
|
||||
} else {
|
||||
return Alert(title: Text(BWIL10n.downtimeTitle),
|
||||
message: Text(ServerDowntimeDefaultService().downtimeText() != "" ? BWIL10n.downtimeDefaultMessage + "\n\n" + ServerDowntimeDefaultService().downtimeText() : BWIL10n.downtimeDefaultMessage),
|
||||
return Alert( title: Text(BWIL10n.downtimeTitle),
|
||||
message: Text(downtimeText() != "" ? BWIL10n.downtimeDefaultMessage + "\n\n" + downtimeText() : BWIL10n.downtimeDefaultMessage),
|
||||
dismissButton: .destructive(Text(isBlocking() ? BWIL10n.blockingDowntimeAlertDismissButton : BWIL10n.downtimeAlertDismissButton)) {
|
||||
if self.isBlocking() {
|
||||
return
|
||||
@@ -218,7 +219,7 @@ extension ServerDowntimeDefaultService : ServerDowntimeService {
|
||||
case .showServerMaintenanceInfoMessageAlert:
|
||||
if BWIBuildSettings.shared.ignoreBlockingMaintenance && isBlocking() {
|
||||
return Alert( title: Text(""),
|
||||
message: Text(ServerDowntimeDefaultService().downtimeText()),
|
||||
message: Text(downtimeText()),
|
||||
primaryButton: .cancel(Text(BWIL10n.blockingDowntimeAlertIgnoreButton)) {
|
||||
completion()
|
||||
},
|
||||
@@ -226,9 +227,9 @@ extension ServerDowntimeDefaultService : ServerDowntimeService {
|
||||
)
|
||||
|
||||
} else {
|
||||
return Alert(title: Text(""),
|
||||
message: Text(ServerDowntimeDefaultService().downtimeText()),
|
||||
dismissButton: .destructive(Text(isBlocking() ? BWIL10n.blockingDowntimeAlertDismissButton : BWIL10n.downtimeAlertDismissButton)) {
|
||||
return Alert( title: Text(""),
|
||||
message: Text(downtimeText()),
|
||||
dismissButton: .destructive(Text(isBlocking() ? BWIL10n.blockingDowntimeAlertDismissButton : BWIL10n.downtimeAlertDismissButton)) {
|
||||
if self.isBlocking() {
|
||||
return
|
||||
} else {
|
||||
@@ -237,9 +238,9 @@ extension ServerDowntimeDefaultService : ServerDowntimeService {
|
||||
})
|
||||
}
|
||||
case .showServerMaintenanceDefaultAlert:
|
||||
return Alert(title: Text(BWIL10n.downtimeTitle),
|
||||
message: Text(BWIL10n.downtimeDefaultMessage),
|
||||
dismissButton: .destructive(Text(BWIL10n.downtimeAlertDismissButton)) {
|
||||
return Alert( title: Text(BWIL10n.downtimeTitle),
|
||||
message: Text(BWIL10n.downtimeDefaultMessage),
|
||||
dismissButton: .destructive(Text(BWIL10n.downtimeAlertDismissButton)) {
|
||||
completion()
|
||||
})
|
||||
}
|
||||
@@ -274,7 +275,7 @@ extension ServerDowntimeDefaultService : ServerDowntimeService {
|
||||
try copyServerDowntimesToUserDefaults(downtimes: downtimes)
|
||||
}
|
||||
|
||||
func fetchDowntimesWithDirectRequest(localUrlString: String? = nil, completion: @escaping (Bool) -> Void) {
|
||||
func fetchDowntimesWithDirectRequest(localUrlString: String? = nil, completion: @escaping (Bool,HTTPURLResponse?,Data?,Error?) -> Void) {
|
||||
var urlString = AppConfigService.shared.serverUrl()
|
||||
|
||||
if let localUrlString = localUrlString {
|
||||
@@ -282,18 +283,18 @@ extension ServerDowntimeDefaultService : ServerDowntimeService {
|
||||
}
|
||||
|
||||
guard let url = URL(string: urlString + maintenanceURL) else {
|
||||
completion(false)
|
||||
completion(false, nil, nil, nil)
|
||||
return
|
||||
}
|
||||
|
||||
let config = URLSessionConfiguration.default
|
||||
config.httpAdditionalHeaders = ["User-Agent": UserAgentService().bwiUserAgent]
|
||||
config.requestCachePolicy = .reloadIgnoringLocalAndRemoteCacheData
|
||||
let session : URLSession = URLSession(configuration: config)
|
||||
session.configuration.requestCachePolicy = .reloadIgnoringLocalAndRemoteCacheData
|
||||
|
||||
let task = session.dataTask(with: url) { data, response, error in
|
||||
guard let response = response as? HTTPURLResponse, response.statusCode == 200 else {
|
||||
completion(false)
|
||||
completion(false, nil, data, error)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -305,7 +306,7 @@ extension ServerDowntimeDefaultService : ServerDowntimeService {
|
||||
print(error.localizedDescription)
|
||||
}
|
||||
|
||||
completion(true)
|
||||
completion(true, response, data, error)
|
||||
}
|
||||
task.resume()
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
import Foundation
|
||||
|
||||
@objcMembers class ValidAppVersionsDefaultService : NSObject {
|
||||
|
||||
static let shared = ValidAppVersionsDefaultService()
|
||||
|
||||
var currentAppVersion: String? {
|
||||
return Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ struct OnboardingBwiSplashScreen: View {
|
||||
|
||||
@Environment(\.theme) private var theme
|
||||
@Environment(\.layoutDirection) private var layoutDirection
|
||||
private let service = ServerDowntimeDefaultService()
|
||||
|
||||
/// The dimensions of the stack with the action buttons and page indicator.
|
||||
@State private var overlayFrame: CGRect = .zero
|
||||
@@ -75,7 +74,7 @@ struct OnboardingBwiSplashScreen: View {
|
||||
.navigationTitle("")
|
||||
.navigationBarHidden(true)
|
||||
.alert(isPresented: $showAlert, content: {
|
||||
service.alert(alertType: activeAlert) {
|
||||
ServerDowntimeDefaultService.shared.alert(alertType: activeAlert) {
|
||||
viewModel.send(viewAction: .login)
|
||||
}
|
||||
})
|
||||
@@ -86,12 +85,12 @@ struct OnboardingBwiSplashScreen: View {
|
||||
isFetchingDowntime = true // show progresview
|
||||
|
||||
if BWIBuildSettings.shared.useTestDataForDowntime {
|
||||
service.fetchDowntimes {
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimes {
|
||||
self.isFetchingDowntime = false // hide progressview
|
||||
self.showAlertIfNeeded()
|
||||
}
|
||||
} else {
|
||||
service.fetchDowntimesWithDirectRequest { success in
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimesWithDirectRequest { success, _, _, _ in
|
||||
DispatchQueue.main.async {
|
||||
self.isFetchingDowntime = false // hide progressview
|
||||
if success {
|
||||
@@ -110,8 +109,8 @@ struct OnboardingBwiSplashScreen: View {
|
||||
|
||||
|
||||
private func showAlertIfNeeded() {
|
||||
if service.showAlert() {
|
||||
activeAlert = service.alertType()
|
||||
if ServerDowntimeDefaultService.shared.showAlert() {
|
||||
activeAlert = ServerDowntimeDefaultService.shared.alertType()
|
||||
showAlert = true
|
||||
} else {
|
||||
viewModel.send(viewAction: .login)
|
||||
|
||||
@@ -36,7 +36,6 @@ fileprivate struct Page: View {
|
||||
|
||||
@State var buttonCallback: (() -> Void)?
|
||||
|
||||
private let service = ServerDowntimeDefaultService()
|
||||
@State private var isFetchingDowntime = false
|
||||
@State private var showAlert = false
|
||||
@State private var activeAlert: ServerMaintenanceAlertType = .showInvalidAppVersionAlert
|
||||
@@ -71,7 +70,7 @@ fileprivate struct Page: View {
|
||||
}
|
||||
.padding(.bottom, 100)
|
||||
.alert(isPresented: $showAlert, content: {
|
||||
service.alert(alertType: activeAlert) {
|
||||
ServerDowntimeDefaultService.shared.alert(alertType: activeAlert) {
|
||||
buttonCallback()
|
||||
}
|
||||
})
|
||||
@@ -92,12 +91,12 @@ fileprivate struct Page: View {
|
||||
isFetchingDowntime = true // show progresview
|
||||
|
||||
if BWIBuildSettings.shared.useTestDataForDowntime {
|
||||
service.fetchDowntimes {
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimes {
|
||||
self.isFetchingDowntime = false // hide progressview
|
||||
self.showAlertIfNeeded()
|
||||
}
|
||||
} else {
|
||||
service.fetchDowntimesWithDirectRequest { success in
|
||||
ServerDowntimeDefaultService.shared.fetchDowntimesWithDirectRequest { success, _, _, _ in
|
||||
DispatchQueue.main.async {
|
||||
self.isFetchingDowntime = false // hide progressview
|
||||
if success {
|
||||
@@ -118,8 +117,8 @@ fileprivate struct Page: View {
|
||||
return
|
||||
}
|
||||
|
||||
if service.showAlert() {
|
||||
activeAlert = service.alertType()
|
||||
if ServerDowntimeDefaultService.shared.showAlert() {
|
||||
activeAlert = ServerDowntimeDefaultService.shared.alertType()
|
||||
showAlert = true
|
||||
} else {
|
||||
buttonCallback()
|
||||
|
||||
Reference in New Issue
Block a user