示例#1
0
 private void AlarmNotifyIcon_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         TrayContextMenuStrip.Show();
     }
 }
示例#2
0
        private void EnabledToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Toggle the checkbox on the menu item
            alarmEnabled = !EnabledToolStripMenuItem.Checked;
            EnabledToolStripMenuItem.Checked = alarmEnabled;
            AlarmEnabledCheckBox.Checked     = alarmEnabled;

            // Set the time for the current or next day accordingly
            RolloverTime();

            // Activate/deactive the timer
            AlarmTimer.Enabled = alarmEnabled;

            TrayContextMenuStrip.Hide();
        }
示例#3
0
        private void TrayIcon_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (e.Button == MouseButtons.Left)
                {
                    TrayContextMenuStrip.Show();
                }
            }
            else if (e.Button == MouseButtons.Left)
            {
                if (!Visible)
                {
                    ShowForm();
                }
                else
                {
                    if (WindowState == FormWindowState.Minimized)
                    {
                        WindowState = FormWindowState.Normal;

                        if (StartHidden)
                        {
                            StartHidden = false;
                            CenterForm();
                        }

                        Opacity = 1;
                    }

                    ShowInTaskbar = true;

                    Activate();
                    Focus();
                    BringToFront();
                }
            }
        }
示例#4
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            MessagesImageList.Images.Add("staff", Properties.Resources.TwitchStaff_18x);
            MessagesImageList.Images.Add("admin", Properties.Resources.Admin_18x);
            MessagesImageList.Images.Add("glomod", Properties.Resources.GlobalModerator_18x);
            MessagesImageList.Images.Add("caster", Properties.Resources.Broadcaster_18x);
            MessagesImageList.Images.Add("mod", Properties.Resources.Moderator_18x);
            MessagesImageList.Images.Add("whisper", Properties.Resources.Whisper_18x);

            ChangingChannelLabel.BringToFront();
            TrayContextMenuStrip.PerformLayout();
            TrayNotifyIcon.Visible = true;

            _NotificationsClient.UserFilter.SetUserWhitelist(SettingsManager.Configuration.Notifications.Whitelist.UsersAsList);
            _NotificationsClient.UserFilter.SetUserBlacklist(SettingsManager.Configuration.Notifications.Blacklist.UsersAsList);
            _NotificationsClient.MessageFilter.SetMessages(SettingsManager.Configuration.Notifications.Blacklist.Messages);

            _NotificationsClient.Notification    += NotificationsClient_Notification;
            _NotificationsClient.ChangingChannel += NotificationsClient_ChangingChannel;

RetryNotificationsClientStart:
            try {
                // Start the notifications client
                _NotificationsClient.Start(SettingsManager.Configuration.Notifications.TwitchChannel);
            } catch (ArgumentException ex) {
                ChangingChannelLabel.Text    = $"{ex.Message}{Environment.NewLine}{Environment.NewLine}Pleae open settings and set a valid channel.";
                ChangingChannelLabel.Visible = true;
            } catch (Exception ex) {
                LoggingManager.Log.Error(ex);

                string errorMessage = string.Empty;
                if (ex.GetType() == typeof(AggregateException))
                {
                    AggregateException agex = (AggregateException)ex;

                    foreach (Exception agexItem in agex.InnerExceptions)
                    {
                        errorMessage += $"{agexItem.Message}{Environment.NewLine}";
                    }
                }
                else
                {
                    errorMessage = ex.Message;
                }

                DialogResult answer = MessageBox.Show(this, $"{errorMessage.Trim()}{Environment.NewLine}{Environment.NewLine}" +
                                                      $"Make sure you have a valid 'twitchToken' in the settings file:{Environment.NewLine}" +
                                                      $"{Constants.SettingsFile}{Environment.NewLine}{Environment.NewLine}" +
                                                      $"Click retry to try again, ignore to enter a new OAuth Token, or abort to exit.", "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2);

                if (answer == DialogResult.Retry)
                {
                    goto RetryNotificationsClientStart;
                }
                else if (answer == DialogResult.Ignore)
                {
                    SetupForm setupForm = new SetupForm();
                    setupForm.ShowDialog();

                    goto RetryNotificationsClientStart;
                }
                else
                {
                    _IsExit = true;
                    Close();

                    return;
                }
            }

            UsernameLabel.Text = _NotificationsClient.AuthorizedUser.DisplayName;
            UserLogoPictureBox.ImageLocation = _NotificationsClient.AuthorizedUser.ProfilePictureUrl;

            UpdateMessagesTimer.Start();
        }
        public TrayApplicationContext(
            ILogger<TrayApplicationContext> logger,
            TrayContextMenuStrip contextMenu,
            NotifyIconManager notifyIconManager,
            AppState appState,
            StartupManager startupManager,
            ConfigurationUpdater configurationUpdater
        )
        {
            if (notifyIconManager == null)
            {
                throw new ArgumentNullException(nameof(notifyIconManager));
            }

            if (appState == null)
            {
                throw new ArgumentNullException(nameof(appState));
            }

            if (startupManager == null)
            {
                throw new ArgumentNullException(nameof(startupManager));
            }

            if (configurationUpdater == null)
            {
                throw new ArgumentNullException(nameof(configurationUpdater));
            }

            this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
            this.contextMenu = contextMenu ?? throw new ArgumentNullException(nameof(contextMenu));

            notifyIconManager.NotifyIcon.ContextMenuStrip = contextMenu;

            appState.OnMachineStateChange += (object _, MachineStateChangeEventArgs __) => UpdateContextMenu();

            appState.OnConfigurationChange += (object _, ConfigurationChangeEventArgs e) =>
            {
                if (e.NewConfiguration.StartWithWindows != startupManager.IsEnabled())
                {
                    if (e.NewConfiguration.StartWithWindows)
                    {
                        startupManager.EnableStartup();
                    }
                    else
                    {
                        startupManager.DisableStartup();
                    }
                }

                if (e.NewConfiguration.ShowTrayIcon)
                {
                    notifyIconManager.ShowIcon();
                }
                else
                {
                    notifyIconManager.HideIcon();
                }

                CreateContextMenu();
            };

            if (appState.Configuration.ShowTrayIcon)
            {
                notifyIconManager.ShowIcon();
            }
            else if (!Program.IsAutoStarting())
            {
                // If the program is not auto-starting and the tray icon is not visible the user launched the
                // application manually and it was not already running.  We will show the configuration under the
                // assumption they are looking for it.
                configurationUpdater.ShowConfigurationForm();
            }

            CreateContextMenu();
        }
示例#6
0
 private void SettingsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     TrayContextMenuStrip.Hide();
     this.Show();
 }