How to extend native window.Notification to handle click events (TypeScript 4.1.2)

最后都变了- 提交于 2021-02-10 16:20:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!