electron 设置开机自启动后 托盘图标无法显示

问题描述

electron 设置开机自启动后 托盘图标无法显示

问题解决

tray = new Tray(path.join(__dirname, './public/logo.png')); //必须是绝对路径和扩展名,像.png等

我的问题是图标之前设置为相对路径,而导致无法显示。将Tray的图标路径设定为绝对路径后,问题解决。

扩展

自启动的两种方式:

  1. 通过自带API
   app.setLoginItemSettings({
     openAtLogin: true,
     path: app.getPath('exe'),
   });
  1. 通过插件jsoncelectron-auto-launch
const AutoLaunch = require('electron-auto-launch');

let autoLaunch = new AutoLaunch({
  name: '可执行文件名称',
  path: app.getPath('exe'),
});

autoLaunch.isEnabled().then((isEnabled) => {
  if (!isEnabled) autoLaunch.enable();
});

你可能感兴趣的:(electron,electron,前端,javascript)