-
-
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.
Merge pull request #101 from TheoD02/feat/add_wsl-send-notify
feat: Add wsl-send-notify for WSL based Linux
- Loading branch information
Showing
9 changed files
with
190 additions
and
3 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
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Stuart Leeks | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,7 @@ | ||
# wsl-notify-send | ||
|
||
These wsl-notify-send binary files come from the [stuartleeks/wsl-notify-send](https://github.com/stuartleeks/wsl-notify-send) | ||
project. All credits for this Windows WSL application goes to [Stuart Leeks](https://github.com/stuartleeks). | ||
|
||
Only the required files were extracted here. If you want to fully test it, | ||
please have a look at the github project instead. |
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