Exemple #1
0
        public static int Initialize(PluginUI plugin)
        {
            PluginUI = plugin;

            Config = PluginUI.LoadConfiguration <PluginConfig>();
            Config.PropertyChanged += Config_PropertyChanged;

            try
            {
                // https://stackoverflow.com/a/36006943
                Thread t = new Thread(new ThreadStart(() =>
                {
                    DispatcherUI = Dispatcher.CurrentDispatcher;
                    DispatcherUI.Invoke(delegate
                    {
                        Windows.Main.AllowsTransparency = Config.Transparent;
                        Windows.Main.Show();
                    });
                    Dispatcher.Run();
                }));

                t.SetApartmentState(ApartmentState.STA);
                t.IsBackground = true;
                t.Start();

                return(0);
            }
            catch (Exception ex)
            {
                ShowExceptionMessage(ex);
                return(1);
            }
        }
Exemple #2
0
        private static void Config_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == nameof(Config.Transparent))
            {
                DispatcherUI.Invoke(delegate
                {
                    Windows.ReopenMain();
                });
            }

            PluginUI.SaveConfiguration(Config);
        }
Exemple #3
0
        public static int Exit()
        {
            IsExiting = true;

            if (Config != null)
            {
                PluginUI.SaveConfiguration(Config);

                try { Config.PropertyChanged -= Config_PropertyChanged; }
                catch (Exception) { }
            }

            Properties.Settings.Default.Save();

            try
            {
                if (DispatcherUI != null)
                {
                    DispatcherUI.Invoke(delegate
                    {
                        Models.Dispose();
                        Windows.Close();
                    });
                    DispatcherUI.InvokeShutdown();
                }

                return(0);
            }
            catch (Exception ex)
            {
                ShowExceptionMessage(ex);
                return(1);
            }
            finally
            {
                Config       = null;
                DispatcherUI = null;
                IsExiting    = false;
            }
        }