Răsfoiți Sursa

Added context-sensitive init/dispose methods for plugins

LukePulverenti Luke Pulverenti luke pulverenti 12 ani în urmă
părinte
comite
507beb76f6

+ 1 - 1
MediaBrowser.Api/Plugin.cs

@@ -18,7 +18,7 @@ namespace MediaBrowser.Api
             get { return "Media Browser API"; }
         }
 
-        protected override void InitializeInternal()
+        protected override void InitializeOnServer()
         {
             var httpServer = Kernel.Instance.HttpServer;
 

+ 40 - 4
MediaBrowser.Common/Plugins/BasePlugin.cs

@@ -184,22 +184,58 @@ namespace MediaBrowser.Common.Plugins
 
                 if (Enabled)
                 {
-                    InitializeInternal();
+                    if (kernel.KernelContext == KernelContext.Server)
+                    {
+                        InitializeOnServer();
+                    }
+                    else if (kernel.KernelContext == KernelContext.UI)
+                    {
+                        InitializeInUI();
+                    }
                 }
             }
         }
 
         /// <summary>
-        /// Starts the plugin.
+        /// Starts the plugin on the server
+        /// </summary>
+        protected virtual void InitializeOnServer()
+        {
+        }
+
+        /// <summary>
+        /// Starts the plugin in the UI
         /// </summary>
-        protected virtual void InitializeInternal()
+        protected virtual void InitializeInUI()
         {
         }
 
         /// <summary>
         /// Disposes the plugins. Undos all actions performed during Init.
         /// </summary>
-        public virtual void Dispose()
+        public void Dispose()
+        {
+            if (Context == KernelContext.Server)
+            {
+                DisposeOnServer();
+            }
+            else if (Context == KernelContext.UI)
+            {
+                InitializeInUI();
+            }
+        }
+
+        /// <summary>
+        /// Disposes the plugin on the server
+        /// </summary>
+        protected virtual void DisposeOnServer()
+        {
+        }
+
+        /// <summary>
+        /// Disposes the plugin in the UI
+        /// </summary>
+        protected virtual void DisposeInUI()
         {
         }
 

+ 2 - 2
MediaBrowser.TV/Plugin.cs

@@ -16,12 +16,12 @@ namespace MediaBrowser.TV
             get { return "TV"; }
         }
 
-        protected override void InitializeInternal()
+        protected override void InitializeOnServer()
         {
             Kernel.Instance.ItemController.PreBeginResolvePath += ItemController_PreBeginResolvePath;
         }
 
-        public override void Dispose()
+        protected override void DisposeOnServer()
         {
             Kernel.Instance.ItemController.PreBeginResolvePath -= ItemController_PreBeginResolvePath;
         }