Merge branch 'pr-143' into feature/download

e kind of a merge, maybe it will work if not then leave it
This commit is contained in:
Hariharan Mudaliar 2025-12-08 23:00:41 +05:30
commit c1d22581dc
No known key found for this signature in database
GPG key ID: D04F1C2B9194DDFC
10 changed files with 494 additions and 78 deletions

View file

@ -0,0 +1,103 @@
//
// DownloadLiveActivity.swift
// DynamicIsland
//
// Shows a download indicator when Chromium-style downloads
// are detected in the user's Downloads folder.
//
import SwiftUI
import Defaults
struct DownloadLiveActivity: View {
@EnvironmentObject var vm: DynamicIslandViewModel
@State private var downloadManager = DownloadManager.shared
@State private var isHovering: Bool = false
@State private var gestureProgress: CGFloat = 0
@State private var isExpanded: Bool = false
private var tint: Color {
.accentColor
}
var body: some View {
HStack(spacing: 0) {
// Left side: download icon capsule
Color.clear
.background {
if isExpanded {
HStack {
ZStack {
RoundedRectangle(cornerRadius: 6, style: .continuous)
.fill(tint.opacity(0.14))
Image(systemName: "arrow.down.circle.fill")
.font(.system(size: 14, weight: .semibold))
.foregroundStyle(tint)
}
.frame(
width: vm.effectiveClosedNotchHeight - 12,
height: vm.effectiveClosedNotchHeight - 12
)
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
}
}
.frame(
width: isExpanded ? max(0, vm.effectiveClosedNotchHeight - (isHovering ? 0 : 12) + gestureProgress / 2) : 0,
height: vm.effectiveClosedNotchHeight - (isHovering ? 0 : 12)
)
// Center: closed notch body (slightly wider during downloads)
Rectangle()
.fill(.black)
.frame(
width: vm.closedNotchSize.width
+ (isHovering ? 8 : 0)
+ (downloadManager.isDownloading ? 40 : 0)
)
// Right side: indeterminate-style progress bar
Color.clear
.background {
if isExpanded {
HStack {
if downloadManager.isDownloadCompleted {
Image(systemName: "checkmark.circle.fill")
.foregroundStyle(.green)
.font(.system(size: 16, weight: .semibold))
.padding(.trailing, 6)
} else if Defaults[.selectedDownloadIndicatorStyle] == .circle {
SpinningCircleDownloadView()
.padding(.trailing, 6)
} else {
ProgressView()
.progressViewStyle(.linear)
.tint(.accentColor)
.frame(width: 40)
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .trailing)
}
}
.frame(
width: isExpanded ? max(60, vm.effectiveClosedNotchHeight) : 0,
height: vm.effectiveClosedNotchHeight - (isHovering ? 0 : 12)
)
}
.frame(height: vm.effectiveClosedNotchHeight + (isHovering ? 8 : 0))
.onAppear {
withAnimation(.smooth(duration: 0.35)) {
isExpanded = true
}
}
.onChange(of: downloadManager.isDownloading) { _, newValue in
withAnimation(.smooth(duration: 0.35)) {
isExpanded = newValue
}
}
}
}

View file

@ -0,0 +1,28 @@
import SwiftUI
struct SpinningCircleDownloadView: View {
@State private var isRotating = false
var body: some View {
ZStack {
// Gray track
Circle()
.stroke(Color.gray.opacity(0.3), lineWidth: 3.5)
// Blue spinning segment
Circle()
.trim(from: 0, to: 0.25)
.stroke(
Color.accentColor,
style: StrokeStyle(lineWidth: 3.5, lineCap: .round)
)
.rotationEffect(Angle(degrees: isRotating ? 360 : 0))
.onAppear {
withAnimation(.linear(duration: 1).repeatForever(autoreverses: false)) {
isRotating = true
}
}
}
.frame(width: 16, height: 16)
}
}

View file

@ -256,13 +256,10 @@ struct SettingsView: View {
.padding(.horizontal, 12)
List(filteredTabs, selection: selectionBinding) { tab in
let isComingSoon = tab == .downloads
NavigationLink(value: tab) {
HStack(spacing: 10) {
sidebarIcon(for: tab)
.opacity(isComingSoon ? 0.45 : 1)
Text(tab.title)
.foregroundStyle(isComingSoon ? Color.secondary : Color.primary)
if tab == .osd {
Spacer()
Text("ALPHA")
@ -274,16 +271,10 @@ struct SettingsView: View {
Capsule()
.fill(Color.orange)
)
} else if isComingSoon {
Spacer()
comingSoonTag()
}
}
.padding(.vertical, 4)
}
.tag(tab)
.disabled(isComingSoon)
.listRowInsets(EdgeInsets(top: 4, leading: 12, bottom: 4, trailing: 10))
}
.listStyle(SidebarListStyle())
.frame(minWidth: 200)
@ -310,7 +301,7 @@ struct SettingsView: View {
.frame(width: 700)
.onChange(of: searchText) { _, newValue in
let matches = tabsMatchingSearch(newValue)
guard let firstMatch = matches.first(where: { $0 != .downloads }) else { return }
guard let firstMatch = matches.first else { return }
if !matches.contains(resolvedSelection) {
selectedTab = firstMatch
}
@ -349,7 +340,6 @@ struct SettingsView: View {
Binding(
get: { resolvedSelection },
set: { newValue in
guard newValue != .downloads else { return }
selectedTab = newValue
}
)
@ -1079,78 +1069,107 @@ struct Downloads: View {
var body: some View {
Form {
warningBadge("We don't support downloads yet", "It will be supported later on.")
Section {
Defaults.Toggle("Show download progress", key: .enableDownloadListener)
.settingsHighlight(id: highlightID("Show download progress"))
.disabled(true)
Defaults.Toggle("Enable Safari Downloads", key: .enableSafariDownloads)
.settingsHighlight(id: highlightID("Enable Safari Downloads"))
.disabled(!Defaults[.enableDownloadListener])
Picker("Download indicator style", selection: $selectedDownloadIndicatorStyle) {
Text("Progress bar")
.tag(DownloadIndicatorStyle.progress)
Text("Percentage")
.tag(DownloadIndicatorStyle.percentage)
Defaults.Toggle("Enable download detection", key: .enableDownloadListener)
.settingsHighlight(id: highlightID("Enable download detection"))
VStack(alignment: .leading, spacing: 12) {
Text("Download indicator style")
.font(.system(size: 13, weight: .semibold))
.foregroundStyle(.white)
HStack(spacing: 16) {
DownloadStyleButton(
style: .progress,
isSelected: selectedDownloadIndicatorStyle == .progress,
disabled: !Defaults[.enableDownloadListener]
) {
selectedDownloadIndicatorStyle = .progress
}
DownloadStyleButton(
style: .circle,
isSelected: selectedDownloadIndicatorStyle == .circle,
disabled: !Defaults[.enableDownloadListener]
) {
selectedDownloadIndicatorStyle = .circle
}
}
}
.settingsHighlight(id: highlightID("Download indicator style"))
Picker("Download icon style", selection: $selectedDownloadIconStyle) {
Text("Only app icon")
.tag(DownloadIconStyle.onlyAppIcon)
Text("Only download icon")
.tag(DownloadIconStyle.onlyIcon)
Text("Both")
.tag(DownloadIconStyle.iconAndAppIcon)
}
.settingsHighlight(id: highlightID("Download icon style"))
} header: {
HStack {
Text("Download indicators")
comingSoonTag()
}
}
Section {
List {
ForEach([].indices, id: \.self) { index in
Text("\(index)")
}
}
.frame(minHeight: 96)
.overlay {
if true {
Text("No excluded apps")
.foregroundStyle(Color(.secondaryLabelColor))
}
}
.actionBar(padding: 0) {
Group {
Button {} label: {
Image(systemName: "plus")
.frame(width: 25, height: 16, alignment: .center)
.contentShape(Rectangle())
.foregroundStyle(.secondary)
}
Divider()
Button {} label: {
Image(systemName: "minus")
.frame(width: 20, height: 16, alignment: .center)
.contentShape(Rectangle())
.foregroundStyle(.secondary)
}
}
}
} header: {
HStack(spacing: 4) {
Text("Exclude apps")
comingSoonTag()
}
Text("Download Detection")
} footer: {
Text("Monitor your Downloads folder for Chromium-style downloads (.crdownload files) and show a live activity in the Dynamic Island while downloads are in progress.")
}
}
.navigationTitle("Downloads")
.disabled(true)
.opacity(0.6)
}
struct DownloadStyleButton: View {
let style: DownloadIndicatorStyle
let isSelected: Bool
let disabled: Bool
let action: () -> Void
@State private var isHovering = false
var body: some View {
VStack(spacing: 8) {
ZStack {
RoundedRectangle(cornerRadius: 12)
.fill(backgroundColor)
.overlay(
RoundedRectangle(cornerRadius: 12)
.strokeBorder(borderColor, lineWidth: isSelected ? 2 : 1)
)
if style == .progress {
ProgressView()
.progressViewStyle(.linear)
.tint(.accentColor)
.frame(width: 40)
} else {
SpinningCircleDownloadView()
}
}
.frame(width: 80, height: 60)
.onHover { hovering in
if !disabled {
withAnimation(.easeInOut(duration: 0.2)) {
isHovering = hovering
}
}
}
Text(style.rawValue)
.font(.caption)
.fontWeight(.medium)
.lineLimit(2)
.multilineTextAlignment(.center)
.frame(width: 100)
.foregroundStyle(disabled ? .secondary : .primary)
}
.contentShape(Rectangle())
.onTapGesture {
if !disabled {
action()
}
}
.opacity(disabled ? 0.5 : 1.0)
}
private var backgroundColor: Color {
if disabled { return Color(nsColor: .controlBackgroundColor) }
if isSelected { return Color.accentColor.opacity(0.1) }
if isHovering { return Color.primary.opacity(0.05) }
return Color(nsColor: .controlBackgroundColor)
}
private var borderColor: Color {
if isSelected { return Color.accentColor }
if isHovering { return Color.primary.opacity(0.1) }
return Color.clear
}
}
}