Skip to content

Commit 99a48e7

Browse files
committed
💥 Drop support for Node.js <10
Migration Guide: Upgrade to Node.js 10.13.0 or newer.
1 parent 1c4d8ba commit 99a48e7

File tree

5 files changed

+55
-58
lines changed

5 files changed

+55
-58
lines changed

impl/darwin.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
const execa = require('execa')
22

3-
function osascript (cmd) {
4-
return execa.stdout('osascript', ['-e', cmd], { preferLocal: false })
3+
async function osascript (cmd) {
4+
return (await execa('osascript', ['-e', cmd])).stdout
55
}
66

7-
exports.getVolume = function () {
8-
return osascript('output volume of (get volume settings)').then(vol => parseInt(vol, 10))
7+
exports.getVolume = async function getVolume () {
8+
return parseInt(await osascript('output volume of (get volume settings)'), 10)
99
}
1010

11-
exports.setVolume = function (val) {
12-
return osascript('set volume output volume ' + val).then(() => undefined)
11+
exports.setVolume = async function setVolume (val) {
12+
await osascript('set volume output volume ' + val)
1313
}
1414

15-
exports.getMuted = function () {
16-
return osascript('output muted of (get volume settings)').then(mute => (mute === 'true'))
15+
exports.getMuted = async function getMuted () {
16+
return (await osascript('output muted of (get volume settings)')) === 'true'
1717
}
1818

19-
exports.setMuted = function (val) {
20-
return osascript('set volume ' + (val ? 'with' : 'without') + ' output muted').then(() => undefined)
19+
exports.setMuted = async function setMuted (val) {
20+
await osascript('set volume ' + (val ? 'with' : 'without') + ' output muted')
2121
}

impl/linux.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const execa = require('execa')
22

3-
function amixer (...args) {
4-
return execa.stdout('amixer', args, { preferLocal: false })
3+
async function amixer (...args) {
4+
return (await execa('amixer', args)).stdout
55
}
66

77
let defaultDeviceCache = null
@@ -17,10 +17,10 @@ function parseDefaultDevice (data) {
1717
return result[1]
1818
}
1919

20-
function getDefaultDevice () {
21-
if (defaultDeviceCache) return Promise.resolve(defaultDeviceCache)
20+
async function getDefaultDevice () {
21+
if (defaultDeviceCache) return defaultDeviceCache
2222

23-
return amixer().then(data => (defaultDeviceCache = parseDefaultDevice(data)))
23+
return (defaultDeviceCache = parseDefaultDevice(await amixer()))
2424
}
2525

2626
const reInfo = /[a-z][a-z ]*: Playback [0-9-]+ \[([0-9]+)%\] (?:[[0-9.-]+dB\] )?\[(on|off)\]/i
@@ -35,22 +35,22 @@ function parseInfo (data) {
3535
return { volume: parseInt(result[1], 10), muted: (result[2] === 'off') }
3636
}
3737

38-
function getInfo () {
39-
return getDefaultDevice().then(dev => amixer('get', dev)).then(data => parseInfo(data))
38+
async function getInfo () {
39+
return parseInfo(await amixer('get', await getDefaultDevice()))
4040
}
4141

42-
exports.getVolume = function () {
43-
return getInfo().then(info => info.volume)
42+
exports.getVolume = async function getVolume () {
43+
return (await getInfo()).volume
4444
}
4545

46-
module.exports.setVolume = function (val) {
47-
return getDefaultDevice().then(dev => amixer('set', dev, val + '%')).then(() => undefined)
46+
exports.setVolume = async function setVolume (val) {
47+
await amixer('set', await getDefaultDevice(), val + '%')
4848
}
4949

50-
module.exports.getMuted = function (cb) {
51-
return getInfo().then(info => info.muted)
50+
exports.getMuted = async function getMuted () {
51+
return (await getInfo()).muted
5252
}
5353

54-
module.exports.setMuted = function (val, cb) {
55-
return amixer('set', 'PCM', (val ? 'mute' : 'unmute')).then(() => undefined)
54+
exports.setMuted = async function setMuted (val) {
55+
await amixer('set', 'PCM', val ? 'mute' : 'unmute')
5656
}

impl/windows/index.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,29 @@ const path = require('path')
33

44
const executablePath = path.join(__dirname, 'adjust_get_current_system_volume_vista_plus.exe')
55

6-
function runProgram (...args) {
7-
return execa.stdout(executablePath, args)
6+
async function runProgram (...args) {
7+
return (await execa(executablePath, args)).stdout
88
}
99

10-
function getVolumeInfo () {
11-
return runProgram().then((data) => {
12-
const args = data.split(' ')
10+
async function getVolumeInfo () {
11+
const data = await runProgram()
12+
const args = data.split(' ')
1313

14-
return { volume: parseInt(args[0], 10), isMuted: Boolean(parseInt(args[1], 10)) }
15-
})
14+
return { volume: parseInt(args[0], 10), muted: Boolean(parseInt(args[1], 10)) }
1615
}
1716

18-
exports.getVolume = function () {
19-
return getVolumeInfo().then(info => info.volume)
17+
exports.getVolume = async function getVolume () {
18+
return (await getVolumeInfo()).volume
2019
}
2120

22-
exports.setVolume = function (val) {
23-
return runProgram(String(val)).then(() => undefined)
21+
exports.setVolume = async function setVolume (val) {
22+
await runProgram(String(val))
2423
}
2524

26-
exports.getMuted = function () {
27-
return getVolumeInfo().then(info => info.isMuted)
25+
exports.getMuted = async function getMuted () {
26+
return (await getVolumeInfo()).muted
2827
}
2928

30-
exports.setMuted = function (val) {
31-
return runProgram(val ? 'mute' : 'unmute').then(() => undefined)
29+
exports.setMuted = async function setMuted (val) {
30+
await runProgram(val ? 'mute' : 'unmute')
3231
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
"test": "standard && mocha"
88
},
99
"dependencies": {
10-
"execa": "^1.0.0"
10+
"execa": "^4.0.3"
1111
},
1212
"devDependencies": {
13-
"mocha": "^5.2.0",
14-
"standard": "^12.0.1"
13+
"mocha": "^8.1.1",
14+
"standard": "^14.3.4"
1515
},
1616
"engines": {
17-
"node": ">=6"
17+
"node": ">=10.13.0"
1818
}
1919
}

test/basics.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,29 @@ const assert = require('assert')
77
describe('loudness', () => {
88
let systemVolume, isMuted
99

10-
before(() => {
11-
return Promise.all([
10+
before(async () => {
11+
await Promise.all([
1212
loudness.getVolume().then(v => { systemVolume = v }),
1313
loudness.getMuted().then(m => { isMuted = m })
1414
])
1515
})
1616

17-
after(() => {
18-
return Promise.all([
17+
after(async () => {
18+
await Promise.all([
1919
loudness.setVolume(systemVolume),
2020
loudness.setMuted(isMuted)
2121
])
2222
})
2323

24-
it('should set and get the volume', () => {
25-
return Promise.resolve()
26-
.then(() => loudness.setVolume(15))
27-
.then(() => loudness.getVolume())
28-
.then(vol => assert.strictEqual(vol, 15))
24+
it('should set and get the volume', async () => {
25+
await loudness.setVolume(15)
26+
const vol = await loudness.getVolume()
27+
assert.strictEqual(vol, 15)
2928
})
3029

31-
it('should set and get the mute state', () => {
32-
return Promise.resolve()
33-
.then(() => loudness.setMuted(true))
34-
.then(() => loudness.getMuted())
35-
.then(mute => assert.strictEqual(mute, true))
30+
it('should set and get the mute state', async () => {
31+
await loudness.setMuted(true)
32+
const mute = await loudness.getMuted()
33+
assert.strictEqual(mute, true)
3634
})
3735
})

0 commit comments

Comments
 (0)