Package Exports
- electron-os-integration-pro
- electron-os-integration-pro/src/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (electron-os-integration-pro) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Electron OS Integration Pro
electron-os-integration-pro
is a powerful Node.js module for Electron that extends the frameworkβs built-in OS APIs with advanced native integrations.
It provides a unified, high-level API for accessing system-level features like power management, audio, storage, displays, notifications, and hardware sensors β all with minimal boilerplate.
Developed and maintained by Fernando Martini.
π Why use Electron OS Integration Pro?
Building a native-like desktop experience in Electron often requires juggling platform-specific APIs (macOS, Windows, Linux).
This module removes that complexity by offering a cross-platform abstraction layer with advanced capabilities not directly exposed by Electron.
βοΈ Reduces boilerplate
βοΈ Simplifies native API learning curve
βοΈ Enables advanced, production-ready Electron apps
β¨ Features
- β‘ Power Management β Monitor detailed battery status & prevent sleep during critical tasks.
- βοΈ Storage & Cloud β Detect local sync folders for iCloud, OneDrive, Google Drive & watch directories natively.
- π System Audio β Get/set system volume, mute state & default output device.
- π₯οΈ Display Control β Control brightness, check HDR mode & display support.
- π Rich Notifications β Interactive notifications with buttons & input fields.
- π‘ Hardware Sensors β Access ambient light sensor (where supported).
π¦ Installation
npm install electron-os-integration-pro
β οΈ Note: This package uses native C++ addons. Youβll need a build environment:
- Node.js & npm
node-gyp
- Python (2.7 or >=3.6)
- C++ compiler (MSVC on Windows, GCC/Clang on Linux/macOS)
β‘ Quick Start
const { app } = require('electron');
const os = require('electron-os-integration-pro');
app.whenReady().then(async () => {
try {
const batteryState = await os.power.getBatteryState();
console.log(`Battery: ${batteryState.percentage}% (Charging: ${batteryState.isCharging})`);
} catch (err) {
console.error('Battery check failed:', err.message);
}
if (os.audio.isAudioSupported()) {
await os.audio.setSystemVolume(0.5);
console.log('System volume set to 50%.');
}
});
π API Reference
The API is organized into modules:
os.power
β Battery & sleep controlos.storage
β Cloud services & file watchingos.audio
β System volume & devicesos.display
β Brightness & HDRos.notifications
β Interactive native notificationsos.sensors
β Hardware sensors
os.power
getBatteryState(): Promise<object>
Returns the current battery status.
Returns: Promise<object>
percentage
:number
(0β100)isCharging
:boolean
error?
:string
(if no battery is found)
preventSystemSleep(reason: string): number | null
Prevents the system from entering idle sleep and returns a blocker ID.
reason
: Description shown in macOS Activity Monitor.
allowSystemSleep()
Releases the sleep blocker, allowing normal sleep.
os.storage
getCloudServices(): Promise<object[]>
Detects installed cloud storage providers.
Returns: Promise<object[]>
with:
name
:string
(e.g., "iCloud Drive", "OneDrive")path
:string
(absolute local sync folder)isAvailable
:boolean
watchDirectory(path: string, callback: (eventType, filePath) => void): { stop: () => void }
Watches a directory for changes.
path
: Absolute directory path.callback
: Called witheventType
('added'
,'removed'
,'modified'
, etc.) andfilePath
.
Returns: A watcher object withstop()
.
os.audio
isAudioSupported(): boolean
Whether the audio module is supported on the current platform.
getSystemVolume(): Promise<number>
Gets the master system volume.
Returns: Promise<number>
(0.0β1.0).
setSystemVolume(level: number): Promise<void>
Sets the master system volume.
level
:number
(0.0β1.0).
isSystemMuted(): Promise<boolean>
Whether the system audio is muted.
getDefaultOutputDevice(): Promise<string>
Gets the name of the default audio output device.
os.display
isDisplaySupported(): boolean
Whether the display module is supported on the current platform.
getBrightness(): Promise<number>
Gets the main display brightness.
Returns: Promise<number>
(0.0β1.0).
setBrightness(level: number): Promise<void>
Sets the main display brightness.
level
:number
(0.0β1.0).
isHDRActive(): Promise<boolean>
Checks if the main display is in HDR mode.
os.notifications
A singleton EventEmitter
instance for interactive notifications.
isSupported(): boolean
Whether rich notifications are supported.
initialize(appId?: string)
Initializes the notification system (call once).
appId
: Windows only β AppUserModelID (AUMID).
send(options: { id: string; title: string; body: string; })
Sends a notification.
Event: 'action'
β fired on user interaction.
Callback:
{
notificationId: string;
actionId: string; // e.g. 'reply'
responseText?: string // if input action
}
Example
os.notifications.initialize('Your.App.ID');
os.notifications.on('action', (data) => {
console.log(`User clicked '${data.actionId}' on '${data.notificationId}'`);
if (data.responseText) console.log(`User replied: ${data.responseText}`);
});
os.notifications.send({
id: 'welcome-notif',
title: 'Welcome!',
body: 'Click a button to interact.'
});
os.sensors
isSupported(): boolean
Whether the sensors module is supported.
getAmbientLightSensorValue(): Promise<{ value: number; unit: 'lux' | 'raw'; }>
Reads the ambient light sensor.
Returns:
value
:number
unit
:'lux' | 'raw'
π₯οΈ Platform Support
Feature | macOS | Windows | Linux |
---|---|---|---|
Power Management | β | β | β |
Storage & Cloud | β | β | β |
Audio Control | β | β | β οΈ Partial |
Display Brightness | β | β | β οΈ Driverβdependent |
Rich Notifications | β | β | β οΈ Limited |
Ambient Light Sensor | β | β οΈ Some devices | β |
Notes: Linux support for audio/brightness/notifications depends on distribution, drivers and desktop environment.
π οΈ Troubleshooting
- Build fails on Windows β Ensure Visual Studio Build Tools and Python are installed.
- Permission errors on macOS β System Settings β Privacy & Security β grant access.
- Notifications missing on Windows β Set a valid
AppUserModelID
vianotifications.initialize(appId)
.
π€ Contributing
- Fork the repo
- Create a branch:
git checkout -b feat/my-feature
- Commit and push
- Open a Pull Request π
π License
MIT β free for personal and commercial use.