微信公众号:[猫十二的日常],欢迎留言和指出问题a
我将对electron提供的基础功能过一遍,这些是一个应用软件的基本功能,也是跟用户一些操作关系密切,这个主要是针对和os系统的一些底层交互,electron进行了一系列的封装,所以我们直接调api,这个文章主要用来学习,这个只适合初学者,说明一下。欢迎各位一起来学习electron。(我的电脑是mac,可能win有问题,可能覆盖不到,童鞋见谅)还有linux也是。
通知
对于渲染进程,Electron 方便地允许开发者使用 HTML5 通知 API 发送通知,然后使用当前运行中的系统的原生通知 API 来进行显示。
#renderer.js
const myNotification = new Notification("我是标题", {
body: "这个是来自渲染进程的通知",
});
myNotification.onclick = () => {
console.log("我的点击事件被触发了");
};
console.log(121);
//我的点击事件被触发了
//121
要在主进程中显示通知,您需要使用 Notification 模块。
#main.js
function showNotification() {
if (Notification.isSupported()) { //检测系统是不是支持
const notification = {
title: "基础通知",
body: "来自主进程的通知",
};
let notice = new Notification(notification);
setTimeout(() => {
notice.show();
}, 3000);
return;
} //不加延迟的话,出不来,可能是异步的问题
return console.log("系统不支持");
}
app.whenReady().then(createWindow).then(showNotificat