From 24596626bd99d0b54672b0a5f51c712e3cc2328f Mon Sep 17 00:00:00 2001 From: stax76 Date: Mon, 11 Oct 2021 12:29:30 +0200 Subject: [PATCH] misc --- src/Misc/App.cs | 19 ++++++---- src/Misc/CorePlayer.cs | 81 ++++++++++++++++++++++++++---------------- src/Misc/Settings.cs | 5 ++- 3 files changed, 65 insertions(+), 40 deletions(-) diff --git a/src/Misc/App.cs b/src/Misc/App.cs index 30e79fb..90b7afc 100644 --- a/src/Misc/App.cs +++ b/src/Misc/App.cs @@ -37,9 +37,7 @@ namespace mpvnet public static Extension Extension { get; set; } - public static bool IsDarkMode { - get => (DarkMode == "system" && Sys.IsDarkTheme) || DarkMode == "always"; - } + public static bool IsDarkMode => (DarkMode == "system" && Sys.IsDarkTheme) || DarkMode == "always"; static AppSettings _Settings; @@ -143,13 +141,22 @@ namespace mpvnet else { if (obj is Exception e) - Msg.ShowException(e); + InvokeOnMainThread(() => Msg.ShowException(e)); else - Msg.ShowError(obj.ToString()); + InvokeOnMainThread(() => Msg.ShowError(obj.ToString())); } } - public static void InvokeOnMainThread(Action action) => MainForm.Instance.BeginInvoke(action); + public static void InvokeOnMainThread(Action action) + { + if (action == null) + return; + + if (MainForm.Instance == null) + action.Invoke(); + else + MainForm.Instance.BeginInvoke(action); + } public static void ShowInfo(string msg) { diff --git a/src/Misc/CorePlayer.cs b/src/Misc/CorePlayer.cs index 1ed85db..b0ac030 100644 --- a/src/Misc/CorePlayer.cs +++ b/src/Misc/CorePlayer.cs @@ -153,33 +153,14 @@ namespace mpvnet SetPropertyBool("keep-open", true); SetPropertyBool("keep-open-pause", false); + SetInputBindingProperties(); + ProcessCommandLine(true); mpv_error err = mpv_initialize(Handle); if (err < 0) throw new Exception("mpv_initialize error" + BR2 + GetError(err) + BR); - if (Debugger.IsAttached) - { - if (GetPropertyString("property-list").Contains("input-builtin-bindings")) - { - SetPropertyBool("input-default-bindings", true); - SetPropertyBool("input-builtin-bindings", false); - } - else - SetPropertyBool("input-default-bindings", false); - } - else - { - SetPropertyBool("input-default-bindings", true); - - try { - SetPropertyBool("input-builtin-bindings", false, true); - } catch { - SetPropertyBool("input-default-bindings", false); - } - } - ObservePropertyInt("video-rotate", value => { VideoRotate = value; UpdateVideoSize("dwidth", "dheight"); @@ -189,6 +170,49 @@ namespace mpvnet InvokeAsync(InitializedAsync); } + void SetInputBindingProperties() + { + if (Debugger.IsAttached) + { + if (GetPropertyString("property-list").Contains("input-builtin-bindings")) + throw new Exception(); + else + SetPropertyBool("input-default-bindings", false); + } + else + { + SetPropertyBool("input-default-bindings", true); + + try + { + SetPropertyBool("input-builtin-bindings", false, true); + } + catch + { + SetPropertyBool("input-default-bindings", false); + } + } + } + + void ApplyCompatibilityFixex() + { + if (!App.Settings.InputDefaultBindingsFixApplied) + { + if (File.Exists(ConfPath)) + { + string content = File.ReadAllText(ConfPath); + + if (content.Contains("input-default-bindings = no")) + File.WriteAllText(ConfPath, content.Replace("input-default-bindings = no", "")); + + if (content.Contains("input-default-bindings=no")) + File.WriteAllText(ConfPath, content.Replace("input-default-bindings=no", "")); + } + + App.Settings.InputDefaultBindingsFixApplied = true; + } + } + public void ProcessProperty(string name, string value) { switch (name) @@ -266,6 +290,8 @@ namespace mpvnet get { if (_Conf == null) { + ApplyCompatibilityFixex(); + _Conf = new Dictionary(); if (File.Exists(ConfPath)) @@ -1092,8 +1118,7 @@ namespace mpvnet } catch (Exception e) { - if (!App.IsTerminalAttached) - Msg.ShowException(e); + App.ShowException(e); } } } @@ -1356,15 +1381,9 @@ namespace mpvnet return id; } - public void RaiseScaleWindow(float value) - { - ScaleWindow(value); - } + public void RaiseScaleWindow(float value) => ScaleWindow(value); - public void RaiseWindowScale(float value) - { - WindowScale(value); - } + public void RaiseWindowScale(float value) => WindowScale(value); void ReadMetaData() { diff --git a/src/Misc/Settings.cs b/src/Misc/Settings.cs index 0dfd8ab..7a64d18 100644 --- a/src/Misc/Settings.cs +++ b/src/Misc/Settings.cs @@ -14,6 +14,7 @@ namespace mpvnet [Serializable()] public class AppSettings { + public bool InputDefaultBindingsFixApplied; public int LastUpdateCheck; public int Volume = 70; public List RecentFiles = new List(); @@ -27,9 +28,7 @@ namespace mpvnet class SettingsManager { - public static string SettingsFile { - get => Core.ConfigFolder + "settings.xml"; - } + public static string SettingsFile => Core.ConfigFolder + "settings.xml"; public static AppSettings Load() {