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); } }
private static void Config_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(Config.Transparent)) { DispatcherUI.Invoke(delegate { Windows.ReopenMain(); }); } PluginUI.SaveConfiguration(Config); }
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; } }