From 00db0a3a3917c91dfd7faf0c29290e92bf1b48ef Mon Sep 17 00:00:00 2001 From: Simon Smith Date: Fri, 12 Jan 2024 22:46:12 +0000 Subject: [PATCH] add timeout to message box notifications (#5689) Signed-off-by: si458 --- agents/meshcore.js | 5 +++- meshctrl.js | 12 +++++---- views/default.handlebars | 56 ++++++++++++++++++++++++++++++---------- 3 files changed, 53 insertions(+), 20 deletions(-) diff --git a/agents/meshcore.js b/agents/meshcore.js index 5ad897c5..a88d31c5 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -1230,8 +1230,11 @@ function handleServerCommand(data) { ipr.message = data.msg; ipr.username = data.username; if (data.realname && (data.realname != '')) { ipr.username = data.realname; } + ipr.timeout = (typeof data.timeout === 'number' ? data.timeout : 120000); global._clientmessage = ipr.then(function (img) { - this.messagebox = require('win-dialog').create(this.title, this.message, this.username, { timeout: 120000, b64Image: img.split(',').pop(), background: color_options.background, foreground: color_options.foreground }); + var options = { b64Image: img.split(',').pop(), background: color_options.background, foreground: color_options.foreground } + if (this.timeout != 0) { options.timeout = this.timeout; } + this.messagebox = require('win-dialog').create(this.title, this.message, this.username, options); this.__childPromise.addMessage = this.messagebox.addMessage.bind(this.messagebox); return (this.messagebox); }); diff --git a/meshctrl.js b/meshctrl.js index cc57f021..cb536835 100644 --- a/meshctrl.js +++ b/meshctrl.js @@ -941,15 +941,17 @@ if (args['_'].length == 0) { console.log("Display a message on the remote device, Example usages:\r\n"); console.log(winRemoveSingleQuotes(" MeshCtrl DeviceMessage --id 'deviceid' --msg \"message\"")); console.log(winRemoveSingleQuotes(" MeshCtrl DeviceMessage --id 'deviceid' --msg \"message\" --title \"title\"")); + console.log(winRemoveSingleQuotes(" MeshCtrl DeviceMessage --id 'deviceid' --msg \"message\" --title \"title\" --timeout 120000")); console.log("\r\nRequired arguments:\r\n"); if (process.platform == 'win32') { - console.log(" --id [deviceid] - The device identifier."); + console.log(" --id [deviceid] - The device identifier."); } else { - console.log(" --id '[deviceid]' - The device identifier."); + console.log(" --id '[deviceid]' - The device identifier."); } - console.log(" --msg [message] - The message to display."); + console.log(" --msg [message] - The message to display."); console.log("\r\nOptional arguments:\r\n"); - console.log(" --title [title] - Messagebox title, default is \"MeshCentral\"."); + console.log(" --title [title] - Messagebox title, default is \"MeshCentral\"."); + console.log(" --timeout [miliseconds] - After timeout messagebox vanishes, 0 keeps messagebox open until closed manually, default is 120000 (2 Minutes)."); break; } case 'devicetoast': { @@ -1735,7 +1737,7 @@ function serverConnect() { break; } case 'devicemessage': { - ws.send(JSON.stringify({ action: 'msg', type: 'messagebox', nodeid: args.id, title: args.title ? args.title : "MeshCentral", msg: args.msg, responseid: 'meshctrl' })); + ws.send(JSON.stringify({ action: 'msg', type: 'messagebox', nodeid: args.id, title: args.title ? args.title : "MeshCentral", msg: args.msg, timeout: args.timeout ? args.timeout : 120000, responseid: 'meshctrl' })); break; } case 'devicetoast': { diff --git a/views/default.handlebars b/views/default.handlebars index d2acdbff..73b69983 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -5766,10 +5766,18 @@ setDialogMode(2, "Edit Device Tags", 3, d2groupActionFunctionTagsExec, x); } else if (op == 108) { // Device notification - var x = "Perform batch device notification" + '

'; - x += ''; - x += '
'; - x += ''; + var x = "
Perform batch device notification
"; + x += ''; + x += ''; + x += ''; + x += ''; setDialogMode(2, "Device Notification", 3, d2groupActionFunctionNotifyExec, x); Q('d2notifyMsg').focus(); } else if (op == 109) { @@ -5812,12 +5820,13 @@ function d2groupActionFunctionAgentDefaultCodeExec() { meshserver.send({ action: 'uploadagentcore', nodeids: getCheckedDevices(), type: 'default' }); } function d2groupActionFunctionNotifyExec() { - var op = Q('d2deviceop').value, title = Q('dp2notifyTitle').value, msg = Q('d2notifyMsg').value, chkNodeIds = getCheckedDevices(); + var op = Q('d2deviceop').value, title = Q('dp2notifyTitle').value, msg = Q('d2notifyMsg').value, chkNodeIds = getCheckedDevices(), timeout = parseFloat(Q('d2notifyTimeout').value); if (msg.length == 0) return; if (title == '') { title = decodeURIComponent('{{{extitle}}}'); } if (title == '') { title = "MeshCentral"; } + if (isNaN(timeout)) { timeout = 2; } if (op == 1) { // MessageBox - for (var i = 0; i < chkNodeIds.length; i++) { meshserver.send({ action: 'msg', type: 'messagebox', nodeid: chkNodeIds[i], title: title, msg: msg }); } + for (var i = 0; i < chkNodeIds.length; i++) { meshserver.send({ action: 'msg', type: 'messagebox', nodeid: chkNodeIds[i], title: title, msg: msg, timeout: (timeout * 60000) }); } } else if (op == 2) { // Toast meshserver.send({ action: 'toast', nodeids: chkNodeIds, title: title, msg: msg }); } else if (op == 3) { // Old Style MessageBox @@ -8094,17 +8103,27 @@ function deviceMessageFunction() { if (xxdialogMode) return; - setDialogMode(2, "Device Message", 3, deviceMessageFunctionEx, '
' + "Display a message box on the remote device." + '
'); + var x = '
Display a message box on the remote device.
'; + x += ''; + x += ''; + setDialogMode(2, "Device Message", 3, deviceMessageFunctionEx, x); Q('d2devMessage').focus(); } function deviceMessageFunctionEx() { - var title = decodeURIComponent('{{{extitle}}}'); + var title = decodeURIComponent('{{{extitle}}}'), timeout = parseFloat(Q('d2devTimeout').value); if (title == '') { title = "MeshCentral"; } + if(isNaN(timeout)){ timeout = 2; } if (currentNode.pmt == 1) { meshserver.send({ action: 'pushmessage', nodeid: currentNode._id, title: title, msg: Q('d2devMessage').value }); } else { - meshserver.send({ action: 'msg', type: 'messagebox', nodeid: currentNode._id, title: title, msg: Q('d2devMessage').value }); + meshserver.send({ action: 'msg', type: 'messagebox', nodeid: currentNode._id, title: title, msg: Q('d2devMessage').value, timeout: (timeout * 60000) }); } } @@ -8142,20 +8161,29 @@ function deviceToastFunction() { if (xxdialogMode) return; - var x = ''; - x += '
'; - x += ''; + var x = ''; + x += ''; + x += ''; + x += ''; setDialogMode(2, "Device Notification", 3, deviceToastFunctionEx, x); Q('d2notifyMsg').focus(); } function deviceToastFunctionEx() { - var op = Q('d2deviceop').value, title = Q('dp2notifyTitle').value, msg = Q('d2notifyMsg').value; + var op = Q('d2deviceop').value, title = Q('dp2notifyTitle').value, msg = Q('d2notifyMsg').value, timeout = parseFloat(Q('d2notifyTimeout').value); if (msg.length == 0) return; if (title == '') { title = decodeURIComponent('{{{extitle}}}'); } if (title == '') { title = "MeshCentral"; } + if(isNaN(timeout)){ timeout = 2; } if (op == 1) { // MessageBox - meshserver.send({ action: 'msg', type: 'messagebox', nodeid: currentNode._id, title: title, msg: msg }); + meshserver.send({ action: 'msg', type: 'messagebox', nodeid: currentNode._id, title: title, msg: msg, timeout: (timeout * 60000) }); } else if (op == 2) { // Toast meshserver.send({ action: 'toast', nodeids: [ currentNode._id ], title: title, msg: msg }); } else if (op == 3) { // Old Style MessageBox