mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-28 15:44:32 +00:00
implement download feature
This commit is contained in:
parent
805f367c44
commit
fc82d5fe05
10 changed files with 533 additions and 78 deletions
103
DynamicIsland/components/Downloads/DownloadLiveActivity.swift
Normal file
103
DynamicIsland/components/Downloads/DownloadLiveActivity.swift
Normal 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
|
||||
@ObservedObject 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue