Пример #1
0
        public void SetSettingsShouldSaveSettings(bool autotrack, bool pomodoro)
        {
            Toggl.TogglSettingsView currentSettings = default;
            Toggl.OnSettings += ReadCurrentSettings;
            Toggl.EditPreferences();
            Toggl.OnSettings -= ReadCurrentSettings;
            void ReadCurrentSettings(bool open, Toggl.TogglSettingsView settings) => currentSettings = settings;

            var savedAutotrack = false;
            var savedPomodoro  = false;

            Toggl.OnSettings += ReadSavedSettings;

            currentSettings.Autotrack = autotrack;
            currentSettings.Pomodoro  = pomodoro;
            Toggl.SetSettings(currentSettings);

            void ReadSavedSettings(bool open, Toggl.TogglSettingsView settings)
            {
                savedAutotrack = settings.Autotrack;
                savedPomodoro  = settings.Pomodoro;
            }

            Assert.Equal(autotrack, savedAutotrack);
            Assert.Equal(pomodoro, savedPomodoro);

            Toggl.OnSettings -= ReadSavedSettings;
        }
Пример #2
0
        private static HttpClientFactory HttpClientFactoryFromProxySettings(Toggl.TogglSettingsView settings)
        {
            var proxyHttpClientFactory = new ProxySupportedHttpClientFactory
            {
                UseProxy = settings.UseProxy
            };

            if (settings.AutodetectProxy)
            {
                proxyHttpClientFactory.Proxy = WebRequest.DefaultWebProxy;
            }
            else if (settings.UseProxy)
            {
                if (!Uri.CheckHostName(settings.ProxyHost).Equals(UriHostNameType.Unknown))
                {
                    var proxy = new WebProxy(settings.ProxyHost + ":" + settings.ProxyPort, true);

                    if (!string.IsNullOrEmpty(settings.ProxyUsername))
                    {
                        proxy.Credentials = new NetworkCredential(settings.ProxyUsername, settings.ProxyPassword);
                    }
                    proxyHttpClientFactory.Proxy = proxy;
                }
            }

            return(proxyHttpClientFactory);
        }
        private void updateUI(Toggl.TogglSettingsView settings)
        {
            #region general

            this.idleDetectionCheckBox.IsChecked   = settings.UseIdleDetection;
            this.idleDetectionDurationTextBox.Text = settings.IdleMinutes.ToString();

            this.recordTimelineCheckBox.IsChecked = settings.RecordTimeline;
            this.onTopCheckBox.IsChecked          = settings.OnTop;

            #endregion

            #region proxy

            this.useNoProxyRadioButton.IsChecked          = true;
            this.useSystemProxySettingsCheckBox.IsChecked = settings.AutodetectProxy;
            this.useProxyCheckBox.IsChecked = settings.UseProxy;
            this.proxyHostTextBox.Text      = settings.ProxyHost;
            this.proxyPortTextBox.Text      = settings.ProxyPort.ToString();
            this.proxyUsernameTextBox.Text  = settings.ProxyUsername;
            this.proxyPasswordBox.Password  = settings.ProxyPassword;

            #endregion

            #region reminder

            this.remindToTrackCheckBox.IsChecked   = settings.Reminder;
            this.remindToTrackIntervalTextBox.Text = settings.ReminderMinutes.ToString();
            this.reminderStartTimeTextBox.Text     = settings.RemindStarts;
            this.reminderEndTimeTextBox.Text       = settings.RemindEnds;

            this.remindOnMondayTextBox.IsChecked    = settings.RemindMon;
            this.remindOnTuesdayTextBox.IsChecked   = settings.RemindTue;
            this.remindOnWednesdayTextBox.IsChecked = settings.RemindWed;
            this.remindOnThursdayTextBox.IsChecked  = settings.RemindThu;
            this.remindOnFridayTextBox.IsChecked    = settings.RemindFri;
            this.remindOnSaturdayTextBox.IsChecked  = settings.RemindSat;
            this.remindOnSundayTextBox.IsChecked    = settings.RemindSun;

            #endregion

            #region global shortcuts

            this.showHideShortcutRecorder.Reset();
            this.continueStopShortcutRecorder.Reset();

            trySetHotKey(
                () => Properties.Settings.Default.ShowKey,
                () => Properties.Settings.Default.ShowModifiers,
                this.showHideShortcutRecordButton
                );
            trySetHotKey(
                () => Properties.Settings.Default.StartKey,
                () => Properties.Settings.Default.StartModifiers,
                this.continueStopShortcutRecordButton
                );

            #endregion
        }
        private Toggl.TogglSettingsView createSettingsFromUI()
        {
            var settings = new Toggl.TogglSettingsView
            {
                #region general

                UseIdleDetection = isChecked(this.idleDetectionCheckBox),
                IdleMinutes      = toULong(this.idleDetectionDurationTextBox.Text),

                RecordTimeline = isChecked(this.recordTimelineCheckBox),
                OnTop          = isChecked(this.onTopCheckBox),

                #endregion

                #region proxy

                AutodetectProxy = isChecked(this.useSystemProxySettingsCheckBox),
                UseProxy        = isChecked(this.useProxyCheckBox),
                ProxyHost       = this.proxyHostTextBox.Text,
                ProxyPort       = toULong(this.proxyPortTextBox.Text),
                ProxyUsername   = this.proxyUsernameTextBox.Text,
                ProxyPassword   = this.proxyPasswordBox.Password,

                #endregion

                #region reminder

                Reminder        = isChecked(this.remindToTrackCheckBox),
                ReminderMinutes = toULong(this.remindToTrackIntervalTextBox.Text),
                RemindStarts    = this.reminderStartTimeTextBox.Text,
                RemindEnds      = this.reminderEndTimeTextBox.Text,

                RemindMon = isChecked(this.remindOnMondayTextBox),
                RemindTue = isChecked(this.remindOnTuesdayTextBox),
                RemindWed = isChecked(this.remindOnWednesdayTextBox),
                RemindThu = isChecked(this.remindOnThursdayTextBox),
                RemindFri = isChecked(this.remindOnFridayTextBox),
                RemindSat = isChecked(this.remindOnSaturdayTextBox),
                RemindSun = isChecked(this.remindOnSundayTextBox),

                #endregion
            };

            return(settings);
        }
        private void onSettings(bool open, Toggl.TogglSettingsView settings)
        {
            if (this.TryBeginInvoke(this.onSettings, open, settings))
            {
                return;
            }

            using (Performance.Measure("filling settings from OnSettings"))
            {
                this.updateUI(settings);
            }

            if (open)
            {
                this.Show();
                this.Topmost = true;
            }
        }
        private Toggl.TogglSettingsView createSettingsFromUI()
        {
            var settings = new Toggl.TogglSettingsView
            {
                #region general

                UseIdleDetection = isChecked(this.idleDetectionCheckBox),
                IdleMinutes = toULong(this.idleDetectionDurationTextBox.Text),

                RecordTimeline = isChecked(this.recordTimelineCheckBox),
                OnTop = isChecked(this.onTopCheckBox),

                #endregion

                #region proxy

                AutodetectProxy = isChecked(this.useSystemProxySettingsCheckBox),
                UseProxy = isChecked(this.useProxyCheckBox),
                ProxyHost = this.proxyHostTextBox.Text,
                ProxyPort = toULong(this.proxyPortTextBox.Text),
                ProxyUsername = this.proxyUsernameTextBox.Text,
                ProxyPassword = this.proxyPasswordBox.Password,

                #endregion

                #region reminder

                Reminder = isChecked(this.remindToTrackCheckBox),
                ReminderMinutes = toULong(this.remindToTrackIntervalTextBox.Text),
                RemindStarts = this.reminderStartTimeTextBox.Text,
                RemindEnds = this.reminderEndTimeTextBox.Text,

                RemindMon = isChecked(this.remindOnMondayTextBox),
                RemindTue = isChecked(this.remindOnTuesdayTextBox),
                RemindWed = isChecked(this.remindOnWednesdayTextBox),
                RemindThu = isChecked(this.remindOnThursdayTextBox),
                RemindFri = isChecked(this.remindOnFridayTextBox),
                RemindSat = isChecked(this.remindOnSaturdayTextBox),
                RemindSun = isChecked(this.remindOnSundayTextBox),

                #endregion
            };

            return settings;
        }
Пример #7
0
 private void OnSettings(bool open, Toggl.TogglSettingsView settings)
 {
     _httpClientFactory = HttpClientFactoryFromProxySettings(settings);
 }