Quiet Hours Scheduling
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Quiet Hours Scheduling is a power-user feature in Messenger Unleashed designed to automate the application's "Do Not Disturb" (DND) state. It allows users to define a specific time range during which notifications are suppressed, ensuring a distraction-free environment without requiring manual toggling of status settings.
The system operates by monitoring the local system time and comparing it against user-defined start and end boundaries. When the current time falls within the "Quiet Hours" window, the application automatically sets the doNotDisturb state to true, effectively muting incoming notification alerts. This feature is integrated directly into the Electron main process for persistence and background monitoring.
Sources: src/main/index.ts:544-555, landing-page/src/app/HomeClient.tsx:436-440
Architecture and Logic
The Quiet Hours system is composed of several functional layers: time parsing, state monitoring, and UI management. The logic is primarily housed in the main process to ensure the timer persists regardless of which windows are open.
Time Parsing and Validation
The system uses a flexible parsing logic to convert user-entered strings (e.g., "10:00 PM" or "22:00") into a numerical "minutes-from-midnight" format for comparison. This allows for easy evaluation of whether the current time sits within the scheduled window.
The logic also handles "overnight" ranges, such as 10:00 PM to 7:00 AM, by checking if the start time is greater than the end time and adjusting the boolean logic accordingly.
Sources: src/main/index.ts:511-542, src/main/utils.ts:88-106
Monitoring Loop
The main process initiates a monitoring interval that checks the status every 60 seconds. This monitor evaluates the current time against the stored preferences and updates the application state if a transition is required.
| Function | Purpose | File Reference |
|---|---|---|
isWithinQuietHours | Core logic to determine if current time is inside the range, including overnight support. | src/main/utils.ts:88-106 |
applyQuietHours | High-level coordinator that reads store values and updates DND state. | src/main/index.ts:557-584 |
startQuietHoursMonitor | Initializes the setInterval (60,000ms) to run applyQuietHours. | src/main/index.ts:586-592 |
State Transitions
The application tracks whether a DND state was applied specifically by Quiet Hours using the quietHoursApplied flag. This prevents the system from accidentally disabling a DND state that a user might have enabled manually.
Configuration and Persistence
Quiet Hours settings are persisted using electron-store. Users can configure these settings through the native application menu or the specialized settings modal.
Data Model
The following fields in the store govern the behavior of Quiet Hours:
| Key | Type | Default/Format | Description |
|---|---|---|---|
quietHoursEnabled | boolean | true/false | Master toggle for the scheduling system. |
quietHoursStart | string | "HH:mm" | The beginning of the quiet window. |
quietHoursEnd | string | "HH:mm" | The end of the quiet window. |
quietHoursApplied | boolean | true/false | Tracking flag to indicate if DND was set by the schedule. |
Sources: src/main/index.ts:544-555, src/preload/settings-modal.ts:566-577
User Interface Integration
The settings are exposed in two primary locations:
- Application Menu: Users can toggle the feature, view the current range label, and trigger the setup dialog directly from the "Unleashed" -> "Power Tools" menu.
- Settings Modal: The "Power Tools" tab in the CSS-injected settings modal provides a toggle and a "Set Hours" action button.
Sources: src/main/index.ts:1149-1172, src/preload/settings-modal.ts:566-577
Implementation Details
The implementation utilizes Electron's ipcMain and dialog modules to capture user input. When setting hours, the app opens a sequence of input dialogs to collect start and end times.
// Example of the normalization and persistence logic
const normalizeTime = (minutes) => {
const hours = Math.floor(minutes / 60);
const mins = minutes % 60;
return `${String(hours).padStart(2, "0")}:${String(mins).padStart(2, "0")}`;
};
store.set("quietHoursStart", normalizeTime(parsedStart));
store.set("quietHoursEnd", normalizeTime(parsedEnd));
Sources: src/main/index.ts:631-638
Summary
Quiet Hours Scheduling provides an automated bridge between the system clock and the application's notification engine. By leveraging a persistent background monitor in the main process and a robust parsing utility that handles edge cases like overnight ranges, the system ensures that user notification preferences are respected without manual intervention. This feature is tightly integrated with the doNotDisturb state, using specific metadata flags to distinguish between manual user overrides and scheduled automation.
Sources: src/main/index.ts:557-592, src/main/utils.ts:88-106