mirror of
https://gitee.com/energye/energy.git
synced 2024-12-16 02:11:35 +08:00
372 lines
14 KiB
Go
372 lines
14 KiB
Go
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<title>ipc-event</title>
|
||
<style>
|
||
button {
|
||
margin: 5px;
|
||
}
|
||
</style>
|
||
<script type="application/javascript">
|
||
let idx = 0;
|
||
let si = null;
|
||
let si1 = null;
|
||
let si2 = null;
|
||
|
||
function autoIpcEmit() {
|
||
if (si != null) {
|
||
clearInterval(si)
|
||
clearInterval(si1)
|
||
clearInterval(si2)
|
||
si = null
|
||
si1 = null
|
||
si2 = null
|
||
idx = 0
|
||
msg("停止 auto ipc emit idx", idx)
|
||
return
|
||
}
|
||
msg("启动 auto ipc emit")
|
||
si = setInterval(testEmitName, 1)
|
||
si1 = setInterval(testEmitName, 1)
|
||
//si2 = setInterval(testEmitName, 1)
|
||
if (si != null) {
|
||
let time = document.getElementById("time").value - 0
|
||
if (time > 0) {
|
||
setTimeout(function () {
|
||
clearInterval(si)
|
||
clearInterval(si1)
|
||
clearInterval(si2)
|
||
si = null
|
||
si1 = null
|
||
si2 = null
|
||
}, time)
|
||
}
|
||
}
|
||
}
|
||
|
||
function testEmitName() {
|
||
idx++;
|
||
let objectValueArray = [
|
||
100, 200, "数组里的字符串", 66996.99,
|
||
]
|
||
let objectValue = {
|
||
"stringField": "string 字符串字符串字符串字符串字符串字符串字符串字符串字string 符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符string 串字符串字符串字符串字符串字符string 串字符串字符串字符串string 字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串字符串",
|
||
"intField": 1000,
|
||
"arrayField": objectValueArray,
|
||
"doubleField": 999991.102,
|
||
"booleanField": true,
|
||
}
|
||
let arrayValue = [
|
||
100, 200, "数组里的字符串", 66996.99, objectValue, true, false
|
||
]
|
||
let args1 = "中文中文中文中文中文中文中文string 中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文string 中文中文中文中文中文中文中文中文中文中文中文中文中string 文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文中文"
|
||
let ok = ipc.emit("testEmitName", [args1, idx, true, 1999.66 + idx, "字符串?", 29999.66 + idx, objectValue, arrayValue, 8888888888888 + idx, null, undefined],
|
||
function (r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10) {
|
||
clearMsg()
|
||
msg("R0:", r0);
|
||
msg("R1:", r1);
|
||
msg("R2:", r2);
|
||
msg("R3:", r3);
|
||
msg("R4:", r4);
|
||
msg("R5:", r5);
|
||
msg("R6:", r6, JSON.stringify(r6));
|
||
msg("R7:", r7, JSON.stringify(r7));
|
||
msg("R8:", r8, JSON.stringify(r8));
|
||
msg("R9:", r9, JSON.stringify(r9));
|
||
msg("R10:", r10, JSON.stringify(r10));
|
||
});
|
||
msg('ipc.emit testEmitName ok?', ok);
|
||
|
||
//let ok1 = ipc.emit([]);
|
||
// msg('ipc.emit ok?', ok1);
|
||
}
|
||
|
||
function testInArgs() {
|
||
clearMsg()
|
||
let in1 = "字符串参数"
|
||
let in2 = 888888
|
||
let in3 = 9999999.0111
|
||
let in4 = true
|
||
let in5 = ["value1", "字符串2", "字符串3"]
|
||
let in6 = [1111111.1111, 222222.222, "这个数组需要使用 []any 类型接收"]
|
||
let in7 = {
|
||
"key1": "value1value1value1value1",
|
||
"key2": "value2value2value2v2",
|
||
"key3": "value3value3value3"
|
||
}
|
||
let in8 = {
|
||
"key1": "value1value1value1value1",
|
||
"key2": "value2value2value2vaaaaaaalue2",
|
||
"key3": "value3value3value3",
|
||
"key4": 1231,
|
||
"key5": 1231.33,
|
||
"key6": true,
|
||
"subObj": {
|
||
"StringField": "StringFieldStringFieldStringField",
|
||
"IntField": 3333333,
|
||
"BoolField": true,
|
||
"FloatField": 1006588.666
|
||
}
|
||
}
|
||
let in9 = {
|
||
"in9key": in8
|
||
}
|
||
ipc.emit("testInArgs", [in1, in2, in3, in4, in5, in6, in7, in8, in9]);
|
||
}
|
||
|
||
function testNotInArgs() {
|
||
ipc.emit("testNotInArgs")
|
||
}
|
||
|
||
function testNotInArgsRev() {
|
||
ipc.emit("testNotInArgs", ['parame1这个参数没有接收'])
|
||
}
|
||
|
||
function testNotInArgsCallback() {
|
||
ipc.emit("testNotInArgs", function (p1) {
|
||
clearMsg()
|
||
msg("有回调函数, 无返回值.", p1);
|
||
})
|
||
}
|
||
|
||
function testResultArgs() {
|
||
clearMsg()
|
||
ipc.emit("testResultArgs", [6666], function (r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10) {
|
||
msg("R0:", r0);
|
||
msg("R1:", r1);
|
||
msg("R2:", r2);
|
||
msg("R3:", r3);
|
||
msg("R4:", r4);
|
||
msg("R5:", r5);
|
||
msg("R6:", r6, JSON.stringify(r6));
|
||
msg("R7:", r7, JSON.stringify(r7));
|
||
msg("R8:", r8, JSON.stringify(r8));
|
||
msg("R9:", r9, JSON.stringify(r9));
|
||
msg("R10:", r10, JSON.stringify(r10));
|
||
})
|
||
}
|
||
|
||
ipc.on('onTestName1', function (r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10) {
|
||
clearMsg()
|
||
msg("onTestName1");
|
||
msg("R0:", r0);
|
||
msg("R1:", r1);
|
||
msg("R2:", r2);
|
||
msg("R3:", r3);
|
||
msg("R4:", r4);
|
||
msg("R5:", r5);
|
||
msg("R6:", r6, JSON.stringify(r6));
|
||
msg("R7:", r7, JSON.stringify(r7));
|
||
msg("R8:", r8, JSON.stringify(r8));
|
||
msg("R9:", r9, JSON.stringify(r9));
|
||
msg("R10:", r10, JSON.stringify(r10));
|
||
});
|
||
let onTestName2Idx = 0;
|
||
ipc.on('onTestName2', function (r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10) {
|
||
onTestName2Idx++;
|
||
clearMsg()
|
||
msg("onTestName2");
|
||
msg("R0:", r0);
|
||
msg("R1:", r1);
|
||
msg("R2:", r2);
|
||
msg("R3:", r3);
|
||
msg("R4:", r4);
|
||
msg("R5:", r5);
|
||
msg("R6:", r6, JSON.stringify(r6));
|
||
msg("R7:", r7, JSON.stringify(r7));
|
||
msg("R8:", r8, JSON.stringify(r8));
|
||
msg("R9:", r9, JSON.stringify(r9));
|
||
msg("R10:", r10, JSON.stringify(r10));
|
||
return ["返回值" + onTestName2Idx, onTestName2Idx, 2222.22 + onTestName2Idx, onTestName2Idx % 2 === 0]
|
||
});
|
||
|
||
function testGoToJSEvent() {
|
||
ipc.emit("testGoToJSEvent")
|
||
}
|
||
|
||
ipc.on('notInArgs', function (r1) {
|
||
msg("notInArgs", r1);
|
||
return 1
|
||
});
|
||
|
||
let tgesi = null
|
||
let tgesi1 = null
|
||
|
||
function autotestGoEmit() {
|
||
if (tgesi != null) {
|
||
clearInterval(tgesi)
|
||
clearInterval(tgesi1)
|
||
tgesi = null
|
||
tgesi1 = null
|
||
idx = 0;
|
||
return
|
||
}
|
||
tgesi = setInterval(testGoEmit, 1)
|
||
tgesi1 = setInterval(testGoEmit, 1)
|
||
if (tgesi != null) {
|
||
let time = document.getElementById("time").value - 0
|
||
if (time > 0) {
|
||
setTimeout(function () {
|
||
clearInterval(tgesi)
|
||
clearInterval(tgesi1)
|
||
msg(idx)
|
||
tgesi = null
|
||
tgesi1 = null
|
||
idx = 0;
|
||
}, time)
|
||
}
|
||
}
|
||
}
|
||
|
||
function testGoEmit() {
|
||
idx++
|
||
ipc.emit("testGoEmit", [idx]);
|
||
}
|
||
|
||
let atia = null
|
||
|
||
function autovariabletestInArgs() {
|
||
if (atia != null) {
|
||
clearInterval(atia)
|
||
atia = null
|
||
idx = 0;
|
||
return
|
||
}
|
||
atia = setInterval(variabletestInArgs, 1)
|
||
if (atia != null) {
|
||
let time = document.getElementById("time").value - 0
|
||
if (time > 0) {
|
||
setTimeout(function () {
|
||
clearInterval(atia)
|
||
msg(idx)
|
||
atia = null
|
||
idx = 0;
|
||
}, time)
|
||
}
|
||
}
|
||
}
|
||
|
||
function variabletestInArgs() {
|
||
idx++
|
||
let vara = ipc.emit("testResultArgs", [idx]);
|
||
clearMsg()
|
||
msg("variabletestInArgs", vara);
|
||
msg("variabletestInArgs", JSON.stringify(vara));
|
||
}
|
||
|
||
|
||
let tgesic = null
|
||
|
||
function autotestGoEmitAndCallback() {
|
||
if (tgesic != null) {
|
||
clearInterval(tgesic)
|
||
tgesic = null
|
||
idx = 0;
|
||
return
|
||
}
|
||
tgesic = setInterval(testGoEmitAndCallback, 1)
|
||
if (tgesic != null) {
|
||
let time = document.getElementById("time").value - 0
|
||
if (time > 0) {
|
||
setTimeout(function () {
|
||
clearInterval(tgesic)
|
||
msg(idx)
|
||
tgesic = null
|
||
idx = 0;
|
||
}, time)
|
||
}
|
||
}
|
||
}
|
||
|
||
function testGoEmitAndCallback() {
|
||
ipc.emit("testGoEmitAndCallback");
|
||
}
|
||
|
||
let tessi = null
|
||
|
||
function autoTestEmitSync() {
|
||
if (tessi != null) {
|
||
clearInterval(tessi)
|
||
tessi = null
|
||
idx = 0;
|
||
return
|
||
}
|
||
tessi = setInterval(testEmitSync, 1)
|
||
if (tessi != null) {
|
||
let time = document.getElementById("time").value - 0
|
||
if (time > 0) {
|
||
setTimeout(function () {
|
||
clearInterval(tessi)
|
||
msg(idx)
|
||
tessi = null
|
||
idx = 0;
|
||
}, time)
|
||
}
|
||
}
|
||
}
|
||
|
||
function testEmitSync() {
|
||
clearMsg()
|
||
let result = ipc.emitSync("testEmitSync", ["同步参数", 1, 2, 3, ["aaaa", "bbb", 6666]])
|
||
msg("GetMyParam", energy.myparam, energy.myparam1);
|
||
energy.myparam1="aaaa"
|
||
msg("testEmitSync", result);
|
||
ipc.emitSync("testEmitSync", ["同步参数", 1, 2, 3, ["aaaa", "bbb", 6666]], function (result) {
|
||
msg("testEmitSync-callback", result);
|
||
})
|
||
}
|
||
</script>
|
||
</head>
|
||
<body style="margin: 0px;padding: 0px;">
|
||
<p>
|
||
<h3 style="-webkit-app-region: drag;">process-message</h3></p>
|
||
<p><a target="_blank" href="ipc-event.html">open</a></p>
|
||
<p>
|
||
自动执行时间/毫秒: <input id="time" value="0">
|
||
<br>
|
||
<button onclick="testEmitName()">testEmitName</button>
|
||
<button onclick="autoIpcEmit()">自动-testEmitName</button>
|
||
<br>
|
||
<button onclick="testInArgs()">只入参testInArgs</button>
|
||
<button onclick="testResultArgs()">出参testResultArgs</button>
|
||
<button onclick="testNotInArgs()">无入参/无出参testNotInArgs</button>
|
||
<button onclick="testNotInArgsRev()">未接收参数/testNotInArgsRev</button>
|
||
<button onclick="testNotInArgsCallback()">有回调函数无返回值/testNotInArgsCallback</button>
|
||
<br>
|
||
<button onclick="testGoToJSEvent()">GO/testGoToJSEvent</button>
|
||
<br>
|
||
<button onclick="testGoEmit()">testGoEmit</button>
|
||
<button onclick="autotestGoEmit()">自动-testGoEmit</button>
|
||
<br>
|
||
<button onclick="variabletestInArgs()">variabletestInArgs</button>
|
||
<button onclick="autovariabletestInArgs()">自动autovariabletestInArgs</button>
|
||
<br>
|
||
<button onclick="testGoEmitAndCallback()">testGoEmitAndCallback</button>
|
||
<button onclick="autotestGoEmitAndCallback()">自动-testGoEmitAndCallback</button>
|
||
<br>
|
||
<button onclick="testEmitSync()">testEmitSync</button>
|
||
<button onclick="autoTestEmitSync()">自动-testEmitSync</button>
|
||
|
||
</p>
|
||
<p id="msgHtml"></p>
|
||
</body>
|
||
<script type="application/javascript">
|
||
let msgHtml = document.getElementById("msgHtml");
|
||
|
||
function msg(...vvv) {
|
||
let str = msgHtml.innerHTML;
|
||
for (let i = 0; i < vvv.length; i++) {
|
||
str = str + " " + vvv[i];
|
||
}
|
||
str += "<br>";
|
||
msgHtml.innerHTML = str;
|
||
}
|
||
|
||
function clearMsg() {
|
||
msgHtml.innerHTML = "";
|
||
}
|
||
|
||
msg("ipc-event: 页面加载完成...");
|
||
</script>
|
||
</html> |