Understanding the TimeState Enum in ClassIsland: How It Tracks Current Class State
The TimeState enum in ClassIsland defines five distinct phases of the school day—None, OnClass, PrepareOnClass, Breaking, and AfterSchool—and is tracked in real-time by LessonsService to drive automation rules and UI updates.
The TimeState enum is the backbone of schedule-aware functionality in the classisland/classisland repository. This enumeration allows the application to understand whether students are currently in class, on a break, or after school, enabling automated actions like displaying reminders or triggering alerts. By mapping timetable entries to these semantic states, ClassIsland creates a responsive environment that adapts to the daily academic rhythm.
What Is the TimeState Enum?
The TimeState enum is defined in ClassIsland.Shared/Enums/TimeState.cs as a public enumeration that categorizes the temporal context of the school schedule. It provides a type-safe way to represent the current operational phase, distinguishing between instructional time, transitions, and non-instructional periods.
The enum comprises five distinct values:
| Value | Description |
|---|---|
None |
Indicates no active schedule period, typically used when the application initializes or when the day is treated as finished. |
OnClass |
Represents an active instructional period when a regular class is in session. |
PrepareOnClass |
Reserved for pre-class preparation phases (currently unused in the codebase but defined for future extensibility). |
Breaking |
Indicates a break or interval between consecutive classes. |
AfterSchool |
Signifies that the school day has concluded and all scheduled periods have ended. |
// ClassIsland.Shared/Enums/TimeState.cs
public enum TimeState
{
None,
OnClass,
PrepareOnClass,
Breaking,
AfterSchool,
}
How TimeState Tracks the Current Class State
Tracking the current class state involves continuous evaluation of the timetable and mapping time-layout items to the appropriate TimeState value. The LessonsService class orchestrates this process, maintaining the state machine and broadcasting changes to subscribers throughout the application.
The LessonsService Orchestrator
The core state management resides in ClassIsland/Services/LessonsService.cs. This service maintains two private fields to track state transitions:
_currentStatus(line 28): Stores the authoritative current state, exposed publicly via theCurrentStateproperty._currentOverlayEventStatus(line 33): Tracks the previously processed state to detect transitions and prevent duplicate event firings.
// ClassIsland/Services/LessonsService.cs
private TimeState _currentStatus = TimeState.None; // line 28
private TimeState _currentOverlayEventStatus = TimeState.None; // line 33
public TimeState CurrentState
{
get => _currentStatus;
set => SetProperty(ref _currentStatus, value);
}
State Determination Logic in ProcessLessons()
The ProcessLessons() method executes on a 50-millisecond timer tick, continuously evaluating the active timetable. The logic follows a deterministic mapping based on the TimeType property of the current time-layout item:
- Type 0 (
TimeType == 0): Maps toTimeState.OnClass(lines 44-45). - Type 1 (
TimeType == 1): Maps toTimeState.Breaking(lines 57-58). - Null checks: When no current item exists but the day has future items, the state remains
Noneor transitions based on context. - End-of-day detection: When both
nextClassTimeLayoutItemandnextBreakingTimeLayoutItemare null, the state transitions toTimeState.AfterSchool(lines 85-86).
The final assignment updates the public property (line 91):
// ClassIsland/Services/LessonsService.cs
if (currentTimeLayoutItem != null)
{
if (currentTimeLayoutItem.TimeType == 0)
currentState = TimeState.OnClass; // line 44-45
else if (currentTimeLayoutItem.TimeType == 1)
currentState = TimeState.Breaking; // line 57-58
}
// End of school day detection
if (nextClassTimeLayoutItem == null && nextBreakingTimeLayoutItem == null)
currentState = TimeState.AfterSchool; // line 85-86
CurrentState = currentState ?? TimeState.None; // line 91
Event Notification System
When CurrentState differs from _currentOverlayEventStatus, the service broadcasts state changes through several events:
CurrentTimeStateChanged: Fires for any state transition.OnClass: Fires specifically when enteringTimeState.OnClass.OnBreakingTime: Fires specifically when enteringTimeState.Breaking.OnAfterSchool: Fires specifically when enteringTimeState.AfterSchool.
// ClassIsland/Services/LessonsService.cs
if (CurrentState != CurrentOverlayEventStatus)
{
CurrentTimeStateChanged?.Invoke(this, EventArgs.Empty);
switch (CurrentState)
{
case TimeState.OnClass:
OnClass?.Invoke(this, EventArgs.Empty);
break;
case TimeState.Breaking:
OnBreakingTime?.Invoke(this, EventArgs.Empty);
break;
case TimeState.AfterSchool:
OnAfterSchool?.Invoke(this, EventArgs.Empty);
break;
}
CurrentOverlayEventStatus = CurrentState;
}
Subscribers can react to these events to update UI components, trigger notifications, or execute automation rules.
Practical Applications of TimeState
The TimeState enum serves as the foundation for automation and visualization features throughout ClassIsland.
Creating Automation Rules
The TimeStateRuleSettings class in ClassIsland/Models/Rules/TimeStateRuleSettings.cs allows users to define automation rules that trigger when the schedule enters a specific state. The rule stores a target TimeState value and compares it against the service's CurrentState.
// ClassIsland/Models/Rules/TimeStateRuleSettings.cs
public class TimeStateRuleSettings : ObservableRecipient
{
private TimeState _state = TimeState.OnClass;
public TimeState State
{
get => _state;
set { if (value != _state) { _state = value; OnPropertyChanged(); } }
}
}
The TimeStateHandler method in LessonsService evaluates these rules by comparing the configured state against the current state, with special handling for the AfterSchool/None equivalence:
// ClassIsland/Services/LessonsService.cs
private bool TimeStateHandler(object? settings)
{
if (settings is not TimeStateRuleSettings s) return false;
return CurrentState == s.State ||
(CurrentState == TimeState.AfterSchool && s.State == TimeState.None);
}
UI Components and State Visualization
Visual components like ScheduleComponent in ClassIsland/Controls/Components/ScheduleComponent.axaml.cs subscribe to CurrentTimeStateChanged to update their appearance dynamically. When the state transitions from OnClass to Breaking, the component can adjust colors, display countdown timers, or show notification overlays.
Summary
- The
TimeStateenum inClassIsland.Shared/Enums/TimeState.csdefines five distinct phases:None,OnClass,PrepareOnClass,Breaking, andAfterSchool. LessonsServiceinClassIsland/Services/LessonsService.cstracks the current state through theCurrentStateproperty, updating it every 50 milliseconds viaProcessLessons().- State determination maps
TimeTypevalues (0 for class, 1 for break) toTimeStatevalues, with fallbacks for end-of-day detection. - The service broadcasts state changes through
CurrentTimeStateChanged,OnClass,OnBreakingTime, andOnAfterSchoolevents. - Automation rules use
TimeStateRuleSettingsto trigger actions when specific states occur, evaluated by theTimeStateHandlermethod.
Frequently Asked Questions
What are the possible values of the TimeState enum?
The TimeState enum defines five values defined in ClassIsland.Shared/Enums/TimeState.cs: None (no active period), OnClass (active instruction), PrepareOnClass (reserved for pre-class preparation, currently unused), Breaking (interval between classes), and AfterSchool (day concluded). These values cover the complete lifecycle of a school day schedule.
How often does ClassIsland check for state changes?
The LessonsService evaluates the current schedule and updates the TimeState every 50 milliseconds through the ProcessLessons() method. This high-frequency polling ensures the UI and automation rules react immediately when a class ends or a break begins, providing real-time accuracy for time-sensitive school notifications.
Can I create custom rules based on TimeState?
Yes, ClassIsland provides the TimeStateRuleSettings class in ClassIsland/Models/Rules/TimeStateRuleSettings.cs specifically for creating automation rules triggered by schedule states. You can configure rules to execute specific actions when the system enters OnClass, Breaking, or AfterSchool states. The LessonsService.TimeStateHandler method evaluates these rules by comparing the configured target state against the current TimeState.
What is the difference between CurrentState and CurrentOverlayEventStatus?
CurrentState is the public property that exposes the active TimeState to the rest of the application, while _currentOverlayEventStatus (exposed as CurrentOverlayEventStatus) is a private tracking field used internally by LessonsService. The service compares these two values to detect state transitions; when they differ, it fires the CurrentTimeStateChanged event and updates CurrentOverlayEventStatus to match, preventing duplicate notifications for the same state.
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:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →