-
Notifications
You must be signed in to change notification settings - Fork 93
feat: add download button for attached videos #5042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,9 +19,10 @@ struct InlineVideoAttachmentView: View { | |
| @State private var isLoading = false | ||
| @State private var failed = false | ||
| @State private var videoAspectRatio: CGFloat = 3.0 / 4.0 | ||
| @State private var isHovering = false | ||
|
|
||
| var body: some View { | ||
| ZStack { | ||
| ZStack(alignment: .topTrailing) { | ||
| RoundedRectangle(cornerRadius: VRadius.md) | ||
| .fill(VColor.surface) | ||
| .overlay( | ||
|
|
@@ -39,9 +40,22 @@ struct InlineVideoAttachmentView: View { | |
| } else { | ||
| placeholderView | ||
| } | ||
|
|
||
| if !failed && !isLoading && isHovering { | ||
| Button(action: saveVideo) { | ||
| Image(systemName: "arrow.down.circle.fill") | ||
| .font(.system(size: 24)) | ||
| .foregroundStyle(.white) | ||
| .shadow(radius: 2) | ||
| } | ||
| .buttonStyle(.plain) | ||
| .padding(VSpacing.sm) | ||
| .accessibilityLabel("Save video") | ||
| } | ||
| } | ||
| .frame(maxWidth: 360) | ||
| .aspectRatio(videoAspectRatio, contentMode: .fit) | ||
| .onHover { isHovering = $0 } | ||
| .onDisappear { | ||
| player?.pause() | ||
| player = nil | ||
|
|
@@ -162,6 +176,34 @@ struct InlineVideoAttachmentView: View { | |
| } | ||
| } | ||
|
|
||
| private func saveVideo() { | ||
| let panel = NSSavePanel() | ||
| panel.nameFieldStringValue = (attachment.filename as NSString).lastPathComponent | ||
| panel.canCreateDirectories = true | ||
| guard panel.runModal() == .OK, let destURL = panel.url else { return } | ||
|
|
||
| if attachment.isLazyLoad { | ||
| guard let port = daemonHttpPort, let attachmentId = attachment.id.isEmpty ? nil : attachment.id else { return } | ||
| isLoading = true | ||
| Task { | ||
| do { | ||
| let base64 = try await fetchAttachmentData(port: port, attachmentId: attachmentId) | ||
| guard let data = Data(base64Encoded: base64) else { | ||
| await MainActor.run { isLoading = false } | ||
| return | ||
| } | ||
| try data.write(to: destURL) | ||
| await MainActor.run { isLoading = false } | ||
| } catch { | ||
| await MainActor.run { isLoading = false } | ||
| } | ||
| } | ||
| } else { | ||
| guard let data = Data(base64Encoded: attachment.data) else { return } | ||
| try? data.write(to: destURL) | ||
|
Comment on lines
+202
to
+203
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In the non-lazy attachment path, both Useful? React with 👍 / 👎. |
||
| } | ||
| } | ||
|
|
||
| private func openInExternalPlayer() { | ||
| if attachment.isLazyLoad { | ||
| guard let port = daemonHttpPort, let attachmentId = attachment.id.isEmpty ? nil : attachment.id else { return } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 saveVideo() sets isLoading=true which hides the active video player during save
When a user is watching a lazy-loaded video and clicks the save button,
saveVideo()setsisLoading = trueat line 187. Because the view body uses anif/else ifchain (InlineVideoAttachmentView.swift:32-42), theisLoadingbranch takes priority over theplayer/isPlayingbranch, causing the video player to be replaced by a "Loading video..." spinner while the save is in progress.Root Cause and Impact
The
isLoadingstate is shared between two different operations: initial video loading for playback and the save/download operation. WhensaveVideo()setsisLoading = trueat line 187, the view body at lines 34-36 showsloadingViewinstead of theVideoPlayerView:This means clicking "Save video" on an already-playing lazy-loaded video will:
Impact: The video playback is visually disrupted every time the user saves a lazy-loaded video. The save operation should use a separate state (e.g.
isSaving) or avoid settingisLoadingaltogether, since the save can happen in the background without affecting the UI.Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.