当前位置: 首页 > wzjs >正文

东莞seo网站关键词优优化腾讯邮箱官网

东莞seo网站关键词优优化,腾讯邮箱官网,下载站源码cms,如何把自己写的html变成网站完成初始应用的创建Electron桌面应用开发:创建应用,随后我们就可以自定义软件的菜单了。菜单可以帮助用户快速找到和执行命令,而不需要记住复杂的快捷键,通过将相关功能组织在一起,用户可以更容易地发现和使用应用程序…

    完成初始应用的创建Electron桌面应用开发:创建应用,随后我们就可以自定义软件的菜单了。菜单可以帮助用户快速找到和执行命令,而不需要记住复杂的快捷键,通过将相关功能组织在一起,用户可以更容易地发现和使用应用程序的各种特性。同时菜单允许开发者提供更多的功能选项而不必担心界面会因此变得拥挤或难以导航,比如下拉菜单弹出菜单等可以在有限的空间内提供大量的选项。
Electron的原始菜单为以下页面:
在这里插入图片描述

取消顶部菜单显示

这里可以使用两种常用的方法,第一种是在窗口创建函数中设置frame: false

const {app, BrowserWindow, Menu} = require('electron');let win = null;function createWindow() {win = new BrowserWindow({width: 800,height: 600,frame: false,webPreferences: {nodeIntegration: true},});win.loadFile('index.html');win.on('closed', () => {win = null;});
}app.on('ready', createWindow);app.on('window-all-closed', () => {if (process.platform !== 'darwin') {app.quit();}
});

这样大小化和关闭按钮、标题也全部消失了,所以只适合个别情况使用。
在这里插入图片描述
第二种是在创建窗口函数中加入Menu.setApplicationMenu(null);设置,这样可以保留标题等内容:

const {app, BrowserWindow, Menu} = require('electron');let win = null;function createWindow() {win = new BrowserWindow({width: 800,height: 600,webPreferences: {nodeIntegration: true},});win.loadFile('index.html');Menu.setApplicationMenu(null);win.on('closed', () => {win = null;});
}app.on('ready', createWindow);app.on('window-all-closed', () => {if (process.platform !== 'darwin') {app.quit();}
});

在这里插入图片描述

自定义子菜单

    这里我们可以在主文件main.js中直接添加自定义菜单的代码,也可以新建一个menu.js文件,随后在main.js中进行引用(个人推荐做法)
在Electron中定义菜单需要先引入Menu

const {Menu} = require('electron')

定义格式如下:

    const template = [{label: '菜单1',submenu: [{label: '子菜单1'},{label: '子菜单2',}]},{label: '菜单2',submenu: [{label: '子菜单1'},{label: '子菜单2',submenu: [{label: '孙子菜单1'},{label: '孙子菜单2'}]}]}]

可以使用click来监听事件,例如:

            {label: '欧耶',accelerator: 'CmdOrCtrl+O',click: () => {console.log('菜单被点击了');}},

main.js中直接添加菜单代码的格式如下:

const { app, BrowserWindow, Menu } = require('electron');let win = null;function createWindow() {win = new BrowserWindow({width: 800,height: 600,webPreferences: {nodeIntegration: true},});win.loadFile('index.html');win.on('closed', () => {win = null;});
}const template = [{label: '菜单1',submenu: [{label: '子菜单1'},{label: '子菜单2',}]},{label: '菜单2',submenu: [{label: '子菜单1'},{label: '子菜单2',submenu: [{label: '孙菜单1'},{label: '孙菜单2'}]}]},{label: '帮助',role: 'help',click() { require('electron').shell.openExternal('https://example.com/help') }}
];const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);app.on('ready', createWindow);app.on('window-all-closed', () => {if (process.platform !== 'darwin') {app.quit();}
});app.on('activate', () => {if (win === null) {createWindow();}
});

这里我们还是推荐使用将创建菜单的代码转移到其他文件中,比如新建一个menu.js,这样可以更加方便的进行代码编写和问题排查:
main.js:

