fix(session-notification): tolerate shell promises without nothrow

This commit is contained in:
YeonGyu-Kim
2026-05-05 23:06:01 +09:00
parent f8defe2588
commit e9d7dca604
+22 -7
View File
@@ -33,6 +33,21 @@ export function getDefaultSoundPath(platform: Platform): string {
} }
} }
type ShellCommand = Promise<unknown> & {
quiet?: () => Promise<unknown>
nothrow?: () => ShellCommand
}
async function runQuietNothrow(command: ShellCommand): Promise<void> {
const safeCommand = typeof command.nothrow === "function" ? command.nothrow() : command
if (typeof safeCommand.quiet === "function") {
await safeCommand.quiet()
return
}
await safeCommand
}
export async function sendSessionNotification( export async function sendSessionNotification(
ctx: PluginInput, ctx: PluginInput,
platform: Platform, platform: Platform,
@@ -72,14 +87,14 @@ export async function sendSessionNotification(
const escapedTitle = escapeAppleScriptText(title) const escapedTitle = escapeAppleScriptText(title)
const escapedMessage = escapeAppleScriptText(message) const escapedMessage = escapeAppleScriptText(message)
await ctx.$`${osascriptPath} -e ${"display notification \"" + escapedMessage + "\" with title \"" + escapedTitle + "\""}`.nothrow().quiet() await runQuietNothrow(ctx.$`${osascriptPath} -e ${"display notification \"" + escapedMessage + "\" with title \"" + escapedTitle + "\""}`)
break break
} }
case "linux": { case "linux": {
const notifySendPath = await getNotifySendPath() const notifySendPath = await getNotifySendPath()
if (!notifySendPath) return if (!notifySendPath) return
await ctx.$`${notifySendPath} ${title} ${message} 2>/dev/null`.nothrow().quiet() await runQuietNothrow(ctx.$`${notifySendPath} ${title} ${message} 2>/dev/null`)
break break
} }
case "win32": { case "win32": {
@@ -87,7 +102,7 @@ export async function sendSessionNotification(
if (!powershellPath) return if (!powershellPath) return
const toastScript = buildWindowsToastScript(title, message) const toastScript = buildWindowsToastScript(title, message)
await ctx.$`${powershellPath} -Command ${toastScript}`.nothrow().quiet() await runQuietNothrow(ctx.$`${powershellPath} -Command ${toastScript}`)
break break
} }
} }
@@ -102,17 +117,17 @@ export async function playSessionNotificationSound(
case "darwin": { case "darwin": {
const afplayPath = await getAfplayPath() const afplayPath = await getAfplayPath()
if (!afplayPath) return if (!afplayPath) return
ctx.$`${afplayPath} ${soundPath}`.nothrow().quiet() await runQuietNothrow(ctx.$`${afplayPath} ${soundPath}`)
break break
} }
case "linux": { case "linux": {
const paplayPath = await getPaplayPath() const paplayPath = await getPaplayPath()
if (paplayPath) { if (paplayPath) {
ctx.$`${paplayPath} ${soundPath} 2>/dev/null`.nothrow().quiet() await runQuietNothrow(ctx.$`${paplayPath} ${soundPath} 2>/dev/null`)
} else { } else {
const aplayPath = await getAplayPath() const aplayPath = await getAplayPath()
if (aplayPath) { if (aplayPath) {
ctx.$`${aplayPath} ${soundPath} 2>/dev/null`.nothrow().quiet() await runQuietNothrow(ctx.$`${aplayPath} ${soundPath} 2>/dev/null`)
} }
} }
break break
@@ -121,7 +136,7 @@ export async function playSessionNotificationSound(
const powershellPath = await getPowershellPath() const powershellPath = await getPowershellPath()
if (!powershellPath) return if (!powershellPath) return
const escaped = escapePowerShellSingleQuotedText(soundPath) const escaped = escapePowerShellSingleQuotedText(soundPath)
ctx.$`${powershellPath} -Command ${"(New-Object Media.SoundPlayer '" + escaped + "').PlaySync()"}`.nothrow().quiet() await runQuietNothrow(ctx.$`${powershellPath} -Command ${"(New-Object Media.SoundPlayer '" + escaped + "').PlaySync()"}`)
break break
} }
} }