/// <summary> /// Changes the current activity and saves the old one. /// Closes the dialog afterwards. /// </summary> /// <param name="name">The name if the new activity. Leave it empty if the name of the last activity should be used.</param> /// <param name="confirmClicked">True, if the confirm button was clicked.</param> private void SetNewActivity(string name = null, bool confirmClicked = false) { if (AppStateTracker.CurrentActivity == null || !ComboBox.Text.Equals(AppStateTracker.CurrentActivity.Name)) { AppStateTracker.SaveCurrentActivity(); AppStateTracker.CreateCurrentActivity(name ?? DefaultName, ToDate); if (confirmClicked) { AppStateTracker.LastConfirmed = DateTime.Now; } } if (this.IsLoaded) // Can only close if the window still exists { this.Close(); } }
/// <summary> /// Sets the activity for the time while the users was away. /// Closes the dialog afterwards. /// </summary> /// <param name="name">The name of the activity</param> private void SetNewActivity(string name) { AppStateTracker.CreateCurrentActivity(name, FromDate); AppStateTracker.SaveCurrentActivity(ToDate); Close(); }
/// <summary> /// Checks if the activity has (presumably) changed. /// Saves the current window if the program has changed. /// If the activity has not changed but no activity is running, also creates a new activity (without notifying the user). /// </summary> /// <param name="windowTitle">The name of the new window/program</param> /// <returns>True, if the activity has (presumably) changed; otherwise False</returns> private bool ActivitySwitched(string windowTitle) { if (AppStateTracker.Paused) { return(false); } string[] SplitWindowTitle = windowTitle.Split(new string[] { "- " }, StringSplitOptions.None); if (SplitWindowTitle.Length < 1) // Ignore empty window titles { return(false); } string ProgramTitle = SplitWindowTitle.Last(); string WindowDetails = SplitWindowTitle.Length > 1 ? string.Join("- ", SplitWindowTitle.Take(SplitWindowTitle.Length - 1)) : ""; bool HasBeenSeen = false; DateTime LastSeen; // Load need variables from settings long TimeNotUsed = Settings.Default.TimeSinceAppLastUsed * 60 * 1000; // Convert to ms long Timeout2 = Settings.Default.TimeBeforeAskingAgain; // Stop if the current activity is blacklisted or a file path if (Settings.Default.Blacklist.Contains(ProgramTitle) || ProgramTitle.Contains("\\")) { if (!windowTitle.Equals("NotificationsWindow - TimeTracker")) { AppStateTracker.SaveCurrentWindow(); } return(false); } // Check if the window has not been see for more than whatever is specified in the settings if (AppStateTracker.WindowsLastSeen.TryGetValue(ProgramTitle, out LastSeen)) { HasBeenSeen = TimeNotUsed > DateTime.Now.Subtract(LastSeen).TotalMilliseconds; } // If window has not changed do nothing if (AppStateTracker.CurrentWindow != null && AppStateTracker.CurrentWindow.Name.Equals(ProgramTitle)) { return(false); } AppStateTracker.SaveCurrentWindow(); AppStateTracker.CreateCurrentWindow(ProgramTitle, WindowDetails); // Show notification if app has not been seen in last few minutes if ((AppStateTracker.LastConfirmed == null || DateTime.Now.Subtract((DateTime)AppStateTracker.LastConfirmed).TotalSeconds > Timeout2) && !HasBeenSeen && AppStateTracker.Disturb) { return(true); } // Handle case that window has been seen shortly before but still no activity is running. In this case just start up another activity of the same kind else if (AppStateTracker.CurrentActivity == null) { AppStateTracker.CreateCurrentActivity(); // Creates a new activity using the name of the last activity. } return(false); }