const {app, BrowserWindow, Menu} = require('electron');
// 引入menu.js文件
const menuTemplate = require('./menu.js'); let win = null;function createWindow() {win = new BrowserWindow({width: 800,height: 600,webPreferences: {nodeIntegration: true},});win.loadFile('index.html');win.on('closed', () => {win = null;});// 创建窗口const menu = Menu.buildFromTemplate(menuTemplate(win));Menu.setApplicationMenu(menu);
}app.on('ready', createWindow);app.on('window-all-closed', () => {if (process.platform !== 'darwin') {app.quit();}
});

menu.js:

const {Menu} = require('electron')module.exports = function (win) {const template = [{label: '菜单1',submenu: [{label: '子菜单1'},{label: '子菜单2',}]},{label: '菜单2',submenu: [{label: '子菜单1'},{label: '子菜单2',submenu: [{label: '孙菜单1'},{label: '孙菜单2'}]}]},{label: '帮助',role: 'help',click() { require('electron').shell.openExternal('https://example.com/help') }}]return template;
}

两种方法的最终效果如下:
在这里插入图片描述

上下文菜单

上下文菜单通常在用户右键点击某个元素时显示,通常通过监听事件来创建和显示上下文菜单。
在主文件中需要导入ipcMain模块,main.js:

const { app, BrowserWindow, Menu, ipcMain } = require('electron');
const menuTemplate = require('./menu.js');let win = null;function createWindow() {win = new BrowserWindow({width: 800,height: 600,webPreferences: {nodeIntegration: true,contextIsolation: false,preload: __dirname + './preload.js'},});win.loadFile('index.html');const menu = Menu.buildFromTemplate(menuTemplate(win));Menu.setApplicationMenu(menu);win.on('closed', () => {win = null;});
}app.on('ready', createWindow);app.on('window-all-closed', () => {if (process.platform !== 'darwin') {app.quit();}
});app.on('activate', () => {if (win === null) {createWindow();}
});

renderer.js,DOM内容加载完成后执行的逻辑:

document.addEventListener('DOMContentLoaded', () => {
});

使用preload脚本处理上下文菜单的preload.js, 用于安全地暴露API给渲染进程:

const { contextBridge, ipcRenderer } = require('electron');contextBridge.exposeInMainWorld('electronAPI', {send: (channel, data) => {// 向主进程发送消息ipcRenderer.send(channel, data);},receive: (channel, func) => {// 接收来自主进程的消息ipcRenderer.on(channel, (event, ...args) => func(...args)); }
});

menu.js:

const {Menu} = require('electron')module.exports = function (win) {const template = [{label: '菜单1',submenu: [{label: '子菜单1'},{label: '子菜单2',}]},{label: '菜单2',submenu: [{label: '子菜单1'},{label: '子菜单2',submenu: [{label: '孙菜单1'},{label: '孙菜单2'}]}]},{label: '帮助',role: 'help',click() { require('electron').shell.openExternal('https://example.com/help') }}]return template;
}

index.html:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="stylesheet" href="./style.css"><title>GGBond勇猛无敌</title>
</head>
<body><h1>Hello GGBond</h1><script src="./renderer.js"></script>
</body>
</html>

在这里插入图片描述

弹出式菜单

弹出式菜单可以通过编程方式手动显示,不需要特定的触发事件。
main.js:

const { app, BrowserWindow, Menu } = require('electron');
const menuTemplate = require('./menu.js'); // 引入自定义菜单模板let win = null;function createWindow() {win = new BrowserWindow({width: 800,height: 600,webPreferences: {nodeIntegration: true,contextIsolation: false, // 在使用nodeIntegration时需要禁用contextIsolationpreload: __dirname + '/preload.js' // 使用preload脚本处理上下文菜单},});win.loadFile('index.html');win.on('closed', () => {win = null;});const menu = Menu.buildFromTemplate(menuTemplate(win));Menu.setApplicationMenu(menu); // 设置为应用菜单
}app.on('ready', createWindow);app.on('window-all-closed', () => {if (process.platform !== 'darwin') {app.quit();}
});app.on('activate', () => {if (win === null) {createWindow();}
});

使用preload脚本处理上下文菜单的preload.js,使用contextBridge来安全地暴露API给渲染进程,允许渲染进程调用showPopupMenu方法。:

