29 lines
659 B
JavaScript
29 lines
659 B
JavaScript
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 在鼠标右击行为发生后显示出来
|
|
*/ |