osxsleep
Allows to monitor macOS device sleep from Node
Last updated 3 years ago by mderezynski .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install osxsleep 
SYNC missed versions from official npm registry.

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!

Current Tags

  • 0.4.6                                ...           latest (3 years ago)

16 Versions

  • 0.4.6                                ...           3 years ago
  • 0.4.5                                ...           3 years ago
  • 0.4.4                                ...           3 years ago
  • 0.4.3                                ...           3 years ago
  • 0.4.2                                ...           3 years ago
  • 0.4.1                                ...           3 years ago
  • 0.4.0                                ...           3 years ago
  • 0.3.0                                ...           3 years ago
  • 0.2.2                                ...           3 years ago
  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
  • 0.0.3                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |