protected override async void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;
            await SettingsService.SaveSettings(Config);

            this.Hide();
        }
Example #2
0
        private async Task LoadSettings()
        {
            if (!(await SettingsService.IsFilePresent()))
            {
                await SettingsService.SaveSettings(_options);
            }

            Config = await SettingsService.LoadSettings();

            if (string.IsNullOrEmpty(Config.RedirectUri))
            {
                await SettingsService.DeleteSettings();

                await SettingsService.SaveSettings(_options);
            }
            if (!string.IsNullOrEmpty(Config.HueApiKey))
            {
                _options.HueApiKey = Config.HueApiKey;
            }

            if (!string.IsNullOrEmpty(Config.HueIpAddress))
            {
                _options.HueIpAddress = Config.HueIpAddress;
            }
        }
Example #3
0
        private async void btnApiSettingsSave_Click(object sender, RoutedEventArgs e)
        {
            await SettingsService.SaveSettings(Config);

            lblCustomApiSaved.Visibility = Visibility.Visible;
            SyncOptions();
        }
Example #4
0
        private async void SaveHueSettings_Click(object sender, RoutedEventArgs e)
        {
            await SettingsService.SaveSettings(Config);

            _hueService = new HueService(Config);
            CheckHueSettings();
        }
Example #5
0
        private async void SignOutButton_Click(object sender, RoutedEventArgs e)
        {
            lightMode = "Graph";
            var accounts = await WPFAuthorizationProvider.Application.GetAccountsAsync();

            if (accounts.Any())
            {
                try
                {
                    await WPFAuthorizationProvider.Application.RemoveAsync(accounts.FirstOrDefault());

                    this.signInPanel.Visibility = Visibility.Visible;
                    dataPanel.Visibility        = Visibility.Collapsed;

                    notificationIcon.Text  = PresenceConstants.Inactive;
                    notificationIcon.Icon  = new BitmapImage(new Uri(IconConstants.GetIcon(string.Empty, IconConstants.Inactive)));
                    hueIpAddress.IsEnabled = true;

                    if (Config.IsPhillipsEnabled && !string.IsNullOrEmpty(Config.HueApiKey) && !string.IsNullOrEmpty(Config.HueIpAddress) && !string.IsNullOrEmpty(Config.SelectedHueLightId))
                    {
                        await _hueService.SetColor("Off", Config.SelectedHueLightId);
                    }

                    if (lightMode == "Graph")
                    {
                        await SetColor("Off");
                    }
                }
                catch (MsalException)
                {
                }
            }
            await SettingsService.SaveSettings(Config);
        }
Example #6
0
        private async void cbSyncLights(object sender, RoutedEventArgs e)
        {
            //savedAvailability = string.Empty;
            SyncOptions();
            await SettingsService.SaveSettings(Config);

            e.Handled = true;
        }
Example #7
0
        private async void SaveLIFXSettings_Click(object sender, RoutedEventArgs e)
        {
            btnLIFX.IsEnabled = false;
            await SettingsService.SaveSettings(Config);

            lblLIFXSaved.Visibility = Visibility.Visible;
            btnLIFX.IsEnabled       = true;
        }
Example #8
0
        private async void SaveHueSettings_Click(object sender, RoutedEventArgs e)
        {
            btnHue.IsEnabled = false;
            await SettingsService.SaveSettings(Config);

            _hueService = new HueService(Config);
            CheckHueSettings();
            lblHueSaved.Visibility = Visibility.Visible;
            btnHue.IsEnabled       = true;
        }
Example #9
0
        private async void Current_SessionEnding(object sender, SessionEndingCancelEventArgs e)
        {
            if (!string.IsNullOrEmpty(Config.HueApiKey) && !string.IsNullOrEmpty(Config.HueIpAddress) && !string.IsNullOrEmpty(Config.SelectedHueLightId))
            {
                await _hueService.SetColor("Off", Config.SelectedHueLightId);
            }

            if (Config.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LIFXApiKey))
            {
                await _lifxService.SetColor("Off", (Selector)Config.SelectedLIFXItemId);
            }
            await SettingsService.SaveSettings(Config);
        }
