public void InitializeChromium(StorageHandler storageHandler, AppStateTracker appStateTracker) { string CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; if (!Cef.IsInitialized) { CefSettings Settings = new CefSettings(); Settings.IgnoreCertificateErrors = true; Settings.BrowserSubprocessPath = String.Format("{0}CefSharp.BrowserSubprocess.exe", CurrentDirectory); // Initialize cef with the provided settings Cef.Initialize(Settings, performDependencyCheck: false, browserProcessHandler: null); } // Create a browser component String Page = string.Format(@"{0}\index.html", CurrentDirectory); ChromeBrowser = new ChromiumWebBrowser(Page); // Add it to the form and fill it to the form window. ChromeBrowser.Dock = DockStyle.Fill; // Allow the use of local resources in the browser BrowserSettings BrowserSettings = new BrowserSettings(); BrowserSettings.FileAccessFromFileUrls = CefState.Enabled; BrowserSettings.UniversalAccessFromFileUrls = CefState.Enabled; ChromeBrowser.BrowserSettings = BrowserSettings; ChromeBrowser.JavascriptObjectRepository.Register("boundAsync", new MyScriptingClass(storageHandler, appStateTracker), true); // ChromeBrowser.FrameLoadEnd += (e, r) => ChromeBrowser.ShowDevTools(); WindowsFormsHost.Child = ChromeBrowser; }
/// <summary> /// Decides if the activity/window has truely changed. /// If so, triggers the activity dialog. /// </summary> /// <param name="appStateTracker">The state tracker for this app</param> /// <param name="programSwitchListener">A listener to determine if the current window has changed</param> /// <param name="machineStateListener">A listener to determine if the machine state has changed</param> /// <param name="hotkeyListener">A listener to detemrine if the hotkey has been pressed</param> public ASDL(AppStateTracker appStateTracker, ProgramSwitchListener programSwitchListener, MachineStateListener machineStateListener, HotkeyListener hotkeyListener) { AppStateTracker = appStateTracker; programSwitchListener.ProgramChanged += ListenerEvent; machineStateListener.StateChanged += ListenerEvent; hotkeyListener.KeyCombinationPressed += ListenerEvent; }
/// <summary> /// Inializes the AwayFromPCDialog. /// </summary> /// <param name="storageHandler">Handles reading and writing from/to the csv files</param> /// <param name="appStateTracker">Tracks the state of the app</param> /// <param name="lastLocked">The time when the machine was locked</param> public AwayFromPCDialog(StorageHandler storageHandler, AppStateTracker appStateTracker, DateTime lastLocked) { InitializeComponent(); FromDate = lastLocked; ToDate = DateTime.Now; StorageHandler = storageHandler; AppStateTracker = appStateTracker; Label.Content = "What were you doing since " + FromDate.ToShortTimeString() + "?"; TimeElapsed.Content = (ToDate - FromDate).ToString().Substring(0, 8); // Load the last acitvities so that they can be displayed in the dropdown menu Activities = StorageHandler.GetLastActivitiesGrouped().Select(rg => new CustomComboBoxItem() { Name = rg.Key, Selectable = true }).ToList(); DefaultName = AppStateTracker.CurrentActivity?.Name ?? Activities.FirstOrDefault()?.Name ?? ""; if (AppStateTracker.CurrentActivity != null && !Activities.Any(a => a.Name.Equals(DefaultName))) { Activities.Insert(0, new CustomComboBoxItem() { Name = DefaultName, Selectable = true }); } // Make only the first 5 options visible. The other should still be loaded so that autocomplete works for (int i = 0; i < Activities.Count(); i++) { Activities[i].Visible = i < 5 ? "Visible" : "Collapsed"; } // Inserst a unselectable template at the top of the list. // This should serve as an example on how to input activities. Activities.Insert(0, new CustomComboBoxItem() { Name = "Activity - Subactivity", Selectable = false }); ComboBox.ItemsSource = Activities; ComboBox.SelectedItem = Activities.Where(a => a.Name.Equals(DefaultName)).FirstOrDefault(); }
/// <summary> /// Sets up the base of the application. /// Everything is coordinated from here. /// </summary> /// <param name="e">The startup event</param> protected override void OnStartup(StartupEventArgs e) { bool createdNew; _instanceMutex = new Mutex(true, "1ca95cf6-561b-4dc0-acd5-d83b3e4030b4", out createdNew); if (!createdNew) { _instanceMutex = null; System.Windows.Application.Current.Shutdown(); return; } // Set up app to run in the background base.OnStartup(e); // Sets up the main window MainWindow = new MainWindow(); // Sets up the taskbar icon and the menu that show if you left-click on it NotifyIcon = new System.Windows.Forms.NotifyIcon(); NotifyIcon.Icon = new Icon(TimeTracker.Properties.Resources.icon, SystemInformation.SmallIconSize); NotifyIcon.Visible = true; CreateContextMenu(); // Creates classes needed to track activities and windows StorageHandler = new StorageHandler(); AppStateTracker = new AppStateTracker(StorageHandler); ProgramSwitchListener = new ProgramSwitchListener(); MachineStateListener = new MachineStateListener(); HotkeyListener = new HotkeyListener(); ASDL = new ASDL(AppStateTracker, ProgramSwitchListener, MachineStateListener, HotkeyListener); // Attaches listeners NotifyIcon.DoubleClick += (s, args) => ASDL.ChangeActivity(); MachineStateListener.StateChanged += ListenerEvent; AppStateTracker.ChangeContextMenu += (s, args) => NotifyIcon.ContextMenuStrip.Items[2].Text = ((bool)args.Value) ? "Unpause" : "Pause"; ASDL.ShowActivityDialog += CreateActivityDialog; ASDL.ShowAwayFromPCDialog += CreateAwayFromPCDialog; ShowTutorialIfNeeded(); CheckForUpdates(); }
/// <summary> /// The activity dialog shown in the bottom right corner asking the users if he is still working on the same acitivity. /// </summary> /// <param name="storageHandler">Handles reading and writing from/to the csv files</param> /// <param name="appStateTracker">Tracks the state of the app</param> /// <param name="focusToast">True, if the dialog should be focused, otherwise False</param> public ActivityDialog(StorageHandler storageHandler, AppStateTracker appStateTracker, bool focusToast) { InitializeComponent(); StorageHandler = storageHandler; AppStateTracker = appStateTracker; ToDate = DateTime.Now; // Move toast to the bottom right Rect DesktopWorkingArea = SystemParameters.WorkArea; Left = DesktopWorkingArea.Right - Width - 15; Top = DesktopWorkingArea.Bottom - Height - 12; // Load the last acitvities so that they can be displayed in the dropdown menu Activities = StorageHandler.GetLastActivitiesGrouped().Select(rg => new CustomComboBoxItem() { Name = rg.Key, Selectable = true }).ToList(); DefaultName = AppStateTracker.CurrentActivity?.Name ?? Activities.FirstOrDefault()?.Name ?? ""; if (AppStateTracker.CurrentActivity != null && !Activities.Any(a => a.Name.Equals(DefaultName))) { Activities.Insert(0, new CustomComboBoxItem() { Name = DefaultName, Selectable = true }); } // Make only the first 5 options visible. The other should still be loaded so that autocomplete works for (int i = 0; i < Activities.Count(); i++) { Activities[i].Visible = i < 5 ? "Visible" : "Collapsed"; } // Inserst a unselectable template at the top of the list. // This should serve as an example on how to input activities. Activities.Insert(0, new CustomComboBoxItem() { Name = "Activity - Subactivity", Selectable = false }); ComboBox.ItemsSource = Activities; ComboBox.SelectedItem = Activities.Where(a => a.Name.Equals(DefaultName)).FirstOrDefault(); TextBlock2.Text = AppStateTracker.CurrentWindow?.Name.Trim() ?? "No window active"; Timeout = Settings.Default.TimeNotificationVisible * 1000; // Convert to ms if (Settings.Default.PlayNotificationSound) { SystemSounds.Hand.Play(); } if (focusToast) { ComboBox.Focus(); } DeletedSuggestion = false; DeletedSuggestionCounter = 0; TextLengthCounter = ComboBox.Text.Length; SetupClose(); }
public HTMLDataWindow(StorageHandler storageHandler, AppStateTracker appStateTracker) { InitializeComponent(); InitializeChromium(storageHandler, appStateTracker); }