Skip to content

Commit

Permalink
Merge pull request #114 from aurac/main
Browse files Browse the repository at this point in the history
feat(driver): Sound option with TerminalNotifierDriver
  • Loading branch information
pyrech authored Oct 4, 2024
2 parents ce27ee0 + 59e6c5f commit 87a02e2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
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;
}
}

0 comments on commit 87a02e2

Please sign in to comment.