mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-17 23:18:27 +02:00
Feature/3811 appconfig
This commit is contained in:
@@ -678,4 +678,7 @@ class BWIBuildSettings: NSObject {
|
|||||||
|
|
||||||
// MARK: Create Room Menu
|
// MARK: Create Room Menu
|
||||||
var enableAllChatsToolbar = true
|
var enableAllChatsToolbar = true
|
||||||
|
|
||||||
|
// MARK: App Config
|
||||||
|
var avoidServerSelectionOnAppConfig = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,6 @@ extension BWIBuildSettings {
|
|||||||
enableAllChatsToolbar = false
|
enableAllChatsToolbar = false
|
||||||
|
|
||||||
itunesAppLink = "itms://itunes.apple.com/app/bundesmessenger-beta/id1617068656?mt=8"
|
itunesAppLink = "itms://itunes.apple.com/app/bundesmessenger-beta/id1617068656?mt=8"
|
||||||
|
avoidServerSelectionOnAppConfig = true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ extension BWIBuildSettings {
|
|||||||
bwiEnableLoginProtection = false
|
bwiEnableLoginProtection = false
|
||||||
|
|
||||||
itunesAppLink = "itms://itunes.apple.com/app/bundesmessenger-open/id6450672686?mt=8"
|
itunesAppLink = "itms://itunes.apple.com/app/bundesmessenger-open/id6450672686?mt=8"
|
||||||
|
avoidServerSelectionOnAppConfig = true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ extension BWIBuildSettings {
|
|||||||
bwiNotificationTimes = true
|
bwiNotificationTimes = true
|
||||||
enableNewSessionManagerByDefault = true
|
enableNewSessionManagerByDefault = true
|
||||||
itunesAppLink = "itms://itunes.apple.com/app/bundesmessenger/id1616866351?mt=8"
|
itunesAppLink = "itms://itunes.apple.com/app/bundesmessenger/id1616866351?mt=8"
|
||||||
|
avoidServerSelectionOnAppConfig = true
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,7 +144,12 @@ final class AuthenticationCoordinator: NSObject, AuthenticationCoordinatorProtoc
|
|||||||
// bwi: force serverselection on test apps
|
// bwi: force serverselection on test apps
|
||||||
if (BWIBuildSettings.shared.authScreenShowTestServerOptions && BWIBuildSettings.shared.bwiLoginFlowLayout) ||
|
if (BWIBuildSettings.shared.authScreenShowTestServerOptions && BWIBuildSettings.shared.bwiLoginFlowLayout) ||
|
||||||
BWIBuildSettings.shared.bumLoginFlowLayout {
|
BWIBuildSettings.shared.bumLoginFlowLayout {
|
||||||
showServerSelectionScreen(for: flow)
|
// bwi #3811: when there is a valid url from app config don't show server selection
|
||||||
|
if BWIBuildSettings.shared.avoidServerSelectionOnAppConfig && AppConfigService.shared.isAppConfig {
|
||||||
|
self.useHomeserver(AppConfigService.shared.serverUrl())
|
||||||
|
} else {
|
||||||
|
showServerSelectionScreen(for: flow)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
do {
|
do {
|
||||||
// Start the flow using the default server (or a provisioning link if set).
|
// Start the flow using the default server (or a provisioning link if set).
|
||||||
@@ -267,6 +272,21 @@ final class AuthenticationCoordinator: NSObject, AuthenticationCoordinatorProtoc
|
|||||||
callback?(.cancel(.register))
|
callback?(.cancel(.register))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Updates the login flow using the supplied homeserver address, or shows an error when this isn't possible.
|
||||||
|
@MainActor private func useHomeserver(_ homeserverAddress: String) {
|
||||||
|
|
||||||
|
let homeserverAddress = HomeserverAddress.sanitized(homeserverAddress)
|
||||||
|
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
try await authenticationService.startFlow(.login, for: homeserverAddress)
|
||||||
|
showLoginScreen()
|
||||||
|
} catch {
|
||||||
|
displayError(message: error.localizedDescription)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Login
|
// MARK: - Login
|
||||||
|
|
||||||
/// Shows the login screen.
|
/// Shows the login screen.
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ final class OnboardingCoordinator: NSObject, OnboardingCoordinatorProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func showWelcomeExperience() {
|
private func showWelcomeExperience() {
|
||||||
let welcomeVC = WelcomeExperienceViewController.makeViewController(completion: { [weak self] in
|
let welcomeVC = WelcomeExperienceViewController.makeViewController(completion: { [weak self] in
|
||||||
if BWIBuildSettings.shared.onboardingEnableNewAuthenticationFlow {
|
if BWIBuildSettings.shared.onboardingEnableNewAuthenticationFlow {
|
||||||
self?.startLoading()
|
self?.startLoading()
|
||||||
self?.beginAuthentication(with: .login) { [weak self] in
|
self?.beginAuthentication(with: .login) { [weak self] in
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ targets:
|
|||||||
- path: ../Config/BWIBuildSettings.swift
|
- path: ../Config/BWIBuildSettings.swift
|
||||||
- path: ../Config/BuM/BWIBuildSettings+BuM.swift
|
- path: ../Config/BuM/BWIBuildSettings+BuM.swift
|
||||||
- path: ../bwi/UserAgent/UserAgentService.swift
|
- path: ../bwi/UserAgent/UserAgentService.swift
|
||||||
|
- path: ../bwi/LoginProtection/LoginProtectionService.swift
|
||||||
- path: ../Riot/Utils/DataProtectionHelper.swift
|
- path: ../Riot/Utils/DataProtectionHelper.swift
|
||||||
- path: ../Config/CommonConfiguration.swift
|
- path: ../Config/CommonConfiguration.swift
|
||||||
- path: ../Riot/Experiments/
|
- path: ../Riot/Experiments/
|
||||||
|
|||||||
@@ -17,10 +17,6 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
import AVKit
|
import AVKit
|
||||||
|
|
||||||
enum AuthenticationServerSelectionScreenAlertType {
|
|
||||||
case showServerMaintenanceInfoMessageAlert, showServerMaintenanceDefaultAlert, showInvalidAppVersionAlert, showDowntimeTimeAlert, showInvalidServerAlert
|
|
||||||
}
|
|
||||||
|
|
||||||
struct AuthenticationServerSelectionScreen: View {
|
struct AuthenticationServerSelectionScreen: View {
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
|
|
||||||
@@ -39,7 +35,8 @@ struct AuthenticationServerSelectionScreen: View {
|
|||||||
// bwi #4976 show maintenance alert
|
// bwi #4976 show maintenance alert
|
||||||
@State private var isFetchingDowntime = false
|
@State private var isFetchingDowntime = false
|
||||||
@State private var showAlert = false
|
@State private var showAlert = false
|
||||||
@State private var activeAlert: AuthenticationServerSelectionScreenAlertType = .showInvalidAppVersionAlert
|
@State private var isInvalidServerAlert = false
|
||||||
|
@State private var activeAlert: ServerMaintenanceAlertType = .showInvalidAppVersionAlert
|
||||||
|
|
||||||
private var textFieldFooterColor: Color {
|
private var textFieldFooterColor: Color {
|
||||||
viewModel.viewState.hasValidationError ? theme.colors.alert : theme.colors.tertiaryContent
|
viewModel.viewState.hasValidationError ? theme.colors.alert : theme.colors.tertiaryContent
|
||||||
@@ -98,67 +95,12 @@ struct AuthenticationServerSelectionScreen: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.alert(isPresented: $showAlert, content: {
|
.alert(isPresented: $showAlert, content: {
|
||||||
switch activeAlert {
|
if isInvalidServerAlert {
|
||||||
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 && service.isBlocking() {
|
|
||||||
return Alert( title: Text(""),
|
|
||||||
message: Text(ServerDowntimeDefaultService().downtimeText()),
|
|
||||||
primaryButton: .cancel(Text(BWIL10n.blockingDowntimeAlertIgnoreButton)) {
|
|
||||||
UserDefaults.standard.set(false, forKey: "ServerDownTimeBlockingKey")
|
|
||||||
service.setManuallyIgnored()
|
|
||||||
self.submit()
|
|
||||||
},
|
|
||||||
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(service.isBlocking() ? BWIL10n.blockingDowntimeAlertDismissButton : BWIL10n.downtimeAlertDismissButton)) {
|
|
||||||
if service.isBlocking() {
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
self.submit()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
case .showServerMaintenanceInfoMessageAlert:
|
|
||||||
if BWIBuildSettings.shared.ignoreBlockingMaintenance && service.isBlocking() {
|
|
||||||
return Alert( title: Text(""),
|
|
||||||
message: Text(ServerDowntimeDefaultService().downtimeText()),
|
|
||||||
primaryButton: .cancel(Text(BWIL10n.blockingDowntimeAlertIgnoreButton)) {
|
|
||||||
self.submit()
|
|
||||||
},
|
|
||||||
secondaryButton: .destructive(Text(BWIL10n.blockingDowntimeAlertDismissButton))
|
|
||||||
)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return Alert(title: Text(""),
|
|
||||||
message: Text(ServerDowntimeDefaultService().downtimeText()),
|
|
||||||
dismissButton: .destructive(Text(service.isBlocking() ? BWIL10n.blockingDowntimeAlertDismissButton : BWIL10n.downtimeAlertDismissButton)) {
|
|
||||||
if service.isBlocking() {
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
self.submit()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
case .showServerMaintenanceDefaultAlert:
|
|
||||||
return Alert(title: Text(BWIL10n.downtimeTitle),
|
|
||||||
message: Text(BWIL10n.downtimeDefaultMessage),
|
|
||||||
dismissButton: .destructive(Text(BWIL10n.downtimeAlertDismissButton)) {
|
|
||||||
self.submit()
|
|
||||||
})
|
|
||||||
case .showInvalidServerAlert:
|
|
||||||
return self.invalidServerAlert()
|
return self.invalidServerAlert()
|
||||||
|
} else {
|
||||||
|
return service.alert(alertType: activeAlert) {
|
||||||
|
self.submit()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -274,7 +216,7 @@ struct AuthenticationServerSelectionScreen: View {
|
|||||||
if isHomeserverAddressValid(viewModel.homeserverAddress) {
|
if isHomeserverAddressValid(viewModel.homeserverAddress) {
|
||||||
viewModel.send(viewAction: .confirm)
|
viewModel.send(viewAction: .confirm)
|
||||||
} else {
|
} else {
|
||||||
activeAlert = .showInvalidServerAlert
|
isInvalidServerAlert = true
|
||||||
showAlert = true
|
showAlert = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -362,18 +304,11 @@ struct AuthenticationServerSelectionScreen: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func showAlertIfNeeded() {
|
private func showAlertIfNeeded() {
|
||||||
switch service.nextDowntimeStatus() {
|
if service.showAlert() {
|
||||||
case .none, .warning:
|
activeAlert = service.alertType()
|
||||||
self.submit()
|
|
||||||
break
|
|
||||||
case .ongoing:
|
|
||||||
if service.downtimeType() == .adhocMessage {
|
|
||||||
activeAlert = .showServerMaintenanceInfoMessageAlert
|
|
||||||
} else {
|
|
||||||
activeAlert = .showDowntimeTimeAlert
|
|
||||||
}
|
|
||||||
showAlert = true
|
showAlert = true
|
||||||
break
|
} else {
|
||||||
|
self.submit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ extension UserDefaults
|
|||||||
@objcMembers class AppConfigService : NSObject {
|
@objcMembers class AppConfigService : NSObject {
|
||||||
static let shared = AppConfigService()
|
static let shared = AppConfigService()
|
||||||
|
|
||||||
private let serverUrlKey = "serverUrl"
|
private let serverUrlKey = "home_server_url"
|
||||||
private let contentScannerKey = "contentScanner"
|
private let contentScannerKey = "contentScanner"
|
||||||
private let pusherUrlKey = "pusherUrl"
|
private let pusherUrlKey = "pusherUrl"
|
||||||
private let permalinkUrlKey = "permalinkUrl"
|
private let permalinkUrlKey = "permalinkUrl"
|
||||||
@@ -50,10 +50,14 @@ extension UserDefaults
|
|||||||
|
|
||||||
var session: MXSession?
|
var session: MXSession?
|
||||||
|
|
||||||
|
var isAppConfig: Bool
|
||||||
|
|
||||||
private func loadAppConfig() {
|
private func loadAppConfig() {
|
||||||
|
isAppConfig = false
|
||||||
do {
|
do {
|
||||||
if let dataIn = UserDefaults.standard.value(forKey: savedConfig) as? Data {
|
if let dataIn = UserDefaults.standard.value(forKey: savedConfig) as? Data {
|
||||||
appConfig = try JSONDecoder().decode(AppConfig.self, from: dataIn)
|
appConfig = try JSONDecoder().decode(AppConfig.self, from: dataIn)
|
||||||
|
isAppConfig = true
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|
||||||
@@ -70,17 +74,18 @@ extension UserDefaults
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func checkUrlSavety(_ serverUrl: String) -> Bool {
|
private func checkUrlSavety(_ serverUrl: String) -> Bool {
|
||||||
if serverUrl.hasSuffix("bwi.de")
|
if BWIBuildSettings.shared.bwiEnableLoginProtection {
|
||||||
|| serverUrl.hasSuffix("example.com")
|
let protectionService = LoginProtectionService()
|
||||||
|| serverUrl.hasSuffix("example.com")
|
protectionService.hashes = BWIBuildSettings.shared.bwiHashes
|
||||||
|| serverUrl.hasSuffix("example.com") {
|
|
||||||
return true
|
return protectionService.isValid(serverUrl)
|
||||||
} else {
|
} else {
|
||||||
return false
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
|
isAppConfig = false
|
||||||
super.init()
|
super.init()
|
||||||
self.loadAppConfig()
|
self.loadAppConfig()
|
||||||
}
|
}
|
||||||
@@ -93,12 +98,13 @@ extension UserDefaults
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleAppConfig() {
|
func handleAppConfig() {
|
||||||
|
|
||||||
if let dict = UserDefaults.standard.dictionary(forKey: configKey) {
|
if let dict = UserDefaults.standard.dictionary(forKey: configKey) {
|
||||||
var config = AppConfig()
|
var config = AppConfig()
|
||||||
|
|
||||||
if let serverUrl = dict[serverUrlKey] as? String {
|
if let serverUrl = dict[serverUrlKey] as? String {
|
||||||
if checkUrlSavety(serverUrl) {
|
if serverUrl.count == 0 {
|
||||||
|
config.serverUrl = nil
|
||||||
|
} else if checkUrlSavety(serverUrl) {
|
||||||
config.serverUrl = 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 {
|
if config != appConfig {
|
||||||
appConfig = config
|
appConfig = config
|
||||||
self.saveAppConfig()
|
self.saveAppConfig()
|
||||||
@@ -125,6 +134,8 @@ extension UserDefaults
|
|||||||
completion(true)
|
completion(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UserDefaults.standard.removeObject(forKey: configKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
enum ServerDowntimeStatus {
|
enum ServerDowntimeStatus {
|
||||||
case none
|
case none
|
||||||
@@ -23,6 +24,10 @@ enum ServerDowntimeStatus {
|
|||||||
case ongoing
|
case ongoing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum ServerMaintenanceAlertType {
|
||||||
|
case showServerMaintenanceInfoMessageAlert, showServerMaintenanceDefaultAlert, showInvalidAppVersionAlert, showDowntimeTimeAlert
|
||||||
|
}
|
||||||
|
|
||||||
enum ServerDowntimeType: String {
|
enum ServerDowntimeType: String {
|
||||||
case adhocMessage = "ADHOC_MESSAGE"
|
case adhocMessage = "ADHOC_MESSAGE"
|
||||||
case maintenance = "MAINTENANCE"
|
case maintenance = "MAINTENANCE"
|
||||||
@@ -38,4 +43,7 @@ protocol ServerDowntimeService {
|
|||||||
func isBlocking() -> Bool
|
func isBlocking() -> Bool
|
||||||
func setManuallyIgnored()
|
func setManuallyIgnored()
|
||||||
func isManuallyIgnored() -> Bool
|
func isManuallyIgnored() -> Bool
|
||||||
|
func alert( alertType:ServerMaintenanceAlertType, completion: @escaping () -> Void) -> Alert
|
||||||
|
func showAlert() -> Bool
|
||||||
|
func alertType() -> ServerMaintenanceAlertType
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
import MatrixSDK
|
import MatrixSDK
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
|
||||||
fileprivate let BWI_ServerDowntimes = "BWI_ServerDowntimes"
|
fileprivate let BWI_ServerDowntimes = "BWI_ServerDowntimes"
|
||||||
@@ -150,6 +151,80 @@ fileprivate let maintenanceURL = "/_matrix/cmaintenance"
|
|||||||
|
|
||||||
extension ServerDowntimeDefaultService : ServerDowntimeService {
|
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) {
|
func fetchDowntimes(session: MXSession, completion: @escaping () -> Void) {
|
||||||
session.matrixRestClient.getDowntime(completion: { (jsonResponse, error) in
|
session.matrixRestClient.getDowntime(completion: { (jsonResponse, error) in
|
||||||
do {
|
do {
|
||||||
|
|||||||
@@ -16,10 +16,6 @@
|
|||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
enum OnBoardingSplashScreenAlertType {
|
|
||||||
case showServerMaintenanceInfoMessageAlert, showServerMaintenanceDefaultAlert, showInvalidAppVersionAlert, showDowntimeTimeAlert
|
|
||||||
}
|
|
||||||
|
|
||||||
@available(iOS 14.0, *)
|
@available(iOS 14.0, *)
|
||||||
/// The splash screen shown at the beginning of the onboarding flow.
|
/// The splash screen shown at the beginning of the onboarding flow.
|
||||||
struct OnboardingBwiSplashScreen: View {
|
struct OnboardingBwiSplashScreen: View {
|
||||||
@@ -36,7 +32,7 @@ struct OnboardingBwiSplashScreen: View {
|
|||||||
@State private var overlayFrame: CGRect = .zero
|
@State private var overlayFrame: CGRect = .zero
|
||||||
@State private var isFetchingDowntime = false
|
@State private var isFetchingDowntime = false
|
||||||
@State private var showAlert = false
|
@State private var showAlert = false
|
||||||
@State private var activeAlert: OnBoardingSplashScreenAlertType = .showInvalidAppVersionAlert
|
@State private var activeAlert: ServerMaintenanceAlertType = .showInvalidAppVersionAlert
|
||||||
|
|
||||||
// MARK: Public
|
// MARK: Public
|
||||||
|
|
||||||
@@ -79,40 +75,8 @@ struct OnboardingBwiSplashScreen: View {
|
|||||||
.navigationTitle("")
|
.navigationTitle("")
|
||||||
.navigationBarHidden(true)
|
.navigationBarHidden(true)
|
||||||
.alert(isPresented: $showAlert, content: {
|
.alert(isPresented: $showAlert, content: {
|
||||||
switch activeAlert {
|
service.alert(alertType: activeAlert) {
|
||||||
case .showInvalidAppVersionAlert:
|
viewModel.send(viewAction: .login)
|
||||||
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:
|
|
||||||
return Alert(title: Text(BWIL10n.downtimeTitle),
|
|
||||||
message: Text(ServerDowntimeDefaultService().downtimeText() != "" ? BWIL10n.downtimeDefaultMessage + "\n\n" + ServerDowntimeDefaultService().downtimeText() : BWIL10n.downtimeDefaultMessage),
|
|
||||||
dismissButton: .destructive(Text(service.isBlocking() ? BWIL10n.blockingDowntimeAlertDismissButton : BWIL10n.downtimeAlertDismissButton)) {
|
|
||||||
if service.isBlocking() {
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
viewModel.send(viewAction: .login)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
case .showServerMaintenanceInfoMessageAlert:
|
|
||||||
return Alert(title: Text(""),
|
|
||||||
message: Text(ServerDowntimeDefaultService().downtimeText()),
|
|
||||||
dismissButton: .destructive(Text(service.isBlocking() ? BWIL10n.blockingDowntimeAlertDismissButton : BWIL10n.downtimeAlertDismissButton)) {
|
|
||||||
if service.isBlocking() {
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
viewModel.send(viewAction: .login)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
case .showServerMaintenanceDefaultAlert:
|
|
||||||
return Alert(title: Text(BWIL10n.downtimeTitle),
|
|
||||||
message: Text(BWIL10n.downtimeDefaultMessage),
|
|
||||||
dismissButton: .destructive(Text(BWIL10n.downtimeAlertDismissButton)) {
|
|
||||||
viewModel.send(viewAction: .login)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -146,24 +110,11 @@ struct OnboardingBwiSplashScreen: View {
|
|||||||
|
|
||||||
|
|
||||||
private func showAlertIfNeeded() {
|
private func showAlertIfNeeded() {
|
||||||
switch service.nextDowntimeStatus() {
|
if service.showAlert() {
|
||||||
case .none:
|
activeAlert = service.alertType()
|
||||||
viewModel.send(viewAction: .login)
|
|
||||||
break
|
|
||||||
case .ongoing:
|
|
||||||
if service.downtimeType() == .adhocMessage {
|
|
||||||
activeAlert = .showServerMaintenanceInfoMessageAlert
|
|
||||||
} else {
|
|
||||||
activeAlert = .showDowntimeTimeAlert
|
|
||||||
}
|
|
||||||
showAlert = true
|
showAlert = true
|
||||||
break
|
} else {
|
||||||
case .warning:
|
|
||||||
// only show active downtimes
|
|
||||||
viewModel.send(viewAction: .login)
|
viewModel.send(viewAction: .login)
|
||||||
// showAlert = true
|
|
||||||
// activeAlert = .showServerMaintenanceAlert
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ fileprivate struct Page: View {
|
|||||||
|
|
||||||
@State var buttonCallback: (() -> Void)?
|
@State var buttonCallback: (() -> Void)?
|
||||||
|
|
||||||
|
private let service = ServerDowntimeDefaultService()
|
||||||
|
@State private var isFetchingDowntime = false
|
||||||
|
@State private var showAlert = false
|
||||||
|
@State private var activeAlert: ServerMaintenanceAlertType = .showInvalidAppVersionAlert
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
GeometryReader { geometry in
|
GeometryReader { geometry in
|
||||||
VStack(alignment: .center, spacing: 40) {
|
VStack(alignment: .center, spacing: 40) {
|
||||||
@@ -54,8 +59,9 @@ fileprivate struct Page: View {
|
|||||||
.multilineTextAlignment(.center)
|
.multilineTextAlignment(.center)
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
|
// bwi #3811: check for maintenance when the server selection is skipped
|
||||||
if let doneButton = doneButton, let buttonCallback = buttonCallback {
|
if let doneButton = doneButton, let buttonCallback = buttonCallback {
|
||||||
Button(action: buttonCallback) {
|
Button(action: startButtonAction) {
|
||||||
Text(doneButton)
|
Text(doneButton)
|
||||||
.foregroundColor(.white)
|
.foregroundColor(.white)
|
||||||
.padding(.vertical, 10)
|
.padding(.vertical, 10)
|
||||||
@@ -64,6 +70,11 @@ fileprivate struct Page: View {
|
|||||||
.clipShape(RoundedRectangle(cornerRadius: 10))
|
.clipShape(RoundedRectangle(cornerRadius: 10))
|
||||||
}
|
}
|
||||||
.padding(.bottom, 100)
|
.padding(.bottom, 100)
|
||||||
|
.alert(isPresented: $showAlert, content: {
|
||||||
|
service.alert(alertType: activeAlert) {
|
||||||
|
buttonCallback()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(.top, 100)
|
.padding(.top, 100)
|
||||||
@@ -71,6 +82,49 @@ fileprivate struct Page: View {
|
|||||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func startButtonAction() {
|
||||||
|
guard let buttonCallback = buttonCallback else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if BWIBuildSettings.shared.enableMaintenanceInfoOnLogin && BWIBuildSettings.shared.avoidServerSelectionOnAppConfig && AppConfigService.shared.isAppConfig {
|
||||||
|
isFetchingDowntime = true // show progresview
|
||||||
|
|
||||||
|
if BWIBuildSettings.shared.useTestDataForDowntime {
|
||||||
|
service.fetchDowntimes {
|
||||||
|
self.isFetchingDowntime = false // hide progressview
|
||||||
|
self.showAlertIfNeeded()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
service.fetchDowntimesWithDirectRequest { success in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.isFetchingDowntime = false // hide progressview
|
||||||
|
if success {
|
||||||
|
self.showAlertIfNeeded()
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
buttonCallback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func showAlertIfNeeded() {
|
||||||
|
guard let buttonCallback = buttonCallback else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if service.showAlert() {
|
||||||
|
activeAlert = service.alertType()
|
||||||
|
showAlert = true
|
||||||
|
} else {
|
||||||
|
buttonCallback()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct WelcomeExperienceView_Previews: PreviewProvider {
|
struct WelcomeExperienceView_Previews: PreviewProvider {
|
||||||
|
|||||||
Reference in New Issue
Block a user