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
				
			
		|  | @ -63,6 +63,24 @@ require('path') | |||
| require('electron').remote.require('path') | ||||
| ``` | ||||
| 
 | ||||
| ## `powerMonitor.querySystemIdleState` | ||||
| 
 | ||||
| ```js | ||||
| // Deprecated | ||||
| powerMonitor.querySystemIdleState(threshold, callback) | ||||
| // Replace with synchronous API | ||||
| const idleState = getSystemIdleState(threshold) | ||||
| ``` | ||||
| 
 | ||||
| ## `powerMonitor.querySystemIdleTime` | ||||
| 
 | ||||
| ```js | ||||
| // Deprecated | ||||
| powerMonitor.querySystemIdleTime(callback) | ||||
| // Replace with synchronous API | ||||
| const idleTime = getSystemIdleTime() | ||||
| ``` | ||||
| 
 | ||||
| # Planned Breaking API Changes (5.0) | ||||
| 
 | ||||
| ## `new BrowserWindow({ webPreferences })` | ||||
|  |  | |||
|  | @ -59,7 +59,7 @@ Emitted as soon as the systems screen is unlocked. | |||
| 
 | ||||
| The `powerMonitor` module has the following methods: | ||||
| 
 | ||||
| #### `powerMonitor.querySystemIdleState(idleThreshold, callback)` | ||||
| #### `powerMonitor.querySystemIdleState(idleThreshold, callback)` _(Deprecated)_ | ||||
| 
 | ||||
| * `idleThreshold` Integer | ||||
| * `callback` Function | ||||
|  | @ -70,9 +70,25 @@ before considered idle. `callback` will be called synchronously on some systems | |||
| and with an `idleState` argument that describes the system's state. `locked` is | ||||
| available on supported systems only. | ||||
| 
 | ||||
| #### `powerMonitor.querySystemIdleTime(callback)` | ||||
| #### `powerMonitor.querySystemIdleTime(callback)` _(Deprecated)_ | ||||
| 
 | ||||
| * `callback` Function | ||||
|   * `idleTime` Integer - Idle time in seconds | ||||
| 
 | ||||
| Calculate system idle time in seconds. | ||||
| 
 | ||||
| #### `powerMonitor.getSystemIdleState(idleThreshold)` | ||||
| 
 | ||||
| * `idleThreshold` Integer | ||||
| 
 | ||||
| Returns `String` - The system's current state. Can be `active`, `idle`, `locked` or `unknown`. | ||||
| 
 | ||||
| Calculate the system idle state. `idleThreshold` is the amount of time (in seconds) | ||||
| before considered idle.  `locked` is available on supported systems only. | ||||
| 
 | ||||
| #### `powerMonitor.getSystemIdleTime()` | ||||
| 
 | ||||
| Returns `Integer` - Idle time in seconds | ||||
| 
 | ||||
| Calculate system idle time in seconds. | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Nitish Sakhawalkar
				Nitish Sakhawalkar