Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I am adding appID, button are not showing in popup. #444

Open
artisharma24 opened this issue Jun 11, 2024 · 1 comment
Open

When I am adding appID, button are not showing in popup. #444

artisharma24 opened this issue Jun 11, 2024 · 1 comment

Comments

@artisharma24
Copy link

Here is my code .

const notifier = require('node-notifier');
const path = require('path');
const { shell, ipcMain } = require('electron');
const socket = require('socket.io-client')('http://192.168.50.25:5050/');
const { insertRecordsIntoNotification, createNotificationTable } = require('../repos/notificationRepo.js');

async function showNotification(message, isResponse) {
try {
console.log("showNotification triggered");

    if (!message) {
        throw new Error('No message provided.');
    }

    const messageJson = JSON.parse(message);
    const iconPath = path.resolve(__dirname, '../assets/images/logo.png');
    const contentImage = path.resolve(__dirname, '../assets/images/background-image.png')
    if (!messageJson.Title || !messageJson.Message || !messageJson.Records || !Array.isArray(messageJson.Records)) {
        throw new Error('Invalid message format.');
    }
    console.log(messageJson.Message);
    if (!isResponse) {
        createNotificationTable();
        await insertRecordsIntoNotification(messageJson.Message);
    }
    const buttons = messageJson.Records.map(record => record.label);

    notifier.notify({
        title: messageJson.Title,
        message: messageJson.Message,
        icon: iconPath,
        contentImage: contentImage,
        wait: true,
        actions: buttons,
        appID:"Smart Agent"
    });

    messageJson.Records.forEach(element => {
        const label = element.label.toLowerCase();
        switch (element.type.toLowerCase()) {
            case 'button': {
                if (messageJson.NotificationType === 'RemoteShare') {
                    notifier.on(label, () => {
                        try {
                            console.log(`${label}ed the remote desktop sharing request and Emitting ${label} response... ${element.action}`);
                            const obj = { response: label, room: element.action, clntName: messageJson.clntName };
                            ipcMain.emit('start-share', obj);
                        } catch (error) {
                            console.error('Error:', error.message);
                        }

                    });
                } else if(messageJson.NotificationType === 'RemoteShareResponse'){
                    console.log(`disconnected the remote desktop sharing request`);                               
                } 
                else{
                    notifier.on(label, () => {                            
                        shell.openExternal(element.action);
                    });
                }
                break;
            }
            case 'link':
                {
                    shell.openExternal(element.action);
                    break;
                }
            default:
                break;
        }
    });
} catch (error) {
    console.error('Error:', error.message);
}

}

module.exports = { showNotification };

@Aetherinox
Copy link

Aetherinox commented Jul 10, 2024

Unfortunately, this is a known issue with node-nodifier.

I'm actually in the middle of resolving a few of these issues. I need node-notifier and SnoreToast for my application, and since they haven't been touched in awhile by the developers; I forked my own version.

Thus far I've fixed the issue with notifications not staying on-screen, and I've got about 20 other bugs I'm working through.

If I find a quick solution once I finish it, I'll post it here.


An update, this issue is with SnoreToast, not with node-notifier. The code in this library is just passing the actions and appID on to snoretoast.

I'm going through the code to fix it in mine.


Edit 2:

I reviewed the code, and I need to see exactly why these steps are needed, but without editing the code, I found the solution.

In the SnoreToast readme, they mention that you must run the following command:

X:\YourNodeProject\node_modules\node-notifier\vendor\snoreToast\snoretoast-x64.exe -install "YourProject\YourProject.lnk" "X:\Path\To\Your.exe" "com.yourapp.id"

Basically what you need to do with the above command is:

  • For the first part of the command, you need to open Command Prompt and you're going to call snoretoast.exe, which is in the node_modules folder of whatever project you're working on.
  • For the second part of the command: YourProject\YourProject.lnk, it's creating a shortcut link, you can name it whatever your program is
    • MyAppName\MyAppName.lnk
  • Next, figure out what application you want to show at the top of each notification for the name.
  • Find the path to the exe for that app, it can be any app, or your project's exe, and then replace X:\Path\To\Your.exe with the path to your exe.
  • For com.yourapp.id, you can name it whatever you want, such as my-proggy

Then back in your notifier code, you'll want to use:

    notifier.notify({
        title: messageJson.Title,
        message: messageJson.Message,
        icon: iconPath,
        contentImage: contentImage,
        wait: true,
        actions: buttons,
        appID:"my-proggy"         <-----------
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants