Skip to content

Commit

Permalink
add timeout to message box notifications
Browse files Browse the repository at this point in the history
Signed-off-by: si458 <[email protected]>
  • Loading branch information
si458 committed Jan 12, 2024
1 parent 78a49c5 commit b16057d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
5 changes: 4 additions & 1 deletion agents/meshcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
12 changes: 7 additions & 5 deletions meshctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down Expand Up @@ -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': {
Expand Down
43 changes: 36 additions & 7 deletions views/default.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -5770,6 +5770,14 @@
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>';
x += '<br /><input id=dp2notifyTitle maxlength=256 placeholder="' + "Title" + '" style=width:100% />';
x += '<textarea id=d2notifyMsg style=background-color:#fcf3cf;width:100%;height:140px;resize:none;overflow-y:scroll></textarea>';
x += '<select style=width:100% id=d2notifyTimeout>';
x += '<option disabled value="">Only Applicable to Message Box Notifications</option>';
x += '<option value=2 selected>' + "Show for 2 Minutes (Default)" + '</option>';
x += '<option value=10>' + "Show for 10 minutes" + '</option>';
x += '<option value=30>' + "Show for 30 minutes" + '</option>';
x += '<option value=60>' + "Show for 60 minutes" + '</option>';
x += '<option value=0>' + "Show message until dismissed by user" + '</option>';
x += '</select>';
setDialogMode(2, "Device Notification", 3, d2groupActionFunctionNotifyExec, x);
Q('d2notifyMsg').focus();
} else if (op == 109) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -8094,17 +8103,28 @@

function deviceMessageFunction() {
if (xxdialogMode) return;
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>');
var x = '<div style=margin-bottom:4px>Display a message box on the remote device.</div>';
x += '<textarea id=d2devMessage style=background-color:#fcf3cf;width:100%;height:80px;resize:none;overflow-y:scroll></textarea>';
x += '<select style=width:100% id=d2devTimeout>';
x += '<option disabled value="">Only Applicable to Message Box Notifications</option>';
x += '<option value=2 selected>' + "Show for 2 Minutes (Default)" + '</option>';
x += '<option value=10>' + "Show for 10 minutes" + '</option>';
x += '<option value=30>' + "Show for 30 minutes" + '</option>';
x += '<option value=60>' + "Show for 60 minutes" + '</option>';
x += '<option value=0>' + "Show message until dismissed by user" + '</option>';
x += '</div>';
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) });
}
}

Expand Down Expand Up @@ -8145,17 +8165,26 @@
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>';
x += '<br /><input id=dp2notifyTitle maxlength=256 placeholder="' + "Title" + '" style=width:100% />';
x += '<textarea id=d2notifyMsg style=background-color:#fcf3cf;width:100%;height:140px;resize:none;overflow-y:scroll></textarea>';
x += '<select style=width:100% id=d2notifyTimeout>';
x += '<option disabled value="">Only Applicable to Message Box Notifications</option>';
x += '<option value=2 selected>' + "Show for 2 Minutes (Default)" + '</option>';
x += '<option value=10>' + "Show for 10 minutes" + '</option>';
x += '<option value=30>' + "Show for 30 minutes" + '</option>';
x += '<option value=60>' + "Show for 60 minutes" + '</option>';
x += '<option value=0>' + "Show message until dismissed by user" + '</option>';
x += '</select>';
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
Expand Down

0 comments on commit b16057d

Please sign in to comment.