windowutils.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const app = require('electron')
  2. const remote = require('electron').BrowserWindow
  3. /**
  4. * Doesn't work yet.
  5. */
  6. exports.setIconBadge = function(text){
  7. if(process.platform === 'darwin'){
  8. app.dock.setBadge('' + text)
  9. } else if (process.platform === 'win32'){
  10. const win = remote.getFocusedWindow()
  11. if(text === ''){
  12. win.setOverlayIcon(null, '')
  13. return;
  14. }
  15. //Create badge
  16. const canvas = document.createElement('canvas')
  17. canvas.height = 140;
  18. canvas.width = 140;
  19. const ctx = canvas.getContext('2d')
  20. ctx.fillStyle = '#a02d2a'
  21. ctx.beginPath()
  22. ctx.ellipse(70, 70, 70, 70, 0, 0, 2 * Math.PI)
  23. ctx.fill()
  24. ctx.textAlign = 'center'
  25. ctx.fillStyle = 'white'
  26. if(text.length > 2 ){
  27. ctx.font = '75px sans-serif'
  28. ctx.fillText('' + text, 70, 98)
  29. } else if (text.length > 1){
  30. ctx.font = '100px sans-serif'
  31. ctx.fillText('' + text, 70, 105)
  32. } else {
  33. ctx.font = '125px sans-serif'
  34. ctx.fillText('' + text, 70, 112)
  35. }
  36. const badgeDataURL = canvas.toDataURL()
  37. const img = NativeImage.createFromDataURL(badgeDataURL)
  38. win.setOverlayIcon(img, '' + text)
  39. }
  40. }