Example #10
0
        private async Task LoadSettings()
        {
            if (!(await SettingsService.IsFilePresent()))
            {
                await SettingsService.SaveSettings(_options);
            }

            Config = await SettingsService.LoadSettings();

            if (string.IsNullOrEmpty(Config.RedirectUri))
            {
                await SettingsService.DeleteSettings();

                await SettingsService.SaveSettings(_options);
            }

            if (Config.IsPhillipsEnabled)
            {
                pnlPhillips.Visibility = Visibility.Visible;
                SyncOptions();
            }
            else
            {
                pnlPhillips.Visibility = Visibility.Collapsed;
            }

            if (Config.IsYeelightEnabled)
            {
                pnlYeelight.Visibility = Visibility.Visible;
                SyncOptions();
            }
            else
            {
                pnlYeelight.Visibility = Visibility.Collapsed;
            }

            if (Config.IsLIFXEnabled)
            {
                getTokenLink.Visibility = Visibility.Visible;
                pnlLIFX.Visibility      = Visibility.Visible;

                SyncOptions();
            }
            else
            {
                getTokenLink.Visibility = Visibility.Collapsed;
                pnlLIFX.Visibility      = Visibility.Collapsed;
            }
        }
Example #11
0
        private async void cbSyncLights(object sender, RoutedEventArgs e)
        {
            if (!Config.LightSettings.SyncLights)
            {
                await SetColor("Off");

                turnOffButton.Visibility = Visibility.Collapsed;
                turnOnButton.Visibility  = Visibility.Visible;
            }

            SyncOptions();
            await SettingsService.SaveSettings(Config);

            e.Handled = true;
        }
Example #12
0
        private async void OnExitClick(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(Config.HueApiKey) && !string.IsNullOrEmpty(Config.HueIpAddress) && !string.IsNullOrEmpty(Config.SelectedHueLightId))
            {
                await _hueService.SetColor("Off", Config.SelectedHueLightId);
            }

            if (Config.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LIFXApiKey))
            {
                await _lifxService.SetColor("Off", (Selector)Config.SelectedLIFXItemId);
            }
            await SettingsService.SaveSettings(Config);

            System.Windows.Application.Current.Shutdown();
        }
Example #13
0
        private async void SignOutButton_Click(object sender, RoutedEventArgs e)
        {
            lightMode = "Graph";
            var accounts = await WPFAuthorizationProvider.Application.GetAccountsAsync();

            if (accounts.Any())
            {
                try
                {
                    await WPFAuthorizationProvider.Application.RemoveAsync(accounts.FirstOrDefault());

                    this.signInPanel.Visibility = Visibility.Visible;
                    dataPanel.Visibility        = Visibility.Collapsed;

                    notificationIcon.Text  = PresenceConstants.Inactive;
                    notificationIcon.Icon  = new BitmapImage(new Uri(IconConstants.GetIcon(string.Empty, IconConstants.Inactive)));
                    hueIpAddress.IsEnabled = true;

                    if (Config.IsPhillipsEnabled && !string.IsNullOrEmpty(Config.HueApiKey) && !string.IsNullOrEmpty(Config.HueIpAddress) && !string.IsNullOrEmpty(Config.SelectedHueLightId))
                    {
                        await _hueService.SetColor("Off", Config.SelectedHueLightId);
                    }

                    //if (Config.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LIFXApiKey))
                    //{
                    //    if (ddlLIFXLights.SelectedItem != null && ddlLIFXLights.SelectedItem.GetType() == typeof(LifxCloud.NET.Models.Group))
                    //    {
                    //        Config.SelectedLIFXItemId = $"group_id:{((LifxCloud.NET.Models.Group)ddlLIFXLights.SelectedItem).Id}";
                    //    }

                    //    if (ddlLIFXLights.SelectedItem != null && ddlLIFXLights.SelectedItem.GetType() == typeof(LifxCloud.NET.Models.Light))
                    //    {
                    //        Config.SelectedLIFXItemId = $"id:{((LifxCloud.NET.Models.Light)ddlLIFXLights.SelectedItem).Id}";
                    //    }

                    //    await _lifxService.SetColor("Off", (Selector)Config.SelectedLIFXItemId);
                    //}
                    if (lightMode == "Graph")
                    {
                        await SetColor("Off");
                    }
                }
                catch (MsalException)
                {
                }
            }
            await SettingsService.SaveSettings(Config);
        }
Example #14
0
        private async void cbUseDefaultBrightnessChanged(object sender, RoutedEventArgs e)
        {
            if (Config.LightSettings.UseDefaultBrightness)
            {
                pnlDefaultBrightness.Visibility = Visibility.Visible;
            }
            else
            {
                pnlDefaultBrightness.Visibility = Visibility.Collapsed;
            }

            SyncOptions();
            await SettingsService.SaveSettings(Config);

            e.Handled = true;
        }
Example #15
0
        private async void SaveSettings_Click(object sender, RoutedEventArgs e)
        {
            if (Transparent.IsChecked == true)
            {
                Config.IconType = "Transparent";
            }
            else
            {
                Config.IconType = "White";
            }

            await SettingsService.SaveSettings(Config);

            lblSettingSaved.Visibility = Visibility.Visible;
            CheckHueSettings();
        }
Example #16
0
        private async Task LoadSettings()
        {
            if (!(await SettingsService.IsFilePresent()))
            {
                await SettingsService.SaveSettings(_options);
            }

            Config = await SettingsService.LoadSettings();

            if (string.IsNullOrEmpty(Config.RedirectUri))
            {
                await SettingsService.DeleteSettings();

                await SettingsService.SaveSettings(_options);
            }

            if (Config.IsPhillipsEnabled)
            {
                pnlPhillips.Visibility = Visibility.Visible;
                if (!string.IsNullOrEmpty(Config.HueApiKey))
                {
                    _options.HueApiKey = Config.HueApiKey;
                }

                if (!string.IsNullOrEmpty(Config.HueIpAddress))
                {
                    _options.HueIpAddress = Config.HueIpAddress;
                }
            }
            else
            {
                pnlPhillips.Visibility = Visibility.Collapsed;
            }

            if (Config.IsLIFXEnabled)
            {
                pnlLIFX.Visibility = Visibility.Visible;
                if (!string.IsNullOrEmpty(Config.HueApiKey))
                {
                    _options.LIFXApiKey = Config.LIFXApiKey;
                }
            }
            else
            {
                pnlLIFX.Visibility = Visibility.Collapsed;
            }
        }
        private async void SyncTheme_Click(object sender, RoutedEventArgs e)
        {
            lightMode = "Theme";
            syncTeamsButton.IsEnabled = true;
            syncThemeButton.IsEnabled = false;

            var theme = ((SolidColorBrush)SystemParameters.WindowGlassBrush).Color;

            string color = $"#{theme.ToString().Substring(3)}";

            lblTheme.Content    = $"Theme Color is {color}";
            lblTheme.Foreground = (SolidColorBrush)SystemParameters.WindowGlassBrush;
            lblTheme.Visibility = Visibility.Visible;

            await SetColor(color);

            while (true)
            {
                await Task.Delay(Convert.ToInt32(Config.PollingInterval * 1000));

                try
                {
                    theme = ((SolidColorBrush)SystemParameters.WindowGlassBrush).Color;
                    color = $"#{theme.ToString().Substring(3)}";

                    lblTheme.Content    = $"Theme Color is {color}";
                    lblTheme.Foreground = (SolidColorBrush)SystemParameters.WindowGlassBrush;
                    lblTheme.Visibility = Visibility.Visible;

                    if (lightMode == "Theme")
                    {
                        await SetColor(color);
                    }

                    if (DateTime.Now.Minute % 5 == 0)
                    {
                        await SettingsService.SaveSettings(Config);
                    }
                }
                catch (Exception ex)
                {
                    DiagnosticsClient.TrackException(ex);
                }
            }
        }
        private async Task CallGraph()
        {
            lightMode = "Graph";
            syncTeamsButton.IsEnabled = false;
            syncThemeButton.IsEnabled = true;

            if (_graphServiceClient == null)
            {
                _graphServiceClient = _graphservice.GetAuthenticatedGraphClient(typeof(WPFAuthorizationProvider));
            }

            signInPanel.Visibility  = Visibility.Collapsed;
            lblTheme.Visibility     = Visibility.Collapsed;
            loadingPanel.Visibility = Visibility.Visible;
            var(profile, presence)  = await System.Threading.Tasks.Task.Run(() => GetBatchContent());

            var photo = await System.Threading.Tasks.Task.Run(() => GetPhoto());

            if (photo == null)
            {
                MapUI(presence, profile, new BitmapImage(new Uri("pack://application:,,,/PresenceLight;component/images/UnknownProfile.png")));
            }
            else
            {
                MapUI(presence, profile, LoadImage(photo));
            }

            if (lightMode == "Graph")
            {
                await SetColor(presence.Availability);
            }
            loadingPanel.Visibility     = Visibility.Collapsed;
            this.signInPanel.Visibility = Visibility.Collapsed;
            hueIpAddress.IsEnabled      = false;

            dataPanel.Visibility = Visibility.Visible;
            await SettingsService.SaveSettings(Config);

            turnOffButton.Visibility = Visibility.Visible;
            turnOnButton.Visibility  = Visibility.Collapsed;

            await InteractWithLights();
        }
