mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-21 10:43:36 +00:00
Updated xclip clipboard, to so xclip cleanup occurs if process exits before xclip timeout
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -316,41 +316,45 @@ function lin_xclip_copy(txt)
|
|||||||
ret.child.promise = ret;
|
ret.child.promise = ret;
|
||||||
ret.child.stderr.on('data', function (c) { console.log(c.toString()); });
|
ret.child.stderr.on('data', function (c) { console.log(c.toString()); });
|
||||||
ret.child.stdout.on('data', function (c) { console.log(c.toString()); });
|
ret.child.stdout.on('data', function (c) { console.log(c.toString()); });
|
||||||
|
ret.child._cleanup = function _cleanup(p)
|
||||||
|
{
|
||||||
|
var ch = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
|
ch.stdout.str = ''; ch.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||||
|
ch.stderr.on('data', function (c) { console.log(c.toString()); });
|
||||||
|
if (process.platform == 'freebsd')
|
||||||
|
{
|
||||||
|
ch.stdin.write('ps -axo pid -o command ')
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ch.stdin.write('ps -e -o pid -o cmd ')
|
||||||
|
}
|
||||||
|
ch.stdin.write('| grep "xclip(' + p._hashCode() + ')" | ' + " tr '\\n' '`' | awk -F'`' '");
|
||||||
|
ch.stdin.write('{');
|
||||||
|
ch.stdin.write(' for(i=1;i<NF;++i)');
|
||||||
|
ch.stdin.write(' {');
|
||||||
|
ch.stdin.write(' split($i,tokens," ");');
|
||||||
|
ch.stdin.write(' name=substr($i, length(tokens[1])+2);');
|
||||||
|
ch.stdin.write(' if(substr(name,1,1)==" ") { name=substr($i, length(tokens[1])+3); }');
|
||||||
|
ch.stdin.write(' chkname=substr(name,1,6);')
|
||||||
|
ch.stdin.write(' if(chkname=="xclip(")');
|
||||||
|
ch.stdin.write(' {');
|
||||||
|
ch.stdin.write(' printf "%s", tokens[1];');
|
||||||
|
ch.stdin.write(' }');
|
||||||
|
ch.stdin.write(' }');
|
||||||
|
ch.stdin.write("}'\nexit\n");
|
||||||
|
ch.waitExit();
|
||||||
|
if (ch.stdout.str != '')
|
||||||
|
{
|
||||||
|
process.kill(parseInt(ch.stdout.str), 'SIGKILL');
|
||||||
|
}
|
||||||
|
delete xclipTable[p._hashCode()];
|
||||||
|
};
|
||||||
ret.child.on('exit', function ()
|
ret.child.on('exit', function ()
|
||||||
{
|
{
|
||||||
xclipTable[this.promise._hashCode()] = setTimeout(function (p)
|
xclipTable[this.promise._hashCode()] = setTimeout(function (p)
|
||||||
{
|
{
|
||||||
var ch = require('child_process').execFile('/bin/sh', ['sh']);
|
p.child._cleanup(p);
|
||||||
ch.stdout.str = ''; ch.stdout.on('data', function (c) { this.str += c.toString(); });
|
|
||||||
ch.stderr.on('data', function (c) { console.log(c.toString()); });
|
|
||||||
if (process.platform == 'freebsd')
|
|
||||||
{
|
|
||||||
ch.stdin.write('ps -axo pid -o command ')
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ch.stdin.write('ps -e -o pid -o cmd ')
|
|
||||||
}
|
|
||||||
ch.stdin.write('| grep "xclip(' + p._hashCode() + ')" | ' + " tr '\\n' '`' | awk -F'`' '");
|
|
||||||
ch.stdin.write('{');
|
|
||||||
ch.stdin.write(' for(i=1;i<NF;++i)');
|
|
||||||
ch.stdin.write(' {');
|
|
||||||
ch.stdin.write(' split($i,tokens," ");');
|
|
||||||
ch.stdin.write(' name=substr($i, length(tokens[1])+2);');
|
|
||||||
ch.stdin.write(' if(substr(name,1,1)==" ") { name=substr($i, length(tokens[1])+3); }');
|
|
||||||
ch.stdin.write(' chkname=substr(name,1,6);')
|
|
||||||
ch.stdin.write(' if(chkname=="xclip(")');
|
|
||||||
ch.stdin.write(' {');
|
|
||||||
ch.stdin.write(' printf "%s", tokens[1];');
|
|
||||||
ch.stdin.write(' }');
|
|
||||||
ch.stdin.write(' }');
|
|
||||||
ch.stdin.write("}'\nexit\n");
|
|
||||||
ch.waitExit();
|
|
||||||
if(ch.stdout.str != '')
|
|
||||||
{
|
|
||||||
process.kill(parseInt(ch.stdout.str), 'SIGKILL');
|
|
||||||
}
|
|
||||||
delete xclipTable[p._hashCode()];
|
|
||||||
}, 20000, this.promise);
|
}, 20000, this.promise);
|
||||||
this.promise._res();
|
this.promise._res();
|
||||||
});
|
});
|
||||||
@@ -358,6 +362,13 @@ function lin_xclip_copy(txt)
|
|||||||
{
|
{
|
||||||
this.end();
|
this.end();
|
||||||
});
|
});
|
||||||
|
ret.child.on('~', function ()
|
||||||
|
{
|
||||||
|
if (xclipTable[this.promise._hashCode()])
|
||||||
|
{
|
||||||
|
this._cleanup(this.promise);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user