Skip to content

Commit

Permalink
feat(driver): Sound option with TerminalNotifierDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
adveris-aadam committed Oct 3, 2024
1 parent ce27ee0 commit b47ce70
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
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 @@ -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');
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;
}
}

0 comments on commit b47ce70

Please sign in to comment.