feat: Add new powerMonitor synchronous API (#17144)
`powerMonitor.querySystemIdleState` and `powerMonitor.querySystemIdleTime` had async backing APIs in chromium (https://chromium-review.googlesource.com/c/chromium/src/+/1379183). However, that has changed in ch73. So, this PR deprecates the old async APIs and adds new sync APIs.
This commit is contained in:
		
					parent
					
						
							
								29ab74688d
							
						
					
				
			
			
				commit
				
					
						bfa07ec4be
					
				
			
		
					 7 changed files with 96 additions and 25 deletions
				
			
		|  | @ -2,6 +2,7 @@ | |||
| 
 | ||||
| const { EventEmitter } = require('events') | ||||
| const { powerMonitor, PowerMonitor } = process.atomBinding('power_monitor') | ||||
| const { deprecate } = require('electron') | ||||
| 
 | ||||
| // PowerMonitor is an EventEmitter.
 | ||||
| Object.setPrototypeOf(PowerMonitor.prototype, EventEmitter.prototype) | ||||
|  | @ -22,8 +23,9 @@ if (process.platform === 'linux') { | |||
|   }) | ||||
| } | ||||
| 
 | ||||
| // TODO(deepak1556): Deprecate async api in favor of sync version in 5.0
 | ||||
| // TODO(nitsakh): Remove in 7.0
 | ||||
| powerMonitor.querySystemIdleState = function (threshold, callback) { | ||||
|   deprecate.warn('powerMonitor.querySystemIdleState', 'powerMonitor.getSystemIdleState') | ||||
|   if (typeof threshold !== 'number') { | ||||
|     throw new Error('Must pass threshold as a number') | ||||
|   } | ||||
|  | @ -32,18 +34,19 @@ powerMonitor.querySystemIdleState = function (threshold, callback) { | |||
|     throw new Error('Must pass callback as a function argument') | ||||
|   } | ||||
| 
 | ||||
|   const idleState = this._querySystemIdleState(threshold) | ||||
|   const idleState = this.getSystemIdleState(threshold) | ||||
| 
 | ||||
|   process.nextTick(() => callback(idleState)) | ||||
| } | ||||
| 
 | ||||
| // TODO(deepak1556): Deprecate async api in favor of sync version in 5.0
 | ||||
| // TODO(nitsakh): Remove in 7.0
 | ||||
| powerMonitor.querySystemIdleTime = function (callback) { | ||||
|   deprecate.warn('powerMonitor.querySystemIdleTime', 'powerMonitor.getSystemIdleTime') | ||||
|   if (typeof callback !== 'function') { | ||||
|     throw new Error('Must pass function as an argument') | ||||
|   } | ||||
| 
 | ||||
|   const idleTime = this._querySystemIdleTime() | ||||
|   const idleTime = this.getSystemIdleTime() | ||||
| 
 | ||||
|   process.nextTick(() => callback(idleTime)) | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Nitish Sakhawalkar
				Nitish Sakhawalkar