Пример #1
0
        private async void OnStartupAsync(object sender, StartupEventArgs e)
        {
            await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async() =>
            {
                _portable.PreStartCleanUpAfterPortabilityUpdate();

                Log.Info("|App.OnStartup|Begin Flow Launcher startup ----------------------------------------------------");
                Log.Info($"|App.OnStartup|Runtime info:{ErrorReporting.RuntimeInfo()}");
                RegisterAppDomainExceptions();
                RegisterDispatcherUnhandledException();

                ImageLoader.Initialize();

                _settingsVM = new SettingWindowViewModel(_updater, _portable);
                _settings   = _settingsVM.Settings;

                _alphabet.Initialize(_settings);
                _stringMatcher         = new StringMatcher(_alphabet);
                StringMatcher.Instance = _stringMatcher;
                _stringMatcher.UserSettingSearchPrecision = _settings.QuerySearchPrecision;

                PluginManager.LoadPlugins(_settings.PluginSettings);
                _mainVM = new MainViewModel(_settings);

                API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet);

                Http.API   = API;
                Http.Proxy = _settings.Proxy;

                await PluginManager.InitializePlugins(API);
                var window = new MainWindow(_settings, _mainVM);

                Log.Info($"|App.OnStartup|Dependencies Info:{ErrorReporting.DependenciesInfo()}");

                Current.MainWindow       = window;
                Current.MainWindow.Title = Constant.FlowLauncher;

                HotKeyMapper.Initialize(_mainVM);

                // happlebao todo temp fix for instance code logic
                // load plugin before change language, because plugin language also needs be changed
                InternationalizationManager.Instance.Settings = _settings;
                InternationalizationManager.Instance.ChangeLanguage(_settings.Language);
                // main windows needs initialized before theme change because of blur settigns
                ThemeManager.Instance.Settings = _settings;
                ThemeManager.Instance.ChangeTheme(_settings.Theme);

                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

                RegisterExitEvents();

                AutoStartup();
                AutoUpdates();

                API.SaveAppAllSettings();
                Log.Info("|App.OnStartup|End Flow Launcher startup ----------------------------------------------------  ");
            });
        }
Пример #2
0
        public static IEnumerable <PluginPair> DotNetPlugins(List <PluginMetadata> source)
        {
            var erroredPlugins = new List <string>();

            var plugins   = new List <PluginPair>();
            var metadatas = source.Where(o => AllowedLanguage.IsDotNet(o.Language));

            foreach (var metadata in metadatas)
            {
                var milliseconds = Stopwatch.Debug(
                    $"|PluginsLoader.DotNetPlugins|Constructor init cost for {metadata.Name}", () =>
                {
#if DEBUG
                    var assemblyLoader = new PluginAssemblyLoader(metadata.ExecuteFilePath);
                    var assembly       = assemblyLoader.LoadAssemblyAndDependencies();
                    var type           = assemblyLoader.FromAssemblyGetTypeOfInterface(assembly,
                                                                                       typeof(IAsyncPlugin));

                    var plugin = Activator.CreateInstance(type) as IAsyncPlugin;
#else
                    Assembly assembly   = null;
                    IAsyncPlugin plugin = null;

                    try
                    {
                        var assemblyLoader = new PluginAssemblyLoader(metadata.ExecuteFilePath);
                        assembly           = assemblyLoader.LoadAssemblyAndDependencies();

                        var type = assemblyLoader.FromAssemblyGetTypeOfInterface(assembly,
                                                                                 typeof(IAsyncPlugin));

                        plugin = Activator.CreateInstance(type) as IAsyncPlugin;
                    }
                    catch (Exception e) when(assembly == null)
                    {
                        Log.Exception($"|PluginsLoader.DotNetPlugins|Couldn't load assembly for the plugin: {metadata.Name}", e);
                    }
                    catch (InvalidOperationException e)
                    {
                        Log.Exception($"|PluginsLoader.DotNetPlugins|Can't find the required IPlugin interface for the plugin: <{metadata.Name}>", e);
                    }
                    catch (ReflectionTypeLoadException e)
                    {
                        Log.Exception($"|PluginsLoader.DotNetPlugins|The GetTypes method was unable to load assembly types for the plugin: <{metadata.Name}>", e);
                    }
                    catch (Exception e)
                    {
                        Log.Exception($"|PluginsLoader.DotNetPlugins|The following plugin has errored and can not be loaded: <{metadata.Name}>", e);
                    }
#endif
                    if (plugin == null)
                    {
                        erroredPlugins.Add(metadata.Name);
                        return;
                    }

                    plugins.Add(new PluginPair {
                        Plugin = plugin, Metadata = metadata
                    });
                });
                metadata.InitTime += milliseconds;
            }

            if (erroredPlugins.Count > 0)
            {
                var errorPluginString = String.Join(Environment.NewLine, erroredPlugins);

                var errorMessage = "The following "
                                   + (erroredPlugins.Count > 1 ? "plugins have " : "plugin has ")
                                   + "errored and cannot be loaded:";

                Task.Run(() =>
                {
                    MessageBox.Show($"{errorMessage}{Environment.NewLine}{Environment.NewLine}" +
                                    $"{errorPluginString}{Environment.NewLine}{Environment.NewLine}" +
                                    $"Please refer to the logs for more information", "",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                });
            }

            return(plugins);
        }