Exemple #1
0
        private async void locationCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            locationCheckBox.Enabled = false;
            okButton.Enabled         = false;

            if (locationCheckBox.Checked)
            {
                locationCheckBox.CheckedChanged -= locationCheckBox_CheckedChanged;
                locationCheckBox.Checked         = false;

                bool hasAccess = await UwpLocation.RequestAccess();

                if (hasAccess)
                {
                    JsonConfig.settings.useWindowsLocation = true;
                    locationCheckBox.Checked = true;
                }

                locationCheckBox.CheckedChanged += locationCheckBox_CheckedChanged;
            }
            else
            {
                JsonConfig.settings.useWindowsLocation = false;
            }

            locationCheckBox.Enabled = true;
            UpdateGuiState();
        }
        private async void okButton_Click(object sender, EventArgs e)
        {
            okButton.Enabled = false;

            if (!locationCheckBox.Checked)
            {
                LocationIQService.GetLocationData(inputBox.Text, this);
            }
            else
            {
                bool locationUpdated = await UwpLocation.UpdateGeoposition();

                if (locationUpdated)
                {
                    HandleLocationChange();
                }
                else
                {
                    MessageBox.Show(_("Failed to get location from Windows location service."),
                                    _("Error"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

            okButton.Enabled = true;
        }
        public static void Initialize()
        {
            if (!UwpDesktop.IsRunningAsUwp())
            {
                JsonConfig.settings.useWindowsLocation = false;
            }
            else if (JsonConfig.settings.useWindowsLocation && !UwpLocation.HasAccess())
            {
                JsonConfig.settings.useWindowsLocation = false;
                JsonConfig.settings.latitude           = null;
                JsonConfig.settings.longitude          = null;
            }

            if (JsonConfig.settings.latitude != null && JsonConfig.settings.longitude != null)
            {
                isReady = true;
                AppContext.RunInBackground();
            }
            else
            {
                ChangeLocation();

                if (JsonConfig.firstRun)
                {
                    AppContext.ShowPopup(_("Welcome! Please enter your location so the app can " +
                                           "determine sunrise and sunset times."));
                }
            }
        }
        private async void locationCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            locationCheckBox.Enabled = false;

            if (locationCheckBox.Checked)
            {
                locationCheckBox.CheckedChanged -= locationCheckBox_CheckedChanged;
                locationCheckBox.Checked         = false;

                bool accessGranted = await UwpLocation.RequestAccess(this);

                if (accessGranted)
                {
                    JsonConfig.UpdateSetting("useWindowsLocation", true);
                    locationCheckBox.Checked = true;
                    inputBox.Enabled         = false;
                    okButton.Enabled         = true;
                }

                locationCheckBox.CheckedChanged += locationCheckBox_CheckedChanged;
            }
            else
            {
                JsonConfig.UpdateSetting("useWindowsLocation", false);
                inputBox.Enabled = true;
            }

            locationCheckBox.Enabled = true;
        }
        private async void okButton_Click(object sender, EventArgs e)
        {
            okButton.Enabled = false;
            JsonConfig.settings.useWindowsLocation = radioButton2.Checked;
            JsonConfig.settings.dontUseLocation    = radioButton3.Checked;

            if (radioButton1.Checked)
            {
                LocationIQService.GetLocationData(locationBox.Text, this);
            }
            else if (radioButton2.Checked)
            {
                bool locationUpdated = await UwpLocation.UpdateGeoposition();

                if (locationUpdated)
                {
                    HandleScheduleChange();
                }
                else
                {
                    hasLocationPermission = UwpLocation.HasAccess();
                    UpdateLocationState();
                    MessageDialog.ShowWarning(_("Failed to get location from Windows location service."), _("Error"));
                }
            }
            else if (radioButton3.Checked)
            {
                JsonConfig.settings.sunriseTime           = sunriseTimePicker.Value.ToLongTimeString();
                JsonConfig.settings.sunsetTime            = sunsetTimePicker.Value.ToLongTimeString();
                JsonConfig.settings.sunriseSunsetDuration = (int)sunriseSunsetDurationBox.Value;
                this.Close();
            }

            okButton.Enabled = true;
        }
Exemple #6
0
        private async void okButton_Click(object sender, EventArgs e)
        {
            okButton.Enabled = false;

            if (!locationCheckBox.Checked)
            {
                LocationIQData data = LocationIQService.GetLocationData(inputBox.Text);

                if (data != null)
                {
                    JsonConfig.settings.location  = inputBox.Text;
                    JsonConfig.settings.latitude  = data.lat;
                    JsonConfig.settings.longitude = data.lon;

                    this.Hide();

                    if (ThemeManager.isReady)
                    {
                        AppContext.wcsService.RunScheduler();
                    }

                    MessageBox.Show("Location set successfully to: " + data.display_name +
                                    "\n(Latitude = " + data.lat + ", Longitude = " + data.lon + ")", "Success",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);

                    this.Close();
                }
                else
                {
                    MessageBox.Show("The location you entered was invalid, or you are not " +
                                    "connected to the Internet.", "Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                }
            }
            else
            {
                this.Hide();
                bool locationUpdated = await UwpLocation.UpdateGeoposition();

                if (locationUpdated)
                {
                    if (ThemeManager.isReady)
                    {
                        AppContext.wcsService.RunScheduler();
                    }

                    this.Close();
                }
                else
                {
                    MessageBox.Show("Failed to get location from Windows location service.",
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    this.Show();
                }
            }

            okButton.Enabled = true;
        }
Exemple #7
0
        private void HandleTimerEvent(bool updateLocation)
        {
            if (updateLocation && JsonConfig.settings.useWindowsLocation)
            {
                Task.Run(() => UwpLocation.UpdateGeoposition());
            }

            RunScheduler();
            UpdateChecker.TryCheckAuto();
        }
        private async void okButton_Click(object sender, EventArgs e)
        {
            okButton.Enabled = false;

            if (!locationCheckBox.Checked)
            {
                LocationIQData data = LocationIQService.GetLocationData(inputBox.Text);

                if (data != null)
                {
                    JsonConfig.settings.location  = inputBox.Text;
                    JsonConfig.settings.latitude  = data.lat;
                    JsonConfig.settings.longitude = data.lon;
                    SolarData solarData = SunriseSunsetService.GetSolarData(DateTime.Today);

                    DialogResult result = MessageBox.Show(string.Format(_("Is this location " +
                                                                          "correct?\n\n{0}\nSunrise: {1}, Sunset: {2}"), data.display_name,
                                                                        solarData.sunriseTime.ToShortTimeString(),
                                                                        solarData.sunsetTime.ToShortTimeString()), _("Question"),
                                                          MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (result == DialogResult.Yes)
                    {
                        AppContext.wpEngine.RunScheduler();
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show(_("The location you entered was invalid, or you are not " +
                                      "connected to the Internet. Check your Internet connection and try a " +
                                      "different location. You can use a complete address or just the name of " +
                                      "your city/region."), _("Error"), MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                }
            }
            else
            {
                bool locationUpdated = await UwpLocation.UpdateGeoposition();

                if (locationUpdated)
                {
                    AppContext.wpEngine.RunScheduler();
                    this.Close();
                }
                else
                {
                    MessageBox.Show(_("Failed to get location from Windows location service."),
                                    _("Error"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

            okButton.Enabled = true;
        }
Exemple #9
0
 public static void Initialize()
 {
     if (!UwpDesktop.IsUwpSupported())
     {
         JsonConfig.settings.useWindowsLocation = false;
     }
     else if (JsonConfig.settings.useWindowsLocation && !UwpLocation.HasAccess())
     {
         JsonConfig.settings.useWindowsLocation = false;
         JsonConfig.settings.latitude           = null;
         JsonConfig.settings.longitude          = null;
     }
 }
Exemple #10
0
        public void RunScheduler()
        {
            if (ThemeManager.currentTheme == null)
            {
                return;
            }

            wallpaperTimer.Stop();

            if (JsonConfig.settings.useWindowsLocation)
            {
                Task.Run(() => UwpLocation.UpdateGeoposition());
            }

            string currentDate = GetDateString();

            todaysData = GetWeatherData(currentDate);

            if (DateTime.Now < todaysData.SunriseTime + timerError)
            {
                // Before sunrise
                yesterdaysData = GetWeatherData(GetDateString(-1));
                tomorrowsData  = null;
            }
            else if (DateTime.Now >= todaysData.SunsetTime - timerError)
            {
                // After sunset
                yesterdaysData = null;
                tomorrowsData  = GetWeatherData(GetDateString(1));
            }
            else
            {
                // Between sunrise and sunset
                yesterdaysData = null;
                tomorrowsData  = null;
            }

            isDayNow    = (yesterdaysData == null && tomorrowsData == null);
            lastImageId = -1;

            if (isDayNow)
            {
                UpdateDayImage();
            }
            else
            {
                UpdateNightImage();
            }

            SystemThemeChanger.TryUpdateSystemTheme();
        }
        private void OnWallpaperTimerTick(object sender, EventArgs e)
        {
            if (ThemeManager.currentTheme != null)
            {
                if (JsonConfig.settings.useWindowsLocation)
                {
                    Task.Run(() => UwpLocation.UpdateGeoposition());
                }

                RunScheduler();
            }

            UpdateChecker.TryCheckAuto();
        }
Exemple #12
0
        public void HandleTimerEvent(bool updateLocation)
        {
            if (JsonConfig.settings.fullScreenPause && fullScreenChecker.runningFullScreen)
            {
                fullScreenChecker.timerEventPending = true;
                return;
            }

            if (updateLocation && JsonConfig.settings.useWindowsLocation)
            {
                Task.Run(() => UwpLocation.UpdateGeoposition());
            }

            RunScheduler();
            UpdateChecker.TryCheckAuto();
        }
        private void InputDialog_Load(object sender, EventArgs e)
        {
            if (JsonConfig.settings.location != null)
            {
                locationBox.Text = JsonConfig.settings.location;
            }

            radioButton2.Enabled  = UwpDesktop.IsUwpSupported();
            hasLocationPermission = UwpLocation.HasAccess();

            if (JsonConfig.settings.sunriseTime != null && JsonConfig.settings.sunsetTime != null)
            {
                sunriseTimePicker.Value = DateTime.Parse(JsonConfig.settings.sunriseTime,
                                                         CultureInfo.InvariantCulture);
                sunsetTimePicker.Value = DateTime.Parse(JsonConfig.settings.sunsetTime,
                                                        CultureInfo.InvariantCulture);
            }
            else
            {
                sunriseTimePicker.Value = DateTime.Today.AddHours(6);
                sunsetTimePicker.Value  = DateTime.Today.AddHours(18);
            }

            sunriseTimePicker.MinDate = sunriseTimePicker.Value.Date;
            sunriseTimePicker.MaxDate = sunsetTimePicker.Value.Date.AddHours(24);

            if (JsonConfig.settings.sunriseSunsetDuration > 0)
            {
                sunriseSunsetDurationBox.Value = JsonConfig.settings.sunriseSunsetDuration;
            }

            if (JsonConfig.settings.useWindowsLocation)
            {
                radioButton2.Checked = true;
            }
            else if (JsonConfig.settings.dontUseLocation)
            {
                radioButton3.Checked = true;
            }

            UpdateGuiState();
        }
        public static void Initialize()
        {
            if (!UwpDesktop.IsRunningAsUwp())
            {
                JsonConfig.settings.useWindowsLocation = false;
            }
            else if (JsonConfig.settings.useWindowsLocation && !UwpLocation.HasAccess())
            {
                JsonConfig.settings.useWindowsLocation = false;
                JsonConfig.settings.latitude           = null;
                JsonConfig.settings.longitude          = null;
            }

            if (JsonConfig.settings.latitude != null && JsonConfig.settings.longitude != null)
            {
                isReady = true;
            }
            else
            {
                ChangeLocation();
            }
        }
        private void InputDialog_Load(object sender, EventArgs e)
        {
            foreach (TimeZoneInfo tzi in TimeZoneInfo.GetSystemTimeZones())
            {
                timezoneBox.Items.Add(tzi.Id);
            }

            if (JsonConfig.settings.location != null)
            {
                locationBox.Text = JsonConfig.settings.location;
            }

            radioButton2.Enabled  = UwpDesktop.IsUwpSupported();
            hasLocationPermission = UwpLocation.HasAccess();

            sunriseTimePicker.MinDate = DateTime.Today;
            sunsetTimePicker.MaxDate  = DateTime.Today.AddDays(1);

            if (JsonConfig.settings.sunriseTime != null && JsonConfig.settings.sunsetTime != null)
            {
                sunriseTimePicker.Value = UpdateHandler.SafeParse(JsonConfig.settings.sunriseTime, TimeZoneInfo.FindSystemTimeZoneById(JsonConfig.settings.timezone)).Time;
                sunsetTimePicker.Value  = UpdateHandler.SafeParse(JsonConfig.settings.sunsetTime, TimeZoneInfo.FindSystemTimeZoneById(JsonConfig.settings.timezone)).Time;
            }
            else
            {
                sunriseTimePicker.Value = DateTime.Today.AddHours(6);
                sunsetTimePicker.Value  = DateTime.Today.AddHours(18);
            }

            if (JsonConfig.settings.sunriseSunsetDuration > 0)
            {
                sunriseSunsetDurationBox.Value = JsonConfig.settings.sunriseSunsetDuration;
            }

            if (JsonConfig.settings.useWindowsLocation)
            {
                radioButton2.Checked = true;
            }
            else if (JsonConfig.settings.dontUseLocation)
            {
                radioButton3.Checked = true;
            }

            if (JsonConfig.settings.timezone != null)
            {
                timezoneBox.Text = JsonConfig.settings.timezone;
            }
            else
            {
                timezoneBox.Text = TimeZoneInfo.Local.Id;
            }

            if (JsonConfig.settings.latitude != null)
            {
                latitudeTextBox.Text = JsonConfig.settings.latitude;
            }

            if (JsonConfig.settings.longitude != null)
            {
                longitudeTextBox.Text = JsonConfig.settings.longitude;
            }


            UpdateGuiState();
            isLoaded = true;
        }
 private async void grantPermissionButton_Click(object sender, EventArgs e)
 {
     UpdateLocationState();
     await UwpLocation.RequestAccess();
 }
 private void checkPermissionButton_Click(object sender, EventArgs e)
 {
     hasLocationPermission = UwpLocation.HasAccess();
     UpdateLocationState();
 }