NativePHP / laravel

Laravel wrapper for the NativePHP framework
https://nativephp.com
MIT License
3.17k stars 164 forks source link

[Bug]: Cannot send a notification from scheduler or using Tinker #285

Closed jornicornelese closed 6 months ago

jornicornelese commented 6 months ago

What were you trying to do?

I created a job in which I have a notification. I'm trying to trigger it within the scheduler using: $schedule->job(MyNotification::class)->everyMinute();

Or trigger it within tinker using DispatchSync.

To test that my Job works I used a DD as well, which does trigger, but the notification won't.

The notification does trigger when used within the NativeAppServiceProvider.

What happened?

I expected the Notification to trigger, but nothing pops up.

How to reproduce the bug

Here is my Job:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Native\Laravel\Facades\Notification;

class MyNotification
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        Notification::title('Hello from NativePHP')
            ->message('This is a detail message coming from your Laravel app.')
            ->show();

        dd('Notification sent!');
    }
}

Package Versions

"nativephp/electron": "0.6.1", "nativephp/laravel":"0.5.0", "nativephp/php-bin": "0.4.0"

PHP Version

v8.2.18

Laravel Version

v10.48.10

Node Version

v18.15

Which operating systems have you seen this occur on?

macOS

OS version

14.2.1 (23C71)

Notes

No response

simonhamp commented 6 months ago

When I run this code (also on macOS 14, Laravel 10), the notification shows fine. So I think the problem isn't in NativePHP, but on your system

There are a few things to check:

1. Are Electron Notifications enabled in your System Preferences?

Screenshot 2024-05-02 at 20 17 20

If they're 'Off' (as demonstrated above), please turn them on (as demonstrated below) and try again.

Screenshot 2024-05-02 at 20 19 15

2. Do you have Do Not Disturb on?

Screenshot 2024-05-02 at 20 18 02

If so, please turn it off and try again.

Do Not Disturb will suppress most notifications (except those explicitly allowed during DND):

Screenshot 2024-05-02 at 20 21 49

If you're still having issues, please let me know.

simonhamp commented 6 months ago

@jornicornelese I'm going to close this issue for now. If you still haven't been able to figure out the cause of your troubles after trying the above, feel free to re-open with more details.