diff --git a/CHANGELOG.md b/CHANGELOG.md index 29c7250..85f50c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Not released yet +* Added support for sound option on TerminalNotifier notifier + ## 3.0.0 (2024-10-02) * Remove deprecated code: diff --git a/README.md b/README.md index 56e68cc..06b218c 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ $notification = ->setBody('This is the body of your notification') ->setIcon(__DIR__.'/path/to/your/icon.png') ->addOption('subtitle', 'This is a subtitle') // Only works on macOS (AppleScriptDriver) - ->addOption('sound', 'Frog') // Only works on macOS (AppleScriptDriver) + ->addOption('sound', 'Frog') // Only works on macOS (AppleScriptDriver & TerminalNotifierDriver) ; // Send it diff --git a/doc/01-basic-usage.md b/doc/01-basic-usage.md index b722eb7..40530f1 100644 --- a/doc/01-basic-usage.md +++ b/doc/01-basic-usage.md @@ -45,7 +45,7 @@ $notification = ->setBody('The notification body') ->setTitle('The notification title') ->addOption('subtitle', 'This is a subtitle') // Only works on macOS (AppleScriptDriver) - ->addOption('sound', 'Frog') // Only works on macOS (AppleScriptDriver) + ->addOption('sound', 'Frog') // Only works on macOS (AppleScriptDriver & TerminalNotifierDriver) ->addOption('url', 'https://google.com') // Only works on macOS (TerminalNotifierDriver) ; ``` diff --git a/doc/02-notification.md b/doc/02-notification.md index f874136..bb0a008 100644 --- a/doc/02-notification.md +++ b/doc/02-notification.md @@ -55,7 +55,7 @@ $notification->addOption('subtitle', 'This is a subtitle'); ### Sound -Only works with AppleScriptDriver at the moment. +Only works with AppleScriptDriver and TerminalNotifierDriver at the moment. Non-exhaustive list of sounds: Basso, Frog, Hero, Pop, Submarine, Blow, Funk, Morse, Purr, Tink, Bottle, Glass, Ping, Sosumi. diff --git a/src/Driver/TerminalNotifierDriver.php b/src/Driver/TerminalNotifierDriver.php index f93f0fa..0280469 100644 --- a/src/Driver/TerminalNotifierDriver.php +++ b/src/Driver/TerminalNotifierDriver.php @@ -54,6 +54,11 @@ protected function getCommandLineArguments(Notification $notification): array $arguments[] = (string) $notification->getOption('url'); } + if ($notification->getOption('sound')) { + $arguments[] = '-sound'; + $arguments[] = (string) $notification->getOption('sound'); + } + return $arguments; } } diff --git a/tests/Driver/TerminalNotifierDriverTest.php b/tests/Driver/TerminalNotifierDriverTest.php index f9c110e..fddf14f 100644 --- a/tests/Driver/TerminalNotifierDriverTest.php +++ b/tests/Driver/TerminalNotifierDriverTest.php @@ -61,6 +61,13 @@ protected function getExpectedCommandLineForNotificationWithAnUrl(): string CLI; } + protected function getExpectedCommandLineForNotificationWithASound(): string + { + return <<<'CLI' + 'terminal-notifier' '-message' 'I'\''m the notification body' '-sound' 'Frog' + CLI; + } + protected function getExpectedCommandLineForNotificationWithAnIcon(): string { if (OsHelper::isMacOS() && version_compare(OsHelper::getMacOSVersion(), '10.9.0', '>=')) { @@ -82,12 +89,12 @@ protected function getExpectedCommandLineForNotificationWithAllOptions(): string $iconDir = $this->getIconDir(); return <<