const { contextBridge, ipcRenderer } = require('electron');contextBridge.exposeInMainWorld('electronAPI', {showPopupMenu: (x, y) => {ipcRenderer.invoke('show-popup-menu', x, y);}
});

renderer.js:

document.addEventListener('DOMContentLoaded', () => {document.body.addEventListener('click', (event) => {window.electronAPI.showPopupMenu(event.x, event.y);});
});

menu.js:

const {Menu} = require('electron')module.exports = function (win) {const template = [{label: '菜单1',submenu: [{label: '子菜单1'},{label: '子菜单2',}]},{label: '菜单2',submenu: [{label: '子菜单1'},{label: '子菜单2',submenu: [{label: '孙菜单1'},{label: '孙菜单2'}]}]},{label: '帮助',role: 'help',click() { require('electron').shell.openExternal('https://example.com/help') }}]return template;
}

index.html:

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="stylesheet" href="./style.css"><title>GGBond勇猛无敌</title>
</head>
<body><h1>Hello GGBond</h1><script src="./src/renderer.js"></script>
</body>
</html>

文章转载自:

http://QZ6yxnw4.bfLws.cn
http://60HFhZh1.bfLws.cn
http://NTIvojtK.bfLws.cn
http://MuoIv6I0.bfLws.cn
http://YL3Lc01X.bfLws.cn
http://G5sg1KIR.bfLws.cn
http://eVnADWUW.bfLws.cn
http://aDD9IHeO.bfLws.cn
http://tl3V2n0t.bfLws.cn
http://HjIigPpX.bfLws.cn
http://fdE50xcx.bfLws.cn
http://1jDWKMBe.bfLws.cn
http://6CFpPykU.bfLws.cn
http://UOjwGEaS.bfLws.cn
http://640cxZeC.bfLws.cn
http://mfIczkW1.bfLws.cn
http://OiQ6CbK5.bfLws.cn
http://86rx1o8V.bfLws.cn
http://sIkRiq9L.bfLws.cn
http://Viq2jNPj.bfLws.cn
http://TGppAJFR.bfLws.cn
http://4zonJUIe.bfLws.cn
http://dy8pUXAL.bfLws.cn
http://VzJvgFu8.bfLws.cn
http://4RKIr3Oh.bfLws.cn
http://YxScvznY.bfLws.cn
http://Y3JdaeMb.bfLws.cn
http://bejoIgQE.bfLws.cn
http://tIWf5Q14.bfLws.cn
http://bysFbE31.bfLws.cn
http://www.dtcms.com/wzjs/773121.html

相关文章:

  • 高仿卡西欧手表网站logo大师
  • 网站建设公司 知道万维科技搜索引擎营销原理是什么
  • 网站建设的会计核算赚钱做网站
  • 临海建设银行网站河南app开发公司
  • 推荐 南昌网站建设网站后台管理员职责
  • 网站被百度降权seo推广公司价格
  • 个人备案网站内不能出现什么内容淄博网站营销与推广
  • wordpress 网址 建站wordpress xml-rpc
  • 网站导航图标muse做网站
  • 合肥网站建设怎么样网站侧面菜单展开怎么做
  • 哪里做网站便宜app小程序开发团队
  • 网站建设岗位是干什么的软文发布网站
  • 菜馆网站制作c#网站开发技术
  • 什么是网站建设?小型建筑公司有哪些
  • 淮安公司做网站自己做的网站怎么添加文档
  • 家具网站后台模板wordpress文章排版
  • 官方网站建设银行年利息是多少安阳县地图
  • 广州智能建站建设工程抗震应当坚持的原则
  • 网站 颜色标准网站怎么登陆后台
  • 深圳知名网站外国食品优秀设计网站
  • 衡水网站建设知识定州做网站
  • 网站建站系统有哪些活动策划方案
  • 网站开发充值功能wordpress简约商城
  • 怎么建设自己公司的网站首页建站平台与建站系统
  • seo网站模版郑州外贸网站建设商家
  • 企业门户网站模板html上线互联网平台营销
  • wp可以做商城网站吗前端自我介绍面试技巧
  • 云南省建设工程造价管理协会网站小发明小制作简单易学
  • 网站建设与管理 十四五国规教材售后服务网站
  • 摄影网站设计论文官方智慧团建网站