我有一个 Electron 应用程序,将Vue用作模板部分。
如果单击关闭按钮,应用程序将移至纸盘。
我需要从未发生的Dock/app-icon/task-bar图标重新启动应用程序。
无法从纸盘重新打开该应用程序,或者我们可以说它已经处于 Activity 状态。
波纹管是我的 Electron 主要工艺代码:
'use strict'
import fs from 'fs'
import path from 'path'
import { app, BrowserWindow, shell, ipcMain } from 'electron'
import { autoUpdater } from 'electron-updater'
import request from 'request'
if (process.env.NODE_ENV !== 'development') {
global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
}
let mainWindow
const winURL = process.env.NODE_ENV === 'development'
? `http://localhost:3600`
: `file://${__dirname}/index.html`
function createWindow () {
/**
* Initial window options
*/
mainWindow = new BrowserWindow({
minWidth: 800,
width: 1600,
height: 900,
center: true,
frame: false,
backgroundColor: '#1A1C1F'
})
mainWindow.maximize()
mainWindow.loadURL(winURL)
mainWindow.on('closed', () => {
mainWindow = null
})
mainWindow.webContents.on('new-window', (e, url) => {
e.preventDefault()
shell.openExternal(url)
})
let cliArgs = process.argv
ipcMain.on('get-cliArgs', (event, args) => {
event.sender.send('cliArgs', cliArgs)
})
if (process.env.NODE_ENV !== 'production') {
mainWindow.webContents.openDevTools()
}
}
var shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore()
mainWindow.focus()
}
})
if (shouldQuit) {
app.quit()
process.exit()
}
app.on('ready', createWindow)
app.on('window-all-closed', () => {
app.quit()
})
app.on('activate', () => {
if (mainWindow === null) {
createWindow()
}
})
app.on('ready', () => {
if (process.env.NODE_ENV === 'production') autoUpdater.checkForUpdates()
})
最佳答案
您正在使用哪个命令来最小化窗口到托盘?
在我们的应用程序中,我们执行以下操作以最小化托盘并在需要时还原窗口:
用于最小化:
win.minimize();
用于创建托盘命令以恢复窗口或退出应用程序:
tray = new Tray('<path to app icon>');
let contextMenu = Menu.buildFromTemplate([
{
label: 'showApp', click: () => {
win.maximize();
win.setAlwaysOnTop(true);
}
},
{
label: 'quit', click: () => {
app.isQuiting = true;
app.quit();
}
}
]);
tray.setToolTip('app name');
tray.setContextMenu(contextMenu);
tray.on('right-click', () => {
tray.popUpContextMenu();
})
tray.on('click', () => {
win.maximize();
win.setAlwaysOnTop(true);
// restore overlay icon when going back from tray
setOverlayIcon(currentOverlayIcon);
});
关于windows - 如何从Windows中的底座或任务栏图标重新打开托盘中的 Electron 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54684174/