├── 2019-05-03_16-18-24.png ├── GlucoseTray ├── Enums │ ├── GlucoseUnitType.cs │ ├── GlucoseSource.cs │ ├── DexcomServer.cs │ ├── AlertLevel.cs │ ├── IconTextColor.cs │ └── Trend.cs ├── Read │ ├── IReadStrategy.cs │ ├── GlucoseReading.cs │ ├── Dexcom │ │ ├── DexcomResult.cs │ │ └── DexcomReadStrategy.cs │ ├── Nightscout │ │ ├── NightScoutResult.cs │ │ └── NightscoutReadStrategy.cs │ ├── GlucoseReader.cs │ ├── GlucoseReadingMapper.cs │ └── IExternalCommunicationAdapter.cs ├── AppWrapper.cs ├── Display │ ├── GlucoseDisplay.cs │ ├── Tray.cs │ ├── IScheduler.cs │ ├── AlertService.cs │ ├── GlucoseDisplayMapper.cs │ └── ITrayIcon.cs ├── Properties │ └── PublishProfiles │ │ ├── PublishToSingleSelfContainedExe.pubxml │ │ └── PublishToSingleSelfContainedExeWthoutFramework.pubxml ├── appsettings.json ├── AppRunner.cs ├── GlucoseTray.csproj ├── AppSettings.cs └── Program.cs ├── GlucoseTray.Tests ├── DSL │ ├── Display │ │ ├── DisplayBehaviorDriver.cs │ │ ├── DisplayProvider.cs │ │ ├── DisplayAssertionDriver.cs │ │ └── DisplayDriver.cs │ └── Read │ │ ├── ReadAssertionDriver.cs │ │ ├── ReadProvider.cs │ │ ├── ReadBehaviorDriver.cs │ │ └── ReadDriver.cs ├── GlucoseTray.Tests.csproj ├── ReadTests.cs └── DisplayTests.cs ├── .github ├── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md └── workflows │ ├── pr.yml │ └── generate-release.yml ├── LICENSE.md ├── README.md ├── GlucoseTray.sln ├── .gitattributes └── .gitignore /2019-05-03_16-18-24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Delubear/GlucoseTray/HEAD/2019-05-03_16-18-24.png -------------------------------------------------------------------------------- /GlucoseTray/Enums/GlucoseUnitType.cs: -------------------------------------------------------------------------------- 1 | namespace GlucoseTray.Enums; 2 | 3 | public enum GlucoseUnitType 4 | { 5 | Mg, 6 | Mmol 7 | } 8 | -------------------------------------------------------------------------------- /GlucoseTray/Enums/GlucoseSource.cs: -------------------------------------------------------------------------------- 1 | namespace GlucoseTray.Enums; 2 | 3 | public enum GlucoseSource 4 | { 5 | Dexcom, 6 | Nightscout, 7 | } 8 | -------------------------------------------------------------------------------- /GlucoseTray/Read/IReadStrategy.cs: -------------------------------------------------------------------------------- 1 | namespace GlucoseTray.Read; 2 | 3 | public interface IReadStrategy 4 | { 5 | Task GetLatestGlucoseAsync(); 6 | } 7 | -------------------------------------------------------------------------------- /GlucoseTray/Enums/DexcomServer.cs: -------------------------------------------------------------------------------- 1 | namespace GlucoseTray.Enums; 2 | 3 | public enum DexcomServer 4 | { 5 | DexcomShare1, 6 | DexcomShare2, 7 | DexcomInternational 8 | } -------------------------------------------------------------------------------- /GlucoseTray/Enums/AlertLevel.cs: -------------------------------------------------------------------------------- 1 | namespace GlucoseTray.Enums; 2 | 3 | public enum AlertLevel 4 | { 5 | None, 6 | CriticalLow, 7 | Low, 8 | High, 9 | CriticalHigh, 10 | } -------------------------------------------------------------------------------- /GlucoseTray/Enums/IconTextColor.cs: -------------------------------------------------------------------------------- 1 | namespace GlucoseTray.Enums; 2 | 3 | public enum IconTextColor 4 | { 5 | White, 6 | Black, 7 | Yellow, 8 | Gold, 9 | Red, 10 | } 11 | -------------------------------------------------------------------------------- /GlucoseTray/Read/GlucoseReading.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Enums; 2 | 3 | namespace GlucoseTray.Read; 4 | 5 | public class GlucoseReading 6 | { 7 | public int MgValue { get; set; } 8 | public float MmolValue { get; set; } 9 | public DateTime TimestampUtc { get; set; } 10 | public Trend Trend { get; set; } 11 | } 12 | -------------------------------------------------------------------------------- /GlucoseTray/AppWrapper.cs: -------------------------------------------------------------------------------- 1 | namespace GlucoseTray; 2 | 3 | public class AppWrapper : ApplicationContext 4 | { 5 | public AppWrapper(AppRunner app) 6 | { 7 | try 8 | { 9 | _ = app.Start(); 10 | } 11 | catch (Exception) 12 | { 13 | Environment.Exit(0); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /GlucoseTray/Read/Dexcom/DexcomResult.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace GlucoseTray.Read.Dexcom; 4 | 5 | /// 6 | /// Class that maps to the JSON received from DexCom queries. 7 | /// 8 | public class DexcomResult 9 | { 10 | [JsonPropertyName("ST")] 11 | public string UnixTicks { get; set; } = string.Empty; 12 | [JsonPropertyName("Trend")] 13 | public string Trend { get; set; } = string.Empty; 14 | [JsonPropertyName("Value")] 15 | public float GlucoseValue { get; set; } 16 | } 17 | -------------------------------------------------------------------------------- /GlucoseTray.Tests/DSL/Display/DisplayBehaviorDriver.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Read; 2 | using NSubstitute; 3 | 4 | namespace GlucoseTray.Tests.DSL.Display; 5 | 6 | internal class DisplayBehaviorDriver(DisplayProvider provider, GlucoseReading glucoseResult) 7 | { 8 | public DisplayBehaviorDriver RefreshingIcon() 9 | { 10 | provider.Reader.GetLatestGlucoseAsync().Returns(glucoseResult); 11 | provider.Runner.Process().Wait(); 12 | return this; 13 | } 14 | 15 | public DisplayAssertionDriver Then => new(provider, this); 16 | } 17 | -------------------------------------------------------------------------------- /GlucoseTray/Read/Nightscout/NightScoutResult.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace GlucoseTray.Read.Nightscout; 4 | 5 | /// 6 | /// Class that maps to the JSON from NightScout queries. 7 | /// 8 | public class NightScoutResult 9 | { 10 | [JsonPropertyName("sgv")] 11 | public float GlucoseValue { get; set; } 12 | 13 | [JsonPropertyName("date")] 14 | public long UnixTicks { get; set; } 15 | 16 | [JsonPropertyName("dateString")] 17 | public string DateString { get; set; } = string.Empty; 18 | 19 | [JsonPropertyName("direction")] 20 | public string Trend { get; set; } = string.Empty; 21 | } 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /GlucoseTray/Display/GlucoseDisplay.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Enums; 2 | 3 | namespace GlucoseTray.Display; 4 | 5 | public class GlucoseDisplay 6 | { 7 | public string DisplayValue { get; set; } = string.Empty; 8 | public bool IsStale { get; set; } 9 | public DateTime TimestampUtc { get; set; } 10 | public Trend Trend { get; set; } 11 | public int FontSize { get; set; } 12 | public IconTextColor Color { get; set; } = IconTextColor.White; 13 | 14 | public string GetDisplayMessage(DateTime utcNow) 15 | { 16 | var staleMessage = IsStale ? $"\r\n{Math.Abs((utcNow - TimestampUtc).TotalMinutes):#} minutes ago" : string.Empty; 17 | return $"{DisplayValue} {TimestampUtc.ToLocalTime().ToLongTimeString()} {Trend.GetTrendArrow()} {staleMessage}".Trim(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /GlucoseTray/Properties/PublishProfiles/PublishToSingleSelfContainedExe.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Release 6 | Any CPU 7 | bin\Release\net10.0-windows7.0\publish\win-x64\ 8 | FileSystem 9 | <_TargetId>Folder 10 | net10.0-windows7.0 11 | true 12 | win-x64 13 | true 14 | false 15 | false 16 | 17 | -------------------------------------------------------------------------------- /GlucoseTray.Tests/DSL/Read/ReadAssertionDriver.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Read; 2 | using NSubstitute; 3 | 4 | namespace GlucoseTray.Tests.DSL.Read; 5 | 6 | internal class ReadAssertionDriver(ReadProvider provider, ReadBehaviorDriver behaviorDriver) 7 | { 8 | public ReadBehaviorDriver When => behaviorDriver; 9 | 10 | public ReadAssertionDriver ShouldHaveMgValueOf(int value) 11 | { 12 | provider.Tray.Received().Refresh(Arg.Is(x => x.MgValue == value)); 13 | provider.Tray.ClearReceivedCalls(); 14 | return this; 15 | } 16 | 17 | public ReadAssertionDriver ShouldHaveMmolValueOf(float value) 18 | { 19 | provider.Tray.Received().Refresh(Arg.Is(x => x.MmolValue == value)); 20 | provider.Tray.ClearReceivedCalls(); 21 | return this; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /GlucoseTray/Properties/PublishProfiles/PublishToSingleSelfContainedExeWthoutFramework.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Release 6 | Any CPU 7 | bin\Release\net10.0-windows7.0\publish\win-x64-small\ 8 | FileSystem 9 | GlucoseTray-Slim 10 | <_TargetId>Folder 11 | net10.0-windows7.0 12 | false 13 | win-x64 14 | true 15 | false 16 | false 17 | 18 | -------------------------------------------------------------------------------- /GlucoseTray/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "IsDarkMode": false, 3 | "MinutesUntilStale": 0, 4 | "RefreshIntervalInMinutes": 0, 5 | 6 | "DATA_SOURCE_OPTIONS": "Dexcom,Nightscout", 7 | "DataSource": "Dexcom", 8 | "DEXCOM_SERVER_OPTIONS": "DexcomShare1,DexcomShare2,DexcomInternational", 9 | "DexcomServer": "DexcomShare1", 10 | 11 | "DexcomUsername": "", 12 | "DexcomPassword": "", 13 | 14 | "NightscoutUrl": "", 15 | "NightscoutToken": "", 16 | 17 | "DISPLAY_UNIT_TYPE_OPTIONS": "Mg,Mmol", 18 | "DisplayUnitType": "Mg", 19 | "SERVER_UNIT_TYPE_OPTIONS": "Mg,Mmol", 20 | "ServerUnitType": "Mg", 21 | 22 | "CriticalLowMgThreshold": 0, 23 | "LowMgThreshold": 0, 24 | "HighMgThreshold": 0, 25 | "CriticalHighMgThreshold": 0, 26 | 27 | "CriticalLowMmolThreshold": 0, 28 | "LowMmolThreshold": 0, 29 | "HighMmolThreshold": 0, 30 | "CriticalHighMmolThreshold": 0, 31 | 32 | "EnableAlerts": false 33 | } -------------------------------------------------------------------------------- /GlucoseTray/AppRunner.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Display; 2 | using GlucoseTray.Read; 3 | using Microsoft.Extensions.Options; 4 | 5 | namespace GlucoseTray; 6 | 7 | public class AppRunner(ITray tray, IGlucoseReader reader, IOptionsMonitor options) 8 | { 9 | public async Task Start() 10 | { 11 | options.OnChange(async _ => await Process()); 12 | 13 | while (true) 14 | { 15 | try 16 | { 17 | await Process(); 18 | await Task.Delay(TimeSpan.FromMinutes(Math.Max(options.CurrentValue.RefreshIntervalInMinutes, 1))); 19 | } 20 | catch 21 | { 22 | tray.Dispose(); 23 | throw; 24 | } 25 | } 26 | } 27 | 28 | public async Task Process() 29 | { 30 | var result = await reader.GetLatestGlucoseAsync(); 31 | tray.Refresh(result); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /GlucoseTray/Read/Nightscout/NightscoutReadStrategy.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json; 2 | 3 | namespace GlucoseTray.Read.Nightscout; 4 | 5 | internal class NightscoutReadStrategy(AppSettings settings, IExternalCommunicationAdapter communicator, IGlucoseReadingMapper mapper) : IReadStrategy 6 | { 7 | public async Task GetLatestGlucoseAsync() 8 | { 9 | var response = await GetApiResponseAsync(); 10 | var data = JsonSerializer.Deserialize>(response)!.Last(); 11 | 12 | var result = mapper.Map(data); 13 | return result; 14 | } 15 | 16 | private async Task GetApiResponseAsync() 17 | { 18 | var url = $"{settings.NightscoutUrl.TrimEnd('/')}/api/v1/entries/sgv?count=1"; 19 | url += !string.IsNullOrWhiteSpace(settings.NightscoutToken) ? $"&token={settings.NightscoutToken}" : string.Empty; 20 | 21 | var result = await communicator.GetApiResponseAsync(url); 22 | return result; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /GlucoseTray.Tests/DSL/Read/ReadProvider.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Display; 2 | using GlucoseTray.Read; 3 | using Microsoft.Extensions.Options; 4 | using NSubstitute; 5 | 6 | namespace GlucoseTray.Tests.DSL.Read; 7 | 8 | internal class ReadProvider 9 | { 10 | public readonly AppRunner Runner; 11 | public readonly ITray Tray = Substitute.For(); 12 | public readonly IGlucoseReadingMapper GlucoseReadingMapper; 13 | public readonly ITrayIcon Icon = Substitute.For(); 14 | public readonly IGlucoseReader Reader; 15 | public readonly IOptionsMonitor Options = Substitute.For>(); 16 | public readonly IExternalCommunicationAdapter ExternalCommunicationAdapter = Substitute.For(); 17 | 18 | public ReadProvider() 19 | { 20 | GlucoseReadingMapper = new GlucoseReadingMapper(Options); 21 | Reader = new GlucoseReader(Options, ExternalCommunicationAdapter, GlucoseReadingMapper); 22 | Runner = new AppRunner(Tray, Reader, Options); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /GlucoseTray/GlucoseTray.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | WinExe 5 | net10.0-windows7.0 6 | win-x64 7 | enable 8 | enable 9 | true 10 | true 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Never 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Christopher Baker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /GlucoseTray/Read/GlucoseReader.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Enums; 2 | using GlucoseTray.Read.Dexcom; 3 | using GlucoseTray.Read.Nightscout; 4 | using Microsoft.Extensions.Options; 5 | 6 | namespace GlucoseTray.Read; 7 | 8 | public interface IGlucoseReader 9 | { 10 | Task GetLatestGlucoseAsync(); 11 | } 12 | 13 | public class GlucoseReader(IOptionsMonitor options, IExternalCommunicationAdapter communicator, IGlucoseReadingMapper mapper) : IGlucoseReader 14 | { 15 | private GlucoseReading? _latestReading; 16 | 17 | public async Task GetLatestGlucoseAsync() 18 | { 19 | IReadStrategy strategy = GetReadStrategy(); 20 | 21 | try 22 | { 23 | _latestReading = await strategy.GetLatestGlucoseAsync(); 24 | return _latestReading; 25 | } 26 | catch 27 | { 28 | return _latestReading ?? new GlucoseReading() { TimestampUtc = DateTime.UtcNow, Trend = Trend.Unknown }; 29 | } 30 | } 31 | 32 | private IReadStrategy GetReadStrategy() 33 | { 34 | if (options.CurrentValue.DataSource == GlucoseSource.Dexcom) 35 | return new DexcomReadStrategy(options.CurrentValue, communicator, mapper); 36 | else 37 | return new NightscoutReadStrategy(options.CurrentValue, communicator, mapper); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /GlucoseTray.Tests/DSL/Display/DisplayProvider.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Display; 2 | using GlucoseTray.Read; 3 | using Microsoft.Extensions.Options; 4 | using NSubstitute; 5 | 6 | namespace GlucoseTray.Tests.DSL.Display; 7 | 8 | internal class DisplayProvider 9 | { 10 | public readonly AppRunner Runner; 11 | public readonly ITray Tray; 12 | public readonly IGlucoseDisplayMapper GlucoseDisplayMapper; 13 | public readonly IGlucoseReadingMapper GlucoseReadingMapper; 14 | public readonly IAlertService AlertService; 15 | public readonly IScheduler Scheduler = Substitute.For(); 16 | public readonly ITrayIcon Icon = Substitute.For(); 17 | public readonly IGlucoseReader Reader = Substitute.For(); 18 | public readonly IOptionsMonitor Options = Substitute.For>(); 19 | public readonly IExternalCommunicationAdapter ExternalCommunicationAdapter = Substitute.For(); 20 | 21 | public DisplayProvider() 22 | { 23 | GlucoseDisplayMapper = new GlucoseDisplayMapper(Options); 24 | GlucoseReadingMapper = new GlucoseReadingMapper(Options); 25 | AlertService = new AlertService(Options); 26 | Tray = new Tray(Icon, GlucoseDisplayMapper, Scheduler, AlertService, Options); 27 | Runner = new AppRunner(Tray, Reader, Options); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /.github/workflows/pr.yml: -------------------------------------------------------------------------------- 1 | # Action on pull requests : Build, but don't create a release 2 | 3 | name: .NET Core Pull Request 4 | 5 | on: 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: windows-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v4.1.7 16 | - name: Setup .NET Core 17 | uses: actions/setup-dotnet@v4.0.1 18 | with: 19 | dotnet-version: 10.x 20 | - name: Install dependencies 21 | run: dotnet restore -p:SelfContained=true 22 | - name: Build 23 | run: dotnet build --configuration Release --no-restore 24 | - name: Dotnet Tests 25 | # You may pin to the exact commit or the version. 26 | # uses: EasyDesk/action-dotnet-test@228a60327933ff6200594e89a6fa906a69e5f1e6 27 | uses: EasyDesk/action-dotnet-test@v1.0.0 28 | with: 29 | # Additional arguments to pass to 'dotnet test'. 30 | #test-args: # optional 31 | # The build configuration to use (defaults to 'Release'). 32 | #build-configuration: # optional, default is Release 33 | # The path to the project or solution to test (defaults to the current directory). 34 | #path: # optional, default is . 35 | # Whether or not to skip the build using the '--no-build' flag (defaults to true). 36 | skip-build: true # optional, default is true 37 | - name: Publish 38 | run: dotnet publish --configuration Release --no-restore 39 | -------------------------------------------------------------------------------- /GlucoseTray.Tests/GlucoseTray.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net10.0-windows7.0 5 | latest 6 | enable 7 | enable 8 | false 9 | 10 | 11 | 12 | 13 | all 14 | runtime; build; native; contentfiles; analyzers; buildtransitive 15 | 16 | 17 | 18 | 19 | all 20 | runtime; build; native; contentfiles; analyzers; buildtransitive 21 | 22 | 23 | 24 | all 25 | runtime; build; native; contentfiles; analyzers; buildtransitive 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GlucoseTray 2 | Tray Icon for displaying current BG information in taskbar. 3 | 4 | Always verify the time of the last reading by hovering over the tray icon or double-clicking it. Should it crash, the icon may stay in the taskbar but stop updating. 5 | 6 | Always check with your DexCom reader before making any treatment decisions. 7 | 8 | 9 | Step-by-step Instructions:
10 | Download and run the GlucoseTray.exe (no .NET framework install required) or GlucoseTray-Slim.exe (requires the appropriate .NET framework installed).
11 | On first run, the program will create an `appsettings.json` file alongside the `.exe`. Right-click the new icon in your taskbar and click `Settings` or open `appsettings.json` in a text editor.
12 | This will allow you to connfigure the program settings and immediately see the updates on save. 13 | 14 | Critical High Glucose displays red.
15 | High Glucose displays yellow.
16 | Low Glucose displays yellow.
17 | Critically Low Glucose displays as "DAN" for DANGER and is red.
18 | Normal blood glucose displays as black (or white for dark mode).
19 | Out-of-date readings are shown with a strikethrough effect.
20 | 21 | Features:
22 | -Color coded glucose numbers set to your ranges.
23 | -See latest glucose reading in taskbar. Also get time of reading and trend on hover or double-click.
24 | -Option to start application on system startup.
25 | 26 | ![alt text](https://raw.githubusercontent.com/Delubear/GlucoseTray/master/2019-05-03_16-18-24.png) 27 | 28 | https://github.com/Delubear/GlucoseTray/wiki/Setup-Guide 29 | -------------------------------------------------------------------------------- /GlucoseTray.Tests/DSL/Display/DisplayAssertionDriver.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Display; 2 | using GlucoseTray.Enums; 3 | using NSubstitute; 4 | 5 | namespace GlucoseTray.Tests.DSL.Display; 6 | 7 | internal class DisplayAssertionDriver(DisplayProvider provider, DisplayBehaviorDriver behaviorDriver) 8 | { 9 | public DisplayBehaviorDriver When => behaviorDriver; 10 | 11 | public DisplayAssertionDriver ShouldBeRefreshedWithValue(string displayValue) 12 | { 13 | provider.Icon.Received().RefreshIcon(Arg.Is(x => x.DisplayValue == displayValue)); 14 | return this; 15 | } 16 | 17 | public DisplayAssertionDriver ShouldBeRefreshedWithTextColor(IconTextColor color) 18 | { 19 | provider.Icon.Received().RefreshIcon(Arg.Is(x => x.Color == color)); 20 | return this; 21 | } 22 | 23 | public DisplayAssertionDriver ShouldBeMarkedStale() 24 | { 25 | provider.Icon.Received().RefreshIcon(Arg.Is(x => x.IsStale)); 26 | return this; 27 | } 28 | 29 | public DisplayAssertionDriver ShouldBeRefreshedWithFontSize(int fontSize) 30 | { 31 | provider.Icon.Received().RefreshIcon(Arg.Is(x => x.FontSize == fontSize)); 32 | return this; 33 | } 34 | 35 | public DisplayAssertionDriver ShouldNotShowNotification() 36 | { 37 | provider.Icon.DidNotReceive().ShowNotification(Arg.Any()); 38 | return this; 39 | } 40 | 41 | public DisplayAssertionDriver ShouldShowNotification(string message) 42 | { 43 | provider.Icon.Received().ShowNotification(message); 44 | provider.Icon.ClearReceivedCalls(); 45 | return this; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /GlucoseTray.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.32014.148 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GlucoseTray", "GlucoseTray\GlucoseTray.csproj", "{27AB4908-4214-412D-8C97-8823A4AB373C}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GlucoseTray.Tests", "GlucoseTray.Tests\GlucoseTray.Tests.csproj", "{3F665D5A-36E1-4EB7-914E-C2FE2870F8EE}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {27AB4908-4214-412D-8C97-8823A4AB373C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {27AB4908-4214-412D-8C97-8823A4AB373C}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {27AB4908-4214-412D-8C97-8823A4AB373C}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {27AB4908-4214-412D-8C97-8823A4AB373C}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {3F665D5A-36E1-4EB7-914E-C2FE2870F8EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {3F665D5A-36E1-4EB7-914E-C2FE2870F8EE}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {3F665D5A-36E1-4EB7-914E-C2FE2870F8EE}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {3F665D5A-36E1-4EB7-914E-C2FE2870F8EE}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {EC39EDBD-4C31-4382-9270-C3F0CFBAB652} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /GlucoseTray/Enums/Trend.cs: -------------------------------------------------------------------------------- 1 | namespace GlucoseTray.Enums; 2 | 3 | public enum Trend 4 | { 5 | TripleUp = 0, 6 | DoubleUp = 1, 7 | SingleUp = 2, 8 | FortyFiveUp = 3, 9 | Flat = 4, 10 | FortFiveDown = 5, 11 | SingleDown = 6, 12 | DoubleDown = 7, 13 | TripleDown = 8, 14 | Unknown = 9 15 | } 16 | 17 | public static class TrendExtensions 18 | { 19 | public static string GetTrendArrow(this Trend input) 20 | { 21 | return input switch 22 | { 23 | Trend.TripleUp => "⤊", 24 | Trend.DoubleUp => "⮅", 25 | Trend.SingleUp => "↑", 26 | Trend.FortyFiveUp => "↗", 27 | Trend.Flat => "→", 28 | Trend.FortFiveDown => "↘", 29 | Trend.SingleDown => "↓", 30 | Trend.DoubleDown => "⮇", 31 | Trend.TripleDown => "⤋", 32 | Trend.Unknown => "Unknown", 33 | _ => string.Empty, 34 | }; 35 | } 36 | 37 | public static Trend GetTrend(this string direction) 38 | { 39 | // Values for Direction copied from https://github.com/nightscout/cgm-remote-monitor/blob/41ac93f7217b1b7023ec6ad6fc35d29dcf2e4f88/lib/plugins/direction.js 40 | return direction switch 41 | { 42 | "TripleUp" => Trend.TripleUp, 43 | "DoubleUp" => Trend.DoubleUp, 44 | "SingleUp" => Trend.SingleUp, 45 | "FortyFiveUp" => Trend.FortyFiveUp, 46 | "Flat" => Trend.Flat, 47 | "FortyFiveDown" => Trend.FortFiveDown, 48 | "SingleDown" => Trend.SingleDown, 49 | "DoubleDown" => Trend.DoubleDown, 50 | "TripleDown" => Trend.TripleDown, 51 | _ => Trend.Unknown, 52 | }; 53 | } 54 | } -------------------------------------------------------------------------------- /GlucoseTray/AppSettings.cs: -------------------------------------------------------------------------------- 1 | 2 | using GlucoseTray.Enums; 3 | 4 | namespace GlucoseTray; 5 | 6 | public class AppSettings 7 | { 8 | public bool IsDarkMode { get; set; } = false; 9 | public int MinutesUntilStale { get; set; } = 15; 10 | public int RefreshIntervalInMinutes { get; set; } = 5; 11 | 12 | public string DATA_SOURCE_OPTIONS { get; private set; } = "Dexcom,Nightscout"; 13 | public GlucoseSource DataSource { get; set; } = GlucoseSource.Dexcom; 14 | public string DEXCOM_SERVER_OPTIONS { get; private set; } = "DexcomShare1,DexcomShare2,DexcomInternational"; 15 | public DexcomServer DexcomServer { get; set; } = DexcomServer.DexcomShare1; 16 | 17 | public string DexcomUsername { get; set; } = string.Empty; 18 | public string DexcomPassword { get; set; } = string.Empty; 19 | 20 | public string NightscoutUrl { get; set; } = string.Empty; 21 | public string NightscoutToken { get; set; } = string.Empty; 22 | 23 | public string DISPLAY_UNIT_TYPE_OPTIONS { get; private set; } = "Mg,Mmol"; 24 | public GlucoseUnitType DisplayUnitType { get; set; } 25 | public string SERVER_UNIT_TYPE_OPTIONS { get; private set; } = "Mg,Mmol"; 26 | public GlucoseUnitType ServerUnitType { get; set; } 27 | 28 | public int CriticalLowMgThreshold { get; set; } = 55; 29 | public int LowMgThreshold { get; set; } = 70; 30 | public int HighMgThreshold { get; set; } = 250; 31 | public int CriticalHighMgThreshold { get; set; } = 300; 32 | 33 | 34 | public float CriticalLowMmolThreshold { get; set; } = 3.0f; 35 | public float LowMmolThreshold { get; set; } = 3.8f; 36 | public float HighMmolThreshold { get; set; } = 13.8f; 37 | public float CriticalHighMmolThreshold { get; set; } = 16.6f; 38 | 39 | public bool EnableAlerts { get; set; } 40 | } 41 | -------------------------------------------------------------------------------- /GlucoseTray.Tests/DSL/Read/ReadBehaviorDriver.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Read.Dexcom; 2 | using GlucoseTray.Read.Nightscout; 3 | using NSubstitute; 4 | using NSubstitute.ExceptionExtensions; 5 | using System.Text.Json; 6 | 7 | namespace GlucoseTray.Tests.DSL.Read; 8 | 9 | internal class ReadBehaviorDriver(ReadProvider provider, DexcomResult dexcomResult, NightScoutResult nightscoutResult) 10 | { 11 | public ReadBehaviorDriver GettingLatestDexcomReading() 12 | { 13 | provider.ExternalCommunicationAdapter.PostApiResponseAsync(Arg.Any(), Arg.Is(x => x.Contains("bob"))).Returns("1account"); 14 | provider.ExternalCommunicationAdapter.PostApiResponseAsync(Arg.Any(), Arg.Is(x => x.Contains("1account"))).Returns("1session"); 15 | var data = JsonSerializer.Serialize(new List { dexcomResult }); 16 | provider.ExternalCommunicationAdapter.PostApiResponseAsync(Arg.Any(), Arg.Is(x => x.Contains("1session"))).Returns(data); 17 | provider.Runner.Process().Wait(); 18 | return this; 19 | } 20 | 21 | public ReadBehaviorDriver GettingLatestNightScoutReading() 22 | { 23 | var data = JsonSerializer.Serialize(new List { nightscoutResult }); 24 | provider.ExternalCommunicationAdapter.GetApiResponseAsync(Arg.Any()).Returns(data); 25 | provider.Runner.Process().Wait(); 26 | return this; 27 | } 28 | 29 | public ReadBehaviorDriver CommunicationErrorOccurs() 30 | { 31 | provider.ExternalCommunicationAdapter.GetApiResponseAsync(Arg.Any()).ThrowsAsync(x => throw new Exception()); 32 | provider.ExternalCommunicationAdapter.PostApiResponseAsync(Arg.Any()).ThrowsAsync(x => throw new Exception()); 33 | provider.Runner.Process().Wait(); 34 | return this; 35 | } 36 | 37 | public ReadAssertionDriver Then => new(provider, this); 38 | } 39 | -------------------------------------------------------------------------------- /GlucoseTray/Display/Tray.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Read; 2 | using Microsoft.Extensions.Options; 3 | 4 | namespace GlucoseTray.Display; 5 | 6 | public interface ITray 7 | { 8 | void Refresh(GlucoseReading result); 9 | void Dispose(); 10 | } 11 | 12 | public class Tray : ITray 13 | { 14 | private readonly ITrayIcon _icon; 15 | private readonly IGlucoseDisplayMapper _mapper; 16 | private readonly IScheduler _scheduler; 17 | private readonly IAlertService _alertService; 18 | private readonly IOptionsMonitor _options; 19 | 20 | public Tray(ITrayIcon icon, IGlucoseDisplayMapper mapper, IScheduler scheduler, IAlertService alertService, IOptionsMonitor options) 21 | { 22 | _icon = icon; 23 | _mapper = mapper; 24 | _scheduler = scheduler; 25 | _alertService = alertService; 26 | _options = options; 27 | 28 | RebuildContextMenu(); 29 | } 30 | 31 | private void RebuildContextMenu() 32 | { 33 | _icon.ClearMenu(); 34 | _icon.AddAutoRunMenu(_scheduler.HasTaskEnabled(), ToggleAutoRun); 35 | _icon.AddSettingsMenu(); 36 | _icon.AddExitMenu(); 37 | } 38 | 39 | private void ToggleAutoRun(object? sender, EventArgs e) 40 | { 41 | _scheduler.ToggleTask(!_scheduler.HasTaskEnabled()); 42 | RebuildContextMenu(); 43 | } 44 | 45 | public void Refresh(GlucoseReading result) 46 | { 47 | var display = _mapper.Map(result); 48 | _icon.RefreshIcon(display); 49 | 50 | if (_options.CurrentValue.EnableAlerts) 51 | NotifyUser(result, display); 52 | } 53 | 54 | private void NotifyUser(GlucoseReading result, GlucoseDisplay display) 55 | { 56 | var alert = _alertService.GetAlertMessage(result.MgValue, result.MmolValue, display.IsStale); 57 | if (!string.IsNullOrWhiteSpace(alert)) 58 | _icon.ShowNotification(alert); 59 | } 60 | 61 | public void Dispose() => _icon.Dispose(); 62 | } 63 | -------------------------------------------------------------------------------- /GlucoseTray/Display/IScheduler.cs: -------------------------------------------------------------------------------- 1 | 2 | using Microsoft.Win32.TaskScheduler; 3 | 4 | namespace GlucoseTray.Display; 5 | 6 | public interface IScheduler 7 | { 8 | bool HasTaskEnabled(); 9 | void ToggleTask(bool enable); 10 | } 11 | 12 | public class TaskSchedulerService : IScheduler 13 | { 14 | private readonly string ExecutablePath = "\"" + Environment.ProcessPath + "\""; 15 | private readonly string TaskName = "GlucoseTray-" + Environment.UserName; 16 | private readonly string WorkingDirectory = Directory.GetCurrentDirectory(); 17 | 18 | public bool HasTaskEnabled() 19 | { 20 | using var ts = new TaskService(); 21 | var existingTask = ts.GetTask(TaskName); 22 | if (existingTask is null) 23 | return false; 24 | 25 | var action = (ExecAction)existingTask.Definition.Actions[0]; 26 | if (action.Path != ExecutablePath || action.WorkingDirectory != Directory.GetCurrentDirectory()) // File has been moved since task was created. Update values. 27 | { 28 | action.Path = ExecutablePath; 29 | action.WorkingDirectory = WorkingDirectory; 30 | existingTask.RegisterChanges(); 31 | } 32 | 33 | return existingTask.Enabled; 34 | } 35 | 36 | public void ToggleTask(bool enable) 37 | { 38 | using var ts = new TaskService(); 39 | var task = ts.GetTask(TaskName); 40 | if (task is null) 41 | { 42 | var trigger = new LogonTrigger() { UserId = Environment.UserName }; 43 | var action = new ExecAction(ExecutablePath, workingDirectory: WorkingDirectory); 44 | var description = "GlucoseTray task for " + Environment.UserName; 45 | task = ts.AddTask(TaskName, trigger, action, description: description); 46 | task.Definition.Settings.ExecutionTimeLimit = TimeSpan.FromSeconds(0); // Don't end task after 72 hour default runtime. 47 | task.RegisterChanges(); 48 | } 49 | task.Enabled = enable; 50 | } 51 | } -------------------------------------------------------------------------------- /GlucoseTray/Read/GlucoseReadingMapper.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Enums; 2 | using GlucoseTray.Read.Dexcom; 3 | using GlucoseTray.Read.Nightscout; 4 | using Microsoft.Extensions.Options; 5 | 6 | namespace GlucoseTray.Read; 7 | 8 | public interface IGlucoseReadingMapper 9 | { 10 | GlucoseReading Map(DexcomResult result); 11 | GlucoseReading Map(NightScoutResult result); 12 | } 13 | 14 | public class GlucoseReadingMapper(IOptionsMonitor options) : IGlucoseReadingMapper 15 | { 16 | public GlucoseReading Map(DexcomResult input) 17 | { 18 | var (MgValue, MmolValue) = GetValues((float)input.GlucoseValue); 19 | var unixTime = string.Join("", input.UnixTicks.Where(char.IsDigit)); 20 | 21 | var result = new GlucoseReading 22 | { 23 | MgValue = MgValue, 24 | MmolValue = MmolValue, 25 | Trend = input.Trend.GetTrend(), 26 | TimestampUtc = !string.IsNullOrWhiteSpace(unixTime) ? DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(unixTime)).UtcDateTime : DateTime.MinValue, 27 | }; 28 | 29 | return result; 30 | } 31 | 32 | public GlucoseReading Map(NightScoutResult input) 33 | { 34 | var (MgValue, MmolValue) = GetValues((float)input.GlucoseValue); 35 | 36 | var result = new GlucoseReading 37 | { 38 | MgValue = MgValue, 39 | MmolValue = MmolValue, 40 | Trend = input.Trend.GetTrend(), 41 | TimestampUtc = !string.IsNullOrEmpty(input.DateString) ? DateTime.Parse(input.DateString).ToUniversalTime() : DateTimeOffset.FromUnixTimeMilliseconds(input.UnixTicks).UtcDateTime, 42 | }; 43 | 44 | return result; 45 | } 46 | 47 | private (int MgValue, float MmolValue) GetValues(float value) 48 | { 49 | if (value == 0) 50 | return (0, 0); 51 | if (options.CurrentValue.ServerUnitType == GlucoseUnitType.Mmol) 52 | return ((int)(value * 18.0182f), value); 53 | else 54 | return ((int)value, value / 18.0182f); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /GlucoseTray/Read/IExternalCommunicationAdapter.cs: -------------------------------------------------------------------------------- 1 | 2 | using System.Net.Http.Headers; 3 | using System.Text; 4 | 5 | namespace GlucoseTray.Read; 6 | 7 | public interface IExternalCommunicationAdapter 8 | { 9 | Task PostApiResponseAsync(string url, string? content = null); 10 | Task GetApiResponseAsync(string url, string? content = null); 11 | } 12 | 13 | public class ExternalCommunicationAdapter(IHttpClientFactory httpClientFactory) : IExternalCommunicationAdapter 14 | { 15 | public async Task PostApiResponseAsync(string url, string? content = null) 16 | { 17 | var request = new HttpRequestMessage(HttpMethod.Post, url); 18 | if (content is not null) 19 | { 20 | var requestContent = new StringContent(content, Encoding.UTF8, "application/json"); 21 | request.Content = requestContent; 22 | } 23 | var result = await DoApiResponseAsync(request); 24 | return result; 25 | } 26 | 27 | public async Task GetApiResponseAsync(string url, string? content = null) 28 | { 29 | var request = new HttpRequestMessage(HttpMethod.Get, url); 30 | request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 31 | if (content is not null) 32 | { 33 | var requestContent = new StringContent(content, Encoding.UTF8, "application/json"); 34 | request.Content = requestContent; 35 | } 36 | var result = await DoApiResponseAsync(request); 37 | return result; 38 | } 39 | 40 | private async Task DoApiResponseAsync(HttpRequestMessage request) 41 | { 42 | HttpResponseMessage? response = null; 43 | try 44 | { 45 | var client = httpClientFactory.CreateClient(); 46 | 47 | response = await client.SendAsync(request); 48 | var result = await response.Content.ReadAsStringAsync(); 49 | 50 | return result; 51 | } 52 | finally 53 | { 54 | request?.Dispose(); 55 | response?.Dispose(); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /.github/workflows/generate-release.yml: -------------------------------------------------------------------------------- 1 | # To create a release: 2 | # git tag v1.0.0 3 | # git push origin v1.0.0 4 | # or 5 | # use Github UI -> Create Release -> Create New Tag -> v1.0.0 -> Publish Release 6 | 7 | name: Create release 8 | 9 | on: 10 | push: 11 | tags: 12 | - "v*" 13 | 14 | jobs: 15 | build: 16 | runs-on: windows-latest 17 | steps: 18 | - uses: actions/checkout@v4.1.2 19 | with: 20 | fetch-depth: 0 # Fetch all history for all tags 21 | - name: Setup .NET Core 22 | uses: actions/setup-dotnet@v4.3.1 23 | with: 24 | dotnet-version: 10.x 25 | - name: create-release-notes 26 | id: notes 27 | uses: johnyherangi/create-release-notes@v1 28 | env: 29 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 30 | #with: 31 | # Release note format 32 | #format: - {{subject}} by @{{author}} 33 | - name: Install dependencies 34 | run: dotnet restore -p:SelfContained=true 35 | - name: Build 36 | run: dotnet build --configuration Release --no-restore 37 | - name: Dotnet Tests 38 | uses: EasyDesk/action-dotnet-test@v1.3.0 39 | with: 40 | skip-build: true # optional, default is true 41 | - name: Publish 42 | run: dotnet publish GlucoseTray\GlucoseTray.csproj --configuration Release --no-restore -p:PublishProfile=GlucoseTray\Properties\PublishProfiles\PublishToSingleSelfContainedExe.pubxml 43 | - name: Publish 44 | run: dotnet publish GlucoseTray\GlucoseTray.csproj --configuration Release --no-restore -p:PublishProfile=GlucoseTray\Properties\PublishProfiles\PublishToSingleSelfContainedExeWthoutFramework.pubxml 45 | - name: Create a new release note 46 | uses: softprops/action-gh-release@v1 47 | env: 48 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 49 | with: 50 | tag_name: ${{ github.ref_name }} 51 | name: GlucoseTray ${{ github.ref_name }} 52 | body: | 53 | ${{ steps.notes.outputs.release-notes }} 54 | draft: false 55 | prerelease: false 56 | append_body: true 57 | fail_on_unmatched_files: true 58 | generate_release_notes: true 59 | files: | 60 | ./GlucoseTray/bin/Release/net10.0-windows7.0/publish/win-x64/GlucoseTray.exe 61 | ./GlucoseTray/bin/Release/net10.0-windows7.0/publish/win-x64-small/GlucoseTray-Slim.exe 62 | ./README.md 63 | -------------------------------------------------------------------------------- /GlucoseTray/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.Hosting; 4 | using GlucoseTray; 5 | using GlucoseTray.Display; 6 | using System.Text.Json; 7 | using GlucoseTray.Read; 8 | using System.Text.Json.Serialization; 9 | 10 | public class Program 11 | { 12 | [STAThread] 13 | private static void Main(string[] args) 14 | { 15 | var filePath = "appsettings.json"; 16 | if (!File.Exists(filePath)) 17 | CreateDefaultAppSettings(filePath); 18 | 19 | var host = Host.CreateDefaultBuilder() 20 | .ConfigureAppConfiguration((context, builder) => builder.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)) 21 | .ConfigureServices(static (context, services) => ConfigureServices(context.Configuration, services)) 22 | .Build(); 23 | 24 | var services = host.Services; 25 | var app = services.GetRequiredService(); 26 | Application.Run(app); 27 | } 28 | 29 | private static void ConfigureServices(IConfiguration configuration, IServiceCollection services) 30 | { 31 | services.Configure(configuration) 32 | .AddHttpClient() 33 | .AddSingleton() 34 | .AddSingleton() 35 | .AddScoped() 36 | .AddScoped() 37 | .AddScoped() 38 | .AddScoped() 39 | .AddScoped() 40 | .AddScoped() 41 | .AddScoped() 42 | .AddScoped(); 43 | } 44 | 45 | private static JsonSerializerOptions GetJsonSerializerOptions() => new() 46 | { 47 | Converters = { new JsonStringEnumConverter() }, 48 | WriteIndented = true, 49 | }; 50 | 51 | private static void CreateDefaultAppSettings(string filePath) 52 | { 53 | var settings = new AppSettings(); 54 | var options = GetJsonSerializerOptions(); 55 | var json = JsonSerializer.Serialize(settings, options); 56 | File.WriteAllText(filePath, json); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /GlucoseTray/Display/AlertService.cs: -------------------------------------------------------------------------------- 1 | 2 | using GlucoseTray.Enums; 3 | using Microsoft.Extensions.Options; 4 | 5 | namespace GlucoseTray.Display; 6 | 7 | public interface IAlertService 8 | { 9 | string GetAlertMessage(int mgValue, float mmolValue, bool isStale); 10 | } 11 | 12 | public class AlertService(IOptionsMonitor options) : IAlertService 13 | { 14 | private AlertLevel _currentAlertLevel = AlertLevel.None; 15 | 16 | public string GetAlertMessage(int mgValue, float mmolValue, bool isStale) 17 | { 18 | if (isStale) 19 | return string.Empty; 20 | 21 | if (mgValue == 0 || mmolValue == 0) 22 | return string.Empty; 23 | 24 | var reading = options.CurrentValue.DisplayUnitType == GlucoseUnitType.Mg ? mgValue : mmolValue; 25 | 26 | var settings = options.CurrentValue; 27 | var criticalHigh = settings.DisplayUnitType == GlucoseUnitType.Mg ? settings.CriticalHighMgThreshold : settings.CriticalHighMmolThreshold; 28 | var high = settings.DisplayUnitType == GlucoseUnitType.Mg ? settings.HighMgThreshold : settings.HighMmolThreshold; 29 | var low = settings.DisplayUnitType == GlucoseUnitType.Mg ? settings.LowMgThreshold : settings.LowMmolThreshold; 30 | var criticalLow = settings.DisplayUnitType == GlucoseUnitType.Mg ? settings.CriticalLowMgThreshold : settings.CriticalLowMmolThreshold; 31 | 32 | if (reading >= criticalHigh) 33 | { 34 | if (_currentAlertLevel != AlertLevel.CriticalHigh) 35 | { 36 | _currentAlertLevel = AlertLevel.CriticalHigh; 37 | return "Critical High Glucose Alert"; 38 | } 39 | } 40 | else if (reading >= high) 41 | { 42 | if (_currentAlertLevel != AlertLevel.CriticalHigh && _currentAlertLevel != AlertLevel.High) 43 | { 44 | _currentAlertLevel = AlertLevel.High; 45 | return "High Glucose Alert"; 46 | } 47 | } 48 | else if (reading <= criticalLow) 49 | { 50 | if (_currentAlertLevel != AlertLevel.CriticalLow) 51 | { 52 | _currentAlertLevel = AlertLevel.CriticalLow; 53 | return "Critical Low Glucose Alert"; 54 | } 55 | } 56 | else if (reading <= low) 57 | { 58 | if (_currentAlertLevel != AlertLevel.CriticalLow && _currentAlertLevel != AlertLevel.Low) 59 | { 60 | _currentAlertLevel = AlertLevel.Low; 61 | return "Low Glucose Alert"; 62 | } 63 | } 64 | 65 | return string.Empty; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /GlucoseTray/Read/Dexcom/DexcomReadStrategy.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Enums; 2 | using System.Text.Json; 3 | 4 | namespace GlucoseTray.Read.Dexcom; 5 | 6 | internal class DexcomReadStrategy(AppSettings settings, IExternalCommunicationAdapter communicator, IGlucoseReadingMapper mapper) : IReadStrategy 7 | { 8 | public async Task GetLatestGlucoseAsync() 9 | { 10 | string accountId = await GetAccountIdAsync(); 11 | string sessionId = await GetSessionIdAsync(accountId); 12 | string response = await GetApiResponseAsync(sessionId); 13 | 14 | var data = JsonSerializer.Deserialize>(response)!.First(); 15 | 16 | var result = mapper.Map(data); 17 | return result; 18 | } 19 | 20 | private async Task GetApiResponseAsync(string sessionId) 21 | { 22 | var url = $"https://{GetDexComServer()}/ShareWebServices/Services/Publisher/ReadPublisherLatestGlucoseValues?sessionId={sessionId}&minutes=1440&maxCount=1"; 23 | var result = await communicator.PostApiResponseAsync(url, sessionId); 24 | return result; 25 | } 26 | 27 | private async Task GetSessionIdAsync(string accountId) 28 | { 29 | var sessionIdRequestJson = JsonSerializer.Serialize(new 30 | { 31 | accountId, 32 | applicationId = "d8665ade-9673-4e27-9ff6-92db4ce13d13", 33 | password = settings.DexcomPassword 34 | }); 35 | 36 | var sessionUrl = $"https://{GetDexComServer()}/ShareWebServices/Services/General/LoginPublisherAccountById"; 37 | 38 | var result = await communicator.PostApiResponseAsync(sessionUrl, sessionIdRequestJson); 39 | var sessionId = result.Replace("\"", ""); 40 | 41 | return sessionId; 42 | } 43 | 44 | private async Task GetAccountIdAsync() 45 | { 46 | var accountIdRequestJson = JsonSerializer.Serialize(new 47 | { 48 | accountName = settings.DexcomUsername, 49 | applicationId = "d8665ade-9673-4e27-9ff6-92db4ce13d13", 50 | password = settings.DexcomPassword 51 | }); 52 | 53 | var accountUrl = $"https://{GetDexComServer()}/ShareWebServices/Services/General/AuthenticatePublisherAccount"; 54 | 55 | var result = await communicator.PostApiResponseAsync(accountUrl, accountIdRequestJson); 56 | var accountId = result.Replace("\"", ""); 57 | 58 | return accountId; 59 | } 60 | 61 | public string GetDexComServer() => settings.DexcomServer switch 62 | { 63 | DexcomServer.DexcomShare1 => "share1.dexcom.com", 64 | DexcomServer.DexcomShare2 => "share2.dexcom.com", 65 | DexcomServer.DexcomInternational => "shareous1.dexcom.com", 66 | _ => "share1.dexcom.com", 67 | }; 68 | } 69 | -------------------------------------------------------------------------------- /GlucoseTray/Display/GlucoseDisplayMapper.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Enums; 2 | using GlucoseTray.Read; 3 | using Microsoft.Extensions.Options; 4 | 5 | namespace GlucoseTray.Display; 6 | 7 | public interface IGlucoseDisplayMapper 8 | { 9 | GlucoseDisplay Map(GlucoseReading reading); 10 | } 11 | 12 | public class GlucoseDisplayMapper(IOptionsMonitor options) : IGlucoseDisplayMapper 13 | { 14 | public GlucoseDisplay Map(GlucoseReading reading) 15 | { 16 | return new GlucoseDisplay 17 | { 18 | DisplayValue = GetDisplayValue(reading), 19 | Color = options.CurrentValue.DisplayUnitType == GlucoseUnitType.Mg ? GetColor(reading.MgValue) : GetColor(reading.MmolValue), 20 | FontSize = GetFontSize(reading), 21 | TimestampUtc = reading.TimestampUtc, 22 | Trend = reading.Trend, 23 | IsStale = reading.TimestampUtc < DateTime.UtcNow.AddMinutes(-options.CurrentValue.MinutesUntilStale), 24 | }; 25 | } 26 | 27 | private int GetFontSize(GlucoseReading reading) 28 | { 29 | var defaultFontSize = 40; 30 | var smallerFontSize = 38; 31 | 32 | return options.CurrentValue.DisplayUnitType == GlucoseUnitType.Mmol && reading.MmolValue >= 10 ? smallerFontSize : defaultFontSize; 33 | } 34 | 35 | private string GetDisplayValue(GlucoseReading reading) 36 | { 37 | var displayUnitType = options.CurrentValue.DisplayUnitType; 38 | 39 | if (displayUnitType == GlucoseUnitType.Mg) 40 | { 41 | if (reading.MgValue == 0) 42 | return "NUL"; 43 | if (IsCriticalLow(reading.MgValue)) 44 | return "DAN"; 45 | return reading.MgValue.ToString(); 46 | } 47 | else 48 | { 49 | if (reading.MmolValue == 0) 50 | return "NUL"; 51 | if (IsCriticalLow(reading.MmolValue)) 52 | return "DAN"; 53 | return reading.MmolValue.ToString("0.0").Replace('.', '\''); // ' uses less space than . 54 | } 55 | } 56 | 57 | private bool IsCriticalLow(int mgValue) => mgValue <= options.CurrentValue.CriticalLowMgThreshold; 58 | private bool IsCriticalLow(float mmolValue) => mmolValue <= options.CurrentValue.CriticalLowMmolThreshold; 59 | 60 | private IconTextColor GetColor(int mgValue) 61 | { 62 | var settings = options.CurrentValue; 63 | return GetColor(mgValue, settings.CriticalLowMgThreshold, settings.LowMgThreshold, settings.HighMgThreshold, settings.CriticalHighMgThreshold); 64 | } 65 | 66 | private IconTextColor GetColor(float mmolValue) 67 | { 68 | var settings = options.CurrentValue; 69 | return GetColor(mmolValue, settings.CriticalLowMmolThreshold, settings.LowMmolThreshold, settings.HighMmolThreshold, settings.CriticalHighMmolThreshold); 70 | } 71 | 72 | private IconTextColor GetColor(float value, float criticalLow, float low, float high, float criticalHigh) 73 | { 74 | if (value <= criticalLow) 75 | return IconTextColor.Red; 76 | else if (value <= low) 77 | return options.CurrentValue.IsDarkMode ? IconTextColor.Yellow : IconTextColor.Gold; 78 | else if (value >= criticalHigh) 79 | return IconTextColor.Red; 80 | else if (value >= high) 81 | return options.CurrentValue.IsDarkMode ? IconTextColor.Yellow : IconTextColor.Gold; 82 | else 83 | return options.CurrentValue.IsDarkMode ? IconTextColor.White : IconTextColor.Black; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /GlucoseTray.Tests/ReadTests.cs: -------------------------------------------------------------------------------- 1 | 2 | using GlucoseTray.Tests.DSL.Read; 3 | 4 | namespace GlucoseTray.Tests; 5 | 6 | public class ReadTests 7 | { 8 | [Test] 9 | public void ShouldReadDexcomMgResult() 10 | { 11 | var driver = new ReadDriver(); 12 | driver.GivenADexcomResult() 13 | .WithMgValue(100) 14 | .When.GettingLatestDexcomReading() 15 | .Then.ShouldHaveMgValueOf(100); 16 | } 17 | 18 | [Test] 19 | public void ShouldReadDexcomMmolResult() 20 | { 21 | var driver = new ReadDriver(); 22 | driver.GivenADexcomResult() 23 | .WithMmolServerUnitType() 24 | .WithMmolValue(5.5f) 25 | .When.GettingLatestDexcomReading() 26 | .Then.ShouldHaveMmolValueOf(5.5f); 27 | } 28 | 29 | [Test] 30 | public void ShouldReadDexcomMgResultWhenServerIsReturningMmol() 31 | { 32 | var driver = new ReadDriver(); 33 | driver.GivenADexcomResult() 34 | .WithMmolServerUnitType() 35 | .WithMmolValue(5.55077f) 36 | .When.GettingLatestDexcomReading() 37 | .Then.ShouldHaveMgValueOf(100); 38 | } 39 | 40 | [Test] 41 | public void ShouldReadDexcomMmolResultWhenServerIsReturningMg() 42 | { 43 | var driver = new ReadDriver(); 44 | driver.GivenADexcomResult() 45 | .WithMgServerUnitType() 46 | .WithMgValue(100) 47 | .When.GettingLatestDexcomReading() 48 | .Then.ShouldHaveMmolValueOf(5.549944f); 49 | } 50 | 51 | [Test] 52 | public void ShouldReadNightScoutResult() 53 | { 54 | var driver = new ReadDriver(); 55 | driver.GivenANightscoutResult() 56 | .WithMgValue(100) 57 | .When.GettingLatestNightScoutReading() 58 | .Then.ShouldHaveMgValueOf(100); 59 | } 60 | 61 | [Test] 62 | public void ShouldReadNightScoutMmolResult() 63 | { 64 | var driver = new ReadDriver(); 65 | driver.GivenANightscoutResult() 66 | .WithMmolServerUnit() 67 | .WithMmolValue(5.5f) 68 | .When.GettingLatestNightScoutReading() 69 | .Then.ShouldHaveMmolValueOf(5.5f); 70 | } 71 | 72 | [Test] 73 | public void ShouldReadNightScoutMgResultWhenServerIsReturningMmol() 74 | { 75 | var driver = new ReadDriver(); 76 | driver.GivenANightscoutResult() 77 | .WithMmolServerUnit() 78 | .WithMmolValue(5.55077f) 79 | .When.GettingLatestNightScoutReading() 80 | .Then.ShouldHaveMgValueOf(100); 81 | } 82 | 83 | [Test] 84 | public void ShouldReadNightScoutMmolResultWhenServerIsReturningMg() 85 | { 86 | var driver = new ReadDriver(); 87 | driver.GivenANightscoutResult() 88 | .WithMgServerUnit() 89 | .WithMgValue(100) 90 | .When.GettingLatestNightScoutReading() 91 | .Then.ShouldHaveMmolValueOf(5.549944f); 92 | } 93 | 94 | [Test] 95 | public void ShouldReturnLatestReceivedReadingWhenCommunicationErrorOccurs() 96 | { 97 | var driver = new ReadDriver(); 98 | driver.GivenADexcomResult() 99 | .WithMgValue(100) 100 | .When.GettingLatestDexcomReading() 101 | .Then.ShouldHaveMgValueOf(100) 102 | .When.CommunicationErrorOccurs() 103 | .Then.ShouldHaveMgValueOf(100); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /GlucoseTray.Tests/DSL/Display/DisplayDriver.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Enums; 2 | using GlucoseTray.Read; 3 | using NSubstitute; 4 | 5 | namespace GlucoseTray.Tests.DSL.Display; 6 | 7 | internal class DisplayDriver 8 | { 9 | private readonly DisplayProvider _provider = new(); 10 | private GlucoseReading _reading = new(); 11 | private readonly AppSettings _settings = new() 12 | { 13 | MinutesUntilStale = 5, 14 | CriticalLowMgThreshold = 55, 15 | LowMgThreshold = 70, 16 | HighMgThreshold = 250, 17 | CriticalHighMgThreshold = 300, 18 | CriticalLowMmolThreshold = 3.0f, 19 | LowMmolThreshold = 3.8f, 20 | HighMmolThreshold = 13.8f, 21 | CriticalHighMmolThreshold = 16.6f, 22 | DisplayUnitType = GlucoseUnitType.Mg, 23 | IsDarkMode = false, 24 | ServerUnitType = GlucoseUnitType.Mg, 25 | EnableAlerts = true, 26 | }; 27 | 28 | public DisplayDriver() => _provider.Options.CurrentValue.Returns(_settings); 29 | 30 | public DisplayDriver GivenAGlucoseReading() 31 | { 32 | _reading = new GlucoseReading() { TimestampUtc = DateTime.UtcNow }; 33 | return this; 34 | } 35 | 36 | public DisplayDriver WithMgServerUnit() 37 | { 38 | _settings.ServerUnitType = GlucoseUnitType.Mg; 39 | _provider.Options.CurrentValue.Returns(_settings); 40 | return this; 41 | } 42 | 43 | public DisplayDriver WithMmolServerUnit() 44 | { 45 | _settings.ServerUnitType = GlucoseUnitType.Mmol; 46 | _provider.Options.CurrentValue.Returns(_settings); 47 | return this; 48 | } 49 | 50 | public DisplayDriver WithMgDisplay() 51 | { 52 | _settings.DisplayUnitType = GlucoseUnitType.Mg; 53 | _provider.Options.CurrentValue.Returns(_settings); 54 | return this; 55 | } 56 | 57 | public DisplayDriver WithMmolDisplay() 58 | { 59 | _settings.DisplayUnitType = GlucoseUnitType.Mmol; 60 | _provider.Options.CurrentValue.Returns(_settings); 61 | return this; 62 | } 63 | 64 | public DisplayDriver WithMgValue(int value) 65 | { 66 | _reading.MgValue = value; 67 | return this; 68 | } 69 | 70 | public DisplayDriver WithMmolValue(float value) 71 | { 72 | _reading.MmolValue = value; 73 | return this; 74 | } 75 | 76 | public DisplayDriver WithDarkMode() 77 | { 78 | _settings.IsDarkMode = true; 79 | _provider.Options.CurrentValue.Returns(_settings); 80 | return this; 81 | } 82 | 83 | public DisplayDriver WithStaleData() 84 | { 85 | _settings.MinutesUntilStale = 15; 86 | _provider.Options.CurrentValue.Returns(_settings); 87 | _reading.TimestampUtc = DateTime.UtcNow.AddMinutes(-30); 88 | return this; 89 | } 90 | 91 | public DisplayDriver WithCriticalLowValue() 92 | { 93 | _reading.MgValue = 50; 94 | _reading.MmolValue = 2.8f; 95 | return this; 96 | } 97 | 98 | public DisplayDriver WithLowValue() 99 | { 100 | _reading.MgValue = 65; 101 | _reading.MmolValue = 3.6f; 102 | return this; 103 | } 104 | 105 | public DisplayDriver WithHighValue() 106 | { 107 | _reading.MgValue = 260; 108 | _reading.MmolValue = 14.4f; 109 | return this; 110 | } 111 | 112 | public DisplayDriver WithCriticalHighValue() 113 | { 114 | _reading.MgValue = 300; 115 | _reading.MmolValue = 16.6f; 116 | return this; 117 | } 118 | 119 | public DisplayBehaviorDriver When => new(_provider, _reading); 120 | } 121 | -------------------------------------------------------------------------------- /GlucoseTray/Display/ITrayIcon.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Enums; 2 | using System.ComponentModel; 3 | using System.Diagnostics; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace GlucoseTray.Display; 7 | 8 | public interface ITrayIcon 9 | { 10 | void ClearMenu(); 11 | void AddAutoRunMenu(bool isAlreadyOn, EventHandler toggleCallback); 12 | void AddSettingsMenu(); 13 | void AddExitMenu(); 14 | void RefreshIcon(GlucoseDisplay display); 15 | void ShowNotification(string alertText); 16 | void Dispose(); 17 | } 18 | 19 | public class NotificationIcon : ITrayIcon 20 | { 21 | private readonly NotifyIcon _trayIcon; 22 | private GlucoseDisplay? _latestGlucose; 23 | 24 | public NotificationIcon() 25 | { 26 | _trayIcon = new NotifyIcon 27 | { 28 | ContextMenuStrip = new ContextMenuStrip(new Container()), 29 | Visible = true, 30 | }; 31 | _trayIcon.DoubleClick += ShowBalloon; 32 | } 33 | 34 | public void ShowNotification(string alertText) => _trayIcon.ShowBalloonTip(2000, "Glucose Alert", alertText, ToolTipIcon.Warning); 35 | private void ShowBalloon(object? sender, EventArgs e) => _trayIcon?.ShowBalloonTip(2000, "Glucose", _latestGlucose?.GetDisplayMessage(DateTime.UtcNow) ?? "error", ToolTipIcon.Info); 36 | 37 | public void ClearMenu() => _trayIcon?.ContextMenuStrip?.Items.Clear(); 38 | public void AddAutoRunMenu(bool isAlreadyOn, EventHandler toggleCallback) => _trayIcon?.ContextMenuStrip?.Items.Add(new ToolStripMenuItem(isAlreadyOn ? "Disable auto-start" : "Run on startup", null, toggleCallback)); 39 | public void AddSettingsMenu() => _trayIcon?.ContextMenuStrip?.Items.Add(new ToolStripMenuItem("Settings", null, Settings)); 40 | public void AddExitMenu() => _trayIcon?.ContextMenuStrip?.Items.Add(new ToolStripMenuItem("Exit", null, Exit)); 41 | 42 | private void Settings(object? sender, EventArgs e) 43 | { 44 | ProcessStartInfo startInfo = new() 45 | { 46 | FileName = Path.GetDirectoryName(AppContext.BaseDirectory) + "\\appsettings.json", 47 | UseShellExecute = true, 48 | }; 49 | Process.Start(startInfo); 50 | } 51 | 52 | public void Dispose() => _trayIcon.Dispose(); 53 | 54 | private void Exit(object? sender, EventArgs e) 55 | { 56 | Dispose(); 57 | Application.ExitThread(); 58 | Application.Exit(); 59 | } 60 | 61 | public void RefreshIcon(GlucoseDisplay display) 62 | { 63 | _latestGlucose = display; 64 | CreateTextIcon(display); 65 | } 66 | 67 | private void CreateTextIcon(GlucoseDisplay display) 68 | { 69 | var bitmapText = new Bitmap(64, 64); 70 | var g = Graphics.FromImage(bitmapText); 71 | g.Clear(Color.Transparent); 72 | 73 | var font = new Font("Roboto", display.FontSize, display.IsStale ? FontStyle.Strikeout : FontStyle.Regular, GraphicsUnit.Pixel); 74 | var offset = -10f; 75 | g.DrawString(display.DisplayValue, font, new SolidBrush(Convert(display.Color)), offset, 0f); 76 | var hIcon = bitmapText.GetHicon(); 77 | var myIcon = Icon.FromHandle(hIcon); 78 | _trayIcon.Icon = myIcon; 79 | 80 | DestroyMyIcon(myIcon.Handle); 81 | bitmapText.Dispose(); 82 | g.Dispose(); 83 | myIcon.Dispose(); 84 | } 85 | 86 | 87 | [DllImport("user32.dll", CharSet = CharSet.Auto)] 88 | private static extern bool DestroyIcon(nint handle); 89 | 90 | private static void DestroyMyIcon(nint handle) => DestroyIcon(handle); 91 | 92 | private static Color Convert(IconTextColor color) => color switch 93 | { 94 | IconTextColor.White => Color.White, 95 | IconTextColor.Black => Color.Black, 96 | IconTextColor.Yellow => Color.Yellow, 97 | IconTextColor.Gold => Color.DarkGoldenrod, 98 | IconTextColor.Red => Color.Red, 99 | _ => Color.Black, 100 | }; 101 | } 102 | -------------------------------------------------------------------------------- /GlucoseTray.Tests/DSL/Read/ReadDriver.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Enums; 2 | using GlucoseTray.Read.Dexcom; 3 | using GlucoseTray.Read.Nightscout; 4 | using NSubstitute; 5 | namespace GlucoseTray.Tests.DSL.Read; 6 | 7 | internal class ReadDriver 8 | { 9 | private readonly ReadProvider _provider = new(); 10 | private DexcomResult _dexcomResult = new(); 11 | private NightScoutResult _nightScoutResult = new(); 12 | private readonly AppSettings _settings = new() 13 | { 14 | MinutesUntilStale = 5, 15 | CriticalLowMgThreshold = 55, 16 | LowMgThreshold = 70, 17 | HighMgThreshold = 250, 18 | CriticalHighMgThreshold = 300, 19 | IsDarkMode = false, 20 | DataSource = GlucoseSource.Dexcom, 21 | DexcomServer = DexcomServer.DexcomShare1, 22 | DexcomUsername = "bob", 23 | DexcomPassword = "pass", 24 | ServerUnitType = GlucoseUnitType.Mg, 25 | }; 26 | 27 | public ReadDriver() => _provider.Options.CurrentValue.Returns(_settings); 28 | 29 | public ReadDriver GivenADexcomResult() 30 | { 31 | _settings.DataSource = GlucoseSource.Dexcom; 32 | _provider.Options.CurrentValue.Returns(_settings); 33 | _dexcomResult = new DexcomResult(); 34 | return this; 35 | } 36 | 37 | public ReadDriver GivenANightscoutResult() 38 | { 39 | _settings.DataSource = GlucoseSource.Nightscout; 40 | _provider.Options.CurrentValue.Returns(_settings); 41 | _nightScoutResult = new NightScoutResult(); 42 | return this; 43 | } 44 | 45 | public ReadDriver WithMgServerUnit() 46 | { 47 | _settings.ServerUnitType = GlucoseUnitType.Mg; 48 | _provider.Options.CurrentValue.Returns(_settings); 49 | return this; 50 | } 51 | 52 | public ReadDriver WithMmolServerUnit() 53 | { 54 | _settings.ServerUnitType = GlucoseUnitType.Mmol; 55 | _provider.Options.CurrentValue.Returns(_settings); 56 | return this; 57 | } 58 | 59 | public ReadDriver WithMgDisplay() 60 | { 61 | _settings.DisplayUnitType = GlucoseUnitType.Mg; 62 | _provider.Options.CurrentValue.Returns(_settings); 63 | return this; 64 | } 65 | 66 | public ReadDriver WithMmolDisplay() 67 | { 68 | _settings.DisplayUnitType = GlucoseUnitType.Mmol; 69 | _provider.Options.CurrentValue.Returns(_settings); 70 | return this; 71 | } 72 | 73 | public ReadDriver WithMgValue(int value) 74 | { 75 | _dexcomResult.GlucoseValue = value; 76 | _nightScoutResult.GlucoseValue = value; 77 | return this; 78 | } 79 | 80 | public ReadDriver WithMmolValue(float value) 81 | { 82 | _dexcomResult.GlucoseValue = value; 83 | _nightScoutResult.GlucoseValue = value; 84 | return this; 85 | } 86 | 87 | public ReadDriver WithMgServerUnitType() 88 | { 89 | _settings.ServerUnitType = GlucoseUnitType.Mg; 90 | _provider.Options.CurrentValue.Returns(_settings); 91 | return this; 92 | } 93 | 94 | public ReadDriver WithMmolServerUnitType() 95 | { 96 | _settings.ServerUnitType = GlucoseUnitType.Mmol; 97 | _provider.Options.CurrentValue.Returns(_settings); 98 | return this; 99 | } 100 | 101 | public ReadDriver WithDarkMode() 102 | { 103 | _settings.IsDarkMode = true; 104 | _provider.Options.CurrentValue.Returns(_settings); 105 | return this; 106 | } 107 | 108 | public ReadDriver WithStaleData() 109 | { 110 | _settings.MinutesUntilStale = 15; 111 | _provider.Options.CurrentValue.Returns(_settings); 112 | _dexcomResult.UnixTicks = DateTime.UtcNow.AddMinutes(-30).Ticks.ToString(); 113 | _nightScoutResult.UnixTicks = DateTime.UtcNow.AddMinutes(-30).Ticks; 114 | return this; 115 | } 116 | 117 | public ReadDriver WithCriticalLowValue() 118 | { 119 | _dexcomResult.GlucoseValue = 50; 120 | _nightScoutResult.GlucoseValue = 50; 121 | return this; 122 | } 123 | 124 | public ReadDriver WithLowValue() 125 | { 126 | _dexcomResult.GlucoseValue = 65; 127 | _nightScoutResult.GlucoseValue = 65; 128 | return this; 129 | } 130 | 131 | public ReadDriver WithHighValue() 132 | { 133 | _dexcomResult.GlucoseValue = 260; 134 | _nightScoutResult.GlucoseValue = 260; 135 | return this; 136 | } 137 | 138 | public ReadDriver WithCriticalHighValue() 139 | { 140 | _dexcomResult.GlucoseValue = 300; 141 | _nightScoutResult.GlucoseValue = 300; 142 | return this; 143 | } 144 | 145 | public ReadBehaviorDriver When => new(_provider, _dexcomResult, _nightScoutResult); 146 | } 147 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | #*.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb 341 | /GlucoseTray.Tests/UnitTest1.cs 342 | /Dexcom.Fetch/nuget (1).exe 343 | -------------------------------------------------------------------------------- /GlucoseTray.Tests/DisplayTests.cs: -------------------------------------------------------------------------------- 1 | using GlucoseTray.Display; 2 | using GlucoseTray.Enums; 3 | using GlucoseTray.Tests.DSL.Display; 4 | 5 | namespace GlucoseTray.Tests; 6 | 7 | public class DisplayTests 8 | { 9 | [Test] 10 | public void ShouldMapMgToDisplay() 11 | { 12 | var driver = new DisplayDriver(); 13 | driver.GivenAGlucoseReading() 14 | .WithMgValue(100) 15 | .When.RefreshingIcon() 16 | .Then.ShouldBeRefreshedWithValue("100"); 17 | } 18 | 19 | [Test] 20 | public void ShouldMapMmolToDisplay() 21 | { 22 | var driver = new DisplayDriver(); 23 | driver.GivenAGlucoseReading() 24 | .WithMmolDisplay() 25 | .WithMmolValue(5.5f) 26 | .When.RefreshingIcon() 27 | .Then.ShouldBeRefreshedWithValue("5'5"); 28 | } 29 | 30 | [Test] 31 | public void ShouldShowWhiteTextForStandardMmolReadingInDarkMode() 32 | { 33 | var driver = new DisplayDriver(); 34 | driver.GivenAGlucoseReading() 35 | .WithMmolDisplay() 36 | .WithMmolValue(5.5f) 37 | .WithDarkMode() 38 | .When.RefreshingIcon() 39 | .Then.ShouldBeRefreshedWithTextColor(IconTextColor.White); 40 | } 41 | 42 | [Test] 43 | public void ShouldShowWhiteTextForStandardMgReadingInDarkMode() 44 | { 45 | var driver = new DisplayDriver(); 46 | driver.GivenAGlucoseReading() 47 | .WithMgValue(100) 48 | .WithDarkMode() 49 | .When.RefreshingIcon() 50 | .Then.ShouldBeRefreshedWithTextColor(IconTextColor.White); 51 | } 52 | 53 | [Test] 54 | public void ShouldRecognizeWhenDataIsStale() 55 | { 56 | var driver = new DisplayDriver(); 57 | driver.GivenAGlucoseReading() 58 | .WithMgValue(100) 59 | .WithStaleData() 60 | .When.RefreshingIcon() 61 | .Then.ShouldBeMarkedStale(); 62 | } 63 | 64 | [Test] 65 | public void ShouldShowGoldTextForMgReadingsBelowLow() 66 | { 67 | var driver = new DisplayDriver(); 68 | driver.GivenAGlucoseReading() 69 | .WithLowValue() 70 | .When.RefreshingIcon() 71 | .Then.ShouldBeRefreshedWithTextColor(IconTextColor.Gold); 72 | } 73 | 74 | [Test] 75 | public void ShouldShowGoldTextForMmolReadingsBelowLow() 76 | { 77 | var driver = new DisplayDriver(); 78 | driver.GivenAGlucoseReading() 79 | .WithMmolDisplay() 80 | .WithLowValue() 81 | .When.RefreshingIcon() 82 | .Then.ShouldBeRefreshedWithTextColor(IconTextColor.Gold); 83 | } 84 | 85 | [Test] 86 | public void ShouldShowYellowTextForMgReadingsBelowLowInDarkMode() 87 | { 88 | var driver = new DisplayDriver(); 89 | driver.GivenAGlucoseReading() 90 | .WithLowValue() 91 | .WithDarkMode() 92 | .When.RefreshingIcon() 93 | .Then.ShouldBeRefreshedWithTextColor(IconTextColor.Yellow); 94 | } 95 | 96 | [Test] 97 | public void ShouldShowYellowTextForMmolReadingsBelowLowInDarkMode() 98 | { 99 | var driver = new DisplayDriver(); 100 | driver.GivenAGlucoseReading() 101 | .WithMmolDisplay() 102 | .WithLowValue() 103 | .WithDarkMode() 104 | .When.RefreshingIcon() 105 | .Then.ShouldBeRefreshedWithTextColor(IconTextColor.Yellow); 106 | } 107 | 108 | [Test] 109 | public void ShouldShowRedTextForMgReadingsBelowCriticalLow() 110 | { 111 | var driver = new DisplayDriver(); 112 | driver.GivenAGlucoseReading() 113 | .WithCriticalLowValue() 114 | .When.RefreshingIcon() 115 | .Then.ShouldBeRefreshedWithTextColor(IconTextColor.Red); 116 | } 117 | 118 | [Test] 119 | public void ShouldShowRedTextForMmolReadingsBelowCriticalLow() 120 | { 121 | var driver = new DisplayDriver(); 122 | driver.GivenAGlucoseReading() 123 | .WithMmolDisplay() 124 | .WithCriticalLowValue() 125 | .When.RefreshingIcon() 126 | .Then.ShouldBeRefreshedWithTextColor(IconTextColor.Red); 127 | } 128 | 129 | [Test] 130 | public void ShouldShowRedTextForMgReadingsAboveCriticalHigh() 131 | { 132 | var driver = new DisplayDriver(); 133 | driver.GivenAGlucoseReading() 134 | .WithCriticalHighValue() 135 | .When.RefreshingIcon() 136 | .Then.ShouldBeRefreshedWithTextColor(IconTextColor.Red); 137 | } 138 | 139 | [Test] 140 | public void ShouldShowRedTextForMmolReadingsAboveCriticalHigh() 141 | { 142 | var driver = new DisplayDriver(); 143 | driver.GivenAGlucoseReading() 144 | .WithMmolDisplay() 145 | .WithCriticalHighValue() 146 | .When.RefreshingIcon() 147 | .Then.ShouldBeRefreshedWithTextColor(IconTextColor.Red); 148 | } 149 | 150 | [Test] 151 | public void ShouldShowGoldTextForMgReadingsAboveHigh() 152 | { 153 | var driver = new DisplayDriver(); 154 | driver.GivenAGlucoseReading() 155 | .WithHighValue() 156 | .When.RefreshingIcon() 157 | .Then.ShouldBeRefreshedWithTextColor(IconTextColor.Gold); 158 | } 159 | 160 | [Test] 161 | public void ShouldShowGoldTextForMmolReadingsAboveHigh() 162 | { 163 | var driver = new DisplayDriver(); 164 | driver.GivenAGlucoseReading() 165 | .WithMmolDisplay() 166 | .WithHighValue() 167 | .When.RefreshingIcon() 168 | .Then.ShouldBeRefreshedWithTextColor(IconTextColor.Gold); 169 | } 170 | 171 | [Test] 172 | public void ShouldShowYellowTextForMgReadingsAboveHighInDarkMode() 173 | { 174 | var driver = new DisplayDriver(); 175 | driver.GivenAGlucoseReading() 176 | .WithHighValue() 177 | .WithDarkMode() 178 | .When.RefreshingIcon() 179 | .Then.ShouldBeRefreshedWithTextColor(IconTextColor.Yellow); 180 | } 181 | 182 | [Test] 183 | public void ShouldShowYellowTextForMmolReadingsAboveHighInDarkMode() 184 | { 185 | var driver = new DisplayDriver(); 186 | driver.GivenAGlucoseReading() 187 | .WithMmolDisplay() 188 | .WithHighValue() 189 | .WithDarkMode() 190 | .When.RefreshingIcon() 191 | .Then.ShouldBeRefreshedWithTextColor(IconTextColor.Yellow); 192 | } 193 | 194 | [Test] 195 | public void ShouldUseDefaultFontSizeForAllMgReadings() 196 | { 197 | var driver = new DisplayDriver(); 198 | driver.GivenAGlucoseReading() 199 | .WithMgValue(100) 200 | .When.RefreshingIcon() 201 | .Then.ShouldBeRefreshedWithFontSize(40); 202 | } 203 | 204 | [Test] 205 | public void ShouldUseDefaultFontSizeForMmolReadingsBelow10() 206 | { 207 | var driver = new DisplayDriver(); 208 | driver.GivenAGlucoseReading() 209 | .WithMmolDisplay() 210 | .WithMmolValue(5.5f) 211 | .When.RefreshingIcon() 212 | .Then.ShouldBeRefreshedWithFontSize(40); 213 | } 214 | 215 | [Test] 216 | public void ShouldUseSmallerFontSizeForMmolReadings10AndAbove() 217 | { 218 | var driver = new DisplayDriver(); 219 | driver.GivenAGlucoseReading() 220 | .WithMmolDisplay() 221 | .WithMmolValue(15.5f) 222 | .When.RefreshingIcon() 223 | .Then.ShouldBeRefreshedWithFontSize(38); 224 | } 225 | 226 | [Test] 227 | public void ShouldHaveTheCorrectDisplayMessage() 228 | { 229 | var display = new GlucoseDisplay 230 | { 231 | TimestampUtc = new DateTime(2000, 5, 5, 11, 0, 0, DateTimeKind.Utc), 232 | DisplayValue = "100", 233 | IsStale = true, 234 | Trend = Trend.Flat, 235 | }; 236 | 237 | var result = display.GetDisplayMessage(new DateTime(2000, 5, 5, 10, 0, 0, DateTimeKind.Utc)); 238 | 239 | Assert.That(result, Does.Contain("100 ")); 240 | Assert.That(result, Does.Contain(":00:00 ")); 241 | Assert.That(result, Does.Contain(" → \r\n60 minutes ago")); 242 | } 243 | 244 | [Test] 245 | public void ShouldNotShowNotificationWhenStale() 246 | { 247 | var driver = new DisplayDriver(); 248 | driver.GivenAGlucoseReading() 249 | .WithMgValue(100) 250 | .WithStaleData() 251 | .When.RefreshingIcon() 252 | .Then.ShouldNotShowNotification(); 253 | } 254 | 255 | [Test] 256 | public void ShouldNotShowNotificationIfReadingIs0() 257 | { 258 | var driver = new DisplayDriver(); 259 | driver.GivenAGlucoseReading() 260 | .WithMgValue(0) 261 | .When.RefreshingIcon() 262 | .Then.ShouldNotShowNotification(); 263 | } 264 | 265 | [Test] 266 | public void ShouldShowNotificationIfReadingIsAboveCriticalHighThreshold() 267 | { 268 | var driver = new DisplayDriver(); 269 | driver.GivenAGlucoseReading() 270 | .WithCriticalHighValue() 271 | .When.RefreshingIcon() 272 | .Then.ShouldShowNotification("Critical High Glucose Alert"); 273 | } 274 | 275 | [Test] 276 | public void ShouldShowNotificationIfReadingIsBelowCriticalLowThreshold() 277 | { 278 | var driver = new DisplayDriver(); 279 | driver.GivenAGlucoseReading() 280 | .WithCriticalLowValue() 281 | .When.RefreshingIcon() 282 | .Then.ShouldShowNotification("Critical Low Glucose Alert"); 283 | } 284 | 285 | [Test] 286 | public void ShouldShowNotificationIfReadingIsAboveHighThreshold() 287 | { 288 | var driver = new DisplayDriver(); 289 | driver.GivenAGlucoseReading() 290 | .WithHighValue() 291 | .When.RefreshingIcon() 292 | .Then.ShouldShowNotification("High Glucose Alert"); 293 | } 294 | 295 | [Test] 296 | public void ShouldShowNotificationIfReadingIsBelowLowThreshold() 297 | { 298 | var driver = new DisplayDriver(); 299 | driver.GivenAGlucoseReading() 300 | .WithLowValue() 301 | .When.RefreshingIcon() 302 | .Then.ShouldShowNotification("Low Glucose Alert"); 303 | } 304 | 305 | [Test] 306 | public void ShouldNotShowNotificationIfReadingIsWithinNormalRange() 307 | { 308 | var driver = new DisplayDriver(); 309 | driver.GivenAGlucoseReading() 310 | .WithMgValue(100) 311 | .When.RefreshingIcon() 312 | .Then.ShouldNotShowNotification(); 313 | } 314 | 315 | [Test] 316 | public void ShouldNotShowNotificationIfReadingIsWithinNormalRangeInMmol() 317 | { 318 | var driver = new DisplayDriver(); 319 | driver.GivenAGlucoseReading() 320 | .WithMmolDisplay() 321 | .WithMmolValue(5.5f) 322 | .When.RefreshingIcon() 323 | .Then.ShouldNotShowNotification(); 324 | } 325 | 326 | [Test] 327 | public void ShouldNotShowRepeatNotificationsForCriticalHigh() 328 | { 329 | var driver = new DisplayDriver(); 330 | driver.GivenAGlucoseReading() 331 | .WithCriticalHighValue() 332 | .When.RefreshingIcon() 333 | .Then.ShouldShowNotification("Critical High Glucose Alert") 334 | .When.RefreshingIcon() 335 | .Then.ShouldNotShowNotification(); 336 | } 337 | 338 | [Test] 339 | public void ShouldNotShowRepeatNotificationsForCriticalLow() 340 | { 341 | var driver = new DisplayDriver(); 342 | driver.GivenAGlucoseReading() 343 | .WithCriticalLowValue() 344 | .When.RefreshingIcon() 345 | .Then.ShouldShowNotification("Critical Low Glucose Alert") 346 | .When.RefreshingIcon() 347 | .Then.ShouldNotShowNotification(); 348 | } 349 | 350 | [Test] 351 | public void ShouldNotShowRepeatNotificationsForHigh() 352 | { 353 | var driver = new DisplayDriver(); 354 | driver.GivenAGlucoseReading() 355 | .WithHighValue() 356 | .When.RefreshingIcon() 357 | .Then.ShouldShowNotification("High Glucose Alert") 358 | .When.RefreshingIcon() 359 | .Then.ShouldNotShowNotification(); 360 | } 361 | 362 | [Test] 363 | public void ShouldNotShowRepeatNotificationsForLow() 364 | { 365 | var driver = new DisplayDriver(); 366 | driver.GivenAGlucoseReading() 367 | .WithLowValue() 368 | .When.RefreshingIcon() 369 | .Then.ShouldShowNotification("Low Glucose Alert") 370 | .When.RefreshingIcon() 371 | .Then.ShouldNotShowNotification(); 372 | } 373 | } 374 | --------------------------------------------------------------------------------