Example #19
0
        private async void SaveSettings_Click(object sender, RoutedEventArgs e)
        {
            btnSettings.IsEnabled = false;
            if (Transparent.IsChecked == true)
            {
                Config.IconType = "Transparent";
            }
            else
            {
                Config.IconType = "White";
            }

            CheckAAD();

            await SettingsService.SaveSettings(Config);

            lblSettingSaved.Visibility = Visibility.Visible;
            btnSettings.IsEnabled      = true;
        }
Example #20
0
        private async void SaveSettings_Click(object sender, RoutedEventArgs e)
        {
            btnSettings.IsEnabled = false;
            if (Transparent.IsChecked == true)
            {
                Config.IconType = "Transparent";
            }
            else
            {
                Config.IconType = "White";
            }

            if (HourStatusKeep.IsChecked == true)
            {
                Config.LightSettings.HoursPassedStatus = "Keep";
            }

            if (HourStatusOff.IsChecked == true)
            {
                Config.LightSettings.HoursPassedStatus = "Off";
            }

            if (HourStatusWhite.IsChecked == true)
            {
                Config.LightSettings.HoursPassedStatus = "White";
            }

            CheckAAD();
            Config.LightSettings.DefaultBrightness = Convert.ToInt32(brightness.Value);

            SetWorkingDays();

            SyncOptions();
            await SettingsService.SaveSettings(Config);

            lblSettingSaved.Visibility = Visibility.Visible;
            btnSettings.IsEnabled      = true;
        }
        private async Task CallGraph()
        {
            lightMode = "Graph";
            syncTeamsButton.IsEnabled = false;
            syncThemeButton.IsEnabled = true;

            if (_graphServiceClient == null)
            {
                _graphServiceClient = _graphservice.GetAuthenticatedGraphClient();
            }

            signInPanel.Visibility  = Visibility.Collapsed;
            lblTheme.Visibility     = Visibility.Collapsed;
            loadingPanel.Visibility = Visibility.Visible;

            try
            {
                var(profile, presence) = await System.Threading.Tasks.Task.Run(() => GetBatchContent()).ConfigureAwait(true);

                var photo = await System.Threading.Tasks.Task.Run(() => GetPhoto()).ConfigureAwait(true);

                if (photo == null)
                {
                    MapUI(presence, profile, new BitmapImage(new Uri("pack://application:,,,/PresenceLight;component/images/UnknownProfile.png")));
                }
                else
                {
                    MapUI(presence, profile, LoadImage(photo));
                }


                if (Config.LightSettings.SyncLights)
                {
                    if (!Config.LightSettings.UseWorkingHours)
                    {
                        if (lightMode == "Graph")
                        {
                            await SetColor(presence.Availability, presence.Activity).ConfigureAwait(true);
                        }
                    }
                    else
                    {
                        bool previousWorkingHours = IsWorkingHours;
                        if (IsInWorkingHours())
                        {
                            if (lightMode == "Graph")
                            {
                                await SetColor(presence.Availability, presence.Activity).ConfigureAwait(true);
                            }
                        }
                        else
                        {
                            // check to see if working hours have passed
                            if (previousWorkingHours)
                            {
                                if (lightMode == "Graph")
                                {
                                    switch (Config.LightSettings.HoursPassedStatus)
                                    {
                                    case "Keep":
                                        await SetColor(presence.Availability, presence.Activity).ConfigureAwait(true);

                                        break;

                                    case "White":
                                        await SetColor("Offline", presence.Activity).ConfigureAwait(true);

                                        break;

                                    case "Off":
                                        await SetColor("Off", presence.Activity).ConfigureAwait(true);

                                        break;

                                    default:
                                        await SetColor(presence.Availability, presence.Activity).ConfigureAwait(true);

                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            catch (Exception e)
            {
                _diagClient.TrackException(e);
            }
            loadingPanel.Visibility     = Visibility.Collapsed;
            this.signInPanel.Visibility = Visibility.Collapsed;


            dataPanel.Visibility = Visibility.Visible;
            await _settingsService.SaveSettings(Config).ConfigureAwait(true);

            turnOffButton.Visibility = Visibility.Visible;
            turnOnButton.Visibility  = Visibility.Collapsed;

            await InteractWithLights().ConfigureAwait(true);
        }
Example #22
0
        private async Task LoadSettings()
        {
            if (!(await SettingsService.IsFilePresent()))
            {
                await SettingsService.SaveSettings(_options);
            }

            Config = await SettingsService.LoadSettings();

            if (string.IsNullOrEmpty(Config.RedirectUri))
            {
                await SettingsService.DeleteSettings();

                await SettingsService.SaveSettings(_options);
            }
            if (Config.LightSettings.UseWorkingHours)
            {
                pnlWorkingHours.Visibility = Visibility.Visible;
                SyncOptions();
            }
            else
            {
                pnlWorkingHours.Visibility = Visibility.Collapsed;
                SyncOptions();
            }

            if (Config.LightSettings.Hue.IsPhillipsHueEnabled)
            {
                pnlPhillips.Visibility = Visibility.Visible;
                SyncOptions();
            }
            else
            {
                pnlPhillips.Visibility = Visibility.Collapsed;
            }

            if (Config.LightSettings.Yeelight.IsYeelightEnabled)
            {
                pnlYeelight.Visibility = Visibility.Visible;
                SyncOptions();
            }
            else
            {
                pnlYeelight.Visibility = Visibility.Collapsed;
            }

            if (Config.LightSettings.LIFX.IsLIFXEnabled)
            {
                getTokenLink.Visibility = Visibility.Visible;
                pnlLIFX.Visibility      = Visibility.Visible;

                SyncOptions();
            }
            else
            {
                getTokenLink.Visibility = Visibility.Collapsed;
                pnlLIFX.Visibility      = Visibility.Collapsed;
            }

            if (Config.LightSettings.Custom.IsCustomApiEnabled)
            {
                pnlCustomApi.Visibility = Visibility.Visible;
                customApiAvailableMethod.SelectedValue     = Config.LightSettings.Custom.CustomApiAvailableMethod;
                customApiBusyMethod.SelectedValue          = Config.LightSettings.Custom.CustomApiBusyMethod;
                customApiBeRightBackMethod.SelectedValue   = Config.LightSettings.Custom.CustomApiBeRightBackMethod;
                customApiAwayMethod.SelectedValue          = Config.LightSettings.Custom.CustomApiAwayMethod;
                customApiDoNotDisturbMethod.SelectedValue  = Config.LightSettings.Custom.CustomApiDoNotDisturbMethod;
                customApiAvailableIdleMethod.SelectedValue = Config.LightSettings.Custom.CustomApiAvailableIdleMethod;
                customApiOfflineMethod.SelectedValue       = Config.LightSettings.Custom.CustomApiOfflineMethod;
                customApiOffMethod.SelectedValue           = Config.LightSettings.Custom.CustomApiOffMethod;

                customApiActivityAvailableMethod.SelectedValue    = Config.LightSettings.Custom.CustomApiActivityAvailableMethod;
                customApiActivityPresentingMethod.SelectedValue   = Config.LightSettings.Custom.CustomApiActivityPresentingMethod;
                customApiActivityInACallMethod.SelectedValue      = Config.LightSettings.Custom.CustomApiActivityInACallMethod;
                customApiActivityInAMeetingMethod.SelectedValue   = Config.LightSettings.Custom.CustomApiActivityInAMeetingMethod;
                customApiActivityBusyMethod.SelectedValue         = Config.LightSettings.Custom.CustomApiActivityBusyMethod;
                customApiActivityAwayMethod.SelectedValue         = Config.LightSettings.Custom.CustomApiActivityAwayMethod;
                customApiActivityBeRightBackMethod.SelectedValue  = Config.LightSettings.Custom.CustomApiActivityBeRightBackMethod;
                customApiActivityOfflineMethod.SelectedValue      = Config.LightSettings.Custom.CustomApiActivityOfflineMethod;
                customApiActivityDoNotDisturbMethod.SelectedValue = Config.LightSettings.Custom.CustomApiActivityDoNotDisturbMethod;
                customApiActivityIdleMethod.SelectedValue         = Config.LightSettings.Custom.CustomApiActivityIdleMethod;
                customApiActivityOffMethod.SelectedValue          = Config.LightSettings.Custom.CustomApiActivityOffMethod;
                SyncOptions();
            }
            else
            {
                pnlCustomApi.Visibility = Visibility.Collapsed;
            }
            if (!string.IsNullOrEmpty(Config.LightSettings.LIFX.LIFXClientId) && !(string.IsNullOrEmpty(Config.LightSettings.LIFX.LIFXClientSecret)))
            {
                getTokenLink.Visibility = Visibility.Visible;
            }
            else
            {
                getTokenLink.Visibility = Visibility.Collapsed;
            }
        }
Example #23
0
        private async Task CallGraph()
        {
            if (_graphServiceClient == null)
            {
                _graphServiceClient = _graphservice.GetAuthenticatedGraphClient(typeof(WPFAuthorizationProvider));
            }

            stopThemePolling        = true;
            stopGraphPolling        = false;
            signInPanel.Visibility  = Visibility.Collapsed;
            lblTheme.Visibility     = Visibility.Collapsed;
            loadingPanel.Visibility = Visibility.Visible;
            var(profile, presence)  = await System.Threading.Tasks.Task.Run(() => GetBatchContent());

            var photo = await System.Threading.Tasks.Task.Run(() => GetPhoto());

            if (photo == null)
            {
                MapUI(presence, profile, new BitmapImage(new Uri("pack://application:,,,/PresenceLight;component/images/UnknownProfile.png")));
            }
            else
            {
                MapUI(presence, profile, LoadImage(photo));
            }
            if (!string.IsNullOrEmpty(Config.HueApiKey) && !string.IsNullOrEmpty(Config.HueIpAddress) && !string.IsNullOrEmpty(Config.SelectedHueLightId))
            {
                await _hueService.SetColor(presence.Availability, Config.SelectedHueLightId);
            }

            if (Config.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LIFXApiKey))
            {
                await _lifxService.SetColor(presence.Availability, (Selector)Config.SelectedLIFXItemId);
            }

            loadingPanel.Visibility     = Visibility.Collapsed;
            this.signInPanel.Visibility = Visibility.Collapsed;
            hueIpAddress.IsEnabled      = false;

            dataPanel.Visibility = Visibility.Visible;
            await SettingsService.SaveSettings(Config);

            while (true)
            {
                if (stopGraphPolling)
                {
                    stopGraphPolling      = false;
                    notificationIcon.Text = PresenceConstants.Inactive;
                    notificationIcon.Icon = new BitmapImage(new Uri(IconConstants.GetIcon(String.Empty, IconConstants.Inactive)));
                    return;
                }
                await Task.Delay(Convert.ToInt32(Config.PollingInterval * 1000));

                try
                {
                    presence = await System.Threading.Tasks.Task.Run(() => GetPresence());

                    if (!string.IsNullOrEmpty(Config.HueApiKey) && !string.IsNullOrEmpty(Config.HueIpAddress) && !string.IsNullOrEmpty(Config.SelectedHueLightId))
                    {
                        await _hueService.SetColor(presence.Availability, Config.SelectedHueLightId);
                    }

                    if (Config.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LIFXApiKey))
                    {
                        await _lifxService.SetColor(presence.Availability, (Selector)Config.SelectedLIFXItemId);
                    }

                    MapUI(presence, null, null);
                }
                catch { }
            }
        }
        private async Task InteractWithLights()
        {
            while (true)
            {
                await Task.Delay(Convert.ToInt32(Config.LightSettings.PollingInterval * 1000));

                if (Config.LightSettings.SyncLights)
                {
                    if (!Config.LightSettings.UseWorkingHours || (Config.LightSettings.UseWorkingHours && IsInWorkingHours()))
                    {
                        switch (lightMode)
                        {
                        case "Graph":
                            try
                            {
                                presence = await System.Threading.Tasks.Task.Run(() => GetPresence());

                                await SetColor(presence.Availability);

                                if (DateTime.Now.AddMinutes(-5) > settingsLastSaved)
                                {
                                    await SettingsService.SaveSettings(Config);

                                    settingsLastSaved = DateTime.Now;
                                }

                                MapUI(presence, null, null);
                            }
                            catch (Exception e)
                            {
                                DiagnosticsClient.TrackException(e);
                            }

                            break;

                        case "Theme":

                            try
                            {
                                var theme = ((SolidColorBrush)SystemParameters.WindowGlassBrush).Color;
                                var color = $"#{theme.ToString().Substring(3)}";

                                lblTheme.Content    = $"Theme Color is {color}";
                                lblTheme.Foreground = (SolidColorBrush)SystemParameters.WindowGlassBrush;
                                lblTheme.Visibility = Visibility.Visible;

                                if (lightMode == "Theme")
                                {
                                    await SetColor(color);
                                }

                                if (DateTime.Now.Minute % 5 == 0)
                                {
                                    await SettingsService.SaveSettings(Config);
                                }
                            }
                            catch (Exception ex)
                            {
                                DiagnosticsClient.TrackException(ex);
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
Example #25
0
        private async Task CallGraph()
        {
            lightMode = "Graph";
            syncTeamsButton.IsEnabled = false;
            syncThemeButton.IsEnabled = true;

            if (_graphServiceClient == null)
            {
                _graphServiceClient = _graphservice.GetAuthenticatedGraphClient(typeof(WPFAuthorizationProvider));
            }

            signInPanel.Visibility  = Visibility.Collapsed;
            lblTheme.Visibility     = Visibility.Collapsed;
            loadingPanel.Visibility = Visibility.Visible;
            var(profile, presence)  = await System.Threading.Tasks.Task.Run(() => GetBatchContent());

            var photo = await System.Threading.Tasks.Task.Run(() => GetPhoto());

            if (photo == null)
            {
                MapUI(presence, profile, new BitmapImage(new Uri("pack://application:,,,/PresenceLight;component/images/UnknownProfile.png")));
            }
            else
            {
                MapUI(presence, profile, LoadImage(photo));
            }

            if (lightMode == "Graph")
            {
                await SetColor(presence.Availability);
            }
            loadingPanel.Visibility     = Visibility.Collapsed;
            this.signInPanel.Visibility = Visibility.Collapsed;
            hueIpAddress.IsEnabled      = false;

            dataPanel.Visibility = Visibility.Visible;
            await SettingsService.SaveSettings(Config);

            while (true)
            {
                await Task.Delay(Convert.ToInt32(Config.PollingInterval * 1000));

                try
                {
                    presence = await System.Threading.Tasks.Task.Run(() => GetPresence());

                    if (lightMode == "Graph")
                    {
                        await SetColor(presence.Availability);
                    }

                    if (DateTime.Now.Minute % 5 == 0)
                    {
                        await SettingsService.SaveSettings(Config);
                    }

                    MapUI(presence, null, null);
                }
                catch { }
            }
        }
Example #26
0
        private async Task LoadSettings()
        {
            if (!(await SettingsService.IsFilePresent()))
            {
                await SettingsService.SaveSettings(_options);
            }

            Config = await SettingsService.LoadSettings();

            if (string.IsNullOrEmpty(Config.RedirectUri))
            {
                await SettingsService.DeleteSettings();

                await SettingsService.SaveSettings(_options);
            }
            if (Config.UseWorkingHours)
            {
                pnlWorkingHours.Visibility = Visibility.Visible;
                SyncOptions();
            }
            else
            {
                pnlWorkingHours.Visibility = Visibility.Collapsed;
                SyncOptions();
            }

            if (Config.IsPhillipsEnabled)
            {
                pnlPhillips.Visibility = Visibility.Visible;
                SyncOptions();
            }
            else
            {
                pnlPhillips.Visibility = Visibility.Collapsed;
            }

            if (Config.IsYeelightEnabled)
            {
                pnlYeelight.Visibility = Visibility.Visible;
                SyncOptions();
            }
            else
            {
                pnlYeelight.Visibility = Visibility.Collapsed;
            }

            if (Config.IsLIFXEnabled)
            {
                getTokenLink.Visibility = Visibility.Visible;
                pnlLIFX.Visibility      = Visibility.Visible;

                SyncOptions();
            }
            else
            {
                getTokenLink.Visibility = Visibility.Collapsed;
                pnlLIFX.Visibility      = Visibility.Collapsed;
            }

            if (Config.IsCustomApiEnabled)
            {
                pnlCustomApi.Visibility = Visibility.Visible;
                customApiAvailableMethod.SelectedValue    = Config.CustomApiAvailableMethod;
                customApiBusyMethod.SelectedValue         = Config.CustomApiBusyMethod;
                customApiBeRightBackMethod.SelectedValue  = Config.CustomApiBeRightBackMethod;
                customApiAwayMethod.SelectedValue         = Config.CustomApiAwayMethod;
                customApiDoNotDisturbMethod.SelectedValue = Config.CustomApiDoNotDisturbMethod;
                customApiOfflineMethod.SelectedValue      = Config.CustomApiOfflineMethod;
                customApiOffMethod.SelectedValue          = Config.CustomApiOffMethod;
                SyncOptions();
            }
            else
            {
                pnlCustomApi.Visibility = Visibility.Collapsed;
            }
        }
        private async Task InteractWithLights()
        {
            while (true)
            {
                await Task.Delay(Convert.ToInt32(Config.LightSettings.PollingInterval * 1000));

                bool   touchLight = false;
                string newColor   = "";

                if (Config.LightSettings.SyncLights)
                {
                    if (!Config.LightSettings.UseWorkingHours)
                    {
                        if (lightMode == "Graph")
                        {
                            touchLight = true;
                        }
                    }
                    else
                    {
                        bool previousWorkingHours = IsWorkingHours;
                        if (IsInWorkingHours())
                        {
                            if (lightMode == "Graph")
                            {
                                touchLight = true;
                            }
                        }
                        else
                        {
                            // check to see if working hours have passed
                            if (previousWorkingHours)
                            {
                                switch (Config.LightSettings.HoursPassedStatus)
                                {
                                case "Keep":
                                    break;

                                case "White":
                                    newColor = "Offline";
                                    break;

                                case "Off":
                                    newColor = "Off";
                                    break;

                                default:
                                    break;
                                }
                                touchLight = true;
                            }
                        }
                    }
                }

                if (touchLight)
                {
                    switch (lightMode)
                    {
                    case "Graph":
                        try
                        {
                            presence = await System.Threading.Tasks.Task.Run(() => GetPresence());

                            if (newColor == string.Empty)
                            {
                                await SetColor(presence.Availability, presence.Activity);
                            }
                            else
                            {
                                await SetColor(newColor, presence.Activity);
                            }


                            if (DateTime.Now.AddMinutes(-5) > settingsLastSaved)
                            {
                                await SettingsService.SaveSettings(Config);

                                settingsLastSaved = DateTime.Now;
                            }

                            MapUI(presence, null, null);
                        }
                        catch (Exception e)
                        {
                            DiagnosticsClient.TrackException(e);
                        }

                        break;

                    case "Theme":

                        try
                        {
                            var theme = ((SolidColorBrush)SystemParameters.WindowGlassBrush).Color;
                            var color = $"#{theme.ToString().Substring(3)}";

                            lblTheme.Content    = $"Theme Color is {color}";
                            lblTheme.Foreground = (SolidColorBrush)SystemParameters.WindowGlassBrush;
                            lblTheme.Visibility = Visibility.Visible;

                            if (lightMode == "Theme")
                            {
                                await SetColor(color);
                            }

                            if (DateTime.Now.Minute % 5 == 0)
                            {
                                await SettingsService.SaveSettings(Config);
                            }
                        }
                        catch (Exception ex)
                        {
                            DiagnosticsClient.TrackException(ex);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }