Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
22 changes: 20 additions & 2 deletions resources/electron/electron-plugin/dist/server/api/notification.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
import express from 'express';
import { Notification } from 'electron';
import { notifyLaravel } from "../utils.js";
import playSoundLib from 'play-sound';
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 && typeof sound === 'string') {
try {
playSoundLib().play(sound, () => { });
}
catch (e) {
const { exec } = require('child_process');
exec(`afplay "${sound}"`, () => { });
}
}
notification.on("click", (event) => {
notifyLaravel('events', {
event: eventName || '\\Native\\Desktop\\Events\\Notifications\\NotificationClicked',
Expand Down
24 changes: 22 additions & 2 deletions resources/electron/electron-plugin/src/server/api/notification.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import express from 'express';
import { Notification } from 'electron';
import {notifyLaravel} from "../utils.js";
declare const require: any;
import playSoundLib from 'play-sound';

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 +35,33 @@ 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 && typeof sound === 'string') {
try {
playSoundLib().play(sound, () => {});
} catch (e) {
const { exec } = require('child_process');
exec(`afplay "${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
Loading