覆盖电子通知弹出窗口

Override Electron Notification Popup

我有一个电子应用程序,只有一个浏览器窗口和一个 URL 我们在内部使用的网络应用程序。我想覆盖通知 Window。你有什么建议可以给我吗?

我尝试了以下方法,应该清楚我想做什么:

renderer.js(预加载)

const ipc = require('electron').ipcRenderer;

window.Notification.onshow = function (ev) {
    ipc.send("notification-show", ev);
};

index.js

const ipc = require('electron').ipcMain;

ipc.on('notification-show', function (event, arg) {
    // tray.setImage(__dirname + "/images/favicon-notification.ico");
    var notification = new VcpNotification(arg.title, arg.text);
    notification.show();
});

知道了,很简单。

在您的 renderer.js 中执行以下操作:

var Notification = function(title,ops) {
    ipc.send("notification-show", {title: title, options: ops});
};
Notification.requestPermission = () => {};
Notification.permission = "granted";
window.Notification = Notification;

这将覆盖 Notification 对象,您可以在 IPC 通道内的任何地方捕获它 "notification-show"。