@@ -207,7 +207,7 @@ class SessionActionsViewController: NSViewController {
207
207
/// This publisher includes a flag indicating whether the session can be downloaded, as well as the current download state, if any.
208
208
let downloadButtonConfig : AnyPublisher < DownloadButtonConfig , Never > = Publishers . CombineLatest ( inFlightDownloadSignal, alreadyDownloaded)
209
209
. map { inFlightDownload, session in
210
- if session. isDownloaded {
210
+ if session. isDownloaded, MediaDownloadManager . shared . hasDownloadedMedia ( for : session ) {
211
211
return DownloadButtonConfig ( hasDownloadableContent: true , isDownloaded: true )
212
212
} else {
213
213
guard !session. assets ( matching: Session . mediaDownloadVariants) . isEmpty else {
@@ -253,13 +253,36 @@ class SessionActionsViewController: NSViewController {
253
253
updateDownloadButton ( with: nil )
254
254
return
255
255
}
256
-
256
+
257
257
downloadStateCancellable = inFlightDownload. $state. receive ( on: DispatchQueue . main) . sink { [ weak self] state in
258
258
self ? . updateDownloadButton ( with: state)
259
259
}
260
260
}
261
261
262
262
private func updateDownloadButton( with state: MediaDownloadState ? ) {
263
+ guard let session = viewModel? . session else { return }
264
+
265
+ func applyStartDownloadState( ) {
266
+ resetDownloadButton ( )
267
+ downloadIndicator. isHidden = true
268
+ downloadButton. isHidden = false
269
+ clipButton. isHidden = true
270
+ if case . failed( let message) = state {
271
+ downloadButton. toolTip = message
272
+ } else {
273
+ downloadButton. toolTip = nil
274
+ }
275
+ }
276
+
277
+ /// We may have a download that's in completed state, but where the file has already been deleted,
278
+ /// in which case we show the button state to start the download.
279
+ if case . completed = state {
280
+ guard MediaDownloadManager . shared. hasDownloadedMedia ( for: session) else {
281
+ applyStartDownloadState ( )
282
+ return
283
+ }
284
+ }
285
+
263
286
switch state {
264
287
case . waiting:
265
288
downloadIndicator. isHidden = false
@@ -282,15 +305,7 @@ class SessionActionsViewController: NSViewController {
282
305
downloadIndicator. progress = Float ( progress)
283
306
}
284
307
case . paused, . cancelled, . none, . failed:
285
- resetDownloadButton ( )
286
- downloadIndicator. isHidden = true
287
- downloadButton. isHidden = false
288
- clipButton. isHidden = true
289
- if case . failed( let message) = state {
290
- downloadButton. toolTip = message
291
- } else {
292
- downloadButton. toolTip = nil
293
- }
308
+ applyStartDownloadState ( )
294
309
case . completed:
295
310
downloadButton. toolTip = " Delete downloaded video "
296
311
downloadButton. isHidden = false
0 commit comments