Skip to content

Commit

Permalink
Refactor updateViews function to improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBrest committed Jan 9, 2024
1 parent 37bcdec commit 4cb3525
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
54 changes: 29 additions & 25 deletions Whisky/Views/Updater/UpdateControllerViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,37 @@ struct UpdateControllerViewModifier: ViewModifier {
UpdateControllerErrorView(updater: updater)
})
.onChange(of: updater.state, { _, newValue in
// Dissmiss all old views
sheetCheckingUpdateViewPresented = false
sheetChangeLogViewPresented = false
sheetUpdateInstallingViewPresented = false
sheetUpdateReadyToRelaunchViewPresented = false
sheetUpdateErrorViewPresented = false
sheetUpdateNotFoundViewPresented = false

// Enable new view
switch newValue {
case .checking:
sheetCheckingUpdateViewPresented = true
case .updateFound:
sheetChangeLogViewPresented = true
case .initializing, .downloading, .extracting, .installing:
sheetUpdateInstallingViewPresented = true
case .readyToRelaunch:
sheetUpdateReadyToRelaunchViewPresented = true
case .error:
sheetUpdateErrorViewPresented = true
case .updateNotFound:
sheetUpdateNotFoundViewPresented = true
case .idle:
break
}
updateViews(newState: newValue)
})
}

func updateViews(newState: SparkleUpdaterEvents.UpdaterState) {
// Dissmiss all old views
sheetCheckingUpdateViewPresented = false
sheetChangeLogViewPresented = false
sheetUpdateInstallingViewPresented = false
sheetUpdateReadyToRelaunchViewPresented = false
sheetUpdateErrorViewPresented = false
sheetUpdateNotFoundViewPresented = false

// Enable new view
switch newState {
case .checking:
sheetCheckingUpdateViewPresented = true
case .updateFound:
sheetChangeLogViewPresented = true
case .initializing, .downloading, .extracting, .installing:
sheetUpdateInstallingViewPresented = true
case .readyToRelaunch:
sheetUpdateReadyToRelaunchViewPresented = true
case .error:
sheetUpdateErrorViewPresented = true
case .updateNotFound:
sheetUpdateNotFoundViewPresented = true
case .idle:
break
}
}
}

struct UpdateControllerCheckingForUpdatesView: View {
Expand Down
3 changes: 2 additions & 1 deletion Whisky/Views/Updater/UpdateInstallingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ struct UpdateInstallingView: View {
+ Text(String(" "))
+ (shouldShowEstimate ?
Text(String(format: String(localized: "setup.gptk.eta"),
formatRemainingTime(remainingBytes: downloadableBytes - downloadedBytes)))
formatRemainingTime(
remainingBytes: downloadableBytes - downloadedBytes)))
: Text(String()))
Spacer()
}
Expand Down

0 comments on commit 4cb3525

Please sign in to comment.