ServerNotifyIcon.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. using MediaBrowser.Controller;
  2. using MediaBrowser.Controller.Configuration;
  3. using MediaBrowser.Model.Logging;
  4. using System;
  5. using System.ComponentModel;
  6. using System.Windows.Forms;
  7. using Emby.Server.Core.Browser;
  8. using MediaBrowser.Model.Globalization;
  9. namespace MediaBrowser.ServerApplication
  10. {
  11. public class ServerNotifyIcon : IDisposable
  12. {
  13. private NotifyIcon notifyIcon1;
  14. private ContextMenuStrip contextMenuStrip1;
  15. private ToolStripMenuItem cmdExit;
  16. private ToolStripMenuItem cmdBrowse;
  17. private ToolStripMenuItem cmdConfigure;
  18. private ToolStripSeparator toolStripSeparator2;
  19. private ToolStripMenuItem cmdRestart;
  20. private ToolStripSeparator toolStripSeparator1;
  21. private ToolStripMenuItem cmdCommunity;
  22. private ToolStripMenuItem cmdPremiere;
  23. private Container components;
  24. private readonly ILogger _logger;
  25. private readonly IServerApplicationHost _appHost;
  26. private readonly IServerConfigurationManager _configurationManager;
  27. private readonly ILocalizationManager _localization;
  28. public void Invoke(Action action)
  29. {
  30. contextMenuStrip1.Invoke(action);
  31. }
  32. public ServerNotifyIcon(ILogManager logManager,
  33. IServerApplicationHost appHost,
  34. IServerConfigurationManager configurationManager,
  35. ILocalizationManager localization)
  36. {
  37. _logger = logManager.GetLogger("MainWindow");
  38. _localization = localization;
  39. _appHost = appHost;
  40. _configurationManager = configurationManager;
  41. components = new System.ComponentModel.Container();
  42. var resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
  43. contextMenuStrip1 = new ContextMenuStrip(components);
  44. notifyIcon1 = new NotifyIcon(components);
  45. cmdExit = new ToolStripMenuItem();
  46. cmdCommunity = new ToolStripMenuItem();
  47. cmdPremiere = new ToolStripMenuItem();
  48. toolStripSeparator1 = new ToolStripSeparator();
  49. cmdRestart = new ToolStripMenuItem();
  50. toolStripSeparator2 = new ToolStripSeparator();
  51. cmdConfigure = new ToolStripMenuItem();
  52. cmdBrowse = new ToolStripMenuItem();
  53. //
  54. // notifyIcon1
  55. //
  56. notifyIcon1.ContextMenuStrip = contextMenuStrip1;
  57. notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  58. notifyIcon1.Text = "Emby";
  59. notifyIcon1.Visible = true;
  60. //
  61. // contextMenuStrip1
  62. //
  63. contextMenuStrip1.Items.AddRange(new ToolStripItem[] {
  64. cmdBrowse,
  65. cmdConfigure,
  66. cmdPremiere,
  67. toolStripSeparator2,
  68. cmdRestart,
  69. toolStripSeparator1,
  70. cmdCommunity,
  71. cmdExit});
  72. contextMenuStrip1.Name = "contextMenuStrip1";
  73. contextMenuStrip1.ShowCheckMargin = true;
  74. contextMenuStrip1.ShowImageMargin = false;
  75. contextMenuStrip1.Size = new System.Drawing.Size(209, 214);
  76. //
  77. // cmdExit
  78. //
  79. cmdExit.Name = "cmdExit";
  80. cmdExit.Size = new System.Drawing.Size(208, 22);
  81. //
  82. // cmdCommunity
  83. //
  84. cmdCommunity.Name = "cmdCommunity";
  85. cmdCommunity.Size = new System.Drawing.Size(208, 22);
  86. //
  87. // cmdPremiere
  88. //
  89. cmdPremiere.Name = "cmdPremiere";
  90. cmdPremiere.Size = new System.Drawing.Size(208, 22);
  91. //
  92. // toolStripSeparator1
  93. //
  94. toolStripSeparator1.Name = "toolStripSeparator1";
  95. toolStripSeparator1.Size = new System.Drawing.Size(205, 6);
  96. //
  97. // cmdRestart
  98. //
  99. cmdRestart.Name = "cmdRestart";
  100. cmdRestart.Size = new System.Drawing.Size(208, 22);
  101. //
  102. // toolStripSeparator2
  103. //
  104. toolStripSeparator2.Name = "toolStripSeparator2";
  105. toolStripSeparator2.Size = new System.Drawing.Size(205, 6);
  106. //
  107. // cmdConfigure
  108. //
  109. cmdConfigure.Name = "cmdConfigure";
  110. cmdConfigure.Size = new System.Drawing.Size(208, 22);
  111. //
  112. // cmdBrowse
  113. //
  114. cmdBrowse.Name = "cmdBrowse";
  115. cmdBrowse.Size = new System.Drawing.Size(208, 22);
  116. cmdExit.Click += cmdExit_Click;
  117. cmdRestart.Click += cmdRestart_Click;
  118. cmdConfigure.Click += cmdConfigure_Click;
  119. cmdCommunity.Click += cmdCommunity_Click;
  120. cmdPremiere.Click += cmdPremiere_Click;
  121. cmdBrowse.Click += cmdBrowse_Click;
  122. _configurationManager.ConfigurationUpdated += Instance_ConfigurationUpdated;
  123. LocalizeText();
  124. notifyIcon1.DoubleClick += notifyIcon1_DoubleClick;
  125. }
  126. void notifyIcon1_DoubleClick(object sender, EventArgs e)
  127. {
  128. BrowserLauncher.OpenDashboard(_appHost);
  129. }
  130. private void LocalizeText()
  131. {
  132. _uiCulture = _configurationManager.Configuration.UICulture;
  133. cmdExit.Text = _localization.GetLocalizedString("LabelExit");
  134. cmdCommunity.Text = _localization.GetLocalizedString("LabelVisitCommunity");
  135. cmdPremiere.Text = _localization.GetLocalizedString("Emby Premiere");
  136. cmdBrowse.Text = _localization.GetLocalizedString("LabelBrowseLibrary");
  137. cmdConfigure.Text = _localization.GetLocalizedString("LabelConfigureServer");
  138. cmdRestart.Text = _localization.GetLocalizedString("LabelRestartServer");
  139. }
  140. private string _uiCulture;
  141. /// <summary>
  142. /// Handles the ConfigurationUpdated event of the Instance control.
  143. /// </summary>
  144. /// <param name="sender">The source of the event.</param>
  145. /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
  146. void Instance_ConfigurationUpdated(object sender, EventArgs e)
  147. {
  148. if (!string.Equals(_configurationManager.Configuration.UICulture, _uiCulture,
  149. StringComparison.OrdinalIgnoreCase))
  150. {
  151. LocalizeText();
  152. }
  153. }
  154. void cmdBrowse_Click(object sender, EventArgs e)
  155. {
  156. BrowserLauncher.OpenWebClient(_appHost);
  157. }
  158. void cmdPremiere_Click(object sender, EventArgs e)
  159. {
  160. BrowserLauncher.OpenEmbyPremiere(_appHost);
  161. }
  162. void cmdCommunity_Click(object sender, EventArgs e)
  163. {
  164. BrowserLauncher.OpenCommunity(_appHost);
  165. }
  166. void cmdConfigure_Click(object sender, EventArgs e)
  167. {
  168. BrowserLauncher.OpenDashboard(_appHost);
  169. }
  170. void cmdRestart_Click(object sender, EventArgs e)
  171. {
  172. _appHost.Restart();
  173. }
  174. void cmdExit_Click(object sender, EventArgs e)
  175. {
  176. _appHost.Shutdown();
  177. }
  178. public void Dispose()
  179. {
  180. Dispose(true);
  181. }
  182. protected virtual void Dispose(bool disposing)
  183. {
  184. if (disposing)
  185. {
  186. if (notifyIcon1 != null)
  187. {
  188. notifyIcon1.Visible = false;
  189. notifyIcon1.Dispose();
  190. notifyIcon1 = null;
  191. }
  192. if (components != null)
  193. {
  194. components.Dispose();
  195. }
  196. }
  197. }
  198. }
  199. }