diff --git a/CHANGELOG.md b/CHANGELOG.md index 8551b12..242547a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to Pullo are listed here, newest first. The format follows [ ## [Unreleased] +### Changed +- CI progress now shows below the notch, so it no longer covers the menu bar icons next to it. To keep it beside the notch, choose Beside the notch in Settings › Appearance. + ### Fixed - While checks are running, the notch no longer disappears for a second after you move the pointer away from the open panel. diff --git a/Sources/Pullo/Features/Notch/Header/TopBar.swift b/Sources/Pullo/Features/Notch/Header/TopBar.swift index aab6a41..03c028e 100644 --- a/Sources/Pullo/Features/Notch/Header/TopBar.swift +++ b/Sources/Pullo/Features/Notch/Header/TopBar.swift @@ -6,7 +6,7 @@ struct TopBar: View { var body: some View { let notchSize = notch.geometry.notchSize ZStack { - if notch.state == .closed, let live = notch.liveCI { + if notch.state == .closed, let live = notch.liveCI, live.placement == .beside { LiveCIView(live: live, notchWidth: notchSize.width) .frame(width: notch.layout.size(for: .closed).width) .transition(.opacity) diff --git a/Sources/Pullo/Features/Notch/LiveCI.swift b/Sources/Pullo/Features/Notch/LiveCI.swift index ae86ba5..f3a21af 100644 --- a/Sources/Pullo/Features/Notch/LiveCI.swift +++ b/Sources/Pullo/Features/Notch/LiveCI.swift @@ -2,6 +2,7 @@ import Foundation struct LiveCI: Equatable { static let maxNameLength = 14 + static let dropHeight: CGFloat = 24 let id: String let name: String @@ -11,6 +12,7 @@ struct LiveCI: Equatable { var othersRunning = 0 var finished: CIState? var label: LiveCILabel = .number + var placement: LiveCIPlacement = .below init(pr: PullRequest, othersRunning: Int = 0, finished: CIState? = nil, label: LiveCILabel = .number) { id = pr.id @@ -46,6 +48,21 @@ struct LiveCI: Equatable { return max(46, max(leading, trailing) + 20) } + var belowWidth: CGFloat { + var width: CGFloat = 14 + if showsNumberBeside { width += 5 + Self.width(of: name) } + if let trailingText { width += 5 + Self.width(of: trailingText) } + if let othersText { width += 5 + Self.width(of: othersText) + 8 } + return width + 28 + } + + func closedSize(around notch: CGSize) -> CGSize { + switch placement { + case .beside: CGSize(width: notch.width + wingWidth * 2, height: notch.height) + case .below: CGSize(width: max(notch.width, belowWidth), height: notch.height + Self.dropHeight) + } + } + private static func width(of text: String) -> CGFloat { CGFloat(text.count) * 7 } private static func shortened(_ name: String) -> String { @@ -64,3 +81,14 @@ enum LiveCILabel: String, CaseIterable { } } } + +enum LiveCIPlacement: String, CaseIterable { + case below, beside + + var title: String { + switch self { + case .below: String(localized: "Below the notch") + case .beside: String(localized: "Beside the notch") + } + } +} diff --git a/Sources/Pullo/Features/Notch/LiveCIModel.swift b/Sources/Pullo/Features/Notch/LiveCIModel.swift index 887efda..c8fc4c8 100644 --- a/Sources/Pullo/Features/Notch/LiveCIModel.swift +++ b/Sources/Pullo/Features/Notch/LiveCIModel.swift @@ -26,6 +26,7 @@ final class LiveCIModel { var current: LiveCI? { guard settings.showsLiveCI, var live = peeks.finishedCI ?? running else { return nil } live.label = settings.liveCILabel + live.placement = settings.liveCIPlacement return live } diff --git a/Sources/Pullo/Features/Notch/LiveCIView.swift b/Sources/Pullo/Features/Notch/LiveCIView.swift index 94199c3..b9d3000 100644 --- a/Sources/Pullo/Features/Notch/LiveCIView.swift +++ b/Sources/Pullo/Features/Notch/LiveCIView.swift @@ -5,12 +5,22 @@ struct LiveCIView: View { let notchWidth: CGFloat var body: some View { - HStack(spacing: 0) { - leading - .frame(maxWidth: .infinity) - Color.clear.frame(width: notchWidth) - counter - .frame(maxWidth: .infinity) + Group { + switch live.placement { + case .beside: + HStack(spacing: 0) { + leading + .frame(maxWidth: .infinity) + Color.clear.frame(width: notchWidth) + counter + .frame(maxWidth: .infinity) + } + case .below: + HStack(spacing: 5) { + leading + counter + } + } } .accessibilityElement(children: .ignore) .accessibilityLabel(accessibilityText) diff --git a/Sources/Pullo/Features/Notch/NotchInteraction.swift b/Sources/Pullo/Features/Notch/NotchInteraction.swift index 7408166..2c83967 100644 --- a/Sources/Pullo/Features/Notch/NotchInteraction.swift +++ b/Sources/Pullo/Features/Notch/NotchInteraction.swift @@ -56,7 +56,7 @@ final class NotchInteraction { peeks.host = self } - var layout: NotchLayout { NotchLayout(geometry: geometry, closedWings: liveCI?.wingWidth ?? 0) } + var layout: NotchLayout { NotchLayout(geometry: geometry, live: liveCI) } var liveCI: LiveCI? { liveCIModel.current } diff --git a/Sources/Pullo/Features/Notch/NotchLayout.swift b/Sources/Pullo/Features/Notch/NotchLayout.swift index 90ee832..3f5456f 100644 --- a/Sources/Pullo/Features/Notch/NotchLayout.swift +++ b/Sources/Pullo/Features/Notch/NotchLayout.swift @@ -4,13 +4,13 @@ struct NotchLayout { static let switcherSpace: CGFloat = 56 let geometry: NotchGeometry - var closedWings: CGFloat = 0 + var live: LiveCI? func size(for state: NotchState) -> CGSize { let notch = geometry.notchSize switch state { case .closed: - return CGSize(width: notch.width + closedWings * 2, height: notch.height) + return live?.closedSize(around: notch) ?? notch case .peek: return CGSize(width: max(notch.width + 200, 400), height: notch.height + 54) case .open: diff --git a/Sources/Pullo/Features/Notch/NotchRootView.swift b/Sources/Pullo/Features/Notch/NotchRootView.swift index c2f00d5..41ad8ce 100644 --- a/Sources/Pullo/Features/Notch/NotchRootView.swift +++ b/Sources/Pullo/Features/Notch/NotchRootView.swift @@ -45,6 +45,11 @@ struct NotchRootView: View { private func panel(state: NotchState, size: CGSize, radii: (top: CGFloat, bottom: CGFloat), shape: NotchShape) -> some View { VStack(spacing: 0) { TopBar() + if state == .closed, let live = notch.liveCI, live.placement == .below { + LiveCIView(live: live, notchWidth: notch.geometry.notchSize.width) + .frame(height: LiveCI.dropHeight) + .transition(.opacity) + } if state == .peek, let alert = notch.peekAlert { PeekView(alert: alert) { notch.tapPeek(alert) } .id(alert.id) diff --git a/Sources/Pullo/Features/Settings/AppSettings.swift b/Sources/Pullo/Features/Settings/AppSettings.swift index 1870149..b7f8781 100644 --- a/Sources/Pullo/Features/Settings/AppSettings.swift +++ b/Sources/Pullo/Features/Settings/AppSettings.swift @@ -14,6 +14,7 @@ final class AppSettings { var panelStyle: PanelStyle { didSet { save() } } var showsLiveCI: Bool { didSet { save() } } var liveCILabel: LiveCILabel { didSet { save() } } + var liveCIPlacement: LiveCIPlacement { didSet { save() } } var display: DisplayChoice { didSet { save() } } var shortcut: ShortcutChoice { didSet { save() } } var holdsAlertsInFullScreen: Bool { didSet { save() } } @@ -38,6 +39,7 @@ final class AppSettings { panelStyle = (defaults.object(for: .panelStyle) as? String).flatMap(PanelStyle.init(rawValue:)) ?? .solid showsLiveCI = defaults.object(for: .liveCI) as? Bool ?? true liveCILabel = (defaults.object(for: .liveCILabel) as? String).flatMap(LiveCILabel.init(rawValue:)) ?? .number + liveCIPlacement = (defaults.object(for: .liveCIPlacement) as? String).flatMap(LiveCIPlacement.init(rawValue:)) ?? .below display = (defaults.object(for: .display) as? String).flatMap(DisplayChoice.init(rawValue:)) ?? .builtIn shortcut = (defaults.object(for: .shortcut) as? String).flatMap(ShortcutChoice.init(rawValue:)) ?? .optionCommandP holdsAlertsInFullScreen = defaults.object(for: .holdInFullScreen) as? Bool ?? false @@ -89,6 +91,7 @@ final class AppSettings { defaults.set(panelStyle.rawValue, for: .panelStyle) defaults.set(showsLiveCI, for: .liveCI) defaults.set(liveCILabel.rawValue, for: .liveCILabel) + defaults.set(liveCIPlacement.rawValue, for: .liveCIPlacement) defaults.set(display.rawValue, for: .display) defaults.set(shortcut.rawValue, for: .shortcut) defaults.set(holdsAlertsInFullScreen, for: .holdInFullScreen) diff --git a/Sources/Pullo/Features/Settings/AppearancePage.swift b/Sources/Pullo/Features/Settings/AppearancePage.swift index 6003f0b..7ae1d4b 100644 --- a/Sources/Pullo/Features/Settings/AppearancePage.swift +++ b/Sources/Pullo/Features/Settings/AppearancePage.swift @@ -21,12 +21,17 @@ struct AppearancePage: View { Toggle("Show CI progress on the notch", isOn: $settings.showsLiveCI) .toggleStyle(.switch) if settings.showsLiveCI { + PreviewPicker(options: LiveCIPlacement.allCases, selection: $settings.liveCIPlacement, title: \.title) { placement in + LiveCIPreview(label: settings.liveCILabel, placement: placement) + } PreviewPicker(options: LiveCILabel.allCases, selection: $settings.liveCILabel, title: \.title) { label in - LiveCIPreview(label: label) + LiveCIPreview(label: label, placement: settings.liveCIPlacement) } } } footer: { - Text("While checks run on your pull requests, the notch widens to show their progress.") + Text( + "While checks run on your pull requests, the notch shows their progress. Below the notch keeps the menu bar icons beside it visible." + ) } } } diff --git a/Sources/Pullo/Features/Settings/LiveCIPreview.swift b/Sources/Pullo/Features/Settings/LiveCIPreview.swift index 8752ce9..595e5f7 100644 --- a/Sources/Pullo/Features/Settings/LiveCIPreview.swift +++ b/Sources/Pullo/Features/Settings/LiveCIPreview.swift @@ -2,6 +2,7 @@ import SwiftUI struct LiveCIPreview: View { let label: LiveCILabel + let placement: LiveCIPlacement private static let notchWidth: CGFloat = 30 private static let notchHeight: CGFloat = 32 @@ -9,17 +10,30 @@ struct LiveCIPreview: View { private var live: LiveCI { var pr = PullRequest.sample pr.checks = CheckProgress(done: 2, total: 3) - return LiveCI(pr: pr, othersRunning: 0, label: label) + var live = LiveCI(pr: pr, othersRunning: 0, label: label) + live.placement = placement + return live } var body: some View { - let width = Self.notchWidth + live.wingWidth * 2 + let live = live + let size = live.closedSize(around: CGSize(width: Self.notchWidth, height: Self.notchHeight)) ZStack(alignment: .top) { PreviewWallpaper() - LiveCIView(live: live, notchWidth: Self.notchWidth) - .frame(width: width, height: Self.notchHeight) - .background(NotchShape(topRadius: 6, bottomRadius: 12).fill(Color.black)) - .scaleEffect(0.7, anchor: .top) + VStack(spacing: 0) { + switch placement { + case .beside: + LiveCIView(live: live, notchWidth: Self.notchWidth) + .frame(height: Self.notchHeight) + case .below: + Color.clear.frame(height: Self.notchHeight) + LiveCIView(live: live, notchWidth: Self.notchWidth) + .frame(height: LiveCI.dropHeight) + } + } + .frame(width: size.width, height: size.height) + .background(NotchShape(topRadius: 6, bottomRadius: 12).fill(Color.black)) + .scaleEffect(0.7, anchor: .top) } } } diff --git a/Sources/Pullo/Resources/Localizable.xcstrings b/Sources/Pullo/Resources/Localizable.xcstrings index 3cd69ee..c99af19 100644 --- a/Sources/Pullo/Resources/Localizable.xcstrings +++ b/Sources/Pullo/Resources/Localizable.xcstrings @@ -4352,22 +4352,6 @@ } } }, - "While checks run on your pull requests, the notch widens to show their progress.": { - "localizations": { - "es": { - "stringUnit": { - "state": "translated", - "value": "Mientras se ejecutan los checks de tus pull requests, el notch se ensancha para mostrar su progreso." - } - }, - "pt-BR": { - "stringUnit": { - "state": "translated", - "value": "Enquanto os checks rodam nos seus pull requests, o notch se alarga para mostrar o progresso." - } - } - } - }, "While you were in Focus": { "localizations": { "es": { @@ -5797,6 +5781,54 @@ } } } + }, + "Below the notch": { + "localizations": { + "es": { + "stringUnit": { + "state": "translated", + "value": "Debajo del notch" + } + }, + "pt-BR": { + "stringUnit": { + "state": "translated", + "value": "Embaixo do notch" + } + } + } + }, + "Beside the notch": { + "localizations": { + "es": { + "stringUnit": { + "state": "translated", + "value": "Junto al notch" + } + }, + "pt-BR": { + "stringUnit": { + "state": "translated", + "value": "Ao lado do notch" + } + } + } + }, + "While checks run on your pull requests, the notch shows their progress. Below the notch keeps the menu bar icons beside it visible.": { + "localizations": { + "es": { + "stringUnit": { + "state": "translated", + "value": "Mientras se ejecutan los checks de tus pull requests, el notch muestra su progreso. Debajo del notch deja a la vista los iconos de la barra de menús que tiene al lado." + } + }, + "pt-BR": { + "stringUnit": { + "state": "translated", + "value": "Enquanto os checks rodam nos seus pull requests, o notch mostra o progresso. Embaixo do notch deixa visíveis os ícones da barra de menus ao lado dele." + } + } + } } }, "version": "1.0" diff --git a/Sources/Pullo/Support/DefaultsKey.swift b/Sources/Pullo/Support/DefaultsKey.swift index 056a575..f9406c7 100644 --- a/Sources/Pullo/Support/DefaultsKey.swift +++ b/Sources/Pullo/Support/DefaultsKey.swift @@ -2,7 +2,7 @@ import Foundation enum DefaultsKey: String { case accounts, tabs, runTabs, unreadableTabs, unreadableRunTabs - case mutedCategories, mutedAccounts, haptics, sound, categorySounds, panelStyle, liveCI, liveCILabel + case mutedCategories, mutedAccounts, haptics, sound, categorySounds, panelStyle, liveCI, liveCILabel, liveCIPlacement case display, shortcut, holdInFullScreen case readBaselines, readKnownAccounts case betaUpdates diff --git a/Tests/PulloTests/AppSettingsTests.swift b/Tests/PulloTests/AppSettingsTests.swift index b36c870..ecaa610 100644 --- a/Tests/PulloTests/AppSettingsTests.swift +++ b/Tests/PulloTests/AppSettingsTests.swift @@ -22,6 +22,13 @@ struct AppSettingsTests { #expect(AppSettings(defaults: scratch.defaults).liveCILabel == .both) } + @Test func ciProgressShowsBelowTheNotchUntilBesideIsChosen() { + let scratch = ScratchDefaults() + #expect(AppSettings(defaults: scratch.defaults).liveCIPlacement == .below) + AppSettings(defaults: scratch.defaults).liveCIPlacement = .beside + #expect(AppSettings(defaults: scratch.defaults).liveCIPlacement == .beside) + } + @Test func soundsChosenPerKindAreRemembered() { let scratch = ScratchDefaults() AppSettings(defaults: scratch.defaults).categorySounds = [.ciFailed: "Basso", .ciPassed: ""] diff --git a/Tests/PulloTests/FirstRunTests.swift b/Tests/PulloTests/FirstRunTests.swift index 4c4f1d9..0a54111 100644 --- a/Tests/PulloTests/FirstRunTests.swift +++ b/Tests/PulloTests/FirstRunTests.swift @@ -67,7 +67,7 @@ extension NotchBehavior { hasNotch: false ) #expect(h.notch.liveCI?.id == "PR_1") - #expect(h.notch.layout.size(for: .closed).width > NotchGeometry.pillWidth) + #expect(h.notch.layout.size(for: .closed).height > 24) } } } diff --git a/Tests/PulloTests/LiveCITests.swift b/Tests/PulloTests/LiveCITests.swift index e0a0fe0..855975a 100644 --- a/Tests/PulloTests/LiveCITests.swift +++ b/Tests/PulloTests/LiveCITests.swift @@ -25,14 +25,33 @@ extension NotchBehavior { #expect(h.notch.liveCI?.othersRunning == 1) } - @Test func widensTheClosedNotchWhileChecksRun() async { + @Test func dropsBelowTheClosedNotchWhileChecksRun() async { let idle = await NotchHarness() let busy = await NotchHarness(mine: [Self.running("PR_1", minutesAgo: 1)]) #expect(idle.notch.liveCI == nil) - #expect(busy.notch.layout.size(for: .closed).width > idle.notch.layout.size(for: .closed).width) + let closed = busy.notch.layout.size(for: .closed) + #expect(closed.width == idle.notch.layout.size(for: .closed).width) + #expect(closed.height == idle.notch.layout.size(for: .closed).height + LiveCI.dropHeight) + #expect(busy.notch.layout.hitRect(for: .closed).height > idle.notch.layout.hitRect(for: .closed).height) + } + + @Test func widensTheClosedNotchWhenShownBesideIt() async { + let idle = await NotchHarness() + let busy = await NotchHarness(mine: [Self.running("PR_1", minutesAgo: 1)]) + busy.settings.liveCIPlacement = .beside + let closed = busy.notch.layout.size(for: .closed) + #expect(closed.width > idle.notch.layout.size(for: .closed).width) + #expect(closed.height == idle.notch.layout.size(for: .closed).height) #expect(busy.notch.layout.hitRect(for: .closed).width > idle.notch.layout.hitRect(for: .closed).width) } + @Test func growsWiderBelowANarrowNotchWhenTheLabelDoesNotFit() async { + let h = await NotchHarness(mine: [Self.running("PR_1", minutesAgo: 1)]) + h.notch.geometry.notchSize.width = 60 + h.settings.liveCILabel = .both + #expect(h.notch.layout.size(for: .closed).width > 60) + } + @Test func staysHiddenWhenTurnedOffOrTheAccountIsMuted() async { let h = await NotchHarness(accounts: ["me", "work"], mine: [Self.running("PR_1", minutesAgo: 1, account: "work")]) #expect(h.notch.liveCI != nil) @@ -45,6 +64,7 @@ extension NotchBehavior { @Test func followsTheChosenLabel() async { let h = await NotchHarness(mine: [Self.running("PR_1", minutesAgo: 1)]) + h.settings.liveCIPlacement = .beside #expect(h.notch.liveCI?.trailingText == "#383") h.settings.liveCILabel = .checks #expect(h.notch.liveCI?.trailingText == "3/5")