private static void RunUI() { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(true); var service = new ServiceThread { ServiceFactory = () => new MouseBridgeService() }; var tray = new MouseTrapTrayIcon(service); var app = new TrayApplication(tray); app.BeforeStart += (s, e) => { if (Settings.Load().TeleportationActive) { service.StartService(); } }; app.BeforeExit += (s, e) => { service.StopService(); }; app.Start(); } catch (Exception e) { Logger.Error(e.Message, e); MessageBox.Show($"[{e.GetType().FullName}] {e.Message}\r\n{e.StackTrace}", e.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } }
public DiagnosticForm(ServiceThread service) { Service = service; InitializeComponent(); var diagnostic = false; this.BtnStartDiagnostic.Click += delegate { if (!diagnostic) { ConsoleBox.Text = string.Empty; var config = ScreenConfigCollection.Load(); Service.StopService(); Service.StartService(new MouseBridgeDiagnosticService(config, RealtimeLog)); this.BtnStartDiagnostic.Text = "Stop Diagnostic"; diagnostic = true; } else { Service.RestoreOriginalState(); this.BtnStartDiagnostic.Text = "Start Diagnostic"; diagnostic = false; } }; this.BtnCopy.Click += delegate { var sb = new StringBuilder(); // update log infos LogfileBox.Text = string.Empty; InitLogFileInfos(); sb.AppendLine(InfosBox.Text); sb.AppendLine(); sb.AppendLine(); sb.AppendLine(ConsoleBox.Text); sb.AppendLine(); sb.AppendLine(); sb.AppendLine(LogfileBox.Text); Clipboard.SetText(sb.ToString()); MessageBox.Show("Diagnostic data copied to clipboard."); }; this.Closing += delegate { Service.RestoreOriginalState(); }; ConsoleBox.Text = "\r\n INFO: Start Diagnostic to see Realtime output.."; InitSystemInfos(); InitLogFileInfos(); }
public ConfigFrom(ServiceThread service) { this.Icon = App.Icon; Service = service; Screens = ScreenConfigCollection.Load(); Settings = Settings.Load(); Settings.Configured = Screens.Any(_ => _.HasBridges); InitializeComponent(); this.Text += $" v{Assembly.GetEntryAssembly()?.GetName().Version}"; this.ResizeRedraw = true; this.InfoText.Visible = Settings.Configured == false; this.BtnConfigure.Click += (s, e) => { ShowForms(); }; this.BtnDiagnostic.Click += (s, e) => { ShowDiagnosticForm(); }; this.EnableAutoStart.Checked = Settings.AutoStartEnabled; this.EnableAutoStart.CheckedChanged += delegate { if (EnableAutoStart.Checked) { Task.Run(() => new ProjectInstaller().Install()); Settings.AutoStartEnabled = true; } else { Task.Run(() => new ProjectInstaller().Uninstall()); Settings.AutoStartEnabled = false; } }; if (!Settings.Configured && !Settings.AutoStartEnabled) { this.EnableAutoStart.Checked = true; } this.TeleportationActive.Checked = Settings.TeleportationActive; this.TeleportationActive.CheckedChanged += delegate { if (TeleportationActive.Checked) { Service.StartService(); Settings.TeleportationActive = true; } else { Service.StopService(); Settings.TeleportationActive = false; } }; }