我只是使用node-notifier包发送通知。此外,当我点击通知时,它必须转到一个链接。但是我听不到点击事件。包提供的事件什么都不做。这是我的代码:
const notifier = require("node-notifier");
const open = require("open");
notifier.notify({
title: "Stackoverflow",
message: "A message",
wait: true,
open: "https://stackoverflow.com/",
});
notifier.on("click", function (notifierObject, options, event) {
open("https://sindresorhus.com");
});
Run Code Online (Sandbox Code Playgroud)
这是我的通知:
我可以使用任何其他包。我只想听点击事件。
@ user120242 的答案有效,但在通知消失后单击无效。有什么办法吗?我添加了一个gif。
有谁知道如何测试nodejs中的mail-notifier模块?我想测试里面的逻辑n.on():
const notifier = require('mail-notifier');
const imap = {
user: 'mailId',
password: 'password',
host: 'host',
port: 'port',
tls: true,
tlsOptions: { rejectUnauthorized: false }
};
const n = notifier(imap);
n.on('mail', async function (mail) {
console.log('mail:', mail);
}).start();
Run Code Online (Sandbox Code Playgroud) 我想在电子桌面应用程序中实现通知的粘性行为,直到用户单击通知本身。
我正在使用node-notifier来实现此文档,并使用ngx-electron使用 ElectronService 在角度组件文件中导入 main.js 文件。
这是我的main.js文件:
const notifier = require('node-notifier')
exports.notifier = (msg) => {
notifier.notify({
title: 'Notify Me',
message: msg,
wait: true,
timeout: 1500000,
sound: true,
icon: './assets/images/logo.png'
});
Run Code Online (Sandbox Code Playgroud)
app.component.ts :
import {ElectronService} from 'ngx-electron';
@Component({
selector: 'app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
public main_js : any;
constructor(private _electronService: ElectronService ) {
this.main_js = this._electronService.remote.require("./main.js");
this.getTasks();
}
getTasks() {
var message = 'New Task …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个简单的应用程序,它应该在单击按钮时显示通知.问题是通知没有显示,但是console.logs正在显示.通知应该在开发模式下工作吗?(意思是刚刚运行electron .,我不需要构建和安装应用程序)
Windows操作系统:
System->Notification & Actions码:
// main.js
const { app, BrowserWindow, ipcMain, Notification } = require("electron");
const path = require("path");
const url = require("url");
let win;
function createWindow() {
// Create the browser window.
win = new BrowserWindow({ width: 800, height: 600 });
// and load the index.html of the app.
win.loadURL(
url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file:",
slashes: true
})
);
// Open the DevTools.
// win.webContents.openDevTools()
// Emitted …Run Code Online (Sandbox Code Playgroud)