From 7f2bf2e905977aec403d7a793013b2c485f39556 Mon Sep 17 00:00:00 2001 From: stax76 Date: Wed, 20 Dec 2023 05:19:50 +0100 Subject: [PATCH] misc --- docs/changelog.md | 1 + src/MpvNet.Windows/Help/WinMpvHelp.cs | 12 +- src/MpvNet.Windows/Resources/editor_conf.txt | 8 +- src/MpvNet.Windows/WPF/ConfWindow.xaml.cs | 120 +++++++++---------- src/MpvNet.Windows/WinForms/MainForm.cs | 12 +- src/MpvNet/Player.cs | 2 +- src/MpvNet/Settings.cs | 1 + 7 files changed, 80 insertions(+), 76 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 8207b9b..0bb42b3 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -3,6 +3,7 @@ - Command line parser fix using list options with `-add` suffix. + # v7.0.0.4 Beta (2023-12-19) - When mpv.net is started for the first time from a new startup location, diff --git a/src/MpvNet.Windows/Help/WinMpvHelp.cs b/src/MpvNet.Windows/Help/WinMpvHelp.cs index 10750d1..22cf939 100644 --- a/src/MpvNet.Windows/Help/WinMpvHelp.cs +++ b/src/MpvNet.Windows/Help/WinMpvHelp.cs @@ -8,14 +8,10 @@ public class WinMpvHelp { public static void Setup() { - string dir = RegistryHelp.GetString("PathEnvVarCheck"); // backward compatibility + if (RegistryHelp.GetString("PathEnvVarCheck") == Folder.Startup || + RegistryHelp.GetString("Setup") == Folder.Startup || + App.Settings.StartupFolder == Folder.Startup) - if (dir == Folder.Startup) - return; - - dir = RegistryHelp.GetString("Setup"); - - if (dir == Folder.Startup) return; string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User)!; @@ -53,6 +49,6 @@ public class WinMpvHelp Msg.ShowInfo("If you want to register file associations later," + BR + "you can do so with the context menu (Settings/Setup)."); - RegistryHelp.SetString("Setup", Folder.Startup); + App.Settings.StartupFolder = Folder.Startup; } } diff --git a/src/MpvNet.Windows/Resources/editor_conf.txt b/src/MpvNet.Windows/Resources/editor_conf.txt index 043b431..44598cb 100644 --- a/src/MpvNet.Windows/Resources/editor_conf.txt +++ b/src/MpvNet.Windows/Resources/editor_conf.txt @@ -754,7 +754,7 @@ url = https://mpv.io/manual/master/#options-input-ipc-server name = language file = mpvnet default = system -directory = UI +directory = Appearance help = User interface display language.\nmpv.net must be restarted after a change.\nInterested joining our translation team?: url = https://app.transifex.com/stax76/teams/ option = system @@ -765,7 +765,7 @@ option = german name = dark-mode file = mpvnet default = always -directory = UI +directory = Appearance help = Changes between a light and dark theme.\nmpv.net must be restarted after a change.\nmpv.net specific option. option = always option = system Available on Windows 10 or higher @@ -773,13 +773,13 @@ option = never name = dark-theme file = mpvnet -directory = UI +directory = Appearance url = https://github.com/mpvnet-player/mpv.net/blob/main/docs/manual.md#color-theme help = Color theme used in dark mode.\nmpv.net must be restarted after a change.\nmpv.net specific option. Default: dark name = light-theme file = mpvnet -directory = UI +directory = Appearance url = https://github.com/mpvnet-player/mpv.net/blob/main/docs/manual.md#color-theme help = Color theme used in light mode.\nmpv.net must be restarted after a change.\nmpv.net specific option. Default: light diff --git a/src/MpvNet.Windows/WPF/ConfWindow.xaml.cs b/src/MpvNet.Windows/WPF/ConfWindow.xaml.cs index dbb5c96..9d237d3 100644 --- a/src/MpvNet.Windows/WPF/ConfWindow.xaml.cs +++ b/src/MpvNet.Windows/WPF/ConfWindow.xaml.cs @@ -22,11 +22,11 @@ public partial class ConfWindow : Window, INotifyPropertyChanged { List Settings = Conf.LoadConf(Properties.Resources.editor_conf.TrimEnd()); List ConfItems = new List(); - public ObservableCollection FilterStrings { get; } = new(); string InitialContent; string ThemeConf = GetThemeConf(); string? _searchText; List? _nodes; + bool _shown; public event PropertyChangedEventHandler? PropertyChanged; public ConfWindow() @@ -51,6 +51,8 @@ public partial class ConfWindow : Window, INotifyPropertyChanged node.IsExpanded = true; } + public ObservableCollection FilterStrings { get; } = new(); + public Theme? Theme => Theme.Current; public string SearchText @@ -162,64 +164,6 @@ public partial class ConfWindow : Window, INotifyPropertyChanged static string GetThemeConf() => Theme.DarkMode + App.DarkTheme + App.LightTheme; - protected override void OnClosed(EventArgs e) - { - base.OnClosed(e); - App.Settings.ConfigEditorSearch = SearchText; - - if (InitialContent == GetCompareString()) - return; - - foreach (Setting setting in Settings) - { - if (setting.Name == "libplacebo-opts") - { - setting.Value = GetKeyValueContent("libplacebo"); - break; - } - } - - File.WriteAllText(Player.ConfPath, GetContent("mpv")); - File.WriteAllText(App.ConfPath, GetContent("mpvnet")); - - foreach (Setting it in Settings) - { - if (it.Value != it.StartValue) - { - if (it.File == "mpv") - { - Player.ProcessProperty(it.Name, it.Value); - Player.SetPropertyString(it.Name!, it.Value!); - } - else if (it.File == "mpvnet") - App.ProcessProperty(it.Name ?? "", it.Value ?? "", true); - } - } - - Theme.Init(); - Theme.UpdateWpfColors(); - - if (ThemeConf != GetThemeConf()) - MessageBox.Show("Changed theme settings require mpv.net being restarted.", "Info"); - } - - bool _shown; - - protected override void OnContentRendered(EventArgs e) - { - base.OnContentRendered(e); - - if (_shown) - return; - - _shown = true; - - Application.Current.Dispatcher.BeginInvoke(() => { - SearchControl.SearchTextBox.SelectAll(); - }, - DispatcherPriority.Background); - } - string GetCompareString() => string.Join("", Settings.Select(item => item.Name + item.Value).ToArray()); void LoadConf(string file) @@ -466,6 +410,47 @@ public partial class ConfWindow : Window, INotifyPropertyChanged i.Update(); } + protected override void OnClosed(EventArgs e) + { + base.OnClosed(e); + App.Settings.ConfigEditorSearch = SearchText; + + if (InitialContent == GetCompareString()) + return; + + foreach (Setting setting in Settings) + { + if (setting.Name == "libplacebo-opts") + { + setting.Value = GetKeyValueContent("libplacebo"); + break; + } + } + + File.WriteAllText(Player.ConfPath, GetContent("mpv")); + File.WriteAllText(App.ConfPath, GetContent("mpvnet")); + + foreach (Setting it in Settings) + { + if (it.Value != it.StartValue) + { + if (it.File == "mpv") + { + Player.ProcessProperty(it.Name, it.Value); + Player.SetPropertyString(it.Name!, it.Value!); + } + else if (it.File == "mpvnet") + App.ProcessProperty(it.Name ?? "", it.Value ?? "", true); + } + } + + Theme.Init(); + Theme.UpdateWpfColors(); + + if (ThemeConf != GetThemeConf()) + MessageBox.Show("Changed theme settings require mpv.net being restarted.", "Info"); + } + protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); @@ -480,9 +465,22 @@ public partial class ConfWindow : Window, INotifyPropertyChanged } } - protected void OnPropertyChanged([CallerMemberName] string? name = null) - { + protected void OnPropertyChanged([CallerMemberName] string? name = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); + + protected override void OnContentRendered(EventArgs e) + { + base.OnContentRendered(e); + + if (_shown) + return; + + _shown = true; + + Application.Current.Dispatcher.BeginInvoke(() => { + SearchControl.SearchTextBox.SelectAll(); + }, + DispatcherPriority.Background); } void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs e) diff --git a/src/MpvNet.Windows/WinForms/MainForm.cs b/src/MpvNet.Windows/WinForms/MainForm.cs index 2d11763..35bf58c 100644 --- a/src/MpvNet.Windows/WinForms/MainForm.cs +++ b/src/MpvNet.Windows/WinForms/MainForm.cs @@ -48,8 +48,7 @@ public partial class MainForm : Form { InitializeComponent(); - if (Environment.OSVersion.Version >= new Version(10, 0, 18985) && Theme.DarkMode) - DwmSetWindowAttribute(Handle, 20, new[] { 1 }, 4); // DWMWA_USE_IMMERSIVE_DARK_MODE = 20 + UpdateDarkMode(); try { @@ -125,6 +124,12 @@ public partial class MainForm : Form } } + void UpdateDarkMode() + { + if (Environment.OSVersion.Version >= new Version(10, 0, 18985)) + DwmSetWindowAttribute(Handle, 20, new[] { Theme.DarkMode ? 1 : 0 }, 4); // DWMWA_USE_IMMERSIVE_DARK_MODE = 20 + } + void Player_ClientMessage(string[] args) { if (Command.Current.Commands.ContainsKey(args[0])) @@ -1007,6 +1012,9 @@ public partial class MainForm : Form m.Result = SendMessage(MpvWindowHandle, m.Msg, m.WParam, m.LParam); } break; + case 0x001A: // WM_SETTINGCHANGE + UpdateDarkMode(); + break; case 0x51: // WM_INPUTLANGCHANGE ActivateKeyboardLayout(m.LParam, 0x00000100u /*KLF_SETFORPROCESS*/); break; diff --git a/src/MpvNet/Player.cs b/src/MpvNet/Player.cs index 7fc28cd..b490714 100644 --- a/src/MpvNet/Player.cs +++ b/src/MpvNet/Player.cs @@ -435,7 +435,7 @@ public class MainPlayer : MpvClient { string name = pair.Name[..^4]; string separator = name.Contains("-file") || name.Contains("-path") ? ";" : ","; - SetPropertyString(name, (GetPropertyString(name) + separator + pair.Value).TrimStart(',')); + SetPropertyString(name, (GetPropertyString(name) + separator + pair.Value).TrimStart(',', ';')); } } } diff --git a/src/MpvNet/Settings.cs b/src/MpvNet/Settings.cs index 2c8d6b6..ae8d257 100644 --- a/src/MpvNet/Settings.cs +++ b/src/MpvNet/Settings.cs @@ -18,6 +18,7 @@ public class AppSettings public Size WindowSize; public string ConfigEditorSearch = "Video:"; public string Mute = "no"; + public string StartupFolder = ""; } class SettingsManager