bd44b5aa08
Test / build-libghostty-vt (x86_64-windows-gnu) (push) Has been cancelled
Test / build-libghostty-vt-macos (aarch64-ios) (push) Has been cancelled
Test / build-libghostty-vt-macos (aarch64-macos) (push) Has been cancelled
Test / build-libghostty-vt-macos (x86_64-macos) (push) Has been cancelled
Test / build-nix (namespace-profile-ghostty-md-arm64) (push) Has been cancelled
Test / build-dist (push) Has been cancelled
Test / GTK x11=true wayland=true (push) Has been cancelled
Test / Build -Dsimd=false (push) Has been cancelled
Test / Build -Dsimd=true (push) Has been cancelled
Test / Build -Dsentry=false (push) Has been cancelled
Test / Build -Dsentry=true (push) Has been cancelled
Test / zig-fmt (push) Has been cancelled
Test / GitHub Actions Pins (push) Has been cancelled
Test / prettier (push) Has been cancelled
Test / swiftlint (push) Has been cancelled
Test / alejandra (push) Has been cancelled
Test / typos (push) Has been cancelled
Nix / Required Checks: Nix (push) Has been cancelled
Nix / check-zig-cache-hash (push) Has been cancelled
Test / skip (push) Has been cancelled
Test / Required Checks: Test (push) Has been cancelled
Test / build-bench (push) Has been cancelled
Test / list-examples (push) Has been cancelled
Test / Example ${{ matrix.dir }} (Windows) (push) Has been cancelled
Test / build-cmake (push) Has been cancelled
Test / test-lib-vt-pkgconfig (push) Has been cancelled
Test / build-flatpak (push) Has been cancelled
Test / build-snap (push) Has been cancelled
Test / build-libghostty-vt (aarch64-linux) (push) Has been cancelled
Test / build-libghostty-vt (aarch64-macos) (push) Has been cancelled
Test / build-libghostty-vt (wasm32-freestanding) (push) Has been cancelled
Test / build-libghostty-vt (x86_64-linux) (push) Has been cancelled
Test / build-libghostty-vt (x86_64-linux-musl) (push) Has been cancelled
Test / build-libghostty-vt (x86_64-macos) (push) Has been cancelled
Test / build-libghostty-vt-android (aarch64-linux-android) (push) Has been cancelled
Test / build-libghostty-vt-android (arm-linux-androideabi) (push) Has been cancelled
Test / build-libghostty-vt-android (x86_64-linux-android) (push) Has been cancelled
Test / build-libghostty-vt-windows (push) Has been cancelled
Test / build-libghostty-windows-gnu (push) Has been cancelled
Test / build-linux (namespace-profile-ghostty-md) (push) Has been cancelled
Test / build-linux (namespace-profile-ghostty-md-arm64) (push) Has been cancelled
Test / build-linux-libghostty (push) Has been cancelled
Test / build-nix (namespace-profile-ghostty-md) (push) Has been cancelled
Test / build-dist-lib-vt (push) Has been cancelled
Test / trigger-snap (push) Has been cancelled
Test / trigger-flatpak (push) Has been cancelled
Test / build-macos (push) Has been cancelled
Test / build-macos-freetype (push) Has been cancelled
Test / test (push) Has been cancelled
Test / test-lib-vt (push) Has been cancelled
Test / GTK x11=false wayland=false (push) Has been cancelled
Test / GTK x11=true wayland=false (push) Has been cancelled
Test / GTK x11=false wayland=true (push) Has been cancelled
Test / test-macos (push) Has been cancelled
Test / test-windows (push) Has been cancelled
Test / Build -Di18n=false (push) Has been cancelled
Test / Build -Di18n=true (push) Has been cancelled
Test / Build test/fuzz-libghostty (push) Has been cancelled
Test / shellcheck (push) Has been cancelled
Test / translations (push) Has been cancelled
Test / blueprint-compiler (push) Has been cancelled
Test / Test pkg/wuffs (push) Has been cancelled
Test / Test build on Debian 13 (push) Has been cancelled
Test / valgrind (push) Has been cancelled
Test / Example ${{ matrix.dir }} (push) Has been cancelled
82 lines
2.9 KiB
Swift
82 lines
2.9 KiB
Swift
import SwiftUI
|
|
|
|
/// A pill-shaped button that displays update status and provides access to update actions.
|
|
struct UpdatePill: View {
|
|
/// The update view model that provides the current state and information
|
|
@ObservedObject var model: UpdateViewModel
|
|
|
|
/// Whether the update popover is currently visible
|
|
@State private var showPopover = false
|
|
|
|
/// Task for auto-dismissing the "No Updates" state
|
|
@State private var resetTask: Task<Void, Never>?
|
|
|
|
/// The font used for the pill text
|
|
private let textFont = NSFont.systemFont(ofSize: 11, weight: .medium)
|
|
|
|
var body: some View {
|
|
if !model.state.isIdle {
|
|
pillButton
|
|
.popover(isPresented: $showPopover, arrowEdge: .bottom) {
|
|
UpdatePopoverView(model: model)
|
|
}
|
|
.transition(.opacity.combined(with: .scale(scale: 0.95)))
|
|
.onChange(of: model.state) { newState in
|
|
resetTask?.cancel()
|
|
if case .notFound(let notFound) = newState {
|
|
resetTask = Task { [weak model] in
|
|
try? await Task.sleep(for: .seconds(5))
|
|
guard !Task.isCancelled, case .notFound? = model?.state else { return }
|
|
model?.state = .idle
|
|
notFound.acknowledgement()
|
|
}
|
|
} else {
|
|
resetTask = nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The pill-shaped button view that displays the update badge and text
|
|
@ViewBuilder
|
|
private var pillButton: some View {
|
|
Button(action: {
|
|
if case .notFound(let notFound) = model.state {
|
|
model.state = .idle
|
|
notFound.acknowledgement()
|
|
} else {
|
|
showPopover.toggle()
|
|
}
|
|
}, label: {
|
|
HStack(spacing: 6) {
|
|
UpdateBadge(model: model)
|
|
.frame(width: 14, height: 14)
|
|
|
|
Text(model.text)
|
|
.font(Font(textFont))
|
|
.lineLimit(1)
|
|
.truncationMode(.tail)
|
|
.frame(width: textWidth)
|
|
}
|
|
.padding(.horizontal, 8)
|
|
.padding(.vertical, 4)
|
|
.background(
|
|
Capsule()
|
|
.fill(model.backgroundColor)
|
|
)
|
|
.foregroundColor(model.foregroundColor)
|
|
.contentShape(Capsule())
|
|
})
|
|
.buttonStyle(.plain)
|
|
.help(model.text)
|
|
.accessibilityLabel(model.text)
|
|
}
|
|
|
|
/// Calculated width for the text to prevent resizing during progress updates
|
|
private var textWidth: CGFloat? {
|
|
let attributes: [NSAttributedString.Key: Any] = [.font: textFont]
|
|
let size = (model.maxWidthText as NSString).size(withAttributes: attributes)
|
|
return size.width
|
|
}
|
|
}
|