diff --git a/BrightnessSwitch.csproj b/BrightnessSwitch.csproj index e5c33e8..6ec2d4c 100644 --- a/BrightnessSwitch.csproj +++ b/BrightnessSwitch.csproj @@ -6,7 +6,7 @@ enable true sun.ico - 1.0.0 + 1.0.1 diff --git a/Changelog.md b/Changelog.md index e4a0c40..1f76081 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,8 +1,9 @@ # Changelog -## master +## 1.0.1 * Show message when no update is available. +* Show an error message if the device has no light sensor. ## 1.0.0 diff --git a/LightControl.cs b/LightControl.cs index f259906..2b48adf 100644 --- a/LightControl.cs +++ b/LightControl.cs @@ -24,6 +24,10 @@ public LightControl(uint sensorInterval = 10_000, float illuminanceThreshold = 5 IlluminanceThreshold = illuminanceThreshold; Sensor = LightSensor.GetDefault(); + if (Sensor == null) + { + throw new NotSupportedException("No light sensor present"); + } Sensor.ReportInterval = Math.Max(Sensor.MinimumReportInterval, sensorInterval); Sensor.ReadingChanged += new TypedEventHandler(LightReadingChanged); diff --git a/Program.cs b/Program.cs index 01e833f..e94b6cf 100644 --- a/Program.cs +++ b/Program.cs @@ -78,7 +78,17 @@ static void Main(string[] args) { LoadSettings(); - var lightControl = new LightControl(); + LightControl lightControl = null!; + try + { + lightControl = new LightControl(); + } + catch (NotSupportedException) + { + MessageBox.Show("This app can't run on your device, since it has no light sensor.", "BrightnessSwitch", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + lightControl.PredictionCallback += (float illuminanceInLux) => { var (prediction, certainty) = predictionModel.Predict(Math.Log(illuminanceInLux)); @@ -89,7 +99,7 @@ static void Main(string[] args) trayIcon.OnExit += (object? sender, int reason) => Application.Exit(); trayIcon.OnThemeSwitch += (object? sender, bool useLightTheme) => { - if (trayIcon.AutoSwitchEnabled) // Otherwise we don't have to learn it + if (trayIcon.AutoSwitchEnabled) // Otherwise we don't have to learn from the current action { var currentIlluminance = lightControl.GetCurrentIlluminance(); if (currentIlluminance > 0) diff --git a/TrayIcon.cs b/TrayIcon.cs index 2b221cd..396e217 100644 --- a/TrayIcon.cs +++ b/TrayIcon.cs @@ -146,7 +146,7 @@ private async void CheckUpdates(bool showOptionalMessages = true) var releaseUrl = urlMatch.Groups[1].Value; if (currentVersion < newVersion) { - if (MessageBox.Show("There is a new version available. Do you want to go to the download page?", "Updating BrightnessSwitch", MessageBoxButtons.YesNo) == DialogResult.Yes) + if (MessageBox.Show("There is a new version available. Do you want to go to the download page?", "Updating BrightnessSwitch", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var psi = new ProcessStartInfo { @@ -158,14 +158,14 @@ private async void CheckUpdates(bool showOptionalMessages = true) } else if (showOptionalMessages) { - MessageBox.Show("You are already using the latest version.", "Updating BrightnessSwitch"); + MessageBox.Show("You are already using the latest version.", "Updating BrightnessSwitch", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch { if (showOptionalMessages) { - MessageBox.Show("Error downloading the update information", "Updating BrightnessSwitch"); + MessageBox.Show("Error downloading the update information", "Updating BrightnessSwitch", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }