-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
36 lines (31 loc) · 898 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import * as os from "os";
import { PlatformImplementation, VolumeControl } from "./types";
import { windows } from "./platforms/windows";
import { darwin } from "./platforms/darwin";
import { linux } from "./platforms/linux";
const osType = os.type();
let universal: PlatformImplementation;
switch (osType.toLowerCase()) {
case "windows_nt":
universal = windows;
break;
case "darwin":
universal = darwin;
break;
case "linux":
universal = linux;
break;
default:
throw new Error(
`Your OS (${osType}) is not supported by the easy-volume library!`
);
}
const { getVolume, setVolume, getMute, setMute, toggleMute }: VolumeControl = {
...universal,
toggleMute: async () => {
const currentState = await getMute();
await setMute(!currentState);
return !currentState;
},
};
export { getVolume, setVolume, getMute, setMute, toggleMute };