From b47ce707f7d4cd2c533010339b46337b848921b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20ADAM?= Date: Thu, 3 Oct 2024 22:40:25 +0200 Subject: [PATCH 1/3] feat(driver): Sound option with TerminalNotifierDriver --- doc/01-basic-usage.md | 2 +- doc/02-notification.md | 2 +- src/Driver/TerminalNotifierDriver.php | 5 +++++ tests/Driver/TerminalNotifierDriverTest.php | 11 +++++++++-- 4 files changed, 16 insertions(+), 4 deletions(-) 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..b9577a4 100644 --- a/doc/02-notification.md +++ b/doc/02-notification.md @@ -47,7 +47,7 @@ through the `addOption` method. ### Subtitle -Only works with AppleScriptDriver at the moment. +Only works with AppleScriptDriver and TerminalNotifierDriver at the moment. ```php $notification->addOption('subtitle', 'This is a subtitle'); 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..c08f9b3 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 << Date: Fri, 4 Oct 2024 14:42:24 +0200 Subject: [PATCH 2/3] fix(CI): fixed TerminalNotifierDriver tests --- CHANGELOG.md | 2 ++ README.md | 2 +- tests/Driver/TerminalNotifierDriverTest.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) 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/tests/Driver/TerminalNotifierDriverTest.php b/tests/Driver/TerminalNotifierDriverTest.php index c08f9b3..fddf14f 100644 --- a/tests/Driver/TerminalNotifierDriverTest.php +++ b/tests/Driver/TerminalNotifierDriverTest.php @@ -94,7 +94,7 @@ protected function getExpectedCommandLineForNotificationWithAllOptions(): string } return <<<'CLI' - 'terminal-notifier' '-message' 'I'\''m the notification body' '-title' 'I'\''m the notification title' '-open' 'https://google.com' '-sound' 'Frog' + 'terminal-notifier' '-message' 'I'\''m the notification body' '-title' 'I'\''m the notification title' '-open' 'https://google.com' '-sound' 'Frog' CLI; } } From 59e6c5f5b09cb051b9ce5b4a8243c6b549cbcefb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20ADAM?= Date: Fri, 4 Oct 2024 15:07:20 +0200 Subject: [PATCH 3/3] fix(doc): fixed documentation sound option --- doc/02-notification.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/02-notification.md b/doc/02-notification.md index b9577a4..bb0a008 100644 --- a/doc/02-notification.md +++ b/doc/02-notification.md @@ -47,7 +47,7 @@ through the `addOption` method. ### Subtitle -Only works with AppleScriptDriver and TerminalNotifierDriver at the moment. +Only works with AppleScriptDriver at the moment. ```php $notification->addOption('subtitle', 'This is a subtitle'); @@ -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.