energy/example/dev-test/ipc-event/resources/ipc-event.html
2023-03-15 14:29:45 +08:00

255 lines
9.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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;
function autoIpcEmit() {
if (si != null) {
clearInterval(si)
si = null
idx = 0
msg("停止 auto ipc emit idx", idx)
return
}
msg("启动 auto ipc emit")
si = setInterval(ipcEmit, 1)
if (si != null) {
let time = document.getElementById("time").value - 0
if (time > 0) {
setTimeout(function () {
clearInterval(si)
si = null
}, time)
}
}
}
function ipcEmit() {
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 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 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));
});
ipc.on('onTestName2', function (r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10) {
clearMsg()
msg("onTestName2");
return ["返回值", 111111, 2222.22, true]
});
let tgesi = null
function autotestGoEmit() {
if (tgesi != null) {
clearInterval(tgesi)
tgesi = null
idx = 0;
return
}
tgesi = setInterval(testGoEmit, 1)
if (tgesi != null) {
let time = document.getElementById("time").value - 0
if (time > 0) {
setTimeout(function () {
clearInterval(tgesi)
msg(idx)
tgesi = null
idx = 0;
}, time)
}
}
}
function testGoEmit() {
idx++
ipc.emit("testGoEmit", [idx]);
}
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");
}
function bindFunc() {
energy.funcName();
}
function bindField() {
clearMsg();
msg('stringField', energy.stringField);
msg('intField', energy.intField);
msg('doubleField', energy.doubleField);
msg('boolField', energy.boolField);
}
</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>
<button onclick="ipcEmit()">ipcEmit</button>
<button onclick="autoIpcEmit()">自动-ipcEmit</button>
<input id="time" value="0">
<br>
<button onclick="testInArgs()">testInArgs</button>
<button onclick="testResultArgs()">testResultArgs</button>
<br>
<button onclick="testGoEmit()">testGoEmit</button>
<button onclick="autotestGoEmit()">自动testGoEmit</button>
<br>
<button onclick="testGoEmitAndCallback()">testGoEmitAndCallback</button>
<button onclick="autotestGoEmitAndCallback()">自动testGoEmitAndCallback</button>
<br>
<button onclick="bindFunc()">bindFunc</button>
<button onclick="bindField()">bindField</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>