allow users to set icon for every notification

This commit is contained in:
Khoubza Younes
2021-09-29 18:44:29 +01:00
parent 257b37de81
commit 5a4a909359
10 changed files with 77 additions and 11 deletions
+20
View File
@@ -11,6 +11,9 @@ final class CliNotification extends Notification
*/
private $title;
/** @var string */
private $icon;
/**
* @return string
*/
@@ -27,10 +30,27 @@ final class CliNotification extends Notification
$this->title = $title;
}
/**
* @return string
*/
public function getIcon()
{
return $this->icon;
}
/**
* @param string $icon
*/
public function setIcon($icon)
{
$this->icon = $icon;
}
public function toArray()
{
return array_merge(parent::toArray(), array(
'title' => $this->getTitle(),
'icon' => $this->getIcon(),
));
}
}
+13
View File
@@ -18,4 +18,17 @@ final class CliNotificationBuilder extends NotificationBuilder
return $this;
}
/**
* @param string $icon
*
* @return self
*/
public function icon($icon)
{
$notification = $this->envelope->getNotification();
$notification->setIcon($icon);
return $this;
}
}
+10 -2
View File
@@ -2,6 +2,7 @@
namespace Flasher\Cli\Prime\Notifier;
use Flasher\Cli\Prime\CliNotification;
use Flasher\Cli\Prime\System\Program;
use Flasher\Prime\Envelope;
use Flasher\Prime\Notification\NotificationInterface;
@@ -76,12 +77,19 @@ abstract class AbstractNotifier implements NotifierInterface
}
/**
* @param string $type
* @param Envelope $envelope
*
* @return string
*/
public function getIcon($type)
public function getIcon(Envelope $envelope)
{
$notification = $envelope->getNotification();
if ($notification instanceof CliNotification && $notification->getIcon()) {
return $notification->getIcon();
}
$type = $envelope->getType();
if (isset($this->options['icons'][$type]) && file_exists($this->options['icons'][$type])) {
return $this->options['icons'][$type];
}
@@ -15,7 +15,7 @@ final class GrowlNotifyNotifier extends AbstractNotifier
$cmd
->addOption('--message', $envelope->getMessage())
->addOption('--title', $this->getTitle($envelope))
->addOption('--image', $this->getIcon($envelope->getType()))
->addOption('--image', $this->getIcon($envelope))
;
$cmd->run();
+2 -2
View File
@@ -15,7 +15,7 @@ final class NotifuNotifier extends AbstractNotifier
$cmd
->addOption('/m', $envelope->getMessage())
->addOption('/p', $this->getTitle($envelope))
->addOption('/i', $this->getIcon($envelope->getType()))
->addOption('/i', $this->getIcon($envelope))
;
$cmd->run();
@@ -23,7 +23,7 @@ final class NotifuNotifier extends AbstractNotifier
public function isSupported()
{
return $this->isEnabled() && OS::isWindows() && $this->getProgram();
return $this->isEnabled() && OS::isWindowsSeven() && $this->getProgram();
}
public function configureOptions(array $options)
@@ -15,7 +15,7 @@ final class NotifySendNotifier extends AbstractNotifier
$cmd
->addOption('--urgency', 'normal')
->addOption('--app-name', 'notify')
->addOption('--icon', $this->getIcon($envelope->getType()))
->addOption('--icon', $this->getIcon($envelope))
->addOption('--expire-time', $this->getExpireTime())
->addArgument($this->getTitle($envelope))
->addArgument($envelope->getMessage())
@@ -15,7 +15,7 @@ final class SnoreToastNotifier extends AbstractNotifier
$cmd
->addOption('-m', $envelope->getMessage())
->addOption('-t', $this->getTitle($envelope))
->addOption('-p', $this->getIcon($envelope->getType()))
->addOption('-p', $this->getIcon($envelope))
;
$cmd->run();
@@ -23,7 +23,11 @@ final class SnoreToastNotifier extends AbstractNotifier
public function isSupported()
{
return $this->isEnabled() && OS::isWindows() && $this->getProgram();
if (!$this->getProgram() || !$this->isEnabled()) {
return false;
}
return OS::isWindowsEightOrHigher() || OS::isWindowsSubsystemForLinux();
}
public function configureOptions(array $options)
@@ -15,9 +15,17 @@ final class TerminalNotifierNotifier extends AbstractNotifier
$cmd
->addOption('-message', $envelope->getMessage())
->addOption('-title', $this->getTitle($envelope))
->addOption('-appIcon', $this->getIcon($envelope->getType()))
;
if (version_compare(OS::getMacOSVersion(), '10.9.0', '>=')) {
$cmd->addOption('-appIcon', $this->getIcon($envelope));
}
$url = $envelope->getOption('url');
if ($url) {
$cmd->addOption('-open', $url);
}
$cmd->run();
}
+6 -2
View File
@@ -15,7 +15,7 @@ final class ToasterNotifier extends AbstractNotifier
$cmd
->addOption('-m', $envelope->getMessage())
->addOption('-t', $this->getTitle($envelope))
->addOption('-p', $this->getIcon($envelope->getType()))
->addOption('-p', $this->getIcon($envelope))
;
$cmd->run();
@@ -23,7 +23,11 @@ final class ToasterNotifier extends AbstractNotifier
public function isSupported()
{
return $this->isEnabled() && OS::isWindows() && $this->getProgram();
if (!$this->getProgram() || !$this->isEnabled()) {
return false;
}
return OS::isWindowsEightOrHigher() || OS::isWindowsSubsystemForLinux();
}
public function configureOptions(array $options)
+9
View File
@@ -50,4 +50,13 @@ class OS
{
return false !== strpos(self::getName(), 'Darwin');
}
public static function getMacOSVersion()
{
$cmd = new Command('sw_vers');
$cmd->addArgument('-productVersion');
$cmd->run();
return trim($cmd->getOutput());
}
}