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