Add test for interprocess communication.

This commit is contained in:
kor 2018-08-06 03:05:18 +12:00
parent 8e2902ca49
commit 711192d1d1
6 changed files with 99 additions and 12 deletions

View File

@ -173,8 +173,8 @@ body {
/* visual */
background-color: var(--color-overlay-bg-i);
opacity: 0;
-webkit-transition: opacity var(--animation-time) linear;
transition: opacity var(--animation-time) linear;
/*-webkit-transition: opacity var(--animation-time) linear;
transition: opacity var(--animation-time) linear;*/
width: 100%;
height: 100%;
/* position */

View File

@ -7,6 +7,13 @@
<link rel="stylesheet" href="asset/fontawesome/css/all.css">
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"> -->
<script>
window.nodeRequire = require;
delete window.require;
delete window.exports;
delete window.module;
</script>
<script src="logic/lib/imagesloaded.js"></script>
<script src="logic/lib/masonry.js"></script>
<script src="logic/lib/runic.js"></script>
@ -17,6 +24,7 @@
<script src="logic/view.js"></script>
<script src="logic/main.js"></script>
<script src="logic/add.js"></script>
<script src="logic/write.js"></script>
</head>
<body>
<div class="page-overlay noselect" id="overlay"></div>

View File

@ -1,3 +1,7 @@
const { ipcRenderer } = nodeRequire('electron');
// const mainProcess = remote.nodeRequire('./main.js');
//const mainProcess = nodeRequire('./main.js');
function Add()
{
this.overlay = null;
@ -83,12 +87,24 @@ function Add()
content += `</div>`;
this.overlay.innerHTML += content;
this.display = document.getElementById("display");
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);
});
for (var i = 0; i < this.keys.length; i++)
{
this.elementList[this.keys[i]].elem = document.getElementById(this.elementList[this.keys[i]].key);

View File

@ -3,6 +3,7 @@ function Main()
this.db = null;
this.view = null;
this.add = null;
this.write = null;
this.queryPrev = '';
this.queryCur = '';
@ -14,6 +15,8 @@ function Main()
this.view.install();
this.add = new Add();
this.add.install();
this.write = new Write();
this.write.install();
var escape = document.getElementById("escape");
escape.onclick = function()

23
docs/logic/write.js Normal file
View File

@ -0,0 +1,23 @@
function Write()
{
this.install = function()
{
}
this.insert = function(data)
{
let position = 5; // get insert position
let foo = fs.openSync('foo.txt','r+');
let buf = new Buffer("hello");
fs.writeSync(foo, buf, 0, buf.length, position);
fs.close(foo);
}
}
// fs.appendFile('mynewfile1.txt', 'Hello content!', function (err) {
// if (err) throw err;
// console.log('Saved!');
// });

53
main.js
View File

@ -2,6 +2,7 @@ const {app, BrowserWindow, webFrame, Menu} = require('electron')
const path = require('path')
const url = require('url')
const shell = require('electron').shell;
const fs = require('fs');
let is_shown = true;
@ -49,10 +50,28 @@ app.on('ready', () =>
{
app.win = new BrowserWindow({
webPreferences: {
nodeIntegration: false
nodeIntegration: true
}, 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.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', () => {
@ -79,11 +98,6 @@ app.on('ready', () =>
app.win.webContents.on('new-window', this.handleRedirect)
})
app.on('window-all-closed', () =>
{
app.quit()
@ -93,4 +107,27 @@ app.on('activate', () => {
if (app.win === null) {
createWindow()
}
})
})
// 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!');
// }
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
);
});