mirror of
https://github.com/TangentFoxy/memex.git
synced 2024-11-22 04:54:23 +00:00
Add test for interprocess communication.
This commit is contained in:
parent
8e2902ca49
commit
711192d1d1
@ -173,8 +173,8 @@ body {
|
|||||||
/* visual */
|
/* visual */
|
||||||
background-color: var(--color-overlay-bg-i);
|
background-color: var(--color-overlay-bg-i);
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
-webkit-transition: opacity var(--animation-time) linear;
|
/*-webkit-transition: opacity var(--animation-time) linear;
|
||||||
transition: opacity var(--animation-time) linear;
|
transition: opacity var(--animation-time) linear;*/
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
/* position */
|
/* position */
|
||||||
|
@ -7,6 +7,13 @@
|
|||||||
<link rel="stylesheet" href="asset/fontawesome/css/all.css">
|
<link rel="stylesheet" href="asset/fontawesome/css/all.css">
|
||||||
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"> -->
|
<!-- <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/imagesloaded.js"></script>
|
||||||
<script src="logic/lib/masonry.js"></script>
|
<script src="logic/lib/masonry.js"></script>
|
||||||
<script src="logic/lib/runic.js"></script>
|
<script src="logic/lib/runic.js"></script>
|
||||||
@ -17,6 +24,7 @@
|
|||||||
<script src="logic/view.js"></script>
|
<script src="logic/view.js"></script>
|
||||||
<script src="logic/main.js"></script>
|
<script src="logic/main.js"></script>
|
||||||
<script src="logic/add.js"></script>
|
<script src="logic/add.js"></script>
|
||||||
|
<script src="logic/write.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="page-overlay noselect" id="overlay"></div>
|
<div class="page-overlay noselect" id="overlay"></div>
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
const { ipcRenderer } = nodeRequire('electron');
|
||||||
|
// const mainProcess = remote.nodeRequire('./main.js');
|
||||||
|
//const mainProcess = nodeRequire('./main.js');
|
||||||
|
|
||||||
function Add()
|
function Add()
|
||||||
{
|
{
|
||||||
this.overlay = null;
|
this.overlay = null;
|
||||||
@ -83,12 +87,24 @@ function Add()
|
|||||||
|
|
||||||
content += `</div>`;
|
content += `</div>`;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.overlay.innerHTML += content;
|
this.overlay.innerHTML += content;
|
||||||
|
|
||||||
this.display = document.getElementById("display");
|
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++)
|
for (var i = 0; i < this.keys.length; i++)
|
||||||
{
|
{
|
||||||
this.elementList[this.keys[i]].elem = document.getElementById(this.elementList[this.keys[i]].key);
|
this.elementList[this.keys[i]].elem = document.getElementById(this.elementList[this.keys[i]].key);
|
||||||
|
@ -3,6 +3,7 @@ function Main()
|
|||||||
this.db = null;
|
this.db = null;
|
||||||
this.view = null;
|
this.view = null;
|
||||||
this.add = null;
|
this.add = null;
|
||||||
|
this.write = null;
|
||||||
this.queryPrev = '';
|
this.queryPrev = '';
|
||||||
this.queryCur = '';
|
this.queryCur = '';
|
||||||
|
|
||||||
@ -14,6 +15,8 @@ function Main()
|
|||||||
this.view.install();
|
this.view.install();
|
||||||
this.add = new Add();
|
this.add = new Add();
|
||||||
this.add.install();
|
this.add.install();
|
||||||
|
this.write = new Write();
|
||||||
|
this.write.install();
|
||||||
|
|
||||||
var escape = document.getElementById("escape");
|
var escape = document.getElementById("escape");
|
||||||
escape.onclick = function()
|
escape.onclick = function()
|
||||||
|
23
docs/logic/write.js
Normal file
23
docs/logic/write.js
Normal 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!');
|
||||||
|
// });
|
51
main.js
51
main.js
@ -2,6 +2,7 @@ const {app, BrowserWindow, webFrame, Menu} = require('electron')
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
const url = require('url')
|
const url = require('url')
|
||||||
const shell = require('electron').shell;
|
const shell = require('electron').shell;
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
let is_shown = true;
|
let is_shown = true;
|
||||||
|
|
||||||
@ -49,10 +50,28 @@ app.on('ready', () =>
|
|||||||
{
|
{
|
||||||
app.win = new BrowserWindow({
|
app.win = new BrowserWindow({
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: false
|
nodeIntegration: true
|
||||||
}, width: 950, height: 950, backgroundColor:"#ddd", minWidth: 587, minHeight: 540, frame:true, autoHideMenuBar: true, icon: __dirname + '/icon.ico'})
|
}, 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.toggleDevTools();
|
||||||
|
|
||||||
app.win.on('closed', () => {
|
app.win.on('closed', () => {
|
||||||
@ -79,11 +98,6 @@ app.on('ready', () =>
|
|||||||
app.win.webContents.on('new-window', this.handleRedirect)
|
app.win.webContents.on('new-window', this.handleRedirect)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.on('window-all-closed', () =>
|
app.on('window-all-closed', () =>
|
||||||
{
|
{
|
||||||
app.quit()
|
app.quit()
|
||||||
@ -94,3 +108,26 @@ app.on('activate', () => {
|
|||||||
createWindow()
|
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
|
||||||
|
);
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user