8000 Keep popover update controls on one row by EClinick · Pull Request #31 · EClinick/juice · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 51 additions & 39 deletions Sources/Juice/PopoverView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,49 +250,17 @@ struct PopoverView: View {
}
}

if updater.readyUpdate == nil {
ViewThatFits(in: .horizontal) {
HStack(spacing: 0) {
automaticUpdatesToggle
.fixedSize(horizontal: true, vertical: false)
Spacer(minLength: 6)
checkForUpdatesButton
}

VStack(alignment: .leading, spacing: 8) {
automaticUpdatesToggle
HStack {
Spacer(minLength: 0)
checkForUpdatesButton
}
}
}
} else {
automaticUpdatesToggle
}
PopoverAutomaticUpdateControls(
automaticallyUpdates: Binding(
get: { updater.automaticallyUpdates },
set: { updater.automaticallyUpdates = $0 }
),
showsCheckButton: updater.readyUpdate == nil,
checkForUpdates: updater.checkForUpdates)
}
}
}

private var automaticUpdatesToggle: some View {
Toggle("Automatic updates", isOn: Binding(
get: { updater.automaticallyUpdates },
set: { updater.automaticallyUpdates = $0 }
))
.toggleStyle(.switch)
.controlSize(.small)
.accessibilityLabel("Automatic updates")
.accessibilityHint(
"Checks for and downloads updates automatically when enabled.")
}

private var checkForUpdatesButton: some View {
Button("Check for Updates…") {
updater.checkForUpdates()
}
.controlSize(.small)
}

private func batteryDashboard(_ reading: BatteryReading) -> some View {
VStack(alignment: .leading, spacing: 10) {
// Gauge, its docked mode control, and the mode caption read as one
Expand Down Expand Up @@ -602,6 +570,50 @@ struct PopoverView: View {
}
}

struct PopoverAutomaticUpdateControls: View {
@Binding var automaticallyUpdates: Bool
let showsCheckButton: Bool
let checkForUpdates: () -> Void

var body: some View {
if showsCheckButton {
ViewThatFits(in: .horizontal) {
HStack(spacing: 0) {
automaticUpdatesToggle
.fixedSize(horizontal: true, vertical: false)
Spacer(minLength: 6)
checkForUpdatesButton
}

VStack(alignment: .leading, spacing: 8) {
automaticUpdatesToggle
HStack {
Spacer(minLength: 0)
checkForUpdatesButton
}
}
}
} else {
automaticUpdatesToggle
}
}

private var automaticUpdatesToggle: some View {
Toggle("Automatic updates", isOn: $automaticallyUpdates)
.toggleStyle(.switch)
.controlSize(.small)
.accessibilityLabel("Automatic updates")
.accessibilityHint(
"Checks for and downloads updates automatically when enabled.")
}

private var checkForUpdatesButton: some View {
Button("Check Now…", action: checkForUpdates)
.controlSize(.small)
.accessibilityLabel("Check for Updates")
}
}

/// Gives MenuBarExtra dashboards a finite viewport while leaving action
/// controls outside the scrollable region. ScrollView has no useful intrinsic
/// height in a menu-bar panel, so measure its content and cap the viewport to
Expand Down
26 changes: 26 additions & 0 deletions Tests/JuiceTests/PopoverLayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,32 @@ struct PopoverLayoutTests {
#expect(controller.view.bounds.contains(footer.convert(footer.bounds, to: controller.view)))
}

@Test("automatic update controls share one row at the battery popover width")
func automaticUpdateControlsShareOneRow() {
var automaticallyUpdates = true
let controller = NSHostingController(
rootView: PopoverAutomaticUpdateControls(
automaticallyUpdates: Binding(
get: { automaticallyUpdates },
set: { automaticallyUpdates = $0 }
),
showsCheckButton: true,
checkForUpdates: {})
// The 320-point battery popover has 14 points of padding on
// each side, leaving exactly 292 points for these controls.
.frame(width: 292)
)
controller.view.frame = NSRect(
origin: .zero,
size: controller.view.fittingSize)
controller.view.layoutSubtreeIfNeeded()

// The accessibility fallback is 52 points tall. At the standard text
// size, the horizontal candidate is 24 points tall and must win.
#expect(controller.view.fittingSize.height >= 18)
#expect(controller.view.fittingSize.height < 32)
}

@Test("scroll cue button jumps the viewport to the bottom")
func scrollCueButtonJumpsToBottom() async throws {
let controller = NSHostingController(
Expand Down
0