From ee69ffa4d1fe950c5c3bcfb71e5590fa0b4463cb Mon Sep 17 00:00:00 2001 From: Matthias Heyman Date: Wed, 15 Jun 2022 13:56:30 +0200 Subject: [PATCH] style: fix xo errors --- impl/linux.ts | 108 +++++++++++++++++++++--------------------- impl/windows/index.ts | 38 +++++++-------- 2 files changed, 73 insertions(+), 73 deletions(-) diff --git a/impl/linux.ts b/impl/linux.ts index 40c60f5..7d0708d 100644 --- a/impl/linux.ts +++ b/impl/linux.ts @@ -1,101 +1,101 @@ -import { execa } from "execa"; +import {execa} from 'execa'; let defaultDeviceCache: string; let defaultArgs: string[]; async function amixer(...args: string[]) { - const allArgs = []; - allArgs.push(...(await getDefaultArgs())); - if (args && args.length > 0) { - allArgs.push(...args); - } - - const result = await execa("amixer", allArgs); - return result.stdout; + const allArgs = []; + allArgs.push(...(await getDefaultArgs())); + if (args && args.length > 0) { + allArgs.push(...args); + } + + const result = await execa('amixer', allArgs); + return result.stdout; } const reDefaultDevice = /simple mixer control '([a-z\d -]+)',\d+/i; function parseDefaultDevice(data: string) { - const result = reDefaultDevice.exec(data); + const result = reDefaultDevice.exec(data); - if (result === null) { - throw new Error("Alsa Mixer Error: failed to parse output"); - } + if (result === null) { + throw new Error('Alsa Mixer Error: failed to parse output'); + } - return result[1]!; + return result[1]!; } const reWhichPactl = /^\/.*\/pactl$/; async function systemHasPulseAudio() { - try { - const { stdout } = await execa("which", ["pactl"]); - if (reWhichPactl.test(stdout)) { - return true; - } - } catch {} - - return false; + try { + const {stdout} = await execa('which', ['pactl']); + if (reWhichPactl.test(stdout)) { + return true; + } + } catch {} + + return false; } async function getDefaultArgs() { - if (!defaultArgs) { - const hasPulse = await systemHasPulseAudio(); - defaultArgs = hasPulse ? ["-D", "pulse"] : []; - } + if (!defaultArgs) { + const hasPulse = await systemHasPulseAudio(); + defaultArgs = hasPulse ? ['-D', 'pulse'] : []; + } - return defaultArgs; + return defaultArgs; } async function getDefaultDevice() { - if (defaultDeviceCache) { - return defaultDeviceCache; - } + if (defaultDeviceCache) { + return defaultDeviceCache; + } - const amixerResult = await amixer(); - defaultDeviceCache = parseDefaultDevice(amixerResult); - return defaultDeviceCache; + const amixerResult = await amixer(); + defaultDeviceCache = parseDefaultDevice(amixerResult); + return defaultDeviceCache; } -const reInfo = - /[a-z][a-z ]*: playback [\d-]+ \[(\d+)%] (?:[[\d.-]+db] )?\[(on|off)]/i; +const reInfo + = /[a-z][a-z ]*: playback [\d-]+ \[(\d+)%] (?:[[\d.-]+db] )?\[(on|off)]/i; function parseInfo(data: string) { - const result = reInfo.exec(data); + const result = reInfo.exec(data); - if (result === null) { - throw new Error("Alsa Mixer Error: failed to parse output"); - } + if (result === null) { + throw new Error('Alsa Mixer Error: failed to parse output'); + } - return { - volume: Number.parseInt(result[1]!, 10), - muted: result[2] === "off", - }; + return { + volume: Number.parseInt(result[1]!, 10), + muted: result[2] === 'off', + }; } async function getInfo() { - const device = await getDefaultDevice(); - const amixerOutput = await amixer("get", device); - return parseInfo(amixerOutput); + const device = await getDefaultDevice(); + const amixerOutput = await amixer('get', device); + return parseInfo(amixerOutput); } export async function getVolume() { - const info = await getInfo(); - return info.volume; + const info = await getInfo(); + return info.volume; } export async function setVolume(value: number) { - const device = await getDefaultDevice(); - await amixer("set", device, `${value}%`); + const device = await getDefaultDevice(); + await amixer('set', device, `${value}%`); } export async function getMuted() { - const info = await getInfo(); - return info.muted; + const info = await getInfo(); + return info.muted; } export async function setMuted(value: boolean) { - const device = await getDefaultDevice(); - await amixer("set", device, value ? "mute" : "unmute"); + const device = await getDefaultDevice(); + await amixer('set', device, value ? 'mute' : 'unmute'); } diff --git a/impl/windows/index.ts b/impl/windows/index.ts index 5b0f39c..22cdb13 100644 --- a/impl/windows/index.ts +++ b/impl/windows/index.ts @@ -1,41 +1,41 @@ -import { join, dirname } from "node:path"; -import { fileURLToPath } from "node:url"; -import { execa } from "execa"; +import {join, dirname} from 'node:path'; +import {fileURLToPath} from 'node:url'; +import {execa} from 'execa'; const executablePath = join( - dirname(fileURLToPath(import.meta.url)), - "adjust_get_current_system_volume_vista_plus.exe" + dirname(fileURLToPath(import.meta.url)), + 'adjust_get_current_system_volume_vista_plus.exe', ); async function runProgram(...args: string[]) { - const result = await execa(executablePath, args); - return result.stdout; + const result = await execa(executablePath, args); + return result.stdout; } async function getVolumeInfo() { - const data = await runProgram(); - const args = data.split(" "); + const data = await runProgram(); + const args = data.split(' '); - return { - volume: Number.parseInt(args[0]!, 10), - muted: Boolean(Number.parseInt(args[1]!, 10)), - }; + return { + volume: Number.parseInt(args[0]!, 10), + muted: Boolean(Number.parseInt(args[1]!, 10)), + }; } export async function getVolume() { - const volumeInfo = await getVolumeInfo(); - return volumeInfo.volume; + const volumeInfo = await getVolumeInfo(); + return volumeInfo.volume; } export async function setVolume(value: number) { - await runProgram(String(value)); + await runProgram(String(value)); } export async function getMuted() { - const volumeInfo = await getVolumeInfo(); - return volumeInfo.muted; + const volumeInfo = await getVolumeInfo(); + return volumeInfo.muted; } export async function setMuted(value: boolean) { - await runProgram(value ? "mute" : "unmute"); + await runProgram(value ? 'mute' : 'unmute'); }