feat: Add new powerMonitor synchronous API (#17144)
`powerMonitor.querySystemIdleState` and `powerMonitor.querySystemIdleTime` had async backing APIs in chromium (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
|
@ -128,6 +128,7 @@ describe('powerMonitor', () => {
|
|||
powerMonitor = require('electron').remote.powerMonitor
|
||||
})
|
||||
|
||||
// TODO(nitsakh): Remove in 7.0
|
||||
describe('powerMonitor.querySystemIdleState', () => {
|
||||
it('notify current system idle state', done => {
|
||||
// this function is not mocked out, so we can test the result's
|
||||
|
@ -155,6 +156,7 @@ describe('powerMonitor', () => {
|
|||
})
|
||||
})
|
||||
|
||||
// TODO(nitsakh): Remove in 7.0
|
||||
describe('powerMonitor.querySystemIdleTime', () => {
|
||||
it('notify current system idle time', done => {
|
||||
powerMonitor.querySystemIdleTime(idleTime => {
|
||||
|
@ -163,5 +165,37 @@ describe('powerMonitor', () => {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('powerMonitor.getSystemIdleState', () => {
|
||||
it('gets current system idle state', () => {
|
||||
// this function is not mocked out, so we can test the result's
|
||||
// form and type but not its value.
|
||||
const idleState = powerMonitor.getSystemIdleState(1)
|
||||
expect(idleState).to.be.a('string')
|
||||
const validIdleStates = [ 'active', 'idle', 'locked', 'unknown' ]
|
||||
expect(validIdleStates).to.include(idleState)
|
||||
})
|
||||
|
||||
it('does not accept non positive integer threshold', () => {
|
||||
expect(() => {
|
||||
powerMonitor.getSystemIdleState(-1)
|
||||
}).to.throw(/must be greater than 0/)
|
||||
|
||||
expect(() => {
|
||||
powerMonitor.getSystemIdleState(NaN)
|
||||
}).to.throw(/conversion failure/)
|
||||
|
||||
expect(() => {
|
||||
powerMonitor.getSystemIdleState('a')
|
||||
}).to.throw(/conversion failure/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('powerMonitor.getSystemIdleTime', () => {
|
||||
it('notify current system idle time', () => {
|
||||
const idleTime = powerMonitor.getSystemIdleTime()
|
||||
expect(idleTime).to.be.at.least(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue