Add write test to IPC test.

This commit is contained in:
kor 2018-08-06 03:19:05 +12:00
parent 711192d1d1
commit dd9aac0721
4 changed files with 21 additions and 47 deletions

View File

@ -2236,11 +2236,21 @@ ON ICONS
LINK : https://ia.net/topics/on-icons
PERS : rutherford
SRCE : Merveilles
TAGS : design
TURBO
DATE : 12018-08-05
TYPE : term
TAGS : car
TERM
> Turbo: compressor forcing additional air into an engine to allow for increased fuel ignition and thus increased power output. A turbo has two halves, one is driven by the exhaust from the engine the other forces air into the engine. Negative 'turbo lag' time until the engine can provide enough exhaust to spin up the turbo compressor.
> Supercharger: Like a turbo but instead of being driven by exhaust gas it is driven mechanically (belt to engine). Negative Takes power/efficiency away from driving engine output in order to drive the compressor.
> Electic supercharger: fully electronically driven turbo (generally powered by a higher voltage (48v) seperate from car 12v). Negative high electricity use.
> Electic turbo: a hybrid electric-assisted turbo (generally powered by a higher voltage (48v) seperate from car 12v) using a DC motor to start the turbo spinning sooner to remove turbo lag or at low revs when not enough exhaust to produced. Once the engine is providing enough exhaust to spin the turbo the motor will stop output. It can also be a seperate electric supercharger working in conjunction with a standard turbo. Negative complexity.
ELECTRON IPC
DATE : 12018-08-06
LINK : https://ourcodeworld.com/articles/read/537/how-to-execute-a-function-of-the-main-process-inside-the-renderer-process-in-electron-framework
PROJ : Memex
TAGS : web, code
`

View File

@ -94,15 +94,8 @@ function Add()
document.getElementById("enter").addEventListener('click',
() =>
{
console.log('test test');
// ipcRenderer.send('write', 'test');
let Data =
{
message: "Hi",
someData: "Let's go"
};
ipcRenderer.send('request-mainprocess-action', Data);
console.log('called write');
ipcRenderer.send('write', '<br>'+this.display.innerHTML);
});
for (var i = 0; i < this.keys.length; i++)

1
foo.txt Normal file
View File

@ -0,0 +1 @@
123456789

46
main.js
View File

@ -3,6 +3,7 @@ const path = require('path')
const url = require('url')
const shell = require('electron').shell;
const fs = require('fs');
const { ipcMain } = require('electron');
let is_shown = true;
@ -54,24 +55,6 @@ app.on('ready', () =>
}, width: 950, height: 950, backgroundColor:"#ddd", minWidth: 587, minHeight: 540, frame:true, autoHideMenuBar: true, icon: __dirname + '/icon.ico'})
app.win.loadURL(`file://${__dirname}/docs/index.html`);
// app.win.webContents.on('did-finish-load', () => {
// let code = `
// console.log("3");
// document.getElementById("enter").addEventListener("click",
// function (e)
// {
// let foo = fs.openSync('foo.txt','r+');
// let buf = new Buffer("hello");
// fs.writeSync(foo, buf, 0, buf.length, 5);
// fs.close(foo);
// console.log('WROTE!');
// console.log(document.getElementById("display").value);
// });`;
// app.win.webContents.executeJavaScript(code);
// });
// app.win.toggleDevTools();
app.win.on('closed', () => {
@ -109,25 +92,12 @@ app.on('activate', () => {
}
})
// write = function(data)
// {
// let foo = fs.openSync('foo.txt','r+');
// let buf = new Buffer("hello");
// fs.writeSync(foo, buf, 0, buf.length, 5);
// fs.close(foo);
// console.log('WROTE!');
// }
ipcMain.on('write', (event, arg) =>
{
console.log('Write called! Entry = ' + arg);
const {ipcMain} = require('electron');
// Attach listener in the main process with the given ID
ipcMain.on('request-mainprocess-action', (event, arg) => {
// Displays the object sent from the renderer process:
//{
// message: "Hi",
// someData: "Let's go"
//}
console.log(
arg
);
let foo = fs.openSync('foo.txt','r+');
let buf = new Buffer(arg);
fs.writeSync(foo, buf, 0, buf.length, 5);
fs.close(foo);
});