npm.io
0.4.6 • Published 9 years ago

osxsleep

Licence
MIT
Version
0.4.6
Deps
3
Vulns
0
Weekly
0
Stars
1
Install scriptsThis package runs scripts during installation (preinstall/install/postinstall)

osxsleep

osxsleep allows to monitor macOS device's sleep state from Node; additionally, you can query the current power source.

Example usage:


  const osxsleep = require('osxsleep');
   
  ...

  var source = osxsleep.OSXSleep.getPowerSource();

  switch(source) {
	case osxsleep.POWER_SOURCE_AC:
		break;
	case osxsleep.POWER_SOURCE_BATTERY:
		break;
	case osxsleep.POWER_SOURCE_UPS:
		break;
  }

  ...
 
  osxsleep.OSXSleep.start(function(sleepstate){

	switch(sleepstate) {
		case osxsleep.CAN_SLEEP:
			if (/* can sleep */) {
			    return true;
			} else {
			    return false;
			}
			break;
		case osxsleep.WILL_SLEEP:
			break;
		case osxsleep.WILL_POWER_ON:
			break;
		case osxsleep.HAS_POWERED_ON:
			break;
	}
  });

  ...
  
  osxsleep.OSXSleep.stop();
 

It is important to call stop() in order to unregister the native IOKit sleep state monitor & resources!

Keywords