private static void setShortcut(HotKey hotKey, string shortcutName, Action <ModifierKeys> setModifier, Action <string> setKey) { if (hotKey == null) { return; } try { if (hotKey.Key != Key.None) { setModifier(hotKey.ModifierKeys); setKey(hotKey.Key.ToString()); } else { setModifier(ModifierKeys.None); setKey(null); } } catch (Exception ex) { Toggl.Debug($"Could not set shortcut for {shortcutName}: {ex}"); } }
public static void LoadWindowLocation(Window mainWindow, EditViewPopup editPopup, MiniTimerWindow miniTimer) { if (editPopup != null) { editPopup.Width = Toggl.GetEditViewWidth(); } if (Toggl.GetWindowMaximized()) { mainWindow.WindowState = WindowState.Maximized; } else if (Toggl.GetWindowMinimized()) { mainWindow.WindowState = WindowState.Minimized; } long x = 0, y = 0, h = 0, w = 0; if (Toggl.WindowSettings(ref x, ref y, ref h, ref w) && ValidateWindowSettings(x, y, h, w)) { mainWindow.Left = x; mainWindow.Top = y; mainWindow.Width = w; mainWindow.Height = h; Toggl.Debug("Retrieved window location and size ({0}x{1} by {2}x{3})", x, y, w, h); } else { mainWindow.Width = 330; mainWindow.Height = 510; Toggl.Debug("Failed to retrieve window location and size. Setting the default size."); } // First try to shift the window onto the bounding box of visible screens if (ShiftWindowOntoVisibleArea(mainWindow)) { Toggl.Debug("Shifted main window onto visible area"); } // Then handle the case where the window is in the bounding box but not on any of the screens if (!VisibleOnAnyScreen(mainWindow)) { var location = Screen.PrimaryScreen.WorkingArea.Location; mainWindow.Left = location.X; mainWindow.Top = location.Y; Toggl.Debug("Force moved window to primary screen"); } if (miniTimer != null) { x = Toggl.GetMiniTimerX(); y = Toggl.GetMiniTimerY(); w = Toggl.GetMiniTimerW(); miniTimer.Left = x; miniTimer.Top = y; miniTimer.Width = w; Toggl.Debug("Retrieved mini timer location ({0}x{1} by {2})", x, y, w); CheckMinitimerVisibility(miniTimer); } }
public static void LoadWindowLocation(Window mainWindow, EditViewPopup editPopup, MiniTimerWindow miniTimer) { if (editPopup != null) { editPopup.Width = Toggl.GetEditViewWidth(); } if (Toggl.GetWindowMaximized()) { mainWindow.WindowState = WindowState.Maximized; } else if (Toggl.GetWindowMinimized()) { mainWindow.WindowState = WindowState.Minimized; } long x = 0, y = 0, h = 0, w = 0; if (Toggl.WindowSettings(ref x, ref y, ref h, ref w)) { mainWindow.Left = x; mainWindow.Top = y; mainWindow.Width = w; mainWindow.Height = h; Toggl.Debug("Retrieved window location and size ({0}x{1} by {2}x{3})", x, y, w, h); } else { Toggl.Debug("Failed to retrieve window location and size"); } if (!visibleOnAnyScreen(mainWindow)) { var location = Screen.PrimaryScreen.WorkingArea.Location; mainWindow.Left = location.X; mainWindow.Top = location.Y; Toggl.Debug("Force moved window to primary screen"); } if (miniTimer != null) { x = Toggl.GetMiniTimerX(); y = Toggl.GetMiniTimerY(); w = Toggl.GetMiniTimerW(); miniTimer.Left = x; miniTimer.Top = y; miniTimer.Width = w; Toggl.Debug("Retrieved mini timer location ({0}x{1} by {2})", x, y, w); if (!visibleOnAnyScreen(miniTimer)) { var location = Screen.PrimaryScreen.WorkingArea.Location; miniTimer.Left = location.X; miniTimer.Top = location.Y; Toggl.Debug("Force moved mini timer to primary screen"); } } }
public static void checkMinitimerVisibility(MiniTimerWindow miniTimer) { if (!visibleOnAnyScreen(miniTimer)) { var location = Screen.PrimaryScreen.WorkingArea.Location; miniTimer.Left = location.X; miniTimer.Top = location.Y; Toggl.Debug("Force moved mini timer to primary screen"); } }
static void notifyBugsnag(Exception e) { Toggl.Debug("Notifying bugsnag: " + e); try { bugsnag.Notify(e); } catch (Exception ex) { Toggl.Debug("Could not notify bugsnag: " + ex); } }
public static void SaveWindowLocation(Window mainWindow, EditViewPopup edit, MiniTimerWindow miniTimer) { long x, y, w, h; if (mainWindow.WindowState == WindowState.Minimized) { var rb = mainWindow.RestoreBounds; x = (long)rb.X; y = (long)rb.Y; w = (long)rb.Width; h = (long)rb.Height; } else { x = (long)mainWindow.Left; y = (long)mainWindow.Top; w = (long)mainWindow.Width; h = (long)mainWindow.Height; } var success = ValidateWindowSettings(x, y, h, w) && Toggl.SetWindowSettings(x, y, h, w); Toggl.Debug(success ? "Saved window location and size ({0}x{1} by {2}x{3})" : "Failed to save window location and size ({0}x{1} by {2}x{3})", x, y, w, h); var state = mainWindow.WindowState; Toggl.SetWindowMaximized(state == WindowState.Maximized); Toggl.SetWindowMinimized(state == WindowState.Minimized); if (edit != null) { Toggl.SetEditViewWidth((long)edit.Width); } if (miniTimer != null) { x = (long)miniTimer.Left; y = (long)miniTimer.Top; w = (long)miniTimer.Width; Toggl.SetMiniTimerX(x); Toggl.SetMiniTimerY(y); Toggl.SetMiniTimerW(w); Toggl.Debug("Saved mini timer location ({0}x{1} by {2})", x, y, w); } }
private bool ensureProjectColors() { if (this.colors != null) { return(true); } Toggl.GetProjectColors(); if (this.colors != null) { return(true); } Toggl.Debug("Error: Did not receive project colours when required."); return(false); }
static void notifyBugsnag(Exception e) { Toggl.Debug("Notifying bugsnag: " + e); try { var metadata = new Bugsnag.Metadata(); metadata.AddToTab("Details", "UserID", uid.ToString()); metadata.AddToTab("Details", "OSVersion", Environment.OSVersion.ToString()); metadata.AddToTab("Details", "Version", Version()); metadata.AddToTab("Details", "Channel", Toggl.UpdateChannel()); bugsnag.Notify(e, metadata); } catch (Exception ex) { Toggl.Debug("Could not notify bugsnag: " + ex); } }
public static void CheckMinitimerVisibility(MiniTimerWindow miniTimer) { // First try to shift the window onto the bounding box of visible screens if (ShiftWindowOntoVisibleArea(miniTimer)) { Toggl.Debug("Shifted mini timer onto visible area"); } // Then handle the case where the window is in the bounding box but not on any of the screens if (!VisibleOnAnyScreen(miniTimer)) { var location = Screen.PrimaryScreen.WorkingArea.Location; miniTimer.Left = location.X; miniTimer.Top = location.Y; Toggl.Debug("Force moved mini timer to primary screen"); } }
private void setGlobalShortcutsFromSettings() { try { var keyStart = Toggl.GetKeyStart(); if (keyStart != Key.None) { HotkeyManager.Current.AddOrReplace( "Toggl.ContinueOrStop", keyStart, Toggl.GetKeyModifierStart(), onGlobalStartKeyPressed); } else { HotkeyManager.Current.Remove("Toggl.ContinueOrStop"); } } catch (Exception e) { Toggl.Debug("Could not register start shortcut: " + e); } try { var keyShow = Toggl.GetKeyShow(); if (keyShow != Key.None) { HotkeyManager.Current.AddOrReplace( "Toggl.ShowHideToggl", keyShow, Toggl.GetKeyModifierShow(), onGlobalShowKeyPressed); } else { HotkeyManager.Current.Remove("Toggl.ShowHideToggl"); } } catch (Exception e) { Toggl.Debug("Could not register show hotkey: " + e); } }
private static void trySetHotKey(Func <string> getKeyCode, Func <ModifierKeys> getModifiers, ShortcutRecorder recorder) { try { var keyCode = getKeyCode(); if (string.IsNullOrEmpty(keyCode)) { recorder.Reset(null); return; } var modifiers = getModifiers(); recorder.Reset(new Utils.KeyCombination(modifiers, keyCode)); } catch (Exception e) { Toggl.Debug(string.Format("Could not load hotkey: {0}", e)); recorder.Reset(null); } }
private static void setShortcut(KeyCombination?e, string shortcutName, Action <ModifierKeys> setModifier, Action <string> setKey) { try { if (e.HasValue) { setModifier(e.Value.Modifiers); setKey(e.Value.KeyCode); } else { setModifier(0); setKey(null); } } catch (Exception ex) { Toggl.Debug(string.Format("Could not set shortcut for {0}: {1}", shortcutName, ex)); } }
private void setGlobalShortcutsFromSettings() { try { this.startHook.ChangeTo( Toggl.GetKeyModifierStart(), Toggl.GetKeyStart() ); } catch (Exception e) { Toggl.Debug("Could not register start shortcut: " + e); } try { this.showHook.ChangeTo( Toggl.GetKeyModifierShow(), Toggl.GetKeyShow() ); } catch (Exception e) { Toggl.Debug("Could not register show hotkey: " + e); } }
private void runScript() { if (!File.Exists(Toggl.ScriptPath)) { Toggl.Debug("Script file does not exist: " + Toggl.ScriptPath); this.shutdown(0); } var script = File.ReadAllText(Toggl.ScriptPath); long errorCode = 0; var result = Toggl.RunScript(script, ref errorCode); if (errorCode != 0) { Toggl.Debug(string.Format("Failed to run script, err = {0}", errorCode)); } Toggl.Debug(result); if (errorCode == 0) { this.shutdown(0); } }
static void Main() { Win32.AttachConsole(Win32.ATTACH_PARENT_PROCESS); using (Mutex mutex = new Mutex(false, "Global\\" + Environment.UserName + "_" + appGUID)) { if (!mutex.WaitOne(0, false)) { // See if we get hold of the other process. // If we do, activate it's window and exit. Process current = Process.GetCurrentProcess(); Process[] instances = Process.GetProcessesByName(current.ProcessName); foreach (Process p in instances) { if (p.Id != current.Id) { // gotcha IntPtr hWnd = p.MainWindowHandle; if (hWnd == IntPtr.Zero) { hWnd = Win32.SearchForWindow(current.ProcessName, "Toggl Desktop"); } Win32.ShowWindow(hWnd, Win32.SW_RESTORE); Win32.SetForegroundWindow(hWnd); return; } } // If not, print an error message and exit. System.Windows.MessageBox.Show("Another copy of Toggl Desktop is already running." + Environment.NewLine + "This copy will now quit."); return; } Toggl.InitialiseLog(); bugsnag = new Bugsnag.Clients.BaseClient("2a46aa1157256f759053289f2d687c2f"); #if INVS bugsnag.Config.ReleaseStage = "development"; #else bugsnag.Config.ReleaseStage = "production"; #endif Toggl.OnLogin += delegate(bool open, UInt64 user_id) { uid = user_id; }; Toggl.OnError += delegate(string errmsg, bool user_error) { Toggl.Debug(errmsg); try { if (!user_error && bugsnag.Config.ReleaseStage != "development") { notifyBugsnag(new Exception(errmsg)); } } catch (Exception ex) { Toggl.Debug("Could not check if can notify bugsnag: " + ex); } }; Application.ThreadException += Application_ThreadException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); RenderOptions.ProcessRenderMode = RenderMode.Default; new App().Run(); } }
static void Main() { Win32.AttachConsole(Win32.ATTACH_PARENT_PROCESS); using (Mutex mutex = new Mutex(false, "Global\\" + Environment.UserName + "_" + appGUID)) { if (!mutex.WaitOne(0, false)) { // See if we get hold of the other process. // If we do, activate it's window and exit. Process current = Process.GetCurrentProcess(); Process[] instances = Process.GetProcessesByName(current.ProcessName); foreach (Process p in instances) { if (p.Id != current.Id) { // gotcha IntPtr hWnd = p.MainWindowHandle; if (hWnd == IntPtr.Zero) { hWnd = Win32.SearchForWindow(current.ProcessName, "Toggl Desktop"); } Win32.ShowWindow(hWnd, Win32.SW_RESTORE); Win32.SetForegroundWindow(hWnd); return; } } // If not, print an error message and exit. System.Windows.MessageBox.Show("Another copy of Toggl Desktop is already running." + Environment.NewLine + "This copy will now quit."); return; } Toggl.InitialiseLog(); var configuration = new Bugsnag.Configuration("aa13053a88d5133b688db0f25ec103b7"); configuration.AppVersion = Version(); #if TOGGL_PRODUCTION_BUILD configuration.ReleaseStage = "production"; #else configuration.ReleaseStage = "development"; #endif bugsnag = new Bugsnag.Client(configuration); bugsnag.BeforeNotify(report => { report.Event.User = new Bugsnag.Payload.User { Id = uid.ToString() }; report.Event.Metadata.Add("Details", new Dictionary <string, string> { { "Channel", Toggl.UpdateChannel() } }); }); Toggl.OnLogin += delegate(bool open, UInt64 user_id) { uid = user_id; }; Toggl.OnError += delegate(string errmsg, bool user_error) { Toggl.Debug(errmsg); try { if (!user_error && bugsnag.Configuration.ReleaseStage != "development") { notifyBugsnag(new Exception(errmsg)); } } catch (Exception ex) { Toggl.Debug("Could not check if can notify bugsnag: " + ex); } }; Application.ThreadException += Application_ThreadException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; new App().Run(); } }