現状
ElectronのメインプロセスにおいてwebContents.sendでオブジェクトを送信するとレンダラープロセスに[Object]という展開可能なプロパティのようなものが表示される。
ゴール
出てくるオブジェクトを想定しているメッセージ(送った文字列のみ)にしたい
コード
上から順に メインプロセス、レンダラープロセス、データベース内容、表示されるオブジェクト
Javascript
//メインプロセス function get() { db.find({}, (error, docs) => { console.log(docs[0].notes); return docs[0].notes; }); }; const createWindow = () => { // Create the browser window. const mainWindow = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true, contextIsolation: false, }, }); mainWindow.webContents.once('did-finish-load', () => { mainWindow.webContents.send('message', get() ); }); // and load the index.html of the app. mainWindow.loadFile(path.join(__dirname, 'index.html')); // Open the DevTools. mainWindow.webContents.openDevTools(); mainWindow.setMenu(null); };
Javascript
//レンダラープロセス ipcRenderer.on('message', (message) => { console.log(message); }
db
{"notes":"a","date":{"$$date":1648183077589},"_id":"Cq7THhdzCMz4rmui"}
Javascript
//表示されるもの { "sender": { "_events": {}, "_eventsCount": 1 }, "senderId": 0, "ports": [] } //更に展開可能
ご回答よろしくお願いします。
まだ回答がついていません
会員登録して回答してみよう