예제 #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.ReopenMain(); });
                    Dispatcher.Run();
                }));

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

                return(0);
            }
            catch (Exception ex)
            {
                ShowExceptionMessage(ex);
                return(1);
            }
        }
예제 #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);
        }
예제 #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
                    {
                        Windows.Close();
                        Models.Dispose();
                    });
                    DispatcherUI.InvokeShutdown();
                }

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