Code Walkthrough

How Alerts Works

This section describes how alerts work in VaahShare, including the methods used to display alerts, handle user interactions, and manage alert states.

Alert Handling in VaahShare

This documentation explains how the application detects user idle time and handles it by showing a dialog and saving alerts. The flow involves the main process, renderer process, and inter-process communication (IPC) using Electron.

Components

  1. Main Process (main.ts)
  • Listens for the did-finish-load event to start the idle timer.
  • Manages the idle timer and handles IPC events to toggle the idle time dialog and save alerts.
  1. Renderer Process
  • Handles showing and hiding the idle time dialog.
  • Communicates with the main process via IPC to toggle the dialog and save alerts.

Flow :

  1. Start Idle Timer :
  • When the window finishes loading, the startIdleTimer function is called to begin monitoring idle time.
  1. Idle Timer Function (startIdleTimer) :
  • Sets an interval to check system idle time using powerMonitor.
  • If the idle time exceeds a threshold, the interval is cleared, and the renderer process is notified to show the idle time dialog.
  1. Renderer Process Idle Time Handling (handleIdleTime) (root.js) :
  • Listens for the toggle-idle-time-dialog event to show or hide the idle time dialog.
  • If the user is idle, the dialog is shown, and an alert is saved via IPC
  1. Idle Time Dialog Close Handler (onIdleTimeDialogClose) :
  • Hides the idle time dialog and notifies the main process to resume the idle timer.
  1. Main Process IPC Handlers (main.js) :
  • Listens for the toggle-idle-time-dialog event to start or stop the idle timer based on the dialog visibility.
  • Listens for the save-alert-user-idle event to save an alert indicating the user is idle

Copyright © 2024