How to Implement Weather Notification Settings Using IWeatherNotificationSettingsBase in ClassIsland

IWeatherNotificationSettingsBase is the core interface in ClassIsland that defines how weather-related notifications (alerts and forecasts) are configured, allowing developers to implement custom settings for controlling when and how weather notifications appear.

The ClassIsland open-source project provides a flexible notification system where weather alerts and forecasts can be customized at both global and per-lesson levels. By implementing IWeatherNotificationSettingsBase, developers can create custom configuration models that integrate seamlessly with the existing WeatherNotificationProvider without modifying the core notification logic.

Understanding IWeatherNotificationSettingsBase

The IWeatherNotificationSettingsBase interface resides in ClassIsland.Shared/Abstraction/Models/IWeatherNotificationSettingsBase.cs and establishes the contract for all weather notification configurations. It declares two essential properties that control display behavior:

public interface IWeatherNotificationSettingsBase
{
    NotificationModes AlertShowMode { get; set; }
    NotificationModes ForecastShowMode { get; set; }
}

AlertShowMode determines how severe weather alerts (such as storms or extreme temperatures) are presented to users, while ForecastShowMode controls the display of regular weather forecasts. Both properties use the NotificationModes enumeration, which typically includes values like Default, Disabled, Toast, or Overlay.

Architecture Overview

The weather notification system in ClassIsland follows a layered architecture where IWeatherNotificationSettingsBase serves as the abstraction that decouples configuration from execution:

When the provider fires (ShowAlertsNotification or ShowForecastNotification), it first checks WeatherService.IsWeatherRefreshed, then calls IAttachedSettingsHostService.GetAttachedSettingsByPriority<WeatherNotificationAttachedSettings> to fetch the most specific settings available. If the retrieved AlertShowMode or ForecastShowMode equals Disabled, the provider aborts; otherwise, it builds a NotificationRequest and forwards it to INotificationHostService.

Implementing Custom Weather Notification Settings

Developers can extend the weather notification system by creating custom implementations of IWeatherNotificationSettingsBase. This approach allows plugins or extensions to introduce specialized weather notification behaviors without modifying the core WeatherNotificationProvider.

Creating the Settings Class

Implement the interface and inherit from ObservableRecipient to ensure property changes propagate to the UI and notification services:

using ClassIsland.Shared.Abstraction.Models;
using ClassIsland.Shared.Enums;
using CommunityToolkit.Mvvm.ComponentModel;

namespace MyPlugin.Models;

/// <summary>
/// Custom weather-notification configuration for a specific lesson.
/// </summary>
public class MyWeatherSettings : ObservableRecipient, IWeatherNotificationSettingsBase
{
    private NotificationModes _alertShowMode = NotificationModes.Default;
    private NotificationModes _forecastShowMode = NotificationModes.Default;
    private bool _isEnabled = true;   // extra flag not defined by the interface

    public NotificationModes AlertShowMode
    {
        get => _alertShowMode;
        set => SetProperty(ref _alertShowMode, value);
    }

    public NotificationModes ForecastShowMode
    {
        get => _forecastShowMode;
        set => SetProperty(ref _forecastShowMode, value);
    }

    public bool IsEnabled
    {
        get => _isEnabled;
        set => SetProperty(ref _isEnabled, value);
    }
}

This implementation adds an IsEnabled property for additional granularity while satisfying the interface contract required by WeatherNotificationProvider.

Registering with the Host

Register your custom settings class with the dependency injection container and the attached settings host to make it discoverable:

// In App.Services.xaml.cs (or wherever services are configured)
services.AddSingleton<IAttachedSettingsHostService, AttachedSettingsHostService>();
services.AddTransient<MyWeatherSettings>(); // DI registration

// Tell the host that this type can be attached to the Weather provider
services.Configure<AttachedSettingsRegistration>(opt =>
{
    opt.Add(typeof(MyWeatherSettings), providerGuid: WeatherNotificationProvider.ProviderGuid);
});

The AttachedSettingsRegistration configuration links your custom type to the specific provider GUID, ensuring the host service retrieves your settings when the weather provider queries for attached configurations.

Accessing Settings in Providers

If implementing a custom notification provider that needs to respect weather notification settings, use the same pattern as the built-in provider:

var attached = attachedSettingsHost
    .GetAttachedSettingsByPriority<MyWeatherSettings>(ProviderGuid, currentTimeLayoutItem)
    ?? defaultSettings; // fallback to global defaults

