【发布时间】:2020-09-18 03:21:09
【问题描述】:
如果有托盘,是否可以在窗口(Windows 操作系统)上使用.minimize()?现在我想将它隐藏到 Windows Dock 中(或者它是如何调用的?),但是当我在应用程序中有托盘并试图在浏览器窗口上调用 .minimize() 时,什么也没有发生。当然,我可以改用 .hide(),但我想将其保留在 Dock 中,而不是完全隐藏它。
我正在使用电子 10.1.1。
例如:
// First we have to create the window
const { BrowserWindow, Tray } = require('electron')
const win = new BrowserWindow({ width: 800, height: 600 });
win.loadURL('https://github.com');
// Then we have to create tray
const tray = new Tray('/path/to/my/icon')
const contextMenu = Menu.buildFromTemplate([
{ label: 'Item1', type: 'radio' },
{ label: 'Item2', type: 'radio' },
{ label: 'Item3', type: 'radio', checked: true },
{ label: 'Item4', type: 'radio' }
])
tray.setToolTip('This is my application.')
tray.setContextMenu(contextMenu)
// Here we expect application will be hidden into windows dock, but nothing happens.
win.minimize()
将不胜感激任何帮助,谢谢!
【问题讨论】:
-
你写
const = new Tray(..)。当然,这会产生错误:Uncaught SyntaxError: Unexpected token '='。没有它,它运行良好,并且窗口在启动后立即最小化。 -
@snwflk 最好有语法错误。 :) 当我做了一个例子时,这只是我的错误。真正的源代码没有语法错误。
标签: electron