From 512c617409e2b03c377b6f4e93186faee9abdb15 Mon Sep 17 00:00:00 2001 From: godly-devotion Date: Mon, 18 Mar 2024 20:06:05 -0400 Subject: [PATCH] feat: show playing file in Finder --- Front Row/FrontRowApp.swift | 4 +++- Front Row/Localizable.xcstrings | 3 +++ Front Row/Main Menu/FileCommands.swift | 15 +++++++++++++++ Front Row/Support/PlayEngine.swift | 3 +++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Front Row/FrontRowApp.swift b/Front Row/FrontRowApp.swift index 10f8843..66fe7c4 100644 --- a/Front Row/FrontRowApp.swift +++ b/Front Row/FrontRowApp.swift @@ -51,7 +51,9 @@ struct FrontRowApp: App { .windowStyle(.hiddenTitleBar) .commands { AppCommands(updater: updaterController.updater) - FileCommands(isPresentingOpenURLView: $isPresentingOpenURLView) + FileCommands( + playEngine: $playEngine, + isPresentingOpenURLView: $isPresentingOpenURLView) ViewCommands(windowController: $windowController) PlaybackCommands( playEngine: $playEngine, diff --git a/Front Row/Localizable.xcstrings b/Front Row/Localizable.xcstrings index 1335747..17d3370 100644 --- a/Front Row/Localizable.xcstrings +++ b/Front Row/Localizable.xcstrings @@ -2163,6 +2163,9 @@ } } }, + "Show in Finder" : { + "comment" : "Show the currently playing file using Finder" + }, "Step Backward 5s" : { "localizations" : { "ar" : { diff --git a/Front Row/Main Menu/FileCommands.swift b/Front Row/Main Menu/FileCommands.swift index 5cdf63d..b97d16a 100644 --- a/Front Row/Main Menu/FileCommands.swift +++ b/Front Row/Main Menu/FileCommands.swift @@ -5,9 +5,11 @@ // Created by Joshua Park on 3/4/24. // +import AVKit import SwiftUI struct FileCommands: Commands { + @Binding var playEngine: PlayEngine @Binding var isPresentingOpenURLView: Bool var body: some Commands { @@ -33,6 +35,19 @@ struct FileCommands: Commands { } .keyboardShortcut("L", modifiers: [.command]) } + Section { + Button { + guard let item = PlayEngine.shared.player.currentItem else { return } + guard let asset = item.asset as? AVURLAsset else { return } + NSWorkspace.shared.activateFileViewerSelecting([asset.url]) + } label: { + Text( + "Show in Finder", + comment: "Show the currently playing file in Finder" + ) + } + .disabled(!playEngine.isPlayingLocalFile) + } } } } diff --git a/Front Row/Support/PlayEngine.swift b/Front Row/Support/PlayEngine.swift index 18d3599..2f27b9d 100644 --- a/Front Row/Support/PlayEngine.swift +++ b/Front Row/Support/PlayEngine.swift @@ -18,6 +18,8 @@ import SwiftUI var isPlaying = false + var isPlayingLocalFile = false + var isMuted: Bool { get { access(keyPath: \.isMuted) @@ -113,6 +115,7 @@ import SwiftUI player.play() isLoaded = true + isPlayingLocalFile = FileManager.default.fileExists(atPath: url.path(percentEncoded: false)) } func playPause() {