Add buffer support in clipboard.write()
This commit is contained in:
parent
66cc07d8e9
commit
03fdc7aa28
2 changed files with 17 additions and 1 deletions
|
@ -66,6 +66,7 @@ void Clipboard::Write(const mate::Dictionary& data, mate::Arguments* args) {
|
||||||
ui::ScopedClipboardWriter writer(GetClipboardType(args));
|
ui::ScopedClipboardWriter writer(GetClipboardType(args));
|
||||||
base::string16 text, html, bookmark;
|
base::string16 text, html, bookmark;
|
||||||
gfx::Image image;
|
gfx::Image image;
|
||||||
|
std::map<std::string, v8::Local<v8::Value>> customBuffers;
|
||||||
|
|
||||||
if (data.Get("text", &text)) {
|
if (data.Get("text", &text)) {
|
||||||
writer.WriteText(text);
|
writer.WriteText(text);
|
||||||
|
@ -84,6 +85,14 @@ void Clipboard::Write(const mate::Dictionary& data, mate::Arguments* args) {
|
||||||
|
|
||||||
if (data.Get("image", &image))
|
if (data.Get("image", &image))
|
||||||
writer.WriteImage(image.AsBitmap());
|
writer.WriteImage(image.AsBitmap());
|
||||||
|
|
||||||
|
if (data.Get("buffer", &customBuffers)) {
|
||||||
|
for (auto i = customBuffers.begin(); i != customBuffers.end(); ++i) {
|
||||||
|
writer.WriteData(node::Buffer::Data(i->second),
|
||||||
|
node::Buffer::Length(i->second),
|
||||||
|
ui::Clipboard::GetFormatType(i->first));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
base::string16 Clipboard::ReadText(mate::Arguments* args) {
|
base::string16 Clipboard::ReadText(mate::Arguments* args) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const fs = require('fs')
|
||||||
const {Buffer} = require('buffer')
|
const {Buffer} = require('buffer')
|
||||||
|
|
||||||
const {clipboard, nativeImage} = require('electron')
|
const {clipboard, nativeImage} = require('electron')
|
||||||
|
@ -67,17 +68,23 @@ describe('clipboard module', function () {
|
||||||
var i = nativeImage.createFromPath(p)
|
var i = nativeImage.createFromPath(p)
|
||||||
var markup = process.platform === 'darwin' ? "<meta charset='utf-8'><b>Hi</b>" : process.platform === 'linux' ? '<meta http-equiv="content-type" ' + 'content="text/html; charset=utf-8"><b>Hi</b>' : '<b>Hi</b>'
|
var markup = process.platform === 'darwin' ? "<meta charset='utf-8'><b>Hi</b>" : process.platform === 'linux' ? '<meta http-equiv="content-type" ' + 'content="text/html; charset=utf-8"><b>Hi</b>' : '<b>Hi</b>'
|
||||||
var bookmark = {title: 'a title', url: 'test'}
|
var bookmark = {title: 'a title', url: 'test'}
|
||||||
|
const pdfType = process.platform === 'darwin' ? 'com.adobe.pdf' : 'application/pdf'
|
||||||
|
const pdf = fs.readFileSync(path.join(fixtures, 'assets', 'cat.pdf'))
|
||||||
clipboard.write({
|
clipboard.write({
|
||||||
text: 'test',
|
text: 'test',
|
||||||
html: '<b>Hi</b>',
|
html: '<b>Hi</b>',
|
||||||
rtf: '{\\rtf1\\utf8 text}',
|
rtf: '{\\rtf1\\utf8 text}',
|
||||||
bookmark: 'a title',
|
bookmark: 'a title',
|
||||||
image: p
|
image: p,
|
||||||
|
buffer: {
|
||||||
|
[pdfType]: pdf
|
||||||
|
}
|
||||||
})
|
})
|
||||||
assert.equal(clipboard.readText(), text)
|
assert.equal(clipboard.readText(), text)
|
||||||
assert.equal(clipboard.readHTML(), markup)
|
assert.equal(clipboard.readHTML(), markup)
|
||||||
assert.equal(clipboard.readRTF(), rtf)
|
assert.equal(clipboard.readRTF(), rtf)
|
||||||
assert.equal(clipboard.readImage().toDataURL(), i.toDataURL())
|
assert.equal(clipboard.readImage().toDataURL(), i.toDataURL())
|
||||||
|
assert.deepEqual(clipboard.readBuffer(pdfType), pdf)
|
||||||
|
|
||||||
if (process.platform !== 'linux') {
|
if (process.platform !== 'linux') {
|
||||||
assert.deepEqual(clipboard.readBookmark(), bookmark)
|
assert.deepEqual(clipboard.readBookmark(), bookmark)
|
||||||
|
|
Loading…
Reference in a new issue