private async Task Override()
        {
            if (!string.IsNullOrEmpty(SelectedEffect))
            {
                try
                {
                    var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(UserSettings.Settings.ActiveDevice);

                    if (await orchestrator.TrySetOperationMode(OperationMode.Manual, true))
                    {
                        orchestrator.Device.OverrideEffect     = SelectedEffect;
                        orchestrator.Device.OverrideBrightness = Brightness;

                        await orchestrator.ActivateEffect(SelectedEffect, Brightness);

                        MainWindow.UpdateCurrentEffectLabelsAndLayout();
                    }
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Error during overriding schedule");
                    PopupCreator.Error(MainWindows.Resources.OverrideError);
                }
            }
        }
Ejemplo n.º 2
0
        public void Finish_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(setupViewModel.Name))
            {
                PopupCreator.Error(Setup.Resources.NameCannotBeEmpty);
                return;
            }
            else if (UserSettings.HasSettings() && UserSettings.Settings.Devices.Any(d => d.Name.ToLower().Equals(setupViewModel.Name)))
            {
                PopupCreator.Error(Setup.Resources.NameAlreadyExists);
                return;
            }

            selectedDevice.Name = setupViewModel.Name;

            UserSettings.Settings.AddDevice(selectedDevice);

            _logger.Info($"Successfully added device {selectedDevice.Name}");

            if (_parent != null)
            {
                OrchestratorCollection.AddOrchestratorForDevice(selectedDevice);
                _parent.DeviceAdded(selectedDevice);
                _parent.SelectedDevice = selectedDevice.Name;
            }
            else
            {
                UserSettings.Settings.SetActiveDevice(selectedDevice.Name); //The first added device must always be active
                App.NormalStartup(null);
            }

            Close();
        }
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            //Set the devices of the schedule
            Schedule.AppliesToDeviceNames = string.IsNullOrEmpty(DevicesDropdown.SelectedValue) ? new List <string>() : DevicesDropdown.SelectedValue.Split(',').Select(x => x.Trim()).ToList();

            //Check if a name is entered, a device is selected and if there is any event or trigger
            if (!Schedule.AppliesToDeviceNames.Any() ||
                string.IsNullOrWhiteSpace(Schedule.Name) ||
                (!Schedule.Programs.Any(program => program.Triggers.Any()) && !Schedule.EventTriggers.Any()))
            {
                PopupCreator.Error(Scheduling.Resources.SaveScheduleError);
                return;
            }

            if (_workMode == WorkMode.Add)
            {
                _parent.AddedSchedule(Schedule);
            }
            else
            {
                _parent.UpdatedSchedule(_originalSchedule, Schedule);
            }

            Close();
        }
Ejemplo n.º 4
0
 private void ConnectToSpotify_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         _winleafsServerClient.SpotifyEndpoint.Connect();
     }
     catch (Exception ex)
     {
         Logger.Error(ex, "Unknown error when trying to connect to Spotify");
         PopupCreator.Error(Options.Resources.SpotifyUnknownError);
     }
 }
Ejemplo n.º 5
0
        private void Plus_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (!UserSettings.Settings.SunriseHour.HasValue)
            {
                PopupCreator.Error(Scheduling.Resources.LocationMissing);
                return;
            }

            var addTriggerWindow = new AddTimeTriggerWindow(this);

            addTriggerWindow.ShowDialog();
        }
Ejemplo n.º 6
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            if (_profile.Steps.Count > 0)
            {
                UserSettings.Settings.ActiveDevice.PercentageProfile = _profile;
                UserSettings.Settings.SaveSettings();

                Close();
            }
            else
            {
                PopupCreator.Error(Layout.Resources.AtLeast1Step);
            }
        }
Ejemplo n.º 7
0
        private void DisconnectFromSpotify_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                _winleafsServerClient.SpotifyEndpoint.Disconnect();
                PopupCreator.Success(Options.Resources.DisconnectSuccessful, true);

                DisconnectFromSpotifyButton.Visibility = Visibility.Hidden;
                ConnectToSpotifyButton.Visibility      = Visibility.Visible;
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Unknown error when trying to connect to Spotify");
                PopupCreator.Error(Options.Resources.SpotifyUnknownError);
            }
        }
Ejemplo n.º 8
0
        private void AddSpotifyEvent_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var winleafsServerClient = new WinleafsServerClient();

            try
            {
                var playlist = winleafsServerClient.SpotifyEndpoint.GetPlaylists();

                var spotifyEventWindow = new AddSpotifyEventWindow(this, playlist);
                spotifyEventWindow.ShowDialog();
            }
            catch
            {
                PopupCreator.Error(Scheduling.Resources.ConnectToSpotifyOrError);
            }
        }
