Exemple #1
0
        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>
        /// 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();
        }
Exemple #4
0
 /// <summary>
 /// Allows the user to manually change the activies and their time slots
 /// </summary>
 /// <param name="storageHandler">Used to read and write from/to the csv files</param>
 public ManualEdit(StorageHandler storageHandler)
 {
     InitializeComponent();
     StorageHandler = storageHandler;
     LoadData();
 }
Exemple #5
0
        /// <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();
        }
Exemple #6
0
        /// <summary>
        /// Keeps track of the apps state variables.
        /// </summary>
        /// <param name="storageHandler">
        /// Handles writing to the csv files.
        /// </param>
        public AppStateTracker(StorageHandler storageHandler)
        {
            WindowsLastSeen = new Dictionary <string, DateTime>();
            LastConfirmed   = null;
            CurrentWindow   = null;
            CurrentActivity = null;
            LastLocked      = null;
            Paused          = false;
            Disturb         = true;
            StorageHandler  = storageHandler;

            Colors = new Dictionary <string, List <string> >();

            // Blue
            Colors.Add("#7cd6fd", new List <string>
            {
                "#81d8fd",
                "#4fc8fc",
                "#1db8fc",
                "#039fe2",
            });

            // Lila
            Colors.Add("#5e64ff", new List <string>
            {
                "#8084ff",
                "#4d53ff",
                "#1a22ff",
                "#0009e6"
            });

            // Lila 2
            Colors.Add("#743ee2", new List <string>
            {
                "#af90ee",
                "#8f64e8",
                "#6f37e1",
                "#561ec8"
            });

            // Red
            Colors.Add("#ff5858", new List <string>
            {
                "#ff8080",
                "#ff4d4d",
                "#ff1a1a",
                "#e60000"
            });

            // Orange
            Colors.Add("#ffa00a", new List <string>
            {
                "#ffce80",
                "#ffba4d",
                "#ffa61a",
                "#e68d00"
            });

            // Yellow
            Colors.Add("#feef72", new List <string>
            {
                "#fef180",
                "#feeb4e",
                "#fde51b",
                "#e4cc02"
            });

            // Green
            Colors.Add("#28a745", new List <string>
            {
                "#98e6aa",
                "#6fdd88",
                "#46d366",
                "#2cb94d"
            });

            // Green 2
            Colors.Add("#98d85b", new List <string>
            {
                "#bee798",
                "#a4dd6f",
                "#8bd346",
                "#71b92c"
            });

            // Lila 3
            Colors.Add("#b554ff", new List <string>
            {
                "#c880ff",
                "#b24dff",
                "#9c1aff",
                "#8200e6"
            });

            // Pink
            Colors.Add("#ffa3ef", new List <string>
            {
                "#ff80e9",
                "#ff4de0",
                "#ff1ad7",
                "#e600be"
            });

            // Blue 2
            Colors.Add("#bdd3e6", new List <string>
            {
                "#a3c1dc",
                "#7ea9ce",
                "#5990c0",
                "#3f77a6"
            });

            // Gray
            Colors.Add("#b8c2cc", new List <string>
            {
                "#b5bfca",
                "#97a6b4",
                "#798c9f",
                "#607386"
            });

            AssignColors();
        }
Exemple #7
0
 public HTMLDataWindow(StorageHandler storageHandler, AppStateTracker appStateTracker)
 {
     InitializeComponent();
     InitializeChromium(storageHandler, appStateTracker);
 }