CatalystCode / electron-windows-notifications

Call native windows notifications from Electron using NodeRT
25 stars 3 forks source link

Persistent notifcations #11

Open MehediH opened 7 years ago

MehediH commented 7 years ago

Hey guys,

Thanks for this awesome module! I played with this a bit on my Electron app, but the notifications I am getting aren't persistent and don't stay in the action center. (Not sure if I missed something)

Is there any way of making notifications persistent so that they only go away once the user removes it?

Thanks

nadavbar commented 7 years ago

Can you please share your code? The notifications should be persistent.

MehediH commented 7 years ago

The code is pretty straight forward:

function sendNotification(type, title, content, img, icon, id) {
  const template
  const strings

  if (type === "actionsImg"){
    var notifTemplate = '<toast launch="launchApp"> <visual> <binding template="ToastGeneric"> <image placement="appLogoOverride" hint-crop="circle" src="' + icon + '"/> <text>' + title + '</text> <text>' + content + '</text> <image placement="hero" src="' + img + '"/> </binding> </visual> <actions> <action content="Like" arguments="like-' + id +'"/> <action content="Retweet" arguments="rt-' + id + '"/> </actions> </toast>';

  } else if (type === "actions"){
    var notifTemplate = '<toast launch="launchApp"> <visual> <binding template="ToastGeneric"> <image placement="appLogoOverride" hint-crop="circle" src="' + icon + '"/> <text>' + title + '</text> <text>' + content + '</text></binding> </visual> <actions> <action content="Like" arguments="like-' + id +'"/> <action content="Retweet" arguments="rt-' + id + '"/> </actions> </toast>';
  }

  let notification = new ToastNotification({
        appId: "Tweeten",
        template: notifTemplate,
        strings: strings
  })

  // show notification
  notification.show()
}