问题
I want to extend native window.Notification
to handle click events in an Electron
app (renderer process). I had this working on TypeScript 2
:
const nativeNotification = window.Notification;
const ProxyNotification = (title: any, options: any) => {
const mirrorNotification = new nativeNotification(title, options);
mirrorNotification.onclick = (event) => {
console.log("NOTIFICATION CLICKED!")
};
};
ProxyNotification.permission = nativeNotification.permission;
ProxyNotification.requestPermission = nativeNotification.requestPermission;
window.Notification = ProxyNotification;
In TypeScript 4
isn't working (see). I tried something like this:
const nativeNotification = window.Notification;
class ProxyNotification extends Notification {
constructor(title: string, options?: NotificationOptions | undefined) {
const mirrornotification = new nativeNotification(title, options);
mirrornotification.onclick = (event) => {
console.log("NOTIFICATION CLICKED!")
};
super(title, options);
}
}
window.Notification = ProxyNotification;
I also tried to overwrite onclick property or addEventListener method inside ProxyNotification class, but I cannot make it works. Any help will be appreciate.
Kind regards.
来源:https://stackoverflow.com/questions/65370936/how-to-extend-native-window-notification-to-handle-click-events-typescript-4-1