Fixed setclip bug where success was sent prematurely for Windows Service
Bryan Roe committed
Jun 29, 2022 at 14:18 UTC
c22219f903dbe3d0c2ddedf2dcf73421191499b8
1 file changed
+17
-8
agents/meshcore.js
+17
-8
@@ -1365,13 +1365,18 @@ function handleServerCommand(data) {
1365
}
1366
case 'setclip': {
1367
// Set the load clipboard to a user value
1368
- if (typeof data.data == 'string') {
1368
+ if (typeof data.data == 'string')
1369
+ {
1370
MeshServerLogEx(22, [data.data.length], "Setting clipboard content, " + data.data.length + " byte(s)", data);
1370
- if (require('MeshAgent').isService) {
1371
- if (process.platform != 'win32') {
1371
+ if (require('MeshAgent').isService)
1372
+ {
1373
+ if (process.platform != 'win32')
1374
+ {
1375
require('clipboard').dispatchWrite(data.data);
1376
+ mesh.SendCommand({ action: 'msg', type: 'setclip', sessionid: data.sessionid, success: true });
1377
}
1374
- else {
1378
+ else
1379
+ {
1380
var clipargs = data.data;
1381
var uid = require('user-sessions').consoleUid();
1382
var user = require('user-sessions').getUsername(uid);
@@ -1381,20 +1386,24 @@ function handleServerCommand(data) {
1386
this._dispatcher = require('win-dispatcher').dispatch({ user: user, modules: [{ name: 'clip-dispatch', script: "module.exports = { dispatch: function dispatch(val) { require('clipboard')(val); process.exit(); } };" }], launch: { module: 'clip-dispatch', method: 'dispatch', args: [clipargs] } });
1387
this._dispatcher.parent = this;
1388
//require('events').setFinalizerMetadata.call(this._dispatcher, 'clip-dispatch');
1384
- this._dispatcher.on('connection', function (c) {
1389
+ this._dispatcher.on('connection', function (c)
1390
+ {
1391
this._c = c;
1392
this._c.root = this.parent;
1387
- this._c.on('end', function () {
1393
+ this._c.on('end', function ()
1394
+ {
1395
this.root._dispatcher = null;
1396
this.root = null;
1397
+ mesh.SendCommand({ action: 'msg', type: 'setclip', sessionid: data.sessionid, success: true });
1398
});
1399
});
1400
}
1401
}
1394
- else {
1402
+ else
1403
+ {
1404
require("clipboard")(data.data);
1405
+ mesh.SendCommand({ action: 'msg', type: 'setclip', sessionid: data.sessionid, success: true });
1406
} // Set the clipboard
1397
- mesh.SendCommand({ action: 'msg', type: 'setclip', sessionid: data.sessionid, success: true });
1407
}
1408
break;
1409
}