Commit e4815de8 authored by rocosen's avatar rocosen

feat:ipc 通信

parent ec9da2bf
This diff was suppressed by a .gitattributes entry.
var net = require('net');
var os = require('os');
var events = require('events');
var ipc = require('./ipc');
var L = console.log;
ipc_one = ipc.getEvents()
ipc_one.on('connected', function (m) {
L("Client has connected")
});
ipc_one.on('data', function (m) {
L(m.type)
L(m.data.toString())
});
ipc_one.on('error', function (data) {
L(data.toString());
});
ipc_one.on('close', function (data) {
L(data.toString());
});
ipc.connect("testtest", true)
var a = setInterval(myTimer, 50);
function myTimer() {
if (ipc.status() == "Closed") {
clearInterval(a)
clearInterval(b)
}
L('Connecton status: ' + ipc.status())
ipc.write(4, "Hello server")
ipc.write(212, "Hello server")
ipc.write(663, "Hello server")
}
var b = setInterval(myTimerw, 8000);
function myTimerw() {
// ipc.close()
// clearInterval(myTimerw)
}
\ No newline at end of file
This diff is collapsed.
const child_process = require('child_process');
let child = child_process.spawn('go', ['run', 'gochild.go'], {
stdio: [0, 1, 2, 'ipc'],
});
child.on('close', (code) => {
process.exit(code);
});
child.send({ hello: 'child' });
child.on('message', function (msg, handle) {
if (msg.hello === 'parent') {
console.log(msg);
process.exit(0);
}
process.exit(1);
});
......@@ -19,6 +19,7 @@ const positioner = require('electron-traywindow-positioner');
const storage = require('electron-localstorage');
const fs = require('fs');
const fse = require('fs-extra');
const ipc = require('../commons/utils/ipc');
class AppUpdater {
constructor() {
log.transports.file.level = 'info';
......@@ -126,7 +127,7 @@ ipcMain.on('resize-home', (event) => {
homeWindown.loadURL(resolveHtmlPath(`index.html#/home`));
positioner.position(homeWindown, tray.getBounds(), alignment);
isDev && homeWindown.webContents.openDevTools();
// homeWindown.webContents.openDevTools();
homeWindown.webContents.openDevTools();
homeWindown.once('ready-to-show', () => {
homeWindown?.show();
});
......@@ -157,6 +158,7 @@ ipcMain.on('asynchronous-message', function (event, arg) {
});
ipcMain.on('window-close', (event) => {
ipc.write(4, "Hello server")
app.quit();
});
......@@ -237,6 +239,7 @@ const createWindow = async () => {
{
label: '退出',
click: async () => {
ipc.write(4, "Hello server")
app.quit();
},
},
......@@ -246,7 +249,7 @@ const createWindow = async () => {
tray.setToolTip('北鲲云');
mainWindow.loadURL(resolveHtmlPath('index.html'));
// mainWindow.webContents.openDevTools();
mainWindow.webContents.openDevTools();
fs.mkdir(USER_HOME, { recursive: true }, (err: any) => {
if (err) return;
......@@ -269,7 +272,7 @@ const createWindow = async () => {
mainWindow.minimize();
} else {
mainWindow.hide();
// mainWindow.webContents.openDevTools();
mainWindow.webContents.openDevTools();
}
});
......@@ -314,6 +317,7 @@ app.on('window-all-closed', () => {
// Respect the OSX convention of having the application in memory even
// after all windows have been closed
if (process.platform !== 'darwin') {
ipc.write(4, "Hello server")
app.quit();
}
});
......
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { shell } from 'electron';
//js
......@@ -28,6 +28,8 @@ import siteIcon from '../../commons/assets/img/siteIcon.svg';
const { ipcRenderer } = require('electron');
const electron = window.require('electron');
const ipc = require('../../commons/utils/ipc');
console.log('ipc: ', ipc);
const useStyles = makeStyles()((theme) => {
return {
......@@ -97,6 +99,8 @@ const list = [
{ id: '5', value: siteIcon, lable: '设置' },
];
const ipc_one = ipc.getEvents()
export default (props) => {
const { classes } = useStyles();
const { render, navigate, ipcSend } = public();
......@@ -105,12 +109,49 @@ export default (props) => {
const [hover, setHover] = useState(false);
const [open, setOpen] = useState(false);
useEffect(()=>{
ipc.connect("cloudam", true)
},[])
var a = setInterval(myTimer, 50);
function myTimer() {
if (ipc.status() == "Closed") {
clearInterval(a)
clearInterval(b)
}
console.log('Connecton status: ' + ipc.status())
ipc.write(4, "Hello server")
}
ipc_one.on('connected', function (m) {
console.log("Client has connected")
});
ipc_one.on('data', function (m) {
console.log(m.type)
console.log(m.data.toString())
});
const iconClick = (e) => {
console.log('e: ', e);
switch (e) {
case '1':
return;
case '2':
ipc.connect("cloudam", true)
return;
case '3':
ipcSend(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment