From cedd54d64d3818868f7bc3fe9a7e559077396198 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Sun, 21 Jul 2019 17:06:55 +0200 Subject: [PATCH] start-threshold setting added --- Changelog.md | 5 +++- mpv.net/Misc/Misc.cs | 6 +++++ mpv.net/Resources/mpvNetConfToml.txt | 21 ++++++++++------ mpv.net/WPF/WPF.cs | 7 +++--- mpv.net/WinForms/MainForm.Designer.cs | 1 - mpv.net/WinForms/MainForm.cs | 30 ++++++++--------------- mpv.net/mpv/mp.cs | 35 ++++++++++++--------------- 7 files changed, 52 insertions(+), 53 deletions(-) diff --git a/Changelog.md b/Changelog.md index edbbcc2..dc309e2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,11 +2,14 @@ - on Win 7 the theme color was hardcoded to DarkSlateGrey because WPF was returning a bad color on Win 7, this was fixed by reading - the theme color from the Registry on Win 7 + the theme color from the Registry on Win 7. If the theme color + is identical to the background color it's corrected - new option dark-color was added to overwrite the OS theme color used in dark mode, find the option under 'General' - new option light-color was added to overwrite the OS theme color used in non dark mode, find the option under 'General' - various changes regarding input handling - it's now possible to use a custom folder as config folder +- slightly increased startup performance +- start-threshold setting added. Threshold in milliseconds to wait for libmpv returning the video resolution before the window is shown, otherwise default dimensions are used as defined by autofit and start-size. Default: 1500 ### 4.7.3 diff --git a/mpv.net/Misc/Misc.cs b/mpv.net/Misc/Misc.cs index 0fdb79f..9e9f76d 100644 --- a/mpv.net/Misc/Misc.cs +++ b/mpv.net/Misc/Misc.cs @@ -35,6 +35,8 @@ namespace mpvnet public static bool RememberPosition { get; set; } public static bool DebugMode { get; set; } + public static int StartThreshold { get; set; } = 1500; + public static bool IsDarkMode { get => (DarkMode == "system" && Sys.IsDarkTheme) || DarkMode == "always"; } @@ -94,6 +96,10 @@ namespace mpvnet case "url-whitelist": UrlWhitelist = value.Split(' ', ',', ';'); break; + case "start-threshold": + int.TryParse(value, out int result); + StartThreshold = result; + break; } } diff --git a/mpv.net/Resources/mpvNetConfToml.txt b/mpv.net/Resources/mpvNetConfToml.txt index 503230e..830a297 100644 --- a/mpv.net/Resources/mpvNetConfToml.txt +++ b/mpv.net/Resources/mpvNetConfToml.txt @@ -2,7 +2,7 @@ name = "dark-mode" default = "always" filter = "General" -help = "Enables a dark theme." +help = "Enables a dark theme. (mpv.net specific setting)" options = [{ name = "always" }, { name = "system" , help = "Available on Windows 10 or higher" }, { name = "never" }] @@ -11,25 +11,25 @@ options = [{ name = "always" }, name = "dark-color" type = "color" filter = "General" -help = "Theme color used in dark-mode. Leave empty to use OS theme." +help = "Theme color used in dark-mode. Leave empty to use OS theme. (mpv.net specific setting)" [[settings]] name = "light-color" type = "color" filter = "General" -help = "Theme color used when dark-mode is disabled. Leave empty to use OS theme" +help = "Theme color used when dark-mode is disabled. Leave empty to use OS theme. (mpv.net specific setting)" [[settings]] name = "url-whitelist" filter = "General" type = "string" -help = "mpv.net specific whitelist setting to monitor the clipboard for URLs to play.\n\nDefault: tube vimeo ard zdf" +help = "Whitelist setting to monitor the clipboard for URLs to play. (mpv.net specific setting)\n\nDefault: tube vimeo ard zdf" [[settings]] name = "process-instance" default = "single" filter = "General" -help = "mpv.net specific setting that defines if more then one mpv.net process is allowed.\n\nTip: Whenever the control key is pressed when files or URLs are opened, the playlist is not cleared but the files or URLs are appended to the playlist. This not only works on process startup but in all mpv.net features that open files." +help = "Defines if more then one mpv.net process is allowed. (mpv.net specific setting)\n\nTip: Whenever the control key is pressed when files or URLs are opened, the playlist is not cleared but the files or URLs are appended to the playlist. This not only works on process startup but in all mpv.net features that open files." options = [{ name = "multi", help = "Create a new process everytime the shell starts mpv.net" }, { name = "single", help = "Force a single process everytime the shell starts mpv.net" }, { name = "queue", help = "Force a single process and add files to playlist" }] @@ -38,7 +38,7 @@ options = [{ name = "multi", help = "Create a new process everytime the shell s name = "debug-mode" default = "no" filter = "General" -help = "mpv.net specific debugging setting, enable this only when a developer asks for it." +help = "Enable this only when a developer asks for it. (mpv.net specific setting)" options = [{ name = "yes" }, { name = "no" }] @@ -46,14 +46,19 @@ options = [{ name = "yes" }, name = "start-size" default = "previous" filter = "Screen" -help = "mpv.net specific setting to remember the window height in the current session, otherwise the video's native resolution is used." +help = "Setting to remember the window height in the current session, otherwise the video's native resolution is used. (mpv.net specific setting)" options = [{ name = "video", help = "Window size is set to native video resolution" }, { name = "previous", help = "Window size is remembered but only from the current session" }] +[[settings]] +name = "start-threshold" +filter = "Screen" +help = "Threshold in milliseconds to wait for libmpv returning the video resolution before the window is shown, otherwise default dimensions are used as defined by autofit and start-size. (mpv.net specific setting) Default: 1500" + [[settings]] name = "remember-position" default = "no" filter = "Screen" -help = "mpv.net specific setting to save the window position on exit." +help = "Setting to save the window position on exit. (mpv.net specific setting)" options = [{ name = "yes" }, { name = "no" }] \ No newline at end of file diff --git a/mpv.net/WPF/WPF.cs b/mpv.net/WPF/WPF.cs index 6002ca8..dca20d9 100644 --- a/mpv.net/WPF/WPF.cs +++ b/mpv.net/WPF/WPF.cs @@ -50,14 +50,15 @@ namespace WPF if (Environment.OSVersion.Version.Major < 10) { int argb = Convert.ToInt32(Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM", "ColorizationColor", 0)); - if (argb == 0) System.Drawing.Color.Blue.ToArgb(); - var c = System.Drawing.Color.FromArgb(argb); - color = Color.FromArgb(c.A, c.R, c.G, c.B); + var wfc = System.Drawing.Color.FromArgb(argb); + color = Color.FromArgb(wfc.A, wfc.R, wfc.G, wfc.B); } else color = SystemParameters.WindowGlassColor; } + if (App.IsDarkMode && color == Colors.Black) color = Colors.Orange; + if (!App.IsDarkMode && color == Colors.White) color = Colors.Orange; _ThemeColor = color.Value; WasThemeColorSet = true; } diff --git a/mpv.net/WinForms/MainForm.Designer.cs b/mpv.net/WinForms/MainForm.Designer.cs index e2c7297..d1bc08d 100644 --- a/mpv.net/WinForms/MainForm.Designer.cs +++ b/mpv.net/WinForms/MainForm.Designer.cs @@ -51,7 +51,6 @@ this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "MainForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "mpv.net"; this.ResumeLayout(false); } diff --git a/mpv.net/WinForms/MainForm.cs b/mpv.net/WinForms/MainForm.cs index a0e0b39..90cd96a 100644 --- a/mpv.net/WinForms/MainForm.cs +++ b/mpv.net/WinForms/MainForm.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.Diagnostics; +using System.Threading.Tasks; namespace mpvnet { @@ -33,12 +34,10 @@ namespace mpvnet Instance = this; Hwnd = Handle; mp.Init(); - AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; - Application.ThreadException += Application_ThreadException; + AppDomain.CurrentDomain.UnhandledException += (sender, e) => Msg.ShowError(e.ExceptionObject.ToString()); + Application.ThreadException += (sender, e) => Msg.ShowException(e.Exception); Msg.SupportURL = "https://github.com/stax76/mpv.net#support"; - WPF.WPF.Init(); - System.Windows.Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown; - Text += " " + Application.ProductVersion; + Text = "mpv.net " + Application.ProductVersion; object recent = RegHelp.GetObject(App.RegPath, "Recent"); @@ -47,10 +46,6 @@ namespace mpvnet else RecentFiles = new List(); - var wpfColor = WPF.WPF.ThemeColor; - Color color = Color.FromArgb(wpfColor.A, wpfColor.R, wpfColor.G, wpfColor.B); - ToolStripRendererEx.InitColors(color, App.IsDarkMode); - ContextMenu = new ContextMenuStripEx(components); ContextMenu.Opened += ContextMenu_Opened; ContextMenu.Opening += ContextMenu_Opening; @@ -80,7 +75,7 @@ namespace mpvnet mp.VideoSizeChanged += VideoSizeChanged; mp.FileLoaded += FileLoaded; mp.Idle += Idle; - mp.VideoSizeAutoResetEvent.WaitOne(1500); + mp.VideoSizeAutoResetEvent.WaitOne(App.StartThreshold); if (Height < FontHeight * 4) SetFormPosAndSize(); mp.observe_property_bool("fullscreen", PropChangeFullscreen); mp.observe_property_bool("ontop", PropChangeOnTop); @@ -359,16 +354,6 @@ namespace mpvnet if (RecentFiles.Count > 15) RecentFiles.RemoveAt(15); } - void Application_ThreadException(object sender, ThreadExceptionEventArgs e) - { - Msg.ShowException(e.Exception); - } - - void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) - { - Msg.ShowError(e.ExceptionObject.ToString()); - } - protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; @@ -517,8 +502,13 @@ namespace mpvnet protected override void OnShown(EventArgs e) { base.OnShown(e); + var wpfColor = WPF.WPF.ThemeColor; + Color color = Color.FromArgb(wpfColor.A, wpfColor.R, wpfColor.G, wpfColor.B); + ToolStripRendererEx.InitColors(color, App.IsDarkMode); BuildMenu(); ContextMenuStrip = ContextMenu; + WPF.WPF.Init(); + System.Windows.Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown; IgnoreDpiChanged = false; CheckClipboardForURL(); Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y); diff --git a/mpv.net/mpv/mp.cs b/mpv.net/mpv/mp.cs index 44ff18e..051ab2c 100644 --- a/mpv.net/mpv/mp.cs +++ b/mpv.net/mpv/mp.cs @@ -82,8 +82,6 @@ namespace mpvnet public static float Autofit { get; set; } = 0.5f; - static string LastPlaybackRestartFile; - public static void Init() { LoadLibrary("mpv-1.dll"); @@ -164,7 +162,8 @@ namespace mpvnet if (!Directory.Exists(_ConfigFolder)) Directory.CreateDirectory(_ConfigFolder); - RegHelp.SetObject(App.RegPath, "ConfigFolder", _ConfigFolder); + if (!_ConfigFolder.Contains("portable_config")) + RegHelp.SetObject(App.RegPath, "ConfigFolder", _ConfigFolder); if (!File.Exists(_ConfigFolder + "\\input.conf")) File.WriteAllText(_ConfigFolder + "\\input.conf", Properties.Resources.inputConf); @@ -270,6 +269,16 @@ namespace mpvnet case mpv_event_id.MPV_EVENT_FILE_LOADED: HideLogo(); FileLoaded?.Invoke(); + Size vidSize = new Size(get_property_int("width"), get_property_int("height")); + if (vidSize.Width == 0 || vidSize.Height == 0) + vidSize = new Size(1, 1); + if (VideoSize != vidSize) + { + VideoSize = vidSize; + VideoSizeChanged?.Invoke(); + } + VideoSizeAutoResetEvent.Set(); + Task.Run(new Action(() => ReadMetaData())); WriteHistory(get_property_string("path")); break; case mpv_event_id.MPV_EVENT_TRACKS_CHANGED: @@ -334,21 +343,6 @@ namespace mpvnet break; case mpv_event_id.MPV_EVENT_PLAYBACK_RESTART: PlaybackRestart?.Invoke(); - string path = get_property_string("path"); - if (LastPlaybackRestartFile != path) - { - Size vidSize = new Size(get_property_int("dwidth"), get_property_int("dheight")); - if (vidSize.Width == 0 || vidSize.Height == 0) - vidSize = new Size(1, 1); - if (VideoSize != vidSize) - { - VideoSize = vidSize; - VideoSizeChanged?.Invoke(); - } - VideoSizeAutoResetEvent.Set(); - Task.Run(new Action(() => ReadMetaData())); - LastPlaybackRestartFile = path; - } break; case mpv_event_id.MPV_EVENT_CHAPTER_CHANGE: ChapterChange?.Invoke(); @@ -553,7 +547,7 @@ namespace mpvnet Load(files.ToArray(), App.ProcessInstance != "queue", Control.ModifierKeys.HasFlag(Keys.Control)); - if (files.Count == 0) + if (files.Count == 0 || files[0].Contains("://")) { VideoSizeAutoResetEvent.Set(); VideoSizeChanged?.Invoke(); @@ -605,6 +599,7 @@ namespace mpvnet if (string.IsNullOrEmpty(get_property_string("path"))) set_property_int("playlist-pos", 0); + if (loadFolder && !append) Task.Run(() => LoadFolder()); // user reported race condition } @@ -692,8 +687,8 @@ namespace mpvnet { if (MainForm.Instance is null) return; Rectangle cr = MainForm.Instance.ClientRectangle; - if (cr.Width == 0 || cr.Height == 0) return; int len = cr.Height / 5; + if (len == 0) return; using (Bitmap b = new Bitmap(len, len)) {