Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions PlexServiceCommon/Interface/ITrayInteraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public interface ITrayInteraction : ICommunicationObject
[OperationContract]
void Restart();

[OperationContract]
void UpdateAllLibraries();

[OperationContract]
void SetSettings(Settings settings);

Expand Down
25 changes: 25 additions & 0 deletions PlexServiceTray/NotifyIconApplicationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -506,6 +507,30 @@ private void RestartPlex_Click(object sender, EventArgs e)
}
}

/// <summary>
/// Ask the service to request an update of all plex libraries
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
}
}

/// <summary>
/// Try to open the web manager
/// </summary>
Expand Down
30 changes: 30 additions & 0 deletions PlexServiceWCF/TrayInteraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,36 @@ public void Restart()
});
}

/// <summary>
/// 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.
/// </summary>
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);
}
});
}

/// <summary>
/// Write the settings to the server
/// </summary>
Expand Down