Skip to content

Commit

Permalink
Display migration progress during startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Anderas committed Jan 18, 2023
1 parent f098e77 commit 9480bb7
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 18 deletions.
1 change: 1 addition & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,7 @@ Tap the + to start adding people.";

// MARK: - Launch loading

"launch_loading_migrating_data" = "Migrating data\n%@ %%";
"launch_loading_server_syncing" = "Syncing with the server";
"launch_loading_server_syncing_nth_attempt" = "Syncing with the server\n(%@ attempt)";
"launch_loading_processing_response" = "Processing data\n%@ %%";
Expand Down
4 changes: 4 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3179,6 +3179,10 @@ public class VectorL10n: NSObject {
public static var later: String {
return VectorL10n.tr("Vector", "later")
}
/// Migrating data\n%@ %%
public static func launchLoadingMigratingData(_ p1: String) -> String {
return VectorL10n.tr("Vector", "launch_loading_migrating_data", p1)
}
/// Processing data\n%@ %%
public static func launchLoadingProcessingResponse(_ p1: String) -> String {
return VectorL10n.tr("Vector", "launch_loading_processing_response", p1)
Expand Down
6 changes: 3 additions & 3 deletions Riot/Modules/Application/LegacyAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -2395,14 +2395,14 @@ - (void)showLaunchAnimation
MXLogDebug(@"[AppDelegate] showLaunchAnimation");

LaunchLoadingView *launchLoadingView;
if (MXSDKOptions.sharedInstance.enableSyncProgress)
if (MXSDKOptions.sharedInstance.enableStartupProgress)
{
MXSession *mainSession = self.mxSessions.firstObject;
launchLoadingView = [LaunchLoadingView instantiateWithSyncProgress:mainSession.syncProgress];
launchLoadingView = [LaunchLoadingView instantiateWithStartupProgress:mainSession.startupProgress];
}
else
{
launchLoadingView = [LaunchLoadingView instantiateWithSyncProgress:nil];
launchLoadingView = [LaunchLoadingView instantiateWithStartupProgress:nil];
}

launchLoadingView.frame = window.bounds;
Expand Down
4 changes: 2 additions & 2 deletions Riot/Modules/Authentication/AuthenticationCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,8 @@ final class AuthenticationCoordinator: NSObject, AuthenticationCoordinatorProtoc

/// Replace the contents of the navigation router with a loading animation.
private func showLoadingAnimation() {
let syncProgress: MXSessionSyncProgress? = MXSDKOptions.sharedInstance().enableSyncProgress ? session?.syncProgress : nil
let loadingViewController = LaunchLoadingViewController(syncProgress: syncProgress)
let startupProgress: MXSessionStartupProgress? = MXSDKOptions.sharedInstance().enableStartupProgress ? session?.startupProgress : nil
let loadingViewController = LaunchLoadingViewController(startupProgress: startupProgress)
loadingViewController.modalPresentationStyle = .fullScreen

// Replace the navigation stack with the loading animation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ final class LegacyAuthenticationCoordinator: NSObject, AuthenticationCoordinator
// MARK: - Private

private func showLoadingAnimation() {
let syncProgress: MXSessionSyncProgress? = MXSDKOptions.sharedInstance().enableSyncProgress ? session?.syncProgress : nil
let loadingViewController = LaunchLoadingViewController(syncProgress: syncProgress)
let startupProgress: MXSessionStartupProgress? = MXSDKOptions.sharedInstance().enableStartupProgress ? session?.startupProgress : nil
let loadingViewController = LaunchLoadingViewController(startupProgress: startupProgress)
loadingViewController.modalPresentationStyle = .fullScreen

// Replace the navigation stack with the loading animation
Expand Down
32 changes: 23 additions & 9 deletions Riot/Modules/LaunchLoading/LaunchLoadingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ final class LaunchLoadingView: UIView, NibLoadable, Themable {

// MARK: - Setup

static func instantiate(syncProgress: MXSessionSyncProgress?) -> LaunchLoadingView {
static func instantiate(startupProgress: MXSessionStartupProgress?) -> LaunchLoadingView {
let view = LaunchLoadingView.loadFromNib()
syncProgress?.delegate = view
startupProgress?.delegate = view
return view
}

Expand All @@ -54,7 +54,7 @@ final class LaunchLoadingView: UIView, NibLoadable, Themable {
animationTimeline.play()
self.animationTimeline = animationTimeline

self.statusLabel.isHidden = !MXSDKOptions.sharedInstance().enableSyncProgress
self.statusLabel.isHidden = !MXSDKOptions.sharedInstance().enableStartupProgress
}

// MARK: - Public
Expand All @@ -65,21 +65,35 @@ final class LaunchLoadingView: UIView, NibLoadable, Themable {
}
}

extension LaunchLoadingView: MXSessionSyncProgressDelegate {
func sessionDidUpdateSyncState(_ state: MXSessionSyncState) {
guard MXSDKOptions.sharedInstance().enableSyncProgress else {
extension LaunchLoadingView: MXSessionStartupProgressDelegate {
func sessionDidUpdateStartupStage(_ stage: MXSessionStartupStage) {
guard MXSDKOptions.sharedInstance().enableStartupProgress else {
return
}
updateStatusText(for: stage)

}

private func updateStatusText(for stage: MXSessionStartupStage) {
guard Thread.isMainThread else {
DispatchQueue.main.async { [weak self] in
self?.updateStatusText(for: stage)
}
return
}

// Sync may be doing a lot of heavy work on the main thread and the status text
// does not update reliably enough without explicitly refreshing
CATransaction.begin()
statusLabel.text = statusText(for: state)
statusLabel.text = statusText(for: stage)
CATransaction.commit()
}

private func statusText(for state: MXSessionSyncState) -> String {
switch state {
private func statusText(for stage: MXSessionStartupStage) -> String {
switch stage {
case .migratingData(let progress):
let percent = Int(floor(progress * 100))
return VectorL10n.launchLoadingMigratingData("\(percent)")
case .serverSyncing(let attempts):
if attempts > 1, let nth = numberFormatter.string(from: NSNumber(value: attempts)) {
return VectorL10n.launchLoadingServerSyncingNthAttempt(nth)
Expand Down
4 changes: 2 additions & 2 deletions Riot/Modules/LaunchLoading/LaunchLoadingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class LaunchLoadingViewController: UIViewController, Reusable {

required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }

init(syncProgress: MXSessionSyncProgress?) {
init(startupProgress: MXSessionStartupProgress?) {
super.init(nibName: "LaunchLoadingViewController", bundle: nil)

let launchLoadingView = LaunchLoadingView.instantiate(syncProgress: syncProgress)
let launchLoadingView = LaunchLoadingView.instantiate(startupProgress: startupProgress)
launchLoadingView.update(theme: ThemeService.shared().theme)
view.vc_addSubViewMatchingParent(launchLoadingView)

Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-7286.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CryptoV2: Display migration progress during startup

0 comments on commit 9480bb7

Please sign in to comment.