2016-06-30 15:09:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-06-30 15:09:55 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var child_process = require('child_process');
|
|
|
|
var spawn = child_process.spawn;
|
2017-04-04 17:19:43 +00:00
|
|
|
var path = require('path');
|
|
|
|
var fs = require('fs');
|
2016-06-30 15:09:55 +00:00
|
|
|
|
2017-04-04 17:19:43 +00:00
|
|
|
const xsel = path.join(__dirname, 'external/xsel');
|
|
|
|
fs.chmodSync(xsel, '0755');
|
2016-06-30 15:09:55 +00:00
|
|
|
/**
|
|
|
|
* Copy the content to host system clipboard.
|
|
|
|
*/
|
|
|
|
function copyToClipBoard(content) {
|
|
|
|
switch (process.platform) {
|
|
|
|
case 'darwin':
|
|
|
|
var child = spawn('pbcopy', []);
|
|
|
|
child.stdin.end(new Buffer(content, 'utf8'));
|
|
|
|
return true;
|
2017-01-20 00:23:32 +00:00
|
|
|
case 'win32':
|
|
|
|
var child = spawn('clip', []);
|
|
|
|
child.stdin.end(new Buffer(content, 'utf8'));
|
|
|
|
return true;
|
2017-04-04 17:19:43 +00:00
|
|
|
case 'linux':
|
|
|
|
var child = spawn(xsel, ['--clipboard', '--input']);
|
|
|
|
child.stdin.end(new Buffer(content, 'utf8'));
|
|
|
|
return true;
|
2016-06-30 15:09:55 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = copyToClipBoard;
|