Ejemplo n.º 9
0
        public static void NormalStartup(StartupEventArgs startupEventArgs)
        {
            var silent = false;

            if (startupEventArgs != null && startupEventArgs.Args.Length > 0)
            {
                silent = startupEventArgs.Args[0].Equals("-s");
            }

            try
            {
                UserSettings.LoadSettings();
            }
            catch (SettingsFileJsonException ex)
            {
                _logger.Fatal("Corrupt settings file found", ex);
                PopupCreator.Error(string.Format(AppResources.CorruptSettings, UserSettings.SettingsFolder + "Settings.json"));
                return;
            }

            if (!string.IsNullOrEmpty(UserSettings.Settings.UserLocale))
            {
                Thread.CurrentThread.CurrentCulture   = CultureInfo.GetCultureInfo(UserSettings.Settings.UserLocale);
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(UserSettings.Settings.UserLocale);
            }

            UserSettings.Settings.ResetOperationModes();

            SunTimesUpdater.UpdateSunTimes();

            OrchestratorCollection.Initialize();

            SpotifyEventTimer.Initialize();

            var mainWindow = new MainWindow();

            if (!silent)
            {
                mainWindow.Show();
            }

            mainWindow.Initialize();

            CheckForUpdate();
        }
Ejemplo n.º 10
0
        private void GeoIp_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var geoIpClient = new GeoIpClient();
                var geoIpData   = geoIpClient.GetGeoIpData();
                OptionsViewModel.Latitude  = geoIpData.Latitude.ToString("N7", CultureInfo.InvariantCulture);
                OptionsViewModel.Longitude = geoIpData.Longitude.ToString("N7", CultureInfo.InvariantCulture);

                LatitudeTextBox.Text  = OptionsViewModel.Latitude;
                LongitudeTextBox.Text = OptionsViewModel.Longitude;

                PopupCreator.Success(string.Format(Options.Resources.LocationDetected, geoIpData.City, geoIpData.Country));
            }
            catch
            {
                PopupCreator.Error(Options.Resources.LatLongReceiveError);
            }
        }
Ejemplo n.º 11
0
        private async Task SelectedEffectChanged()
        {
            try
            {
                if (await _orchestrator.TrySetOperationMode(OperationMode.Manual, true, true))
                {
                    _device.ManualEffect     = _selectedEffect;
                    _device.ManualBrightness = Brightness;

                    await _orchestrator.ActivateEffect(_selectedEffect, Brightness);

                    UserSettings.Settings.SaveSettings();
                }
            }
            catch (Exception e)
            {
                _logger.Error(e, "Error during setting manual control");
                PopupCreator.Error(MainWindows.Resources.ManualControlError);
            }
        }
Ejemplo n.º 12
0
        public bool SpotifyEventTriggerAdded(string playlistId, string playlistName, string effectName, int brightness)
        {
            if (string.IsNullOrWhiteSpace(playlistId) || string.IsNullOrWhiteSpace(playlistName))
            {
                PopupCreator.Error(Scheduling.Resources.PlaylistCanNotBeEmpty);
                return(false);
            }

            playlistName = playlistName.Trim();

            if (string.IsNullOrEmpty(effectName))
            {
                PopupCreator.Error(Scheduling.Resources.MustChooseEffect);
                return(false);
            }

            foreach (var eventTrigger in EventTriggers)
            {
                var spotifyEventTrigger = eventTrigger as SpotifyEventTrigger;
                if (spotifyEventTrigger != null && spotifyEventTrigger.PlaylistId.ToLower().Equals(playlistId.ToLower()))
                {
                    PopupCreator.Error(string.Format(Scheduling.Resources.PlaylistAlreadyExists, playlistName));
                    return(false);
                }
            }

            EventTriggers.Add(new SpotifyEventTrigger()
            {
                Brightness       = brightness,
                EffectName       = effectName,
                EventTriggerType = TriggerType.SpotifyEvent,
                PlaylistName     = playlistName,
                PlaylistId       = playlistId,
                Priority         = EventTriggers.Count == 0 ? 1 : EventTriggers.Max(eventTrigger => eventTrigger.Priority) + 1
            });

            BuildTriggerList();

            return(true);
        }
