This commit is contained in:
Shelley Vohr 2021-10-26 14:14:08 +02:00 коммит произвёл GitHub
Родитель 78626a5cc6
Коммит deb7ab2a40
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 23 добавлений и 20 удалений

Просмотреть файл

@ -51,6 +51,17 @@ bool Clipboard::Has(const std::string& format_string,
std::string Clipboard::Read(const std::string& format_string) {
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
ui::ClipboardFormatType format(
ui::ClipboardFormatType::CustomPlatformType(format_string));
std::string data;
clipboard->ReadData(format, /* data_dst = */ nullptr, &data);
return data;
}
v8::Local<v8::Value> Clipboard::ReadBuffer(const std::string& format_string,
gin_helper::Arguments* args) {
ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
std::map<std::string, std::string> custom_format_names;
custom_format_names =
clipboard->ExtractCustomPlatformNames(ui::ClipboardBuffer::kCopyPaste,
@ -68,12 +79,6 @@ std::string Clipboard::Read(const std::string& format_string) {
std::string data;
clipboard->ReadData(format, /* data_dst = */ nullptr, &data);
return data;
}
v8::Local<v8::Value> Clipboard::ReadBuffer(const std::string& format_string,
gin_helper::Arguments* args) {
std::string data = Read(format_string);
return node::Buffer::Copy(args->isolate(), data.data(), data.length())
.ToLocalChecked();
}

Просмотреть файл

@ -44,13 +44,7 @@ ifdescribe(process.platform !== 'win32' || process.arch !== 'arm64')('clipboard
});
});
describe('clipboard.readBookmark', () => {
before(function () {
if (process.platform === 'linux') {
this.skip();
}
});
ifdescribe(process.platform !== 'linux')('clipboard.readBookmark', () => {
it('returns title and url', () => {
clipboard.writeBookmark('a title', 'https://electronjs.org');
@ -68,6 +62,16 @@ ifdescribe(process.platform !== 'win32' || process.arch !== 'arm64')('clipboard
});
});
ifdescribe(process.platform !== 'linux')('clipboard.read()', () => {
it('does not crash when reading various custom clipboard types', () => {
const type = process.platform === 'darwin' ? 'NSFilenamesPboardType' : 'FileNameW';
expect(() => {
const result = clipboard.read(type);
}).to.not.throw();
});
});
describe('clipboard.write()', () => {
it('returns data correctly', () => {
const text = 'test';
@ -100,13 +104,7 @@ ifdescribe(process.platform !== 'win32' || process.arch !== 'arm64')('clipboard
});
});
describe('clipboard.read/writeFindText(text)', () => {
before(function () {
if (process.platform !== 'darwin') {
this.skip();
}
});
ifdescribe(process.platform === 'darwin')('clipboard.read/writeFindText(text)', () => {
it('reads and write text to the find pasteboard', () => {
clipboard.writeFindText('find this');
expect(clipboard.readFindText()).to.equal('find this');