简体   繁体   English

在 electron.js 应用程序中单击通知时打开应用程序

[英]Open application when click on notification in electron.js app

I created one Electron application using webRTC where I implemented the notification for incoming call.我使用 webRTC 创建了一个 Electron 应用程序,我在其中实现了来电通知。 When I click on notification I need that my application should be open if it is minimize.当我点击通知时,我需要我的应用程序在最小化时打开。

Could anyone suggest me the way?任何人都可以建议我的方式吗?

function showNotification (body_content) {
  let myNotification = new Notification({ title: NOTIFICATION_TITLE, 
    body: `Incoming Call from ${body_content}` }).show()

  console.log(myNotification,'notification')
}

You can define the browser window variable as global and display it with the show() function when you click the notification.您可以将浏览器 window 变量定义为全局变量,并在单击通知时使用 show() function 显示它。

var browserWindow = null;

function createWindow () {
  browserWindow = new BrowserWindow({
    width: 800,
    height: 600
  })

  browserWindow.loadFile('index.html')
}

app.whenReady().then(createWindow);

function showNotification (body_content) {
  let myNotification = new Notification({ title: NOTIFICATION_TITLE, 
    body: `Incoming Call from ${body_content}` })

  console.log(myNotification,'notification')
  myNotification.show()
  myNotification.on('click', (event, arg)=>{
    console.log("notification clicked")
    browserWindow.show()
  })
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Android中,如何在单击时重新启动应用程序“应用程序正在运行”通知。 应用是否打开 - In Android How to Restart App On Click Application “onGoing” Notification. if App is open or not 当应用程序在后台运行时,单击通知项(在通知栏中)时,应用程序调用哪种方法? - Which method did application invoke when I click the notification item(in notification bar) when app is in background? Android通知(当应用打开时) - Android notification(when the app is open) 如何打开通知图标上的应用程序点击? - how to open app on notification icon click? 单击时通知打开活动中的android progressbar - android progressbar in notification open activity when click 单击Firebase通知有效负载的通知时,打开自定义Intent - Open a custom Intent when click on notification for Firebase notification payload 如何从通知或应用程序图标单击android知道应用程序打开? - How to know app open from notification or app icon click android? 打开多个应用程序选项卡时通知未关闭 - Notification is not closing when multiple application tabs are open 收到 firebase 通知时打开活动而无需单击通知 - Open activity when the firebase notification is recieved without having to click the notification 打开应用程序时检索APNS的通知 - Retrieve the APNS's notification when open app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM