Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions resources/electron/electron-plugin/dist/server/api/notification.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,49 @@
import express from 'express';
import { Notification } from 'electron';
import { notifyLaravel } from "../utils.js";
import { notifyLaravel, broadcastToWindows } from "../utils.js";
import playSoundLib from 'play-sound';
import fs from 'fs';
const isLocalFile = (sound) => {
if (typeof sound !== 'string')
return false;
if (/^https?:\/\//i.test(sound))
return false;
return sound.includes('/') || sound.includes('\\');
};
const router = express.Router();
router.post('/', (req, res) => {
const { title, body, subtitle, silent, icon, hasReply, timeoutType, replyPlaceholder, sound, urgency, actions, closeButtonText, toastXml, event: customEvent, reference, } = req.body;
const eventName = customEvent !== null && customEvent !== void 0 ? customEvent : '\\Native\\Desktop\\Events\\Notifications\\NotificationClicked';
const notificationReference = reference !== null && reference !== void 0 ? reference : (Date.now() + '.' + Math.random().toString(36).slice(2, 9));
const usingLocalFile = isLocalFile(sound);
const notification = new Notification({
title,
body,
subtitle,
silent,
silent: usingLocalFile ? true : silent,
icon,
hasReply,
timeoutType,
replyPlaceholder,
sound,
sound: usingLocalFile ? undefined : sound,
urgency,
actions,
closeButtonText,
toastXml
});
if (usingLocalFile && !silent) {
fs.access(sound, fs.constants.F_OK, (err) => {
if (err) {
broadcastToWindows('log', {
level: 'error',
message: `Sound file not found: ${sound}`,
context: { sound }
});
return;
}
playSoundLib().play(sound, () => { });
});
}
notification.on("click", (event) => {
notifyLaravel('events', {
event: eventName || '\\Native\\Desktop\\Events\\Notifications\\NotificationClicked',
Expand Down
33 changes: 30 additions & 3 deletions resources/electron/electron-plugin/src/server/api/notification.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import express from 'express';
import { Notification } from 'electron';
import {notifyLaravel} from "../utils.js";
import {notifyLaravel, broadcastToWindows} from "../utils.js";
declare const require: any;
import playSoundLib from 'play-sound';
import fs from 'fs';

const isLocalFile = (sound: unknown) => {
if (typeof sound !== 'string') return false;
if (/^https?:\/\//i.test(sound)) return false;
// Treat any string containing path separators as a local file
return sound.includes('/') || sound.includes('\\');
};
const router = express.Router();

router.post('/', (req, res) => {
Expand All @@ -26,22 +36,39 @@ router.post('/', (req, res) => {

const notificationReference = reference ?? (Date.now() + '.' + Math.random().toString(36).slice(2, 9));

const usingLocalFile = isLocalFile(sound);

const notification = new Notification({
title,
body,
subtitle,
silent,
silent: usingLocalFile ? true : silent,
icon,
hasReply,
timeoutType,
replyPlaceholder,
sound,
sound: usingLocalFile ? undefined : sound,
urgency,
actions,
closeButtonText,
toastXml
});

if (usingLocalFile && !silent) {
fs.access(sound, fs.constants.F_OK, (err) => {
if (err) {
broadcastToWindows('log', {
level: 'error',
message: `Sound file not found: ${sound}`,
context: { sound }
});
return;
}

playSoundLib().play(sound, () => {});
});
}

notification.on("click", (event) => {
notifyLaravel('events', {
event: eventName || '\\Native\\Desktop\\Events\\Notifications\\NotificationClicked',
Expand Down
31 changes: 31 additions & 0 deletions resources/electron/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions resources/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"get-port": "^7.1.0",
"kill-sync": "^1.0.3",
"nodemon": "^3.1.9",
"play-sound": "^1.1.3",
"ps-node": "^0.1.6",
"tree-kill": "^1.2.2",
"yauzl": "^3.2.0"
Expand Down
2 changes: 2 additions & 0 deletions src/Facades/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
/**
* @method static static title(string $title)
* @method static static event(string $event)
* @method static static sound(string $sound)
* @method static static silent(bool $silent = true)
* @method static static message(string $body)
* @method static static reference(string $reference)
* @method static static hasReply(string $placeholder = '')
Expand Down
20 changes: 20 additions & 0 deletions src/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class Notification

protected string $event = '';

protected string $sound = '';

protected bool $silent = false;

private bool $hasReply = false;

private string $replyPlaceholder = '';
Expand Down Expand Up @@ -54,6 +58,20 @@ public function event(string $event): self
return $this;
}

public function sound(string $sound): self
{
$this->sound = $sound;

return $this;
}

public function silent(bool $silent = true): self
{
$this->silent = $silent;

return $this;
}

public function hasReply(string $placeholder = ''): self
{
$this->hasReply = true;
Expand Down Expand Up @@ -83,6 +101,8 @@ public function show(): self
'title' => $this->title,
'body' => $this->body,
'event' => $this->event,
'sound' => $this->sound,
'silent' => $this->silent,
'hasReply' => $this->hasReply,
'replyPlaceholder' => $this->replyPlaceholder,
'actions' => array_map(fn (string $label) => [
Expand Down
Loading