mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Working stuff
This commit is contained in:
parent
9bd445986d
commit
94a612f327
13 changed files with 913 additions and 150 deletions
|
|
@ -1,69 +1,84 @@
|
|||
import SwiftUI
|
||||
import Defaults
|
||||
import AtollExtensionKit
|
||||
|
||||
struct ExtensionStandaloneLayout {
|
||||
let totalWidth: CGFloat
|
||||
let outerHeight: CGFloat
|
||||
let contentHeight: CGFloat
|
||||
let leadingWidth: CGFloat
|
||||
let centerWidth: CGFloat
|
||||
let trailingWidth: CGFloat
|
||||
}
|
||||
|
||||
struct ExtensionLiveActivityStandaloneView: View {
|
||||
let payload: ExtensionLiveActivityPayload
|
||||
let notchWidth: CGFloat
|
||||
let notchHeight: CGFloat
|
||||
let layout: ExtensionStandaloneLayout
|
||||
let isHovering: Bool
|
||||
|
||||
private var descriptor: AtollLiveActivityDescriptor { payload.descriptor }
|
||||
private var contentHeight: CGFloat {
|
||||
max(0, notchHeight - (isHovering ? 0 : 12))
|
||||
}
|
||||
private var contentHeight: CGFloat { layout.contentHeight }
|
||||
private var accentColor: Color { descriptor.accentColor.swiftUIColor }
|
||||
private var resolvedLeadingContent: AtollTrailingContent {
|
||||
descriptor.leadingContent ?? .icon(descriptor.leadingIcon)
|
||||
}
|
||||
private var resolvedCenterStyle: ExtensionCenterContentView.Style {
|
||||
switch descriptor.centerTextStyle {
|
||||
case .inline:
|
||||
return .inline
|
||||
case .standard:
|
||||
return .stacked
|
||||
case .inheritUser:
|
||||
return Defaults[.sneakPeekStyles] == .inline ? .inline : .stacked
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
let baseWingWidth = max(contentHeight, 44)
|
||||
let trailingWidth = ExtensionLayoutMetrics.trailingWidth(
|
||||
for: payload,
|
||||
baseWidth: baseWingWidth,
|
||||
maxWidth: notchWidth * 0.42
|
||||
)
|
||||
let centerWidth = max(96, notchWidth - baseWingWidth - trailingWidth)
|
||||
|
||||
return HStack(spacing: 0) {
|
||||
ExtensionCompositeIconView(
|
||||
leading: descriptor.leadingIcon,
|
||||
HStack(spacing: 0) {
|
||||
ExtensionLeadingContentView(
|
||||
content: resolvedLeadingContent,
|
||||
badge: descriptor.badgeIcon,
|
||||
accent: accentColor,
|
||||
size: contentHeight
|
||||
frameWidth: layout.leadingWidth,
|
||||
frameHeight: contentHeight
|
||||
)
|
||||
.frame(width: baseWingWidth, height: contentHeight)
|
||||
.frame(width: layout.leadingWidth, height: contentHeight)
|
||||
|
||||
Rectangle()
|
||||
.fill(Color.black)
|
||||
.frame(width: centerWidth, height: contentHeight)
|
||||
.overlay(centerContent)
|
||||
.frame(width: layout.centerWidth, height: contentHeight)
|
||||
.overlay(
|
||||
ExtensionCenterContentView(
|
||||
descriptor: descriptor,
|
||||
accent: accentColor,
|
||||
width: layout.centerWidth,
|
||||
style: resolvedCenterStyle
|
||||
)
|
||||
)
|
||||
|
||||
ExtensionMusicWingView(payload: payload, notchHeight: contentHeight)
|
||||
.frame(width: trailingWidth, height: contentHeight)
|
||||
ExtensionMusicWingView(
|
||||
payload: payload,
|
||||
notchHeight: contentHeight,
|
||||
trailingWidth: layout.trailingWidth
|
||||
)
|
||||
.frame(width: layout.trailingWidth, height: contentHeight)
|
||||
}
|
||||
.frame(width: notchWidth, height: notchHeight + (isHovering ? 8 : 0))
|
||||
.frame(width: layout.totalWidth, height: layout.outerHeight + (isHovering ? 8 : 0))
|
||||
.animation(.smooth(duration: 0.25), value: payload.id)
|
||||
.onAppear {
|
||||
logExtensionDiagnostics("Displaying extension live activity \(payload.descriptor.id) for \(payload.bundleIdentifier) as standalone view")
|
||||
}
|
||||
.onDisappear {
|
||||
logExtensionDiagnostics("Hid extension live activity \(payload.descriptor.id) standalone view")
|
||||
}
|
||||
}
|
||||
|
||||
private var centerContent: some View {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(descriptor.title)
|
||||
.font(.system(size: 14, weight: .semibold))
|
||||
.foregroundStyle(.white)
|
||||
.lineLimit(1)
|
||||
if let subtitle = descriptor.subtitle, !subtitle.isEmpty {
|
||||
Text(subtitle)
|
||||
.font(.system(size: 12, weight: .medium))
|
||||
.foregroundStyle(Color.white.opacity(0.7))
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 12)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
|
||||
struct ExtensionMusicWingView: View {
|
||||
let payload: ExtensionLiveActivityPayload
|
||||
let notchHeight: CGFloat
|
||||
let trailingWidth: CGFloat
|
||||
|
||||
private var descriptor: AtollLiveActivityDescriptor { payload.descriptor }
|
||||
private var accentColor: Color { descriptor.accentColor.swiftUIColor }
|
||||
|
|
@ -73,7 +88,12 @@ struct ExtensionMusicWingView: View {
|
|||
if case .none = descriptor.trailingContent {
|
||||
EmptyView()
|
||||
} else {
|
||||
ExtensionTrailingContentView(content: descriptor.trailingContent, accent: accentColor)
|
||||
ExtensionEdgeContentView(
|
||||
content: descriptor.trailingContent,
|
||||
accent: accentColor,
|
||||
availableWidth: trailingWidth,
|
||||
alignment: .trailing
|
||||
)
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
}
|
||||
|
||||
|
|
@ -92,5 +112,93 @@ struct ExtensionMusicWingView: View {
|
|||
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
|
||||
.padding(.trailing, 8)
|
||||
.padding(.vertical, 6)
|
||||
.onAppear {
|
||||
logExtensionDiagnostics("Displaying extension live activity \(payload.descriptor.id) within music wing")
|
||||
}
|
||||
.onDisappear {
|
||||
logExtensionDiagnostics("Hid extension live activity \(payload.descriptor.id) from music wing")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ExtensionLeadingContentView: View {
|
||||
let content: AtollTrailingContent
|
||||
let badge: AtollIconDescriptor?
|
||||
let accent: Color
|
||||
let frameWidth: CGFloat
|
||||
let frameHeight: CGFloat
|
||||
|
||||
var body: some View {
|
||||
if case let .icon(iconDescriptor) = content {
|
||||
ExtensionCompositeIconView(
|
||||
leading: iconDescriptor,
|
||||
badge: badge,
|
||||
accent: accent,
|
||||
size: frameHeight
|
||||
)
|
||||
} else {
|
||||
ExtensionEdgeContentView(
|
||||
content: content,
|
||||
accent: accent,
|
||||
availableWidth: frameWidth,
|
||||
alignment: .leading
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ExtensionCenterContentView: View {
|
||||
enum Style {
|
||||
case stacked
|
||||
case inline
|
||||
}
|
||||
|
||||
let descriptor: AtollLiveActivityDescriptor
|
||||
let accent: Color
|
||||
let width: CGFloat
|
||||
let style: Style
|
||||
|
||||
var body: some View {
|
||||
switch style {
|
||||
case .stacked:
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(descriptor.title)
|
||||
.font(.system(size: 14, weight: .semibold))
|
||||
.foregroundStyle(.white)
|
||||
.lineLimit(1)
|
||||
if let subtitle = descriptor.subtitle, !subtitle.isEmpty {
|
||||
Text(subtitle)
|
||||
.font(.system(size: 12, weight: .medium))
|
||||
.foregroundStyle(Color.white.opacity(0.7))
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 12)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
case .inline:
|
||||
HStack(alignment: .center, spacing: 8) {
|
||||
MarqueeText(
|
||||
.constant(descriptor.title),
|
||||
font: .system(size: 13, weight: .semibold),
|
||||
nsFont: .body,
|
||||
textColor: .white,
|
||||
minDuration: 0.4,
|
||||
frameWidth: max(40, width * 0.55)
|
||||
)
|
||||
Spacer(minLength: 4)
|
||||
if let subtitle = descriptor.subtitle, !subtitle.isEmpty {
|
||||
Text(subtitle)
|
||||
.font(.system(size: 12, weight: .medium))
|
||||
.foregroundStyle(Color.white.opacity(0.75))
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 12)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func logExtensionDiagnostics(_ message: String) {
|
||||
guard Defaults[.extensionDiagnosticsLoggingEnabled] else { return }
|
||||
Logger.log(message, category: .extensions)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import SwiftUI
|
||||
import Defaults
|
||||
import AtollExtensionKit
|
||||
|
||||
struct ExtensionLockScreenWidgetView: View {
|
||||
|
|
@ -20,6 +21,12 @@ struct ExtensionLockScreenWidgetView: View {
|
|||
RoundedRectangle(cornerRadius: descriptor.cornerRadius, style: .continuous)
|
||||
.stroke(Color.white.opacity(0.04), lineWidth: 1)
|
||||
)
|
||||
.onAppear {
|
||||
logWidgetDiagnostics("Rendering extension lock screen widget \(payload.descriptor.id) for \(payload.bundleIdentifier)")
|
||||
}
|
||||
.onDisappear {
|
||||
logWidgetDiagnostics("Lock screen widget \(payload.descriptor.id) removed")
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
|
|
@ -118,6 +125,11 @@ struct ExtensionLockScreenWidgetView: View {
|
|||
}
|
||||
}
|
||||
|
||||
private func logWidgetDiagnostics(_ message: String) {
|
||||
guard Defaults[.extensionDiagnosticsLoggingEnabled] else { return }
|
||||
Logger.log(message, category: .extensions)
|
||||
}
|
||||
|
||||
private struct ExtensionGraphView: View {
|
||||
let data: [Double]
|
||||
let color: Color
|
||||
|
|
|
|||
|
|
@ -254,11 +254,13 @@ struct ExtensionProgressIndicatorView: View {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: - Trailing Content Rendering
|
||||
// MARK: - Edge Content Rendering
|
||||
|
||||
struct ExtensionTrailingContentView: View {
|
||||
struct ExtensionEdgeContentView: View {
|
||||
let content: AtollTrailingContent
|
||||
let accent: Color
|
||||
let availableWidth: CGFloat
|
||||
let alignment: Alignment
|
||||
|
||||
var body: some View {
|
||||
switch content {
|
||||
|
|
@ -267,6 +269,19 @@ struct ExtensionTrailingContentView: View {
|
|||
.font(font.swiftUIFont())
|
||||
.foregroundStyle(accent)
|
||||
.lineLimit(1)
|
||||
.frame(maxWidth: .infinity, alignment: alignment)
|
||||
case let .marquee(value, font: font, minDuration: duration):
|
||||
MarqueeText(
|
||||
.constant(value),
|
||||
font: font.swiftUIFont(),
|
||||
nsFont: .body,
|
||||
textColor: accent,
|
||||
minDuration: duration,
|
||||
frameWidth: max(24, availableWidth - 12)
|
||||
)
|
||||
case let .countdownText(targetDate, font: font):
|
||||
ExtensionCountdownTextView(targetDate: targetDate, font: font, accent: accent)
|
||||
.frame(maxWidth: .infinity, alignment: alignment)
|
||||
case let .icon(descriptor):
|
||||
ExtensionIconView(
|
||||
descriptor: descriptor,
|
||||
|
|
@ -292,12 +307,37 @@ struct ExtensionTrailingContentView: View {
|
|||
}
|
||||
}
|
||||
|
||||
struct ExtensionCountdownTextView: View {
|
||||
let targetDate: Date
|
||||
let font: AtollFontDescriptor
|
||||
let accent: Color
|
||||
|
||||
var body: some View {
|
||||
TimelineView(.periodic(from: .now, by: 1)) { context in
|
||||
Text(formattedRemaining(since: context.date))
|
||||
.font(font.swiftUIFont())
|
||||
.foregroundStyle(accent)
|
||||
.monospacedDigit()
|
||||
}
|
||||
}
|
||||
|
||||
private func formattedRemaining(since date: Date) -> String {
|
||||
let remaining = max(Int(targetDate.timeIntervalSince(date)), 0)
|
||||
let hours = remaining / 3600
|
||||
let minutes = (remaining % 3600) / 60
|
||||
let seconds = remaining % 60
|
||||
if hours > 0 {
|
||||
return String(format: "%02d:%02d:%02d", hours, minutes, seconds)
|
||||
}
|
||||
return String(format: "%02d:%02d", minutes, seconds)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Layout Metrics
|
||||
|
||||
enum ExtensionLayoutMetrics {
|
||||
static func trailingWidth(for payload: ExtensionLiveActivityPayload, baseWidth: CGFloat, maxWidth: CGFloat? = nil) -> CGFloat {
|
||||
var width = baseWidth
|
||||
width = max(width, widthForTrailing(content: payload.descriptor.trailingContent, baseWidth: baseWidth))
|
||||
var width = edgeWidth(for: payload.descriptor.trailingContent, baseWidth: baseWidth, maxWidth: maxWidth)
|
||||
if let indicator = payload.descriptor.progressIndicator {
|
||||
width = max(width, widthForProgress(indicator))
|
||||
}
|
||||
|
|
@ -307,11 +347,26 @@ enum ExtensionLayoutMetrics {
|
|||
return width
|
||||
}
|
||||
|
||||
private static func widthForTrailing(content: AtollTrailingContent, baseWidth: CGFloat) -> CGFloat {
|
||||
static func edgeWidth(for content: AtollTrailingContent, baseWidth: CGFloat, maxWidth: CGFloat? = nil) -> CGFloat {
|
||||
var width = widthForContent(content, baseWidth: baseWidth)
|
||||
if let maxWidth {
|
||||
width = min(width, maxWidth)
|
||||
}
|
||||
return width
|
||||
}
|
||||
|
||||
private static func widthForContent(_ content: AtollTrailingContent, baseWidth: CGFloat) -> CGFloat {
|
||||
switch content {
|
||||
case let .text(text, font: font):
|
||||
let measured = ExtensionTextMeasurer.width(for: text, font: font.nsFont())
|
||||
return max(baseWidth, measured + 32)
|
||||
case let .marquee(text, font: font, _):
|
||||
let measured = ExtensionTextMeasurer.width(for: text, font: font.nsFont())
|
||||
return max(baseWidth, min(measured + 40, baseWidth * 2))
|
||||
case let .countdownText(targetDate, font: font):
|
||||
let sample = targetDate.timeIntervalSinceNow >= 3600 ? "00:00:00" : "00:00"
|
||||
let measured = ExtensionTextMeasurer.width(for: sample, font: font.nsFont())
|
||||
return max(baseWidth, measured + 24)
|
||||
case .icon:
|
||||
return max(baseWidth, 52)
|
||||
case .spectrum:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue