node-copy-paste icon indicating copy to clipboard operation
node-copy-paste copied to clipboard

Clipboard goes blank after program has ended

Open ghost opened this issue 10 years ago • 3 comments

Hi there,

Thank for this awesome module. I am using Ubuntu and every time I close my node app, the clipboard goes blank. Is it possible to have it stay like it last was? Like if I copy "Foo" and then close the program, to still be able to paste "Foo"?

Thanks!

ghost avatar Aug 01 '15 17:08 ghost

I'm glad you are enjoying the module. :)

That's very surprising. Nothing special happens on exit. Underneath the covers, copy-paste uses xclip. I briefly looked through the docs and I don't seeing anything that would explain this behavior.

I'm stumped! Perhaps an extra paste call is being made somewhere?

xavi- avatar Aug 02 '15 17:08 xavi-

I'll check and get back to you, thanks for your help!

ghost avatar Aug 03 '15 08:08 ghost

this is my code, couldn't find anything

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var clipboard = require('copy-paste');
var previousClipboardContent = clipboard.paste();

io.on('connection', function(socket){
  console.log('connection');

  socket.on('clipboard', function(data){    
    clipboard.copy(data, function() {
      console.log('copied some text: ' + clipboard.paste());
      previousClipboardContent = clipboard.paste();
    });
  });
});

http.listen(3000, function(){
  console.log('listening on *:3000');
});

function checkClipboard () {
   if (previousClipboardContent !== clipboard.paste()) {
     io.emit('clipboard', clipboard.paste());
   }
}
setInterval(checkClipboard, 1*1000);

ghost avatar Aug 03 '15 09:08 ghost