public void Run() { bool justCreated = SettingsView.EnsureDefaults(); bool clearAtStartup = !SettingsViewModel.Load().RestoreHistoryAtStartup; ClipboardMonitor.Start(clearAtStartup); TrayIcon.ShowHistory = (s, a) => HistoryView.Popup(); TrayIcon.ShowSettings = (s, a) => SettingsView.Popup(); TrayIcon.Rehook = (s, a) => { ClipboardMonitor.Restart(); TrayIcon.RefreshIcon(); }; TrayIcon.Test = (s, a) => ClipboardMonitor.Test(); TrayIcon.Exit = (s, a) => this.Close(); TrayIcon.Init(); hotKeys.Start(); HotKeysMapping.EmbeddedHandlers[HistoryView.PopupActionName] = HistoryView.Popup; HotKeysMapping.EmbeddedHandlers[ClipboardMonitor.ToPlainTextActionName] = ClipboardMonitor.ToPlainText; HotKeysMapping.EmbeddedHandlers[HotKeysView.PopupActionName] = HotKeysView.Popup; HotKeysMapping.EmbeddedHandlers[ClipboardMonitor.RestartActionName] = ClipboardMonitor.Restart; HotKeysMapping.Bind(hotKeys, TrayIcon.InvokeMenu); var timer = new System.Windows.Threading.DispatcherTimer(); var lastCheck = DateTime.Now; timer.Tick += (s, e) => { ClipboardMonitor.Test(); if ((DateTime.Now - lastCheck) > TimeSpan.FromMinutes(5)) // to ensure that after a long sleep we are restarting { ClipboardMonitor.Restart(); } lastCheck = DateTime.Now; // refreshing works but I am not convinced it is beneficial enough to be released // it also creates a short flickering effect every minute. // TrayIcon.RefreshIcon(); }; timer.Interval = TimeSpan.FromMinutes(1); timer.Start(); var test2 = "The quick brown fox jumps over a lazy dog" + DateTime.Now; if (justCreated) { SettingsView.Popup(); //can pop it up without any side effect only after all messaging is initialized } SystemEvents.PowerModeChanged += OnPowerChange; }
private void Close() { try { ClipboardMonitor.Stop(shutdown: true); SettingsView.CloseIfAny(); HistoryView.CloseIfAny(); hotKeys.Stop(); TrayIcon.Close(); } catch { } }
public static void Popup() { if (activeView == null) { try { HotKeys.Instance.UnregisterAll(); (activeView = new SettingsView()).ShowDialog(); } catch { } finally { activeView = null; HotKeysMapping.Bind(HotKeys.Instance, TrayIcon.InvokeMenu); } } }