Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/i18n-uk-updates-3
Browse files Browse the repository at this point in the history
  • Loading branch information
josser committed Jan 29, 2025
2 parents 6ed33a5 + eb7d6a7 commit f3268e6
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private struct ToggleButton: View {
nextProfileId: $nextProfileId,
errorHandler: errorHandler,
flow: flow?.connectionFlow,
label: { _ in
label: { _, _ in
ThemeImage(.tunnelToggle)
.scaleEffect(1.5, anchor: .trailing)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ private extension ProfileContextMenu {
nextProfileId: .constant(nil),
errorHandler: errorHandler,
flow: flow?.connectionFlow,
label: {
label: { canConnect, _ in
ThemeImageLabel(
$0 ? Strings.Global.Actions.enable : Strings.Global.Actions.disable,
$0 ? .tunnelEnable : .tunnelDisable
canConnect ? Strings.Global.Actions.enable : Strings.Global.Actions.disable,
canConnect ? .tunnelEnable : .tunnelDisable
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private extension ProfileRowView {
nextProfileId: $nextProfileId,
errorHandler: errorHandler,
flow: flow?.connectionFlow,
label: { _ in
label: { _, _ in
ProfileCardView(
style: style,
preview: preview
Expand Down
34 changes: 29 additions & 5 deletions Packages/App/Sources/AppUITV/Views/Profile/ActiveProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct ActiveProfileView: View {
toggleConnectionButton
switchProfileButton
}
.clipShape(RoundedRectangle(cornerRadius: 50))
.buttonStyle(.borderless)
}
.padding(.horizontal, 100)
// .padding(.top, 50)
Expand Down Expand Up @@ -136,11 +136,14 @@ private extension ActiveProfileView {
label: {
Text($0 ? Strings.Global.Actions.connect : Strings.Global.Actions.disconnect)
.frame(maxWidth: .infinity)
.padding(.vertical, 10)
.fontWeight(theme.relevantWeight)
.forMainButton(
withColor: toggleConnectionColor,
focused: focusedField == .connect,
disabled: $1
)
}
)
.background(toggleConnectionColor)
.fontWeight(theme.relevantWeight)
.focused($focusedField, equals: .connect)
}

Expand All @@ -159,12 +162,33 @@ private extension ActiveProfileView {
} label: {
Text(Strings.Global.Actions.select)
.frame(maxWidth: .infinity)
.padding(.vertical, 10)
.forMainButton(
withColor: .gray,
focused: focusedField == .switchProfile,
disabled: false
)
}
.focused($focusedField, equals: .switchProfile)
}
}

// MARK: - Local modifiers

private extension View {
func forMainButton(withColor color: Color, focused: Bool, disabled: Bool) -> some View {
padding(.vertical, 25)
.background(disabled ? .gray : color)
.cornerRadius(50)
.font(.title3)
.foregroundColor(disabled ? .white.opacity(0.6) : .white)
.overlay(
RoundedRectangle(cornerRadius: 50)
.fill(.white.opacity(focused ? 0.3 : 0.0))
)
.scaleEffect(focused ? 1.05 : 1.0)
}
}

// MARK: - Previews

#Preview("Host") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private extension ProfileListView {
nextProfileId: .constant(nil),
errorHandler: errorHandler,
flow: flow,
label: { _ in
label: { _, _ in
toggleView(for: preview)
}
)
Expand Down
12 changes: 8 additions & 4 deletions Packages/App/Sources/UILibrary/Views/UI/TunnelToggleButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public struct TunnelToggleButton<Label>: View, Routable, ThemeProviding where La

public let flow: ConnectionFlow?

private let label: (Bool) -> Label
private let label: (Bool, Bool) -> Label

public init(
tunnel: ExtendedTunnel,
profile: Profile?,
nextProfileId: Binding<Profile.ID?>,
errorHandler: ErrorHandler,
flow: ConnectionFlow?,
label: @escaping (Bool) -> Label
label: @escaping (_ canConnect: Bool, _ isDisabled: Bool) -> Label
) {
self.tunnel = tunnel
self.profile = profile
Expand All @@ -65,13 +65,13 @@ public struct TunnelToggleButton<Label>: View, Routable, ThemeProviding where La

public var body: some View {
Button(action: tryPerform) {
label(canConnect)
label(canConnect, isDisabled)
}
#if os(macOS)
.buttonStyle(.plain)
.cursor(.hand)
#endif
.disabled(profile == nil || (isInstalled && tunnel.status == .deactivating))
.disabled(isDisabled)
}
}

Expand All @@ -83,6 +83,10 @@ private extension TunnelToggleButton {
var canConnect: Bool {
!isInstalled || (tunnel.status == .inactive && tunnel.currentProfile?.onDemand != true)
}

var isDisabled: Bool {
profile == nil || (isInstalled && tunnel.status == .deactivating)
}
}

private extension TunnelToggleButton {
Expand Down

0 comments on commit f3268e6

Please sign in to comment.