Intento usar notificar en mi proyecto de electrones en el servidor de nodos. Así que instalé el módulo notificador de nodos en la carpeta de mi aplicación usando el siguiente comando.
$ npm install --save node-notifier Después de eso, agrego un botón a mi página web para mostrar el mensaje de notificación.
Cuando el usuario hace clic en el botón, se ejecuta el siguiente método js:
<script type = "text/javascript"> const notifier = require('node-notifier') const path = require('path'); document.getElementById('notify').onclick = (event) => { notifier.notify ({ title: 'My awesome title', message: 'Hello from electron, Mr. User!', icon: path.join('','images/images.png'), // Absolute path (doesn't work on balloons) sound: true, // Only Notification Center or Windows Toasters wait: true // Wait with callback, until user action is taken against notification }, function (err, response) { // Response is response from notification }); notifier.on('click', function (notifierObject, options) { console.log("You clicked on the notification") }); notifier.on('timeout', function (notifierObject, options) { console.log("Notification timed out!") }); } </script>Pero cuando hago clic en mi botón de notificación, aparece el siguiente error:
Uncaught TypeError: _crypto.default.randomFillSync is not a function rng @ Project\MyElectronProject\node_modules\uuid\dist\rng.js:19 v4 @ Project\MyElectronProject\node_modules\uuid\dist\v4.js:17 getPipeName @ Project\MyElectronProject\node_modules\node-notifier\notifiers\toaster.js:51 notifyRaw@ Project\MyElectronProject\node_modules\nodenotifier\notifiers\toaster.js:60 document.getElementById.onclick @notification_index.html:16El error anterior arroja la función rng en rng.js.
function rng() { if (poolPtr > rnds8Pool.length - 16) { debugger; _crypto.default.randomFillSync(rnds8Pool); poolPtr = 0; }El método randomFillSync no existe. No puedo entender este error, ¿ha encontrado este error antes? Gracias por tus sugerencias.
versión de nodo que usé en mi proyecto: v16.13.1
node-notifier es un módulo nodejs, no se puede usar en el script del navegador.
Creo que debería llamar al notificador de nodos en el proceso principal y luego comunicarse desde un proceso de representación al proceso principal.
Consulte: https://www.electronjs.org/docs/latest/api/ipc-renderer