Ejemplo n.º 13
0
        private void AddColor_Click(object sender, RoutedEventArgs e)
        {
            var color = ColorPicker.SelectedColor;
            var name  = EffectTextBox.Text;

            if (UserSettings.Settings.CustomEffects != null && UserSettings.Settings.CustomEffects.Any(effect => effect.EffectName == name))
            {
                PopupCreator.Error(Options.Resources.NameTaken);
                return;
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                PopupCreator.Error(Options.Resources.NoNameProvided);
                return;
            }

            if (color == null)
            {
                PopupCreator.Error(Options.Resources.NoColorSelected);
                return;
            }

            var customEffect = new UserCustomColorEffect()
            {
                Color      = Color.FromArgb(color.Value.A, color.Value.R, color.Value.G, color.Value.B),
                EffectName = name
            };

            if (OptionsViewModel.CustomColorEffects == null)
            {
                OptionsViewModel.CustomColorEffects = new List <UserCustomColorEffect>();
            }

            // Add color in settings.
            OptionsViewModel.CustomColorEffects.Add(customEffect);

            // Add color to UI.
            ColorList.Children.Add(new ColorUserControl(this, customEffect.EffectName, customEffect.Color));
        }
Ejemplo n.º 14
0
        public bool ProcessEventTriggerAdded(string processName, string effectName, int brightness)
        {
            if (string.IsNullOrWhiteSpace(processName))
            {
                PopupCreator.Error(Scheduling.Resources.ProcessNameCanNotBeEmpty);
                return false;
            }

            processName = processName.Trim();

            if (string.IsNullOrEmpty(effectName))
            {
                PopupCreator.Error(Scheduling.Resources.MustChooseEffect);
                return false;
            }

            foreach (var eventTrigger in EventTriggers)
            {
                var processEventTrigger = eventTrigger as ProcessEventTrigger;
                if (processEventTrigger != null && processEventTrigger.ProcessName.ToLower().Equals(processName.ToLower()))
                {
                    PopupCreator.Error(string.Format(Scheduling.Resources.ProcessNameAlreadyExists, processName));
                    return false;
                }
            }

            EventTriggers.Add(new ProcessEventTrigger()
            {
                Brightness = brightness,
                EffectName = effectName,
                EventTriggerType = TriggerType.ProcessEvent,
                ProcessName = processName
            });

            BuildTriggerList();

            return true;
        }
Ejemplo n.º 15
0
        private async Task SelectedEffectChanged()
        {
            try
            {
                var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(_device);
                if (await orchestrator.TrySetOperationMode(OperationMode.Manual, true, true))
                {
                    _logger.Info($"User manually enabling effect {_selectedEffect} with brightness {Brightness} for device {_device.IPAddress}");

                    _device.ManualEffect     = _selectedEffect;
                    _device.ManualBrightness = Brightness;

                    await orchestrator.ActivateEffect(_selectedEffect, Brightness);

                    UserSettings.Settings.SaveSettings();
                }
            }
            catch (Exception e)
            {
                _logger.Error(e, "Error during setting manual control");
                PopupCreator.Error(MainWindows.Resources.ManualControlError);
            }
        }
Ejemplo n.º 16
0
        private async Task Pair()
        {
            try
            {
                var authToken = await nanoleafClient.AuthorizationEndpoint.GetAuthTokenAsync();

                await nanoleafClient.IdentifyEndpoint.Identify();

                var effects = await nanoleafClient.EffectsEndpoint.GetEffectsListAsync();

                Dispatcher.Invoke(() =>
                {
                    selectedDevice.AuthToken = authToken;
                    selectedDevice.LoadEffectsFromNameList(effects);

                    AuthorizeDevice.Visibility = Visibility.Hidden;
                    NameDevice.Visibility      = Visibility.Visible;
                });
            }
            catch
            {
                PopupCreator.Error(Setup.Resources.UnknownError);
            }
        }
