Ejemplo n.º 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.ApplyPluginLanguages();

            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;
                        }
                    }
                }
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Load and init all Wox plugins
        /// </summary>
        public static void Init(IPublicAPI api)
        {
            if (api == null)
            {
                throw new WoxCritialException("api is null");
            }

            SetupPluginDirectories();
            API = api;
            plugins.Clear();

            pluginMetadatas = PluginConfig.Parse(pluginDirectories);
            plugins.AddRange(new CSharpPluginLoader().LoadPlugin(pluginMetadatas));
            plugins.AddRange(new JsonRPCPluginLoader <PythonPlugin>().LoadPlugin(pluginMetadatas));

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

            foreach (PluginPair pluginPair in plugins)
            {
                PluginPair pair = pluginPair;
                ThreadPool.QueueUserWorkItem(o =>
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    pair.Plugin.Init(new PluginInitContext()
                    {
                        CurrentPluginMetadata = pair.Metadata,
                        Proxy = HttpProxy.Instance,
                        API   = API
                    });
                    sw.Stop();
                    DebugHelper.WriteLine(string.Format("Plugin init:{0} - {1}", pair.Metadata.Name, sw.ElapsedMilliseconds));
                    pair.InitTime = sw.ElapsedMilliseconds;
                    InternationalizationManager.Instance.UpdatePluginMetadataTranslations(pair);
                });
            }

            ThreadPool.QueueUserWorkItem(o =>
            {
                LoadInstantSearches();
            });
        }