From 0cbe8054f89668daf039d5c2f8fdd2a5f33dc6a7 Mon Sep 17 00:00:00 2001 From: Alexey Martemyanov Date: Wed, 24 Apr 2024 22:02:03 +0600 Subject: [PATCH] Fix downloads not appearing (#2693) Task/Issue URL: https://app.asana.com/0/1177771139624306/1207138015653734/f --- .../View/NavigationBarViewController.swift | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/DuckDuckGo/NavigationBar/View/NavigationBarViewController.swift b/DuckDuckGo/NavigationBar/View/NavigationBarViewController.swift index dc181f12b1..582a8b4f28 100644 --- a/DuckDuckGo/NavigationBar/View/NavigationBarViewController.swift +++ b/DuckDuckGo/NavigationBar/View/NavigationBarViewController.swift @@ -644,15 +644,20 @@ final class NavigationBarViewController: NSViewController { private func subscribeToDownloads() { downloadListCoordinator.updates + .filter { update in + // filter download completion events only + if case .updated(let oldValue) = update.kind, + oldValue.progress != nil && update.item.progress == nil { + return true + } else { + return false + } + } .throttle(for: 1.0, scheduler: DispatchQueue.main, latest: true) .sink { [weak self] update in guard let self else { return } - if case .updated(let oldValue) = update.kind, - DownloadsPreferences.shared.shouldOpenPopupOnCompletion, - update.item.destinationURL != nil, - update.item.tempURL == nil, - oldValue.tempURL != nil, // download finished + if DownloadsPreferences.shared.shouldOpenPopupOnCompletion, !update.item.isBurner, WindowControllersManager.shared.lastKeyMainWindowController?.window === downloadsButton.window { @@ -661,11 +666,11 @@ final class NavigationBarViewController: NSViewController { downloadsDelegate: self) } else if update.item.isBurner { invalidateDownloadButtonHidingTimer() - updateDownloadsButton(updatingFromPinnedViewsNotification: false) } updateDownloadsButton() } .store(in: &downloadsCancellables) + downloadListCoordinator.progress.publisher(for: \.totalUnitCount) .combineLatest(downloadListCoordinator.progress.publisher(for: \.completedUnitCount)) .throttle(for: 0.2, scheduler: DispatchQueue.main, latest: true)