Ejemplo n.º 17
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            #region LatLong

            double latitude  = 0;
            double longitude = 0;
            try
            {
                if (!string.IsNullOrWhiteSpace(OptionsViewModel.Latitude))
                {
                    latitude = Convert.ToDouble(OptionsViewModel.Latitude, CultureInfo.InvariantCulture);
                }
            }
            catch
            {
                PopupCreator.Error(Options.Resources.InvalidLatitude);
                return;
            }

            try
            {
                if (!string.IsNullOrWhiteSpace(OptionsViewModel.Longitude))
                {
                    longitude = Convert.ToDouble(OptionsViewModel.Longitude, CultureInfo.InvariantCulture);
                }
            }
            catch
            {
                PopupCreator.Error(Options.Resources.InvalidLongitude);
                return;
            }

            if ((latitude != UserSettings.Settings.Latitude || longitude != UserSettings.Settings.Longitude) && (latitude != 0 && longitude != 0))
            {
                var client = new SunsetSunriseClient();

                try
                {
                    var sunTimes = client.GetSunsetSunriseAsync(latitude, longitude).GetAwaiter().GetResult();

                    UserSettings.Settings.UpdateSunriseSunset(sunTimes.SunriseHour, sunTimes.SunriseMinute, sunTimes.SunsetHour, sunTimes.SunsetMinute);
                }
                catch
                {
                    PopupCreator.Error(Options.Resources.SunsetSunriseError);
                    return;
                }

                UserSettings.Settings.Latitude  = latitude;
                UserSettings.Settings.Longitude = longitude;
            }
            #endregion

            #region StartAtWindowsStartup
            if (UserSettings.Settings.StartAtWindowsStartup != OptionsViewModel.StartAtWindowsStartUp)
            {
                if (OptionsViewModel.StartAtWindowsStartUp)
                {
                    //Replace .dll with .exe since in .net core 3 the current executing assembly is the dll
                    _startupKey.SetValue(UserSettings.APPLICATIONNAME, $"{System.Reflection.Assembly.GetExecutingAssembly().Location.Replace(".dll", ".exe")} -s");
                }
                else
                {
                    _startupKey.DeleteValue(UserSettings.APPLICATIONNAME, false);
                }

                _startupKey.Close();

                UserSettings.Settings.StartAtWindowsStartup = OptionsViewModel.StartAtWindowsStartUp;
            }
            #endregion

            #region ScreenMirror
            foreach (var device in UserSettings.Settings.Devices)
            {
                device.ScreenMirrorAlgorithm = OptionsViewModel.AlgorithmPerDevice[device.Name];
            }

            UserSettings.Settings.ScreenMirrorMonitorIndex         = Array.IndexOf(_monitorNames.ToArray(), OptionsViewModel.SelectedMonitor);
            UserSettings.Settings.ScreenMirrorRefreshRatePerSecond = OptionsViewModel.ScreenMirrorRefreshRatePerSecond;

            #endregion

            #region Language

            if (OptionsViewModel.SelectedLanguage != null)
            {
                UserSettings.Settings.UserLocale = _languageDictionary[OptionsViewModel.SelectedLanguage];
            }

            #endregion

            #region MinimizeToSystemTray
            UserSettings.Settings.MinimizeToSystemTray = OptionsViewModel.MinimizeToSystemTray;
            #endregion

            #region Colors

            var deletedColors = UserSettings.Settings.CustomEffects?.Except(OptionsViewModel.CustomColorEffects).ToList();

            UserSettings.Settings.CustomEffects = OptionsViewModel.CustomColorEffects;

            //Remove invalid triggers from the schedules
            if (deletedColors?.Any() == true)
            {
                UserSettings.Settings.DeleteTriggers(deletedColors.Select(color =>
                                                                          UserCustomColorEffect.DisplayName(color.EffectName)));
            }

            #endregion Colors


            UserSettings.Settings.SaveSettings();

            //Reload the orchestrator so custom effects are reloaded.
            OrchestratorCollection.ResetOrchestrators();

            //Reload effects such that custom effects are updated in the view
            _mainWindow.ReloadEffectsInView();

            Close();
        }
