2016-11-11 10 views
0

私はOSトレイメニューを持つ電子アプリケーションを構築しています。メインプロセスでメインプロセスから開始された電子チャネルメッセージがレンダラープロセスによって受信されない

tray menu

私は「について」のメニュー項目へのクリックを聞くと、それはそれに応じて、ウィンドウのビューを更新できるようにレンダリングプロセスを通知したいです。私は窓やトレイメニューをレンダリングしていたときにここで

は私の主なプロセスの一部です:

const {app, BrowserWindow, Menu, Tray} = require('electron') 
const appConfig = require('./appConfig') 
const ipc = require('electron').ipcMain 
const path = require('path') 
const config = require('../config') 

let win, tray 

function createWindow(){ 
    win = new BrowserWindow({ 
     height: appConfig.window.height, 
     width: appConfig.window.width 
    }) 

    win.loadURL(`file://${__dirname}/client/index.html`) 

    if(appConfig.debugMode){ 
     win.webContents.openDevTools() 
    } 

    win.on('closed',() => { 
     win = null 
    }) 
} 

function setTrayIcon(){ 
    tray = new Tray(path.resolve(__dirname, './assets/rocketTemplate.png')) 
    tray.setToolTip('Launch applications by group') 

    let menuitems = config.groups.map(group => { 
     return {label: `Launch group: ${group.name}`} 
    }) 
    win.webContents.send('ShowAboutPage' , {msg:'hello from main process'}); 
    win.webContents.send('ShowAboutPage') 

    menuitems.unshift({type: 'separator'}) 

    // Here where I add the "About" menu item that has the click event listener 
    menuitems.unshift({ 
     label: 'About AppLauncher', 
     click(menuitem, browserWin, event){ 
      // sending a log to the console to confirm that the click listener did indeed hear the click 
      console.log('about menu clicked') 
      win.webContents.send('ShowAboutPage') 
     } 
    }) 
    menuitems.push({type: 'separator'}) 
    menuitems.push({label: 'Quit AppLauncher'}) 

    const contextMenu = Menu.buildFromTemplate(menuitems) 
    tray.setContextMenu(contextMenu) 
} 

app.on('ready',() => { 
    createWindow() 
    setTrayIcon() 
}) 

そしてここでは、チャネルメッセージをリッスンする必要があるレンダラスクリプトです:

const Vue = require('vue') 
const App = require('./App.vue') 
const ipc = require('electron').ipcRenderer 

ipc.on('ShowAboutPage',() => { 
    console.log('show about fired in store') 
    alert('show about fired in store') 
    this.notificationMessage = 'Show about page' 
}) 


require('./style/base.sass') 

new Vue({ 
    el: '#app', 
    render: h => h(App) 
}) 

トレイの[バージョン情報]メニューをクリックすると、メインプロセスからconsole.log出力が表示されますが、レンダラープロセスでconsole.logや警告が表示されることはありません。

私のアプリは1つのウィンドウしか持っていません(window closeの変数winの無効化によって証明されています)ので、間違ったレンダラープロセスにメッセージを送信しているような問題はありません。

私はelectron documentation on using webContents to send messages to renderer instancesを調べましたが、私のコードが正しく構成されているようですが、明らかに何か不足しています。

アイデア?

答えて

-1

は、ちょっと

const { ipcRenderer } = require("electron"); 
ipcRenderer.on("ShowAboutPage",() => { 
    //etc 
}); 
+2

としてあなたのレンダラのスクリプトを書き換え返事に感謝してみてください。機能上、私のコードとあなたが提案したコードの変更には違いはありません。変数の名前を変更するだけです。 –