aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Plugins/PluginSecurityManager.cs
blob: 341e3582bbcf339609b15c29f1f7a383ab098123 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using Mediabrowser.Model.Entities;
using Mediabrowser.PluginSecurity;
using MediaBrowser.Common.Kernel;
using System.Threading;
using System.Threading.Tasks;

namespace MediaBrowser.Controller.Plugins
{
    public class PluginSecurityManager : BaseManager<Kernel>
    {
        private bool? _isMBSupporter;
        private bool _isMBSupporterInitialized;
        private object _isMBSupporterSyncLock = new object();
        
        public bool IsMBSupporter
        {
            get
            {
                LazyInitializer.EnsureInitialized(ref _isMBSupporter, ref _isMBSupporterInitialized, ref _isMBSupporterSyncLock, () => GetRegistrationStatus("MBSupporter").Result.IsRegistered);
                return _isMBSupporter.Value;
            }
        }

        public PluginSecurityManager(Kernel kernel) : base(kernel)
        {
        }

        public async Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent = null)
        {
            return await MBRegistration.GetRegistrationStatus(feature, mb2Equivalent).ConfigureAwait(false);
        }

        public string SupporterKey
        {
            get { return MBRegistration.SupporterKey; }
            set {
                if (value != MBRegistration.SupporterKey)
                {
                    MBRegistration.SupporterKey = value;
                    // Clear this so it will re-evaluate
                    ResetSupporterInfo();
                    // And we'll need to restart to re-evaluate the status of plug-ins
                    Kernel.NotifyPendingRestart();
                    
                }
            }
        }

        public string LegacyKey
        {
            get { return MBRegistration.LegacyKey; }
            set { 
                MBRegistration.LegacyKey = value;
                // And we'll need to restart to re-evaluate the status of plug-ins
                Kernel.NotifyPendingRestart();
            }
        }

        private void ResetSupporterInfo()
        {
            _isMBSupporter = null;
            _isMBSupporterInitialized = false;
        }
    }
}