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; }
void StartApp() { //The app must be hosted as x86 otherwise the Clipboard some operations can lead to //the CLR crash. Shocking! // //Very tempting to use Caliburn.Micro but for such a simple UI it's a bit overkill. //But more importantly the current CB.M depends on .NET v4.5 at least. It also requires //System.Windows.Interactivity, which is distributed by MS individually. Thus the deployment pressure //is to much for such a simple app as this one. // //Packing of MultiClip.exe into MultiClip.UI.exe resources is also motivated by the deployment considerations //SettingsView.Popup(); //return; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; ClipboardMonitor.Restart(); new Bootstrapper().Run(); }