[Android] Copy button in the redbox should also support Windows and Linux platforms
See original GitHub issueThis is not a bug report but Help Wanted!
I have added a new feature of adding copy button in the redbox for RN Android, which copies the error message and stack trace to the host (your laptop’s) clipboard. Please see Add Copy and Dismiss Button in RN Android Red Box and have a try on it!
However it’s only supported on Mac OS for now. The reason is just that I don’t have available Windows or Linux computers to test this feature on. So I appreciate anyone’s help to add this feature on these two platforms.
Actually I already have the code for you, which I think should work. Please see https://github.com/facebook/react-native/blob/master/local-cli/server/util/copyToClipBoard.js
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
var child_process = require('child_process');
// Changes begin.
var iconv = require('iconv-lite');
// Changes end.
var spawn = child_process.spawn;
/**
* Copy the content to host system clipboard.
* This is only supported on Mac for now.
*/
function copyToClipBoard(content) {
switch (process.platform) {
case 'darwin':
var child = spawn('pbcopy', []);
child.stdin.end(new Buffer(content, 'utf8'));
return true;
// Changes begin.
case 'linux':
var child = spawn('xclip', ['-selection', 'clipboard']);
child.stdin.end(new Buffer(content, 'utf8'));
return true;
case 'win32':
var child = spawn('clip', []);
child.stdin.end(iconv.encode(content, 'utf16le'));
return true;
// Changes end.
default:
return false;
}
}
module.exports = copyToClipBoard;
The code between // Changes begin.
and // Changes end.
are the only things to be added by you. (Don’t forget to add the dependency for iconv at the beginning.)
Hope this will work on Windows and Linux!
If anyone needs more information on this, feel free to contact me.
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (9 by maintainers)
@jrodiger Thanks for your interest! This feature is extremely easy for you to test and enable on Windows. Here are some steps as follows: (1) Make a mistake and trigger a red box, where I believe there will be a copy button on the bottom. (2) Pressing the copy button should behave the same as on Mac OS (copy the red box information onto your host PC clipboard), however it’s not enabled on Windows as I described in this issue. What you could help is to follow my guidance in this issue above and try to enable this feature at https://github.com/facebook/react-native/blob/master/local-cli/server/util/copyToClipBoard.js
Hope this will help and this feature will be enabled with your effort and help!
Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we’re automatically closing issues after a period of inactivity. Please do not take it personally!
If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.