A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.
Rust archive-managerdesktop-appdual-paneexplorer-alternativefile-browserfile-explorerfile-managerfluent-designgpu-acceleratedgpuimacosmicaproductivityquick-lookrustrust-guitabswindowswindows-11windows-explorer
Show progress while ejecting volumes on macOS
sunzhaozheng23964a3f9add
diff --git a/macos/Localization/zh-Hans.json b/macos/Localization/zh-Hans.jsonindex d6c8ce1e..a4b32165 100644--- a/macos/Localization/zh-Hans.json+++ b/macos/Localization/zh-Hans.json@@ -345,6 +345,7 @@"Move here": "移到此处","Hide this place": "隐藏此位置","Eject": "弹出",+"Ejecting…": "正在弹出…","Stop": "停止","Make sure both devices show the same code. Paired devices can send each other files without asking.": "请确认两台设备显示的代码相同。已配对的设备之间可以直接互传文件,无需再次询问。","No devices nearby": "附近没有设备",diff --git a/macos/Localization/zh-Hant.json b/macos/Localization/zh-Hant.jsonindex 1118c622..5b87b8a8 100644--- a/macos/Localization/zh-Hant.json+++ b/macos/Localization/zh-Hant.json@@ -345,6 +345,7 @@"Move here": "移至此處","Hide this place": "隱藏此位置","Eject": "退出",+"Ejecting…": "正在退出…","Stop": "停止","Make sure both devices show the same code. Paired devices can send each other files without asking.": "請確認兩部裝置顯示相同的代碼。已配對的裝置之間可以互相傳送檔案,無需再詢問。","No devices nearby": "附近沒有裝置",diff --git a/macos/Sources/RustyFiles/BrowserWindowController.swift b/macos/Sources/RustyFiles/BrowserWindowController.swiftindex 273bb70a..dd83aeb9 100644--- a/macos/Sources/RustyFiles/BrowserWindowController.swift+++ b/macos/Sources/RustyFiles/BrowserWindowController.swift@@ -1045,11 +1045,13 @@ final class BrowserWindowController: NSWindowController, NSWindowDelegate, NSMen/// Failed ejects don't change the current location; successful unmounts notify all windows.func eject(_ volume: URL) {+ guard SidebarView.beginEject(volume) else { return }// The directory watcher holds an open descriptor that can prevent ejecting.watcher = nilTask.detached(priority: .userInitiated) {let result = Result { try NSWorkspace.shared.unmountAndEjectDevice(at: volume) }await MainActor.run { [weak self] in+ SidebarView.endEject(volume)switch result {case .success:for controller in AppDelegate.shared.controllers { controller.volumeDidUnmount(volume) }diff --git a/macos/Sources/RustyFiles/Sidebar.swift b/macos/Sources/RustyFiles/Sidebar.swiftindex c2f0d8df..4eb16425 100644--- a/macos/Sources/RustyFiles/Sidebar.swift+++ b/macos/Sources/RustyFiles/Sidebar.swift@@ -93,6 +93,24 @@ final class SidebarView: FlippedView {var onSelect: ((Item) -> Void)?var onEject: ((URL) -> Void)?++ private static let ejectStateChanged = Notification.Name("rfSidebarEjectStateChanged")+ private static var ejecting: Set<String> = []++ static func isEjecting(_ volume: URL) -> Bool { ejecting.contains(volume.standardizedFileURL.path) }++ static func beginEject(_ volume: URL) -> Bool {+ guard ejecting.insert(volume.standardizedFileURL.path).inserted else { return false }+ NotificationCenter.default.post(name: ejectStateChanged, object: nil)+ return true+ }++ static func endEject(_ volume: URL) {+ ejecting.remove(volume.standardizedFileURL.path)+ NotificationCenter.default.post(name: ejectStateChanged, object: nil)+ }++ @objc private func refreshEjectIndicators() { list.refreshEjectIndicators() }var onOpenInNewTab: ((URL) -> Void)?var onOpenInNewWindow: ((URL) -> Void)?var onDiskUsage: ((URL) -> Void)?@@ -156,6 +174,7 @@ final class SidebarView: FlippedView {for name in [NSWorkspace.didMountNotification, NSWorkspace.didUnmountNotification, NSWorkspace.didRenameVolumeNotification] {center.addObserver(self, selector: #selector(volumesChanged), name: name, object: nil)}+ NotificationCenter.default.addObserver(self, selector: #selector(refreshEjectIndicators), name: Self.ejectStateChanged, object: nil)NotificationCenter.default.addObserver(self, selector: #selector(volumesChanged), name: .rfPinsChanged, object: nil)NotificationCenter.default.addObserver(self, selector: #selector(settingsChanged(_:)), name: .rfSettingsChanged, object: nil)}@@ -293,7 +312,42 @@ final class SidebarListView: HoverView {weak var owner: SidebarView?/// The item a drag is over (drawn as a drop target).private var dropIndex: Int? { didSet { if dropIndex != oldValue { needsDisplay = true } } }- var items: [SidebarView.Item] = [] { didSet { needsDisplay = true } }+ var items: [SidebarView.Item] = [] { didSet { refreshEjectIndicators() } }+ private final class EjectIndicator: NSProgressIndicator {+ override func hitTest(_ point: NSPoint) -> NSView? { nil }+ }++ private var ejectIndicators: [String: EjectIndicator] = [:]++ func refreshEjectIndicators() {+ needsDisplay = true+ needsLayout = true+ }++ override func layout() {+ super.layout()+ let rows = rects()+ var active: Set<String> = []+ for (i, item) in items.enumerated() {+ guard item.ejectable, let url = item.url, SidebarView.isEjecting(url) else { continue }+ let path = url.standardizedFileURL.path+ active.insert(path)+ let spinner = ejectIndicators[path] ?? EjectIndicator(frame: .zero)+ spinner.frame = ejectRect(i, row: rows[i])+ if ejectIndicators[path] == nil {+ spinner.style = .spinning+ spinner.controlSize = .small+ spinner.isIndeterminate = true+ spinner.setAccessibilityLabel(String(localized: "Ejecting…"))+ addSubview(spinner)+ spinner.startAnimation(nil)+ ejectIndicators[path] = spinner+ }+ }+ for path in Set(ejectIndicators.keys).subtracting(active) {+ ejectIndicators.removeValue(forKey: path)?.removeFromSuperview()+ }+ }/// The list in the scroll view has a lens under its selected item; the bottom one draws/// the Fluent selection (fill and pill) itself.var hasLens = true@@ -492,7 +546,7 @@ final class SidebarListView: HoverView {}// (an ejectable drive's name and bar make room for its eject button)let ejectW: CGFloat = item.ejectable ? 22 : 0- if item.ejectable {+ if item.ejectable, let url = item.url, !SidebarView.isEjecting(url) {let hotEject = hoverPoint.map { ejectRect(i).contains($0) } ?? falseDraw.icon("eject", in: ejectRect(i), size: 14, color: hotEject ? p.text : p.textTertiary)}@@ -513,8 +567,8 @@ final class SidebarListView: HoverView {}/// Where an ejectable drive's eject button is: at the end of its row, centred on the name.- private func ejectRect(_ i: Int) -> NSRect {- let r = rects()[i]+ private func ejectRect(_ i: Int, row: NSRect? = nil) -> NSRect {+ let r = row ?? rects()[i]let midY = items[i].used != nil ? r.minY + 6 + 10 : r.midYreturn NSRect(x: r.maxX - 8 - 16, y: midY - 8, width: 16, height: 16)}@@ -592,7 +646,8 @@ final class SidebarListView: HoverView {if item.kind == .drive {if item.ejectable {b.separator()- b.add(String(localized: "Eject"), "eject") { owner.onEject?(url) }+ let busy = SidebarView.isEjecting(url)+ b.add(busy ? String(localized: "Ejecting…") : String(localized: "Eject"), "eject", enabled: !busy) { owner.onEject?(url) }}}return b.done()