mikaelbr / node-notifier

A Node.js module for sending notifications on native Mac, Windows and Linux (or Growl as fallback)
MIT License
5.73k stars 322 forks source link

Terminal Click Event With Custom terminal-notifier.app #273

Open Ivorfason opened 5 years ago

Ivorfason commented 5 years ago

when I install the newest package: npm install mikaelbr/node-notifier. And I found the terminal.app icon is default.So I replace node_modules/node-notifier/vendor/mac.noindex/terminal-notifier.app to my custom .app with my custom icon.

It worked with new icon, but the click event doesn't work which is confused.

Have seen a few issues before, but couldn't found a useful solution, I need help...

yyccQQu commented 3 years ago

In Mac, I also encountered the same problem,and If the click prompt is too fast, or it is not the current app, an error will be prompted.

截屏2021-03-21 下午2 16 47
yyccQQu commented 3 years ago
const isDev = require("electron-is-dev");
const fixPath = () => {
    var icon
    var contentImage
    var open
    if(isDev){
        icon = path.join(__dirname, 'a.png')
        contentImage = path.join(__dirname, 'a.png')
        open =  path.join(__dirname, 'a.png')
    }else{
        icon = path.join(__dirname, "/static/icon.png");
        contentImage = path.join(__dirname, "/static/icon.png");
        open = path.join(__dirname, "/static/icon.png");
    }

    return {
        icon,
        contentImage,
        open
    }
}

let {icon, contentImage, open} = fixPath()
ipcMain.on("notify", (evt, data) => {
        const { title, message } = data;
        console.log("notify:", title, message);
        notifier.notify({
            title,
            message,
            wait: true,
            icon: icon, 
            contentImage: contentImage, 
            open: open, 

        },(err, res) => {
            if (err) {
                console.log("error:", err);
            }
        });
        // 点击之后
        // After clicking on
        notifier.on('click', function (notifierObject, options, event) {
            console.log(notifierObject, options, event)
            // Triggers if `wait: true` and user clicks notification
        });
        // 自动消失之后
        // After it goes away automatically
        notifier.on('timeout', function (notifierObject, options) {
            console.log(notifierObject, options)
            // Triggers if `wait: true` and notification closes
        });
    });