Skip to content

Commit

Permalink
style: fix xo errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Heyman committed Jun 15, 2022
1 parent 13c526e commit ee69ffa
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 73 deletions.
108 changes: 54 additions & 54 deletions impl/linux.ts
Original file line number Diff line number Diff line change
@@ -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');
}
38 changes: 19 additions & 19 deletions impl/windows/index.ts
Original file line number Diff line number Diff line change
@@ -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');
}

0 comments on commit ee69ffa

Please sign in to comment.