add timeout to message box notifications (#5689)

Signed-off-by: si458 <simonsmith5521@gmail.com>

Simon Smith committed Jan 12, 2024 at 22:46 UTC 00db0a3a3917c91dfd7faf0c29290e92bf1b48ef
3 files changed +53 -20
agents/meshcore.js
+4 -1
@@ -1230,8 +1230,11 @@ function handleServerCommand(data) {
1230 ipr.message = data.msg;
1231 ipr.username = data.username;
1232 if (data.realname && (data.realname != '')) { ipr.username = data.realname; }
1233 + ipr.timeout = (typeof data.timeout === 'number' ? data.timeout : 120000);
1234 global._clientmessage = ipr.then(function (img) {
1234 - 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 });
1235 + var options = { b64Image: img.split(',').pop(), background: color_options.background, foreground: color_options.foreground }
1236 + if (this.timeout != 0) { options.timeout = this.timeout; }
1237 + this.messagebox = require('win-dialog').create(this.title, this.message, this.username, options);
1238 this.__childPromise.addMessage = this.messagebox.addMessage.bind(this.messagebox);
1239 return (this.messagebox);
1240 });
meshctrl.js
+7 -5
@@ -941,15 +941,17 @@ if (args['_'].length == 0) {
941 console.log("Display a message on the remote device, Example usages:\r\n");
942 console.log(winRemoveSingleQuotes(" MeshCtrl DeviceMessage --id 'deviceid' --msg \"message\""));
943 console.log(winRemoveSingleQuotes(" MeshCtrl DeviceMessage --id 'deviceid' --msg \"message\" --title \"title\""));
944 + console.log(winRemoveSingleQuotes(" MeshCtrl DeviceMessage --id 'deviceid' --msg \"message\" --title \"title\" --timeout 120000"));
945 console.log("\r\nRequired arguments:\r\n");
946 if (process.platform == 'win32') {
946 - console.log(" --id [deviceid] - The device identifier.");
947 + console.log(" --id [deviceid] - The device identifier.");
948 } else {
948 - console.log(" --id '[deviceid]' - The device identifier.");
949 + console.log(" --id '[deviceid]' - The device identifier.");
950 }
950 - console.log(" --msg [message] - The message to display.");
951 + console.log(" --msg [message] - The message to display.");
952 console.log("\r\nOptional arguments:\r\n");
952 - console.log(" --title [title] - Messagebox title, default is \"MeshCentral\".");
953 + console.log(" --title [title] - Messagebox title, default is \"MeshCentral\".");
954 + console.log(" --timeout [miliseconds] - After timeout messagebox vanishes, 0 keeps messagebox open until closed manually, default is 120000 (2 Minutes).");
955 break;
956 }
957 case 'devicetoast': {
@@ -1735,7 +1737,7 @@ function serverConnect() {
1737 break;
1738 }
1739 case 'devicemessage': {
1738 - ws.send(JSON.stringify({ action: 'msg', type: 'messagebox', nodeid: args.id, title: args.title ? args.title : "MeshCentral", msg: args.msg, responseid: 'meshctrl' }));
1740 + 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' }));
1741 break;
1742 }
1743 case 'devicetoast': {
views/default.handlebars
+42 -14
@@ -5766,10 +5766,18 @@
5766 setDialogMode(2, "Edit Device Tags", 3, d2groupActionFunctionTagsExec, x);
5767 } else if (op == 108) {
5768 // Device notification
5769 - var x = "Perform batch device notification" + '<br /><br />';
5770 - x += '<select id=d2deviceop style=width:100%><option value=2>' + "Toast Notification" + '</option><option value=1>' + "Message Box" + '</option><option value=3>' + "Alert Box" + '</option></select>';
5771 - x += '<br /><input id=dp2notifyTitle maxlength=256 placeholder="' + "Title" + '" style=width:100% />';
5772 - x += '<textarea id=d2notifyMsg style=background-color:#fcf3cf;width:100%;height:140px;resize:none;overflow-y:scroll></textarea>';
5769 + var x = "<div style=margin-bottom:4px>Perform batch device notification</div>";
5770 + x += '<select id=d2deviceop style=width:100%;margin-bottom:4px><option value=2>' + "Toast Notification" + '</option><option value=1>' + "Message Box" + '</option><option value=3>' + "Alert Box" + '</option></select>';
5771 + x += '<input id=dp2notifyTitle maxlength=256 placeholder="' + "Title" + '" style=width:100%;box-sizing:border-box;margin-bottom:4px />';
5772 + x += '<textarea id=d2notifyMsg style=background-color:#fcf3cf;width:100%;height:140px;resize:none;overflow-y:scroll;box-sizing:border-box;margin-bottom:4px></textarea>';
5773 + x += '<select style=width:100% id=d2notifyTimeout>';
5774 + x += '<option disabled value="">Only Applicable to Message Box Notifications</option>';
5775 + x += '<option value=2 selected>' + "Show for 2 Minutes (Default)" + '</option>';
5776 + x += '<option value=10>' + "Show for 10 minutes" + '</option>';
5777 + x += '<option value=30>' + "Show for 30 minutes" + '</option>';
5778 + x += '<option value=60>' + "Show for 60 minutes" + '</option>';
5779 + x += '<option value=0>' + "Show message until dismissed by user" + '</option>';
5780 + x += '</select>';
5781 setDialogMode(2, "Device Notification", 3, d2groupActionFunctionNotifyExec, x);
5782 Q('d2notifyMsg').focus();
5783 } else if (op == 109) {
@@ -5812,12 +5820,13 @@
5820 function d2groupActionFunctionAgentDefaultCodeExec() { meshserver.send({ action: 'uploadagentcore', nodeids: getCheckedDevices(), type: 'default' }); }
5821
5822 function d2groupActionFunctionNotifyExec() {
5815 - var op = Q('d2deviceop').value, title = Q('dp2notifyTitle').value, msg = Q('d2notifyMsg').value, chkNodeIds = getCheckedDevices();
5823 + var op = Q('d2deviceop').value, title = Q('dp2notifyTitle').value, msg = Q('d2notifyMsg').value, chkNodeIds = getCheckedDevices(), timeout = parseFloat(Q('d2notifyTimeout').value);
5824 if (msg.length == 0) return;
5825 if (title == '') { title = decodeURIComponent('{{{extitle}}}'); }
5826 if (title == '') { title = "MeshCentral"; }
5827 + if (isNaN(timeout)) { timeout = 2; }
5828 if (op == 1) { // MessageBox
5820 - for (var i = 0; i < chkNodeIds.length; i++) { meshserver.send({ action: 'msg', type: 'messagebox', nodeid: chkNodeIds[i], title: title, msg: msg }); }
5829 + for (var i = 0; i < chkNodeIds.length; i++) { meshserver.send({ action: 'msg', type: 'messagebox', nodeid: chkNodeIds[i], title: title, msg: msg, timeout: (timeout * 60000) }); }
5830 } else if (op == 2) { // Toast
5831 meshserver.send({ action: 'toast', nodeids: chkNodeIds, title: title, msg: msg });
5832 } else if (op == 3) { // Old Style MessageBox
@@ -8094,17 +8103,27 @@
8103
8104 function deviceMessageFunction() {
8105 if (xxdialogMode) return;
8097 - setDialogMode(2, "Device Message", 3, deviceMessageFunctionEx, '<div style=margin-bottom:4px>' + "Display a message box on the remote device." + '</div><textarea id=d2devMessage style=background-color:#fcf3cf;width:100%;height:80px;resize:none;overflow-y:scroll></textarea>');
8106 + var x = '<div style=margin-bottom:4px>Display a message box on the remote device.</div>';
8107 + x += '<textarea id=d2devMessage style=background-color:#fcf3cf;width:100%;height:80px;resize:none;overflow-y:scroll;box-sizing:border-box;margin-bottom:4px></textarea>';
8108 + x += '<select style=width:100% id=d2devTimeout>';
8109 + x += '<option value=2 selected>' + "Show for 2 Minutes (Default)" + '</option>';
8110 + x += '<option value=10>' + "Show for 10 minutes" + '</option>';
8111 + x += '<option value=30>' + "Show for 30 minutes" + '</option>';
8112 + x += '<option value=60>' + "Show for 60 minutes" + '</option>';
8113 + x += '<option value=0>' + "Show message until dismissed by user" + '</option>';
8114 + x += '</select>';
8115 + setDialogMode(2, "Device Message", 3, deviceMessageFunctionEx, x);
8116 Q('d2devMessage').focus();
8117 }
8118
8119 function deviceMessageFunctionEx() {
8102 - var title = decodeURIComponent('{{{extitle}}}');
8120 + var title = decodeURIComponent('{{{extitle}}}'), timeout = parseFloat(Q('d2devTimeout').value);
8121 if (title == '') { title = "MeshCentral"; }
8122 + if(isNaN(timeout)){ timeout = 2; }
8123 if (currentNode.pmt == 1) {
8124 meshserver.send({ action: 'pushmessage', nodeid: currentNode._id, title: title, msg: Q('d2devMessage').value });
8125 } else {
8107 - meshserver.send({ action: 'msg', type: 'messagebox', nodeid: currentNode._id, title: title, msg: Q('d2devMessage').value });
8126 + meshserver.send({ action: 'msg', type: 'messagebox', nodeid: currentNode._id, title: title, msg: Q('d2devMessage').value, timeout: (timeout * 60000) });
8127 }
8128 }
8129
@@ -8142,20 +8161,29 @@
8161
8162 function deviceToastFunction() {
8163 if (xxdialogMode) return;
8145 - var x = '<select id=d2deviceop style=width:100%><option value=2>' + "Toast Notification" + '</option><option value=1>' + "Message Box" + '</option><option value=3>' + "Alert Box" + '</option></select>';
8146 - x += '<br /><input id=dp2notifyTitle maxlength=256 placeholder="' + "Title" + '" style=width:100% />';
8147 - x += '<textarea id=d2notifyMsg style=background-color:#fcf3cf;width:100%;height:140px;resize:none;overflow-y:scroll></textarea>';
8164 + var x = '<select id=d2deviceop style=width:100%;margin-bottom:4px><option value=2>' + "Toast Notification" + '</option><option value=1>' + "Message Box" + '</option><option value=3>' + "Alert Box" + '</option></select>';
8165 + x += '<input id=dp2notifyTitle maxlength=256 placeholder="' + "Title" + '" style=width:100%;box-sizing:border-box;margin-bottom:4px />';
8166 + x += '<textarea id=d2notifyMsg style=background-color:#fcf3cf;width:100%;height:140px;resize:none;overflow-y:scroll;box-sizing:border-box;margin-bottom:4px></textarea>';
8167 + x += '<select style=width:100% id=d2notifyTimeout>';
8168 + x += '<option disabled value="">Only Applicable to Message Box Notifications</option>';
8169 + x += '<option value=2 selected>' + "Show for 2 Minutes (Default)" + '</option>';
8170 + x += '<option value=10>' + "Show for 10 minutes" + '</option>';
8171 + x += '<option value=30>' + "Show for 30 minutes" + '</option>';
8172 + x += '<option value=60>' + "Show for 60 minutes" + '</option>';
8173 + x += '<option value=0>' + "Show message until dismissed by user" + '</option>';
8174 + x += '</select>';
8175 setDialogMode(2, "Device Notification", 3, deviceToastFunctionEx, x);
8176 Q('d2notifyMsg').focus();
8177 }
8178
8179 function deviceToastFunctionEx() {
8153 - var op = Q('d2deviceop').value, title = Q('dp2notifyTitle').value, msg = Q('d2notifyMsg').value;
8180 + var op = Q('d2deviceop').value, title = Q('dp2notifyTitle').value, msg = Q('d2notifyMsg').value, timeout = parseFloat(Q('d2notifyTimeout').value);
8181 if (msg.length == 0) return;
8182 if (title == '') { title = decodeURIComponent('{{{extitle}}}'); }
8183 if (title == '') { title = "MeshCentral"; }
8184 + if(isNaN(timeout)){ timeout = 2; }
8185 if (op == 1) { // MessageBox
8158 - meshserver.send({ action: 'msg', type: 'messagebox', nodeid: currentNode._id, title: title, msg: msg });
8186 + meshserver.send({ action: 'msg', type: 'messagebox', nodeid: currentNode._id, title: title, msg: msg, timeout: (timeout * 60000) });
8187 } else if (op == 2) { // Toast
8188 meshserver.send({ action: 'toast', nodeids: [ currentNode._id ], title: title, msg: msg });
8189 } else if (op == 3) { // Old Style MessageBox