Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(driver): Sound option with TerminalNotifierDriver #114

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Not released yet

* Added support for sound option on TerminalNotifier notifier

## 3.0.0 (2024-10-02)

* Remove deprecated code:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion doc/01-basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;
```
Expand Down
2 changes: 1 addition & 1 deletion doc/02-notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions src/Driver/TerminalNotifierDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
11 changes: 9 additions & 2 deletions tests/Driver/TerminalNotifierDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '>=')) {
Expand All @@ -82,12 +89,12 @@ protected function getExpectedCommandLineForNotificationWithAllOptions(): string
$iconDir = $this->getIconDir();

return <<<CLI
'terminal-notifier' '-message' 'I'\\''m the notification body' '-title' 'I'\\''m the notification title' '-contentImage' '{$iconDir}/image.gif' '-open' 'https://google.com'
'terminal-notifier' '-message' 'I'\\''m the notification body' '-title' 'I'\\''m the notification title' '-contentImage' '{$iconDir}/image.gif' '-open' 'https://google.com' '-sound' 'Frog'
CLI;
}

return <<<'CLI'
'terminal-notifier' '-message' 'I'\''m the notification body' '-title' 'I'\''m the notification title' '-open' 'https://google.com'
'terminal-notifier' '-message' 'I'\''m the notification body' '-title' 'I'\''m the notification title' '-open' 'https://google.com' '-sound' 'Frog'
CLI;
}
}
Loading