コード例 #1
0
        /// <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();
        }
コード例 #2
0
        /// <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;
        }