Beispiel #1
0
        /// <summary>
        /// Load and init all Wox plugins
        /// </summary>
        public static void Init(IPublicAPI api)
        {
            if (api == null)
            {
                throw new WoxFatalException("api is null");
            }

            SetupPluginDirectories();
            API = api;

            var metadatas = PluginConfig.Parse(pluginDirectories);

            AllPlugins = (new CSharpPluginLoader().LoadPlugin(metadatas)).
                         Concat(new JsonRPCPluginLoader <PythonPlugin>().LoadPlugin(metadatas));

            //load plugin i18n languages
            ResourceMerger.UpdatePluginLanguages();

            foreach (PluginPair pluginPair in AllPlugins)
            {
                PluginPair pair = pluginPair;
                ThreadPool.QueueUserWorkItem(o =>
                {
                    var milliseconds = Stopwatch.Normal($"Plugin init: {pair.Metadata.Name}", () =>
                    {
                        pair.Plugin.Init(new PluginInitContext
                        {
                            CurrentPluginMetadata = pair.Metadata,
                            Proxy = HttpProxy.Instance,
                            API   = API
                        });
                    });
                    pair.InitTime = milliseconds;
                    InternationalizationManager.Instance.UpdatePluginMetadataTranslations(pair);
                });
            }

            ThreadPool.QueueUserWorkItem(o =>
            {
                InstantQueryPlugins = GetPluginsForInterface <IInstantQuery>();
                contextMenuPlugins  = GetPluginsForInterface <IContextMenu>();
                foreach (var plugin in AllPlugins)
                {
                    if (IsGlobalPlugin(plugin.Metadata))
                    {
                        GlobalPlugins.Add(plugin);
                    }
                    else
                    {
                        foreach (string actionKeyword in plugin.Metadata.ActionKeywords)
                        {
                            NonGlobalPlugins[actionKeyword] = plugin;
                        }
                    }
                }
            });
        }
Beispiel #2
0
        public static void InitializePlugins(IPublicAPI api)
        {
            //load plugin i18n languages
            ResourceMerger.UpdatePluginLanguages();

            API = api;
            foreach (PluginPair pluginPair in AllPlugins)
            {
                PluginPair pair = pluginPair;
                ThreadPool.QueueUserWorkItem(o =>
                {
                    var milliseconds = Stopwatch.Normal($"Plugin init: {pair.Metadata.Name}", () =>
                    {
                        pair.Plugin.Init(new PluginInitContext
                        {
                            CurrentPluginMetadata = pair.Metadata,
                            Proxy = HttpProxy.Instance,
                            API   = API
                        });
                    });
                    pair.InitTime = milliseconds;
                    InternationalizationManager.Instance.UpdatePluginMetadataTranslations(pair);
                });
            }

            ThreadPool.QueueUserWorkItem(o =>
            {
                _contextMenuPlugins = GetPluginsForInterface <IContextMenu>();
                foreach (var plugin in AllPlugins)
                {
                    if (IsGlobalPlugin(plugin.Metadata))
                    {
                        GlobalPlugins.Add(plugin);
                    }
                    else
                    {
                        foreach (string actionKeyword in plugin.Metadata.ActionKeywords)
                        {
                            NonGlobalPlugins[actionKeyword] = plugin;
                        }
                    }
                }
            });
        }
Beispiel #3
0
        public static void InitializePlugins(IPublicAPI api)
        {
            //load plugin i18n languages
            ResourceMerger.UpdatePluginLanguages();

            API = api;
            Parallel.ForEach(AllPlugins, pair =>
            {
                var milliseconds = Stopwatch.Debug($"|PluginManager.InitializePlugins|Init method time cost for <{pair.Metadata.Name}>", () =>
                {
                    pair.Plugin.Init(new PluginInitContext
                    {
                        CurrentPluginMetadata = pair.Metadata,
                        API = API
                    });
                });
                pair.Metadata.InitTime += milliseconds;
                Log.Info($"|PluginManager.InitializePlugins|Total init cost for <{pair.Metadata.Name}> is <{pair.Metadata.InitTime}ms>");
                InternationalizationManager.Instance.UpdatePluginMetadataTranslations(pair);
            });

            _contextMenuPlugins = GetPluginsForInterface <IContextMenu>();
            foreach (var plugin in AllPlugins)
            {
                if (IsGlobalPlugin(plugin.Metadata))
                {
                    GlobalPlugins.Add(plugin);
                }
                else
                {
                    foreach (string actionKeyword in plugin.Metadata.ActionKeywords)
                    {
                        NonGlobalPlugins[actionKeyword] = plugin;
                    }
                }
            }
        }