mirror of
https://github.com/yattee/yattee.git
synced 2024-12-13 22:00:31 +05:30
Add MPV logs export
This commit is contained in:
parent
e0a862fb36
commit
36363628d4
@ -8,6 +8,10 @@ import Logging
|
||||
#endif
|
||||
|
||||
final class MPVClient: ObservableObject {
|
||||
static var logFile: URL {
|
||||
YatteeApp.logsDirectory.appendingPathComponent("yattee-\(YatteeApp.build)-mpv-log.txt")
|
||||
}
|
||||
|
||||
private var logger = Logger(label: "mpv-client")
|
||||
|
||||
var mpv: OpaquePointer!
|
||||
@ -36,11 +40,20 @@ final class MPVClient: ObservableObject {
|
||||
exit(1)
|
||||
}
|
||||
|
||||
if Defaults[.mpvEnableLogging] {
|
||||
checkError(mpv_set_option_string(
|
||||
mpv,
|
||||
"log-file",
|
||||
Self.logFile.absoluteString.replacingOccurrences(of: "file://", with: "")
|
||||
))
|
||||
checkError(mpv_request_log_messages(mpv, "debug"))
|
||||
} else {
|
||||
#if DEBUG
|
||||
checkError(mpv_request_log_messages(mpv, "debug"))
|
||||
#else
|
||||
checkError(mpv_request_log_messages(mpv, "warn"))
|
||||
checkError(mpv_request_log_messages(mpv, "no"))
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
checkError(mpv_set_option_string(mpv, "input-media-keys", "yes"))
|
||||
|
@ -101,6 +101,7 @@ extension Defaults.Keys {
|
||||
|
||||
static let mpvCacheSecs = Key<String>("mpvCacheSecs", default: "20")
|
||||
static let mpvCachePauseWait = Key<String>("mpvCachePauseWait", default: "2")
|
||||
static let mpvEnableLogging = Key<Bool>("mpvEnableLogging", default: false)
|
||||
}
|
||||
|
||||
enum ResolutionSetting: String, CaseIterable, Defaults.Serializable {
|
||||
|
@ -6,6 +6,12 @@ struct AdvancedSettings: View {
|
||||
@Default(.showMPVPlaybackStats) private var showMPVPlaybackStats
|
||||
@Default(.mpvCacheSecs) private var mpvCacheSecs
|
||||
@Default(.mpvCachePauseWait) private var mpvCachePauseWait
|
||||
@Default(.mpvEnableLogging) private var mpvEnableLogging
|
||||
|
||||
@EnvironmentObject<PlayerModel> private var player
|
||||
|
||||
@State private var presentingShareSheet = false
|
||||
@State private var filesToShare = [MPVClient.logFile]
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading) {
|
||||
@ -17,6 +23,10 @@ struct AdvancedSettings: View {
|
||||
advancedSettings
|
||||
}
|
||||
#if os(iOS)
|
||||
.sheet(isPresented: $presentingShareSheet) {
|
||||
ShareSheet(activityItems: filesToShare)
|
||||
.id("logs-\(filesToShare.count)")
|
||||
}
|
||||
.listStyle(.insetGrouped)
|
||||
#endif
|
||||
#endif
|
||||
@ -27,9 +37,29 @@ struct AdvancedSettings: View {
|
||||
.navigationTitle("Advanced")
|
||||
}
|
||||
|
||||
var logButton: some View {
|
||||
Button {
|
||||
#if os(macOS)
|
||||
NSWorkspace.shared.selectFile(MPVClient.logFile.path, inFileViewerRootedAtPath: YatteeApp.logsDirectory.path)
|
||||
#else
|
||||
presentingShareSheet = true
|
||||
#endif
|
||||
} label: {
|
||||
#if os(macOS)
|
||||
let labelText = "Open logs in Finder"
|
||||
#else
|
||||
let labelText = "Share Logs..."
|
||||
#endif
|
||||
Text(labelText)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder var advancedSettings: some View {
|
||||
Section(header: SettingsHeader(text: "MPV"), footer: mpvFooter) {
|
||||
showMPVPlaybackStatsToggle
|
||||
#if !os(tvOS)
|
||||
mpvEnableLoggingToggle
|
||||
#endif
|
||||
|
||||
HStack {
|
||||
Text("cache-secs")
|
||||
@ -44,6 +74,10 @@ struct AdvancedSettings: View {
|
||||
TextField("cache-pause-wait", text: $mpvCachePauseWait)
|
||||
}
|
||||
.multilineTextAlignment(.trailing)
|
||||
|
||||
if mpvEnableLogging {
|
||||
logButton
|
||||
}
|
||||
}
|
||||
|
||||
Section(header: manifestHeader) {
|
||||
@ -85,6 +119,10 @@ struct AdvancedSettings: View {
|
||||
Toggle("Show playback statistics", isOn: $showMPVPlaybackStats)
|
||||
}
|
||||
|
||||
var mpvEnableLoggingToggle: some View {
|
||||
Toggle("Enable logging", isOn: $mpvEnableLogging)
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
private func onHover(_ inside: Bool) {
|
||||
if inside {
|
||||
|
@ -226,7 +226,7 @@ struct SettingsView: View {
|
||||
case .locations:
|
||||
return 480
|
||||
case .advanced:
|
||||
return 300
|
||||
return 320
|
||||
case .help:
|
||||
return 600
|
||||
}
|
||||
|
@ -20,6 +20,10 @@ struct YatteeApp: App {
|
||||
ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
|
||||
}
|
||||
|
||||
static var logsDirectory: URL {
|
||||
URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
|
||||
}
|
||||
|
||||
#if os(macOS)
|
||||
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
||||
#elseif os(iOS)
|
||||
|
Loading…
Reference in New Issue
Block a user