简体   繁体   English

运行电子生成器后 setBadgeCount() 不起作用

[英]setBadgeCount() not working after running electron-builder

setBadgeCount() is not working after running electron-builder运行electron-buildersetBadgeCount()不起作用

Everything is working when running locally, but when I run yarn electron-builder the distributed app does not update the badge count, no matter what method I use.在本地运行时一切正常,但是当我运行yarn electron-builder时,无论我使用什么方法,分布式应用程序都不会更新徽章计数。 I've check the build folder inside my repo and the compiled function is there.我检查了我的 repo 中的 build 文件夹,编译后的 function 就在那里。 The breaking step is somewhere in the electron-builder deployment.突破步骤是在electron-builder部署中的某个地方。

electron: "^8.2.3"

electron-builder: "^22.5.1"

React Component反应组件

const { app } = window.require('electron').remote;

function openCountText(count) {
  let badgeCount = `(${count}) `;
  if (!count) badgeCount = '';
  if (count > 9) badgeCount = '(9+) ';

  // Sets the badge count on the Desktop Application
  !!count && !!app && app.dock.setBadgeCount(count)

  return badgeCount;
}

Variations (Some of these methods are deprecated)变化(其中一些方法已弃用)

  !!count && !!app && app.dock.setBadge(`${count}`)
  !!count && !!app && app.dock.setBadge("19")
  !!count && !!app && app.setBadgeCount(2)

try to use:尝试使用:

const { app } = require('electron');
let badgeCount = 0;
    
app.setBadgeCount(badgeCount + 1);
// `0` will hide the badge.
app.setBadgeCount(badgeCount = 0);

docs https://www.electronjs.org/docs/api/app#appsetbadgecountcount-linux-macos文档https://www.electronjs.org/docs/api/app#appsetbadgecountcount-linux-macos

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM