seriema / electron-notification-shim

Get Notification API events in Electron main-process. Perfect for adding Notification toasters in Windows with node-notifier or other solution.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught Exception: ReferenceError: Notification is not defined at module.exports

rubencodes opened this issue · comments

Getting this issue on Mac, using electron-prebuilt@0.37.4. Note: native notifications work great, I'm using this package specifically for Windows, but this probably shouldn't be happening?

screen shot 2016-04-13 at 7 52 51 pm

`

Seeing same thing on Windows... Will post code snippet in a minute.

screen shot 2016-04-13 at 8 58 58 pm

So this is my main rendering file, where I use electon-notification-shim. Is this correct usage?

import { app, BrowserWindow, Menu } from 'electron';
import ipc from 'ipc';

import windowStateKeeper from './vendor/electron_boilerplate/window_state';

var mainWindow;

// Preserver of the window size and position between app launches.
var mainWindowState = windowStateKeeper('main', {
    width: 1000,
    height: 600
});

app.on('ready', function () {
    mainWindow = new BrowserWindow({
        x: mainWindowState.x,
        y: mainWindowState.y,
        width: mainWindowState.width,
        height: mainWindowState.height, 
        frame: false
    });

    if (mainWindowState.isMaximized) {
        mainWindow.maximize();
    }

//    if(process.platform === 'win32') {
      require('electron-notification-shim')();
//    }
    // Listen for notification events.
    ipc.on('notification-shim', (e, msg) => {
      console.log(msg);
    });

    mainWindow.on('close', function () {
        mainWindowState.saveState(mainWindow);
    });
});

app.on('window-all-closed', function () {
    app.quit();
});

EDIT: Found that if I move

//    if(process.platform === 'win32') {
      require('electron-notification-shim')();
//    }

into the browser JS file, it looks like it works!

@rubencodes Glad you got it working! Is there some way I could make this clearer in the readme? Maybe if I put the file names as headers in the readme, instead of comments inside the code blocks of the readme?

Tbqh I didn't know what "main process" and "renderer process" meant in regards to electron, so it was a terminology gap on my part. In retrospect it's quite obvious haha...