ravi7648/hrms-tracker

โ˜… 0Forks 0JavaScriptGitHub โ†—Compare

README

HRMS Attendance Tracker - Chrome Extension (Developer Guide)

A premium, customizable floating dashboard Chrome Extension to track biometric office hours, breaks, and exit time in real-time. Built with Manifest V3 and modular ES components.


๐Ÿ“Œ Prerequisites

  • Node.js: v18.0.0 or higher
  • NPM: v9.0.0 or higher
  • Google Chrome (or any Chromium-based browser like Edge, Brave, Vivaldi)

๐Ÿ“ Project Architecture

All source code is cleanly split into single-responsibility modules in src/. Built assets are output to dist/:

hrms-extension/
โ”œโ”€โ”€ manifest.json                  # Manifest V3 extension configuration
โ”œโ”€โ”€ package.json                   # NPM dependencies and development scripts
โ”œโ”€โ”€ build.js                       # Lightning-fast esbuild bundler script
โ”œโ”€โ”€ dist/                          # Compiled distribution folder (DO NOT EDIT DIRECTLY)
โ”‚   โ””โ”€โ”€ content-script.js          # Compiled bundle output injected into HRMS page
โ”œโ”€โ”€ assets/
โ”‚   โ””โ”€โ”€ icons/                     # Extension icons (16px, 48px, 128px)
โ””โ”€โ”€ src/
    โ”œโ”€โ”€ background/
    โ”‚   โ””โ”€โ”€ background.js          # MV3 Service Worker for background alarms & notifications
    โ”œโ”€โ”€ styles/
    โ”‚   โ””โ”€โ”€ widget.css             # Vanilla CSS stylesheet & design tokens
    โ”œโ”€โ”€ modules/
    โ”‚   โ”œโ”€โ”€ api.js                 # Backend HRMS API fetchers
    โ”‚   โ”œโ”€โ”€ storage.js             # Storage abstraction (localStorage & chrome.storage.local)
    โ”‚   โ”œโ”€โ”€ metrics.js             # Pure business calculations (work/break mins, target exit time)
    โ”‚   โ”œโ”€โ”€ notifier.js            # Desktop notification manager & throttler
    โ”‚   โ”œโ”€โ”€ icons.js               # Centralized SVG icon registry
    โ”‚   โ”œโ”€โ”€ state.js               # Central reactive state manager & subscriber
    โ”‚   โ”œโ”€โ”€ todo.js                # Core pure business logic & urgency calculations for tasks
    โ”‚   โ””โ”€โ”€ utils.js               # Time formatting & formula expression parser
    โ”œโ”€โ”€ controllers/
    โ”‚   โ””โ”€โ”€ WidgetController.js    # Main widget UI controller, polling timers & lifecycle
    โ”œโ”€โ”€ components/
    โ”‚   โ”œโ”€โ”€ Draggable.js           # Drag & Drop controller with bounds detection
    โ”‚   โ”œโ”€โ”€ BadgeView.js           # Collapsed floating badge UI
    โ”‚   โ”œโ”€โ”€ DashboardCard.js       # Main expanded dashboard card UI
    โ”‚   โ”œโ”€โ”€ TodoPanel.js           # Interactive TODO manager subpanel
    โ”‚   โ”œโ”€โ”€ ShortcutsPanel.js      # Quick bookmark links manager subpanel
    โ”‚   โ”œโ”€โ”€ SettingsPanel.js       # Settings modal (custom target hours, themes, notification toggles)
    โ”‚   โ””โ”€โ”€ SyncPanel.js           # Mobile PWA QR code sync modal
    โ””โ”€โ”€ content.js                 # Clean 15-line entry point bootstrapping WidgetController

๐Ÿš€ Quick Start & Development

1. Install Dependencies

Open your terminal in the project root directory:

npm install

(Note for Windows PowerShell users: If script execution is blocked, run cmd /c npm install)


2. Build Commands

Command Description
npm run build One-time production build. Bundles src/ into dist/content-script.js.
npm run watch Watch mode. Re-bundles automatically whenever you edit any file in src/.

3. Load & Test in Google Chrome

  1. Open Google Chrome and navigate to chrome://extensions/.
  2. Enable Developer mode using the toggle switch in the top-right corner.
  3. Click the "Load unpacked" button in the top-left menu.
  4. Select the hrms-extension project folder.
  5. Open or refresh https://apps.pal.tech/hrms/.
  6. The floating HRMS Attendance widget will appear in the bottom-right corner!

๐Ÿ”„ Development & Iteration Flow

When developing new features or tweaking styles:

  1. Start watch mode in your terminal:
    npm run watch
  2. Edit source code inside src/:
    • Styles -> src/styles/widget.css
    • UI views -> src/components/
    • Controller logic -> src/controllers/WidgetController.js
    • Data & calculation logic -> src/modules/
  3. The build script automatically updates dist/content-script.js.
  4. Refresh the https://apps.pal.tech/hrms/ webpage in Chrome to see your changes instantly!
  5. If you modify manifest.json or src/background/background.js, go to chrome://extensions/ and click the Reload ๐Ÿ”„ button on the extension card.

๐Ÿ› ๏ธ Debugging Tips

  • Content Script Console Logs: Open Chrome DevTools (F12 or Ctrl + Shift + I) on the HRMS webpage to view logs, network calls, and UI state.
  • Background Service Worker Logs: On chrome://extensions/, click "service worker" under the extension card to open DevTools for background.js.
  • Reset Storage State: To clear saved settings and drag position during testing, run this in the Chrome Console on the HRMS page:
    localStorage.clear();
    location.reload();

๐Ÿ’ก Code Organization Summary

  • src/content.js: Pure bootstrap (~15 lines). Initializes WidgetController.
  • src/controllers/WidgetController.js: Owns UI mounting, collapse state toggling, and 1-sec / 1-min timers.
  • src/modules/notifier.js: Owns desktop notification permission checks and 5-minute interval throttling.
  • src/modules/metrics.js: Pure functions for work/break math. Zero DOM dependencies.
  • docs/NOTIFICATION_GUIDE.md: Detailed architectural guide on how desktop notifications work.
  • dist/content-script.js: Generated bundle file output by esbuild. Never edit manually!

Contributors

ravishankarydv

Issues