Ejemplo n.º 18
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            #region LatLong

            double latitude  = 0;
            double longitude = 0;
            try
            {
                if (!string.IsNullOrWhiteSpace(OptionsViewModel.Latitude))
                {
                    latitude = Convert.ToDouble(OptionsViewModel.Latitude, CultureInfo.InvariantCulture);
                }
            }
            catch
            {
                PopupCreator.Error(Options.Resources.InvalidLatitude);
                return;
            }

            try
            {
                if (!string.IsNullOrWhiteSpace(OptionsViewModel.Longitude))
                {
                    longitude = Convert.ToDouble(OptionsViewModel.Longitude, CultureInfo.InvariantCulture);
                }
            }
            catch
            {
                PopupCreator.Error(Options.Resources.InvalidLongitude);
                return;
            }

            if ((latitude != UserSettings.Settings.Latitude || longitude != UserSettings.Settings.Longitude) && (latitude != 0 && longitude != 0))
            {
                var client = new SunsetSunriseClient();

                try
                {
                    var sunTimes = client.GetSunsetSunriseAsync(latitude, longitude).GetAwaiter().GetResult();

                    UserSettings.Settings.UpdateSunriseSunset(sunTimes.SunriseHour, sunTimes.SunriseMinute, sunTimes.SunsetHour, sunTimes.SunsetMinute);
                }
                catch
                {
                    PopupCreator.Error(Options.Resources.SunsetSunriseError);
                    return;
                }

                UserSettings.Settings.Latitude  = latitude;
                UserSettings.Settings.Longitude = longitude;
            }
            #endregion

            #region StartAtWindowsStartup
            if (UserSettings.Settings.StartAtWindowsStartup != OptionsViewModel.StartAtWindowsStartUp)
            {
                if (OptionsViewModel.StartAtWindowsStartUp)
                {
                    _startupKey.SetValue(UserSettings.APPLICATIONNAME, $"{System.Reflection.Assembly.GetExecutingAssembly().Location} -s");
                }
                else
                {
                    _startupKey.DeleteValue(UserSettings.APPLICATIONNAME, false);
                }

                _startupKey.Close();

                UserSettings.Settings.StartAtWindowsStartup = OptionsViewModel.StartAtWindowsStartUp;
            }
            #endregion

            #region ScreenMirror
            var monitorNames = WindowsDisplayAPI.DisplayConfig.PathDisplayTarget.GetDisplayTargets().Select(m => m.FriendlyName).ToArray();

            foreach (var device in UserSettings.Settings.Devices)
            {
                device.ScreenMirrorAlgorithm            = OptionsViewModel.AlgorithmPerDevice[device.Name];
                device.ScreenMirrorRefreshRatePerSecond = OptionsViewModel.ScreenMirrorRefreshRatePerDevice[device.Name];
                device.ScreenMirrorControlBrightness    = OptionsViewModel.ScreenMirrorControlBrightnessPerDevice[device.Name];
                device.ScreenMirrorMonitorIndex         = Array.IndexOf(monitorNames, OptionsViewModel.MonitorPerDevice[device.Name]);
            }
            #endregion

            #region Language

            if (OptionsViewModel.SelectedLanguage != null)
            {
                UserSettings.Settings.UserLocale = _languageDictionary[OptionsViewModel.SelectedLanguage];
            }

            #endregion

            #region MinimizeToSystemTray
            UserSettings.Settings.MinimizeToSystemTray = OptionsViewModel.MinimizeToSystemTray;
            #endregion

            #region Colors

            UserSettings.Settings.CustomEffects = OptionsViewModel.CustomColorEffects;

            #endregion Colors
            UserSettings.Settings.SaveSettings();

            // Reload the orchestrator so custom effects are reloaded.
            OrchestratorCollection.ResetOrchestratorForActiveDevice();

            _mainWindow.ReloadEffects();

            Close();
        }
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(SelectedEffect))
            {
                PopupCreator.Error(Scheduling.Resources.MustChooseEffect);
                return;
            }

            int hours;
            int minutes;

            try
            {
                hours = Convert.ToInt32(Hours.Text, CultureInfo.InvariantCulture);

                if (hours < 0 || hours > 23)
                {
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch
            {
                PopupCreator.Error(Scheduling.Resources.InvalidHoursValue);
                return;
            }

            try
            {
                minutes = Convert.ToInt32(Minutes.Text, CultureInfo.InvariantCulture);

                if (minutes < 0 || minutes > 59)
                {
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch
            {
                PopupCreator.Error(Scheduling.Resources.InvalidMinutesValue);
                return;
            }

            bool addSucceeded;

            if (_triggerType == TriggerType.Sunrise || _triggerType == TriggerType.Sunset)
            {
                var beforeAfter = GetBeforeAfter();

                addSucceeded = _parent.TriggerAdded(new TimeTrigger
                {
                    TriggerType  = _triggerType,
                    BeforeAfter  = beforeAfter,
                    Brightness   = _brightness,
                    Effect       = SelectedEffect,
                    ExtraHours   = hours,
                    ExtraMinutes = minutes,
                    Hours        = GetHoursForTriggerType(_triggerType),
                    Minutes      = GetMinutesForTriggerType(_triggerType)
                });
            }
            else
            {
                addSucceeded = _parent.TriggerAdded(new TimeTrigger
                {
                    TriggerType  = _triggerType,
                    BeforeAfter  = BeforeAfter.None,
                    Brightness   = _brightness,
                    Effect       = SelectedEffect,
                    ExtraHours   = 0,
                    ExtraMinutes = 0,
                    Hours        = hours,
                    Minutes      = minutes
                });
            }

            if (!addSucceeded)
            {
                PopupCreator.Error(Scheduling.Resources.TriggerOverlaps);
                return;
            }

            Close();
        }