✨ feat: play system bell on volume change
it can be disabled within the colorshell's configuration file, under the `misc` section: misc:play_bell_on_volume_change: (true|false)
This commit is contained in:
@@ -6,6 +6,8 @@ import { Runner } from "../runner/Runner";
|
||||
import { showWorkspaceNumber } from "../widget/bar/Workspaces";
|
||||
|
||||
import AstalIO from "gi://AstalIO";
|
||||
import { playSystemBell } from "./utils";
|
||||
import { Config } from "./config";
|
||||
|
||||
|
||||
let wsTimeout: (AstalIO.Time|undefined);
|
||||
@@ -113,30 +115,33 @@ function handleVolumeArgs(args: Array<string>) {
|
||||
case "set":
|
||||
command[0] === "sink" ?
|
||||
Wireplumber.getDefault().setSinkVolume(Number.parseInt(args[2]))
|
||||
:
|
||||
Wireplumber.getDefault().setSourceVolume(Number.parseInt(args[2]))
|
||||
: Wireplumber.getDefault().setSourceVolume(Number.parseInt(args[2]))
|
||||
return `Done! Set ${command[0]} volume to ${args[2]}`;
|
||||
|
||||
case "mute":
|
||||
command[0] === "sink" ?
|
||||
Wireplumber.getDefault().toggleMuteSink()
|
||||
:
|
||||
Wireplumber.getDefault().toggleMuteSource()
|
||||
: Wireplumber.getDefault().toggleMuteSource()
|
||||
|
||||
return `Done toggling mute!`;
|
||||
|
||||
case "increase":
|
||||
command[0] === "sink" ?
|
||||
Wireplumber.getDefault().increaseSinkVolume(Number.parseInt(args[2]))
|
||||
:
|
||||
Wireplumber.getDefault().increaseSourceVolume(Number.parseInt(args[2]))
|
||||
: Wireplumber.getDefault().increaseSourceVolume(Number.parseInt(args[2]))
|
||||
|
||||
Config.getDefault().getProperty("misc.play_bell_on_volume_change", "boolean") === true &&
|
||||
playSystemBell();
|
||||
|
||||
return `Done increasing volume by ${args[2]}`;
|
||||
|
||||
case "decrease":
|
||||
command[0] === "sink" ?
|
||||
Wireplumber.getDefault().decreaseSinkVolume(Number.parseInt(args[2]))
|
||||
:
|
||||
Wireplumber.getDefault().decreaseSourceVolume(Number.parseInt(args[2]))
|
||||
: Wireplumber.getDefault().decreaseSourceVolume(Number.parseInt(args[2]))
|
||||
|
||||
Config.getDefault().getProperty("misc.play_bell_on_volume_change", "boolean") === true &&
|
||||
playSystemBell();
|
||||
|
||||
return `Done decreasing volume to ${args[2]}`;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export type ConfigEntries = Partial<{
|
||||
}>;
|
||||
|
||||
clock: Partial<{
|
||||
/** use the same formats as gnu's `date` command */
|
||||
/** use the same format as gnu's `date` command */
|
||||
date_format: string;
|
||||
}>;
|
||||
|
||||
@@ -42,6 +42,10 @@ export type ConfigEntries = Partial<{
|
||||
/** whether to save night light values to disk */
|
||||
save_on_shutdown: boolean;
|
||||
}>;
|
||||
|
||||
misc: Partial<{
|
||||
play_bell_on_volume_change: boolean;
|
||||
}>;
|
||||
}>;
|
||||
|
||||
type ValueTypes = "string" | "boolean" | "object" | "number" | "undefined" | "any";
|
||||
@@ -79,6 +83,10 @@ class Config extends GObject.Object {
|
||||
|
||||
clock: {
|
||||
date_format: "%A %d, %H:%M"
|
||||
},
|
||||
|
||||
misc: {
|
||||
play_bell_on_volume_change: true
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -92,6 +92,12 @@ export function deleteFile(path: string): void {
|
||||
execAsync([ "rm", "-r", path ]);
|
||||
}
|
||||
|
||||
export function playSystemBell(): void {
|
||||
execAsync("canberra-gtk-play -i bell").catch((e: Error) => {
|
||||
console.error(`Couldn't play system bell. Stderr: ${e.message}\n${e.stack}`);
|
||||
});
|
||||
}
|
||||
|
||||
export function isInstalled(commandName: string): boolean {
|
||||
const proc = Gio.Subprocess.new(["bash", "-c", `command -v ${commandName}`],
|
||||
Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE);
|
||||
|
||||
Reference in New Issue
Block a user