From 440a0a0b1796bab18bbd3bade2ef277fd3058b24 Mon Sep 17 00:00:00 2001 From: Dave <306332572+beni-ma-ru@users.noreply.github.com> Date: Fri, 17 Jul 2026 17:16:31 -0600 Subject: [PATCH] Add 'Update Plex Libraries' tray menu option Adds a new UpdateAllLibraries operation to the WCF service contract. The service requests http://localhost:32400/library/sections/all/refresh (with the X-Plex-Token from the registry when available) so the request always originates from the machine hosting plex, meaning it also works when the tray app is connected to a remote service. The tray context menu shows the new option while plex is running and confirms the request with a balloon tip. --- .../Interface/ITrayInteraction.cs | 3 ++ .../NotifyIconApplicationContext.cs | 25 ++++++++++++++++ PlexServiceWCF/TrayInteraction.cs | 30 +++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/PlexServiceCommon/Interface/ITrayInteraction.cs b/PlexServiceCommon/Interface/ITrayInteraction.cs index 96d6ac7..4d5a95f 100644 --- a/PlexServiceCommon/Interface/ITrayInteraction.cs +++ b/PlexServiceCommon/Interface/ITrayInteraction.cs @@ -18,6 +18,9 @@ public interface ITrayInteraction : ICommunicationObject [OperationContract] void Restart(); + [OperationContract] + void UpdateAllLibraries(); + [OperationContract] void SetSettings(Settings settings); diff --git a/PlexServiceTray/NotifyIconApplicationContext.cs b/PlexServiceTray/NotifyIconApplicationContext.cs index 269e459..4f5b093 100644 --- a/PlexServiceTray/NotifyIconApplicationContext.cs +++ b/PlexServiceTray/NotifyIconApplicationContext.cs @@ -198,6 +198,7 @@ private void ContextMenuStrip_Opening(object sender, System.ComponentModel.Cance case PlexState.Running: _notifyIcon.ContextMenuStrip.Items.Add("Stop Plex", null, StopPlex_Click); _notifyIcon.ContextMenuStrip.Items.Add("Restart Plex", null, RestartPlex_Click); + _notifyIcon.ContextMenuStrip.Items.Add("Update Plex Libraries", null, UpdateLibraries_Click); _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator()); _notifyIcon.ContextMenuStrip.Items.Add("Open Plex...", null, OpenManager_Click); break; @@ -506,6 +507,30 @@ private void RestartPlex_Click(object sender, EventArgs e) } } + /// + /// Ask the service to request an update of all plex libraries + /// + /// + /// + private void UpdateLibraries_Click(object sender, EventArgs e) + { + if (_plexService == null) + { + return; + } + + try + { + _plexService.UpdateAllLibraries(); + _notifyIcon.ShowBalloonTip(2000, "Plex Service", "Library update requested", ToolTipIcon.Info); + } + catch (Exception ex) + { + Logger("Exception updating libraries..." + ex.Message); + Disconnect(); + } + } + /// /// Try to open the web manager /// diff --git a/PlexServiceWCF/TrayInteraction.cs b/PlexServiceWCF/TrayInteraction.cs index 2bf8bb9..f1757d3 100644 --- a/PlexServiceWCF/TrayInteraction.cs +++ b/PlexServiceWCF/TrayInteraction.cs @@ -100,6 +100,36 @@ public void Restart() }); } + /// + /// Ask the local plex server to update (scan) all libraries. + /// The request is made from the service so it comes from localhost and the machine hosting plex. + /// + public void UpdateAllLibraries() + { + //fire the request off in another thread so the tray isn't kept waiting + Task.Factory.StartNew(() => + { + var address = "http://localhost:32400/library/sections/all/refresh"; + //include the token if we can find one, localhost is usually trusted without it + var token = PlexRegistryHelper.ReadUserRegistryValue("PlexOnlineToken"); + if (!string.IsNullOrEmpty(token)) + { + address += "?X-Plex-Token=" + token; + } + try + { + var request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(address); + request.Timeout = 30000; + using var response = (System.Net.HttpWebResponse)request.GetResponse(); + Log.Write(LogEventLevel.Information, "Update of all libraries requested, plex responded: " + response.StatusCode); + } + catch (Exception ex) + { + Log.Warning("Exception requesting library update: " + ex.Message); + } + }); + } + /// /// Write the settings to the server ///