if (!attached.IsEnabled || attached.AlertShowMode == NotificationModes.Disabled)
    return; // skip showing alert

This code retrieves the most specific settings available using priority-based resolution, then evaluates whether to proceed with notification display based on the configured modes.

Building the UI

Create an Avalonia user control to allow users to configure your custom settings:

<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:vm="clr-namespace:MyPlugin.ViewModels">
    <UserControl.DataContext>
        <vm:MyWeatherSettingsViewModel />
    </UserControl.DataContext>

    <StackPanel Margin="10">
        <CheckBox IsChecked="{Binding IsEnabled}" Content="Enable Weather Alerts" />
        <ComboBox SelectedItem="{Binding AlertShowMode}"
                  Items="{Binding AlertModes}" Header="Alert Display Mode"/>
        <ComboBox SelectedItem="{Binding ForecastShowMode}"
                  Items="{Binding ForecastModes}" Header="Forecast Display Mode"/>
    </StackPanel>
</UserControl>

The view model receives the attached settings instance via dependency injection and exposes the properties for data binding, allowing seamless integration with ClassIsland's settings framework.

Key Source Files

File Purpose
ClassIsland.Shared/Abstraction/Models/IWeatherNotificationSettingsBase.cs Core interface defining AlertShowMode and ForecastShowMode properties.
ClassIsland/Models/NotificationProviderSettings/WeatherNotificationProviderSettings.cs Global default implementation used when no attached settings exist.
ClassIsland/Models/AttachedSettings/WeatherNotificationAttachedSettings.cs Per-lesson override implementation for time-layout-specific configurations.
ClassIsland/Services/NotificationProviders/WeatherNotificationProvider.cs Runtime provider that consumes IWeatherNotificationSettingsBase to determine notification display.
ClassIsland/Views/SettingPages/WeatherSettingsPage.axaml.cs UI page for configuring global weather notification options.

Summary

  • IWeatherNotificationSettingsBase is the central contract in ClassIsland for configuring weather alert and forecast display modes through the AlertShowMode and ForecastShowMode properties.
  • The interface is implemented by both global settings (WeatherNotificationProviderSettings) and per-lesson attached settings (WeatherNotificationAttachedSettings), enabling flexible configuration at different scopes.
  • The WeatherNotificationProvider automatically respects any implementation of IWeatherNotificationSettingsBase retrieved via IAttachedSettingsHostService.GetAttachedSettingsByPriority, requiring no code changes when new settings types are introduced.
  • Developers can extend the system by creating custom classes that implement IWeatherNotificationSettingsBase, register them with the attached settings host, and bind them to Avalonia UI controls for user configuration.

Frequently Asked Questions

What is the purpose of IWeatherNotificationSettingsBase in ClassIsland?

IWeatherNotificationSettingsBase defines the contract for configuring how weather notifications appear in the ClassIsland application. It specifies two properties—AlertShowMode and ForecastShowMode—that control whether severe weather alerts and daily forecasts are displayed, and in what format (such as toast notifications or overlay panels). This interface allows the WeatherNotificationProvider to remain decoupled from specific configuration implementations.

How does WeatherNotificationProvider use IWeatherNotificationSettingsBase?

The WeatherNotificationProvider retrieves settings by calling IAttachedSettingsHostService.GetAttachedSettingsByPriority<WeatherNotificationAttachedSettings> to find the most specific configuration for the current time layout item. If no attached settings exist, it falls back to the global WeatherNotificationProviderSettings. Before displaying any notification, the provider checks the AlertShowMode or ForecastShowMode properties; if either is set to Disabled, the notification is suppressed.

Can I create custom weather notification settings for specific lessons?

Yes, you can create custom implementations of IWeatherNotificationSettingsBase for specific lessons or time layouts. Create a class that implements the interface and inherit from ObservableRecipient to support property change notifications. Register this class with the attached settings host using AttachedSettingsRegistration, specifying the WeatherNotificationProvider.ProviderGuid. The existing provider will automatically detect and use your custom settings according to the priority resolution rules.

What is the difference between WeatherNotificationProviderSettings and WeatherNotificationAttachedSettings?

WeatherNotificationProviderSettings serves as the global default implementation of IWeatherNotificationSettingsBase, storing system-wide preferences in the SettingsService. It applies when no lesson-specific overrides exist. WeatherNotificationAttachedSettings implements the same interface but functions as an attached setting that can be linked to specific time layout items or lessons, allowing different weather notification behaviors for different classes. The attached settings take precedence over global settings when retrieved via GetAttachedSettingsByPriority.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →