h2> on pit
turn on electron, and found that the system tray icon would automatically disappear after a period of time. To solve this problem, I found the reason why the system tray icon would automatically disappear.
Reason
h2>
when we declare a variable in Tray, we do not declare it as a global variable, which results in it being recycled by the garbage collection mechanism during operation.
solution h2>
declares the variable of the storage window/system tray as a global variable, that is, it is declared before app.on('ready',fuc)
in main.js. In the app. On (' ready 'fuc) code> internal part to use
code: p>
//创建系统托盘图标
let iconTary = null
let path = require('path')
let {Tray} = require('electron')
//将iconTary声明为全局变量
let iconTary = null
app.on('ready',() => {
//将iconTary赋值Tary模块
iconTary = new Tray(path.join(__dirname,'../static/flag.png'))
})
problem solved.
Read More:
- How to solve the problem that the console window disappears in a flash after visual studio 2017 runs
- Solve the problem that Windows 7 cannot be updated automatically_ Prompt error code 80246008
- An error is reported when the electron Vue Vue component introduces the electron
- error 1962:no operating system found.boot sequence will automatically repeat.
- Quickly solve the problem of Vmware virtual machine “\\.\Global\vmx86”: the system cannot find the specified file
- Solve the problem of non system disk or disk error, replace and strike any key when ready
- Solve rstudio software error: fatal error error system error 5 (access denied) problem, pro test effective
- Solve the problem that comdlg32.ocx, mscomm32.ocx and other controls cannot be registered under WIN7 64-bit system
- Apple computer download file automatically with suffix problem solving
- To solve the problem that deep in 20.2 system cannot save and transform the format of typora, and provide an effective installation method of typora
- Solve Charles use 30 minutes to automatically close
- Solution to electron error “cannot find module app”
- Centos7 solves the problem of unable to use tab to complete automatically
- Android studio “sync project with gradle files” button disappears
- MacOS: How to Fix Intellij-IDEA main menu disappears Bug
- Problems in compiling and using node FFI under electron
- Win10 system [createfile() error: 5] problem solving
- Error: cannot load system.img problem
- The version number of robot JS running by electron does not match
- “Practical tips” to solve the error after installing inode in MAC system: libcoreutils.dylib