This repository has been archived on 2025-01-09. You can view files and clone it, but cannot push or open issues or pull requests.

29 lines
659 B
JavaScript
Raw Normal View History

2025-01-09 18:30:49 +08:00
const { remote } = require('electron')
const Menu = remote.Menu
let contextTemp = [
{lable: 'Run Code'},
{lable: '转到定义'},
{type: 'separator'},
{
lable: '其他功能',
click() {
alert('其他功能选项');
}
},
]
let menu = Menu.buildFromTemplate(contextTemp)
// 给鼠标添加监听
window.addEventListener('DOMContentLoaded', () => {
window.addEventListener('contextmenu', (ev) => {
ev.preventDefault()
menu.popup({window: remote.getCurrentWindow()})
}, false)
})
/**
* 01 创建一个自定义的菜单内容
* 02 在鼠标右击行为发生后显示出来
*/