Skip to content

Commit

Permalink
Make LibNotifyDriver working inside a PHAR
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrech committed May 3, 2024
1 parent 59939dd commit d3530fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,6 @@ jobs:
- name: Trigger a notification
run: |
tools/phar/build/jolinotif.phar --title "Yolo" --body "Hello world!" --verbose
# This command will fail because libnotify will fail to send a notification to a real desktop environment
# But we still ensure that everything else in the PHAR works
tools/phar/build/jolinotif.phar --title "Yolo" --body "Hello world!" --verbose | grep "Notification failed with LibNotifyDriver"
9 changes: 8 additions & 1 deletion src/Driver/LibNotifyDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Joli\JoliNotif\Exception\FFIRuntimeException;
use Joli\JoliNotif\Exception\InvalidNotificationException;
use Joli\JoliNotif\Notification;
use Joli\JoliNotif\Util\PharExtractor;
use JoliCode\PhpOsHelper\OsHelper;

class LibNotifyDriver implements DriverInterface
Expand Down Expand Up @@ -72,7 +73,13 @@ private function initialize(): void
return;
}

$ffi = \FFI::load(__DIR__ . '/FFI/ffi-libnotify.h');
$headerFile = __DIR__ . '/FFI/ffi-libnotify.h';

if (PharExtractor::isLocatedInsideAPhar($headerFile)) {
$headerFile = PharExtractor::extractFile($headerFile);
}

$ffi = \FFI::load($headerFile);

if (!$ffi) {
throw new FFIRuntimeException('Unable to load libnotify');
Expand Down

0 comments on commit d3530fd

Please sign in to comment.