Skip to content

Commit

Permalink
feat: Add UpdateRequiredView (#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinperignon authored Feb 9, 2024
2 parents 10400d6 + d11e261 commit 1a3be8f
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 23 deletions.
30 changes: 15 additions & 15 deletions .package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/ProxymanApp/atlantis",
"state" : {
"revision" : "131d757cf8e6e368ad338728379174f7cfff9326",
"version" : "1.23.0"
"revision" : "5145a7041ec71421d09653db87dcc80c81792004",
"version" : "1.24.0"
}
},
{
"identity" : "cocoalumberjack",
"kind" : "remoteSourceControl",
"location" : "https://github.com/CocoaLumberjack/CocoaLumberjack",
"state" : {
"revision" : "363ed23d19a931809ea834a7d722da830353806a",
"version" : "3.8.2"
"revision" : "ae8e475260b978299134d42d739f0ec8241d9af0",
"version" : "3.8.3"
}
},
{
Expand Down Expand Up @@ -94,8 +94,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Infomaniak/ios-version-checker",
"state" : {
"revision" : "821a785fd229afae83c0a982d772fe89542ab502",
"version" : "1.0.1"
"revision" : "deeb4fa8377f9bcf3303216d1ea61c1e893b2abd",
"version" : "1.1.0"
}
},
{
Expand Down Expand Up @@ -166,17 +166,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/realm/realm-core.git",
"state" : {
"revision" : "7227d6a447821c28895daa099b6c7cd4c99d461b",
"version" : "13.25.1"
"revision" : "a5e87a39cffdcc591f3203c11cfca68100d0b9a6",
"version" : "13.26.0"
}
},
{
"identity" : "realm-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/realm/realm-swift",
"state" : {
"revision" : "836cc4b8619886f979f8961c3f592a82b0741591",
"version" : "10.45.3"
"revision" : "eafdd3720a8cc750bdd38bf776082d2c8cf743fc",
"version" : "10.46.0"
}
},
{
Expand Down Expand Up @@ -236,10 +236,10 @@
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"location" : "https://github.com/apple/swift-log",
"state" : {
"revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed",
"version" : "1.5.3"
"revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5",
"version" : "1.5.4"
}
},
{
Expand Down Expand Up @@ -301,8 +301,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/markiv/SwiftUI-Shimmer",
"state" : {
"revision" : "1f3a620e4abe890d00008cb2af7023d810b433a7",
"version" : "1.4.0"
"revision" : "5659a623567cefe258d1e3e67cb65585fbb6ecb6",
"version" : "1.4.2"
}
},
{
Expand Down
6 changes: 4 additions & 2 deletions Mail/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ struct RootView: View {
.environmentObject(mainViewState)
case .onboarding:
OnboardingView()
case .authorization:
AuthorizationView()
case .noMailboxes:
NoMailboxView()
case .unavailableMailboxes:
UnavailableMailboxesView()
case .updateRequired:
MailUpdateRequiredView()
case .preloading(let currentAccount):
PreloadingView(currentAccount: currentAccount)
case .authorization:
AuthorizationView()
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions Mail/UserAccountScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import MailResources
import Sentry
import SwiftUI
import UIKit
import VersionChecker

struct UserAccountScene: Scene {
@Environment(\.scenePhase) private var scenePhase
Expand All @@ -37,6 +38,7 @@ struct UserAccountScene: Scene {
@LazyInjectService private var accountManager: AccountManager
@LazyInjectService private var appLaunchCounter: AppLaunchCounter
@LazyInjectService private var refreshAppBackgroundTask: RefreshAppBackgroundTask
@LazyInjectService private var platformDetector: PlatformDetectable

@StateObject private var rootViewState = RootViewState()

Expand All @@ -51,6 +53,7 @@ struct UserAccountScene: Scene {
appLaunchCounter.increase()
refreshCacheData()
rootViewState.transitionToLockViewIfNeeded()
checkAppVersion()
UserDefaults.shared.openingUntilReview -= 1
case .background:
refreshAppBackgroundTask.scheduleForBackgroundLaunchIfNeeded()
Expand Down Expand Up @@ -108,4 +111,25 @@ struct UserAccountScene: Scene {
}
}
}

func checkAppVersion() {
Task {
do {
let platform: Platform = platformDetector.isMacCatalyst ? .macOS : .ios
let versionStatus = try await VersionChecker.standard.checkAppVersionStatus(platform: platform)
switch versionStatus {
case .updateIsRequired:
rootViewState.transitionToRootViewDestination(.updateRequired)
case .canBeUpdated:
if case .mainView(let mainViewState) = rootViewState.state {
mainViewState.isShowingUpdateAvailable = true
}
case .isUpToDate:
break
}
} catch {
DDLogError("Error while checking version status: \(error)")
}
}
}
}
51 changes: 51 additions & 0 deletions Mail/Views/MailUpdateRequiredView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Infomaniak Mail - iOS App
Copyright (C) 2024 Infomaniak Network SA
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import MailCore
import MailResources
import SwiftUI
import VersionChecker

struct MailUpdateRequiredView: View {
@Environment(\.openURL) private var openURL

private let sharedStyle = TemplateSharedStyle(
background: MailResourcesAsset.backgroundColor.swiftUIColor,
titleTextStyle: .init(font: MailTextStyle.header2.font, color: MailTextStyle.header2.color),
descriptionTextStyle: .init(font: MailTextStyle.bodySecondary.font, color: MailTextStyle.bodySecondary.color),
buttonStyle: .init(
background: .accentColor,
textStyle: .init(font: MailTextStyle.bodyAccent.font, color: UserDefaults.shared.accentColor.onAccent.swiftUIColor),
height: UIConstants.buttonLargeHeight,
radius: UIConstants.buttonsRadius
)
)

var body: some View {
UpdateRequiredView(image: MailResourcesAsset.updateRequired.swiftUIImage, sharedStyle: sharedStyle, handler: updateApp)
}

private func updateApp() {
let url: URLConstants = Bundle.main.isRunningInTestFlight ? .testFlight : .appStore
openURL(url.url)
}
}

#Preview {
MailUpdateRequiredView()
}
7 changes: 2 additions & 5 deletions Mail/Views/SplitView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import MailResources
import NavigationBackport
import RealmSwift
import SwiftUI
import VersionChecker
@_spi(Advanced) import SwiftUIIntrospect

public class SplitViewManager: ObservableObject {
Expand Down Expand Up @@ -64,7 +63,6 @@ struct SplitView: View {
@LazyInjectService private var platformDetector: PlatformDetectable
@LazyInjectService private var appLaunchCounter: AppLaunchCounter

@State private var isShowingUpdateAvailable = false
@State private var isShowingSyncDiscovery = false
@State private var isShowingSyncProfile = false

Expand Down Expand Up @@ -120,7 +118,7 @@ struct SplitView: View {
}
}
}
.discoveryPresenter(isPresented: $isShowingUpdateAvailable) {
.discoveryPresenter(isPresented: $mainViewState.isShowingUpdateAvailable) {
DiscoveryView(item: .updateDiscovery) { willUpdate in
guard willUpdate else { return }
let url: URLConstants = Bundle.main.isRunningInTestFlight ? .testFlight : .appStore
Expand Down Expand Up @@ -166,8 +164,7 @@ struct SplitView: View {
}
guard !platformDetector.isDebug else { return }
// We don't want to show both DiscoveryView at the same time
isShowingUpdateAvailable = try await VersionChecker.standard.showUpdateVersion()
isShowingSyncDiscovery = isShowingUpdateAvailable ? false : showSync()
isShowingSyncDiscovery = mainViewState.isShowingUpdateAvailable ? false : showSync()
}
}
.onOpenURL { url in
Expand Down
1 change: 1 addition & 0 deletions MailCore/Cache/MainViewState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class MainViewState: ObservableObject, SelectedThreadOwnable {

@Published public var isShowingSearch = false
@Published public var isShowingReviewAlert = false
@Published public var isShowingUpdateAvailable = false
@Published public var isShowingSetAppAsDefaultDiscovery = false
@Published public var isShowingChristmasEasterEgg = false

Expand Down
6 changes: 6 additions & 0 deletions MailCore/Cache/RootViewState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public enum RootViewType: Equatable {
return true
case (.unavailableMailboxes, .unavailableMailboxes):
return true
case (.updateRequired, .updateRequired):
return true
case (.mainView(let lhsMainViewState), .mainView(let rhsMainViewState)):
return lhsMainViewState.mailboxManager == rhsMainViewState.mailboxManager
case (.preloading(let lhsAccount), .preloading(let rhsAccount)):
Expand All @@ -52,6 +54,7 @@ public enum RootViewType: Equatable {
case authorization
case noMailboxes
case unavailableMailboxes
case updateRequired
case preloading(Account)
}

Expand All @@ -61,6 +64,7 @@ public enum RootViewDestination {
case onboarding
case noMailboxes
case unavailableMailboxes
case updateRequired
}

/// Something that represents the state of the root view
Expand Down Expand Up @@ -127,6 +131,8 @@ public class RootViewState: ObservableObject {
state = .noMailboxes
case .unavailableMailboxes:
state = .unavailableMailboxes
case .updateRequired:
state = .updateRequired
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"images" : [
{
"filename" : "update-required-light.svg",
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "update-required-dark.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1a3be8f

Please sign in to comment.