Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why did not become a tray after packaging, but a window #12

Open
2812848295 opened this issue May 12, 2022 · 2 comments
Open

Why did not become a tray after packaging, but a window #12

2812848295 opened this issue May 12, 2022 · 2 comments

Comments

@2812848295
Copy link

3DU6(XOJBECQ_EWUFRRXJ8J
)5 JTY~3{9AX7%_2A@DIY%K

Before packing - After packing

@2812848295
Copy link
Author

import { Tray, BrowserWindow, ipcMain, app, session } from "electron";
const path = require("path");
const TrayWindow = require("electron-tray-window");
const log = require("electron-log");
let trayAll = {
win32: {
production: path.join("resources/static/tray"),
development: path.join("../../static/tray"),
},
};
const Createtray = () => {
let win = new BrowserWindow({
frame: false,
hasShadow: true,
webPreferences: {
nodeIntegration: true, // 使用node
contextIsolation: false, // 为了解决require 识别问题
},
});
win.shadow = true;
win.webContents.openDevTools();
// console.log(require(path.join(__dirname, "../static/tray/tray.html")));
win.loadURL(path.join(__dirname, "../static/tray/tray.html"));
TrayWindow.setOptions({
trayIconPath: path.join(__dirname, "../src/assets/Tessync.ico"),
window: win,
});
TrayWindow.setWindowSize({
width: 400, //optional
height: 500, //optional
margin_x: 0, //optional
margin_y: 30, //optional
});
ipcMain.on("tray-window-ready", (e, a) => {
console.log("托盘窗口已准备就绪");
// console.log(e.window)
// console.log(e.tray)
});

ipcMain.on("tray-window-clicked", (e, a) => {
console.log("单击托盘图标");
// console.log(e.window)
// console.log(e.tray)
});

ipcMain.on("tray-window-visible", (e, a) => {
console.log("托盘窗口现在可见");
// console.log(e.window)
// console.log(e.tray)
});

ipcMain.on("tray-window-hidden", (e, a) => {
console.log("托盘窗口现在隐藏");
// console.log(e.window)
// console.log(e.tray)
});

ipcMain.handle("tray_hide", (e, a) => {
win.hide();
// console.log(e.window)
// console.log(e.tray)
});
};

export { Createtray };
托盘代码是这样的

@lekhahuynh
Copy link

This ticket has been around for a long time, but I'm still chatting so that everyone who encounters it can handle this issue. The reason for this issue is that when packaging, the path to load the tray icon is no longer correct. Please check the icon assets path again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants