-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add wsl-send-notify for WSL based Linux
- Loading branch information
Showing
7 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the JoliNotif project. | ||
* | ||
* (c) Loïck Piera <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Joli\JoliNotif\Notifier; | ||
|
||
use Joli\JoliNotif\Notification; | ||
use JoliCode\PhpOsHelper\OsHelper; | ||
|
||
/* | ||
* This notifier can be used on Windows Subsystem for Linux and provides notifications using the `wsl-notify-send` binary. | ||
* | ||
* @see https://github.com/stuartleeks/wsl-notify-send the source code of the `wsl-notify-send` binary | ||
*/ | ||
class WslNotifySendNotifier extends CliBasedNotifier implements BinaryProvider | ||
{ | ||
public function getBinary(): string | ||
{ | ||
return 'wsl-notify-send'; | ||
} | ||
|
||
public function getPriority(): int | ||
{ | ||
return static::PRIORITY_HIGH; | ||
} | ||
|
||
public function canBeUsed(): bool | ||
{ | ||
return OsHelper::isWindowsSubsystemForLinux(); | ||
} | ||
|
||
public function getRootDir(): string | ||
{ | ||
return \dirname(__DIR__, 2) . '/bin/wsl-notify-send'; | ||
} | ||
|
||
public function getEmbeddedBinary(): string | ||
{ | ||
return 'wsl-notify-send.exe'; | ||
} | ||
|
||
public function getExtraFiles(): array | ||
{ | ||
return []; | ||
} | ||
|
||
protected function getCommandLineArguments(Notification $notification): array | ||
{ | ||
$arguments = [ | ||
'--appId', | ||
'JoliNotif', | ||
$notification->getBody(), | ||
]; | ||
|
||
if ($notification->getTitle()) { | ||
$arguments[] = '-c'; | ||
$arguments[] = $notification->getTitle(); | ||
} | ||
|
||
return $arguments; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the JoliNotif project. | ||
* | ||
* (c) Loïck Piera <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Joli\JoliNotif\tests\Notifier; | ||
|
||
use Joli\JoliNotif\Notifier; | ||
use Joli\JoliNotif\Notifier\WslNotifySendNotifier; | ||
|
||
class WslNotifySendNotifierTest extends NotifierTestCase | ||
{ | ||
use BinaryProviderTestTrait; | ||
use CliBasedNotifierTestTrait; | ||
|
||
private const BINARY = 'wsl-notify-send'; | ||
|
||
public function testGetBinary() | ||
{ | ||
$notifier = $this->getNotifier(); | ||
|
||
$this->assertSame(self::BINARY, $notifier->getBinary()); | ||
} | ||
|
||
public function testGetPriority() | ||
{ | ||
$notifier = $this->getNotifier(); | ||
|
||
$this->assertSame(Notifier::PRIORITY_HIGH, $notifier->getPriority()); | ||
} | ||
|
||
protected function getNotifier(): WslNotifySendNotifier | ||
{ | ||
return new WslNotifySendNotifier(); | ||
} | ||
|
||
protected function getExpectedCommandLineForNotification(): string | ||
{ | ||
return <<<'CLI' | ||
'wsl-notify-send' '--appId' 'JoliNotif' 'I'\''m the notification body' | ||
CLI; | ||
} | ||
|
||
protected function getExpectedCommandLineForNotificationWithATitle(): string | ||
{ | ||
return <<<'CLI' | ||
'wsl-notify-send' '--appId' 'JoliNotif' 'I'\''m the notification body' '-c' 'I'\''m the notification title' | ||
CLI; | ||
} | ||
|
||
protected function getExpectedCommandLineForNotificationWithAnIcon(): string | ||
{ | ||
return <<<'CLI' | ||
'wsl-notify-send' '--appId' 'JoliNotif' 'I'\''m the notification body' | ||
CLI; | ||
} | ||
|
||
protected function getExpectedCommandLineForNotificationWithAllOptions(): string | ||
{ | ||
return <<<'CLI' | ||
'wsl-notify-send' '--appId' 'JoliNotif' 'I'\''m the notification body' '-c' 'I'\''m the notification title' | ||
CLI; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters