feat(macos): Add clipboard support to match Linux implementation
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#import "ScreenHandler.h"
|
||||
#import "H264Encoder.h"
|
||||
#import "InputHandler.h"
|
||||
#import "ClipboardHandler.h"
|
||||
#import "../client/IOCPClient.h"
|
||||
#import "../common/commands.h"
|
||||
#import "../common/FileTransferV2.h"
|
||||
@@ -282,6 +283,56 @@ void ScreenHandler::OnReceive(uint8_t* data, ULONG size)
|
||||
}
|
||||
break;
|
||||
|
||||
case COMMAND_SCREEN_SET_CLIPBOARD:
|
||||
// 服务端设置剪贴板: [cmd:1][text:N]
|
||||
if (size > 1) {
|
||||
if (ClipboardHandler::SetTextRaw((const char*)(data + 1), size - 1)) {
|
||||
NSLog(@">>> Clipboard SET: %zu bytes", size - 1);
|
||||
} else {
|
||||
NSLog(@"*** Clipboard SET failed");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case COMMAND_SCREEN_GET_CLIPBOARD:
|
||||
// 服务端请求剪贴板: [cmd:1][hash:64][hmac:16]
|
||||
// 返回: [TOKEN_CLIPBOARD_TEXT:1][text:N] 或 [COMMAND_GET_FOLDER:1][files]
|
||||
{
|
||||
// 优先检查剪贴板中的文件
|
||||
auto files = ClipboardHandler::GetFiles();
|
||||
if (!files.empty()) {
|
||||
// 返回 COMMAND_GET_FOLDER + 文件列表(多字符串格式:file1\0file2\0\0)
|
||||
std::vector<uint8_t> buf;
|
||||
buf.push_back(COMMAND_GET_FOLDER);
|
||||
for (const auto& f : files) {
|
||||
// 文件路径需要转换为 GBK 编码(服务端预期)
|
||||
std::string gbkPath = FileTransferV2::utf8ToGbk(f);
|
||||
buf.insert(buf.end(), gbkPath.begin(), gbkPath.end());
|
||||
buf.push_back(0); // 每个路径后的 null 终止符
|
||||
}
|
||||
buf.push_back(0); // 结束标记
|
||||
m_client->Send2Server((char*)buf.data(), buf.size());
|
||||
NSLog(@">>> Clipboard GET: %zu files", files.size());
|
||||
break;
|
||||
}
|
||||
|
||||
// 没有文件,返回文本
|
||||
std::string text = ClipboardHandler::GetText();
|
||||
if (!text.empty()) {
|
||||
std::vector<uint8_t> buf(1 + text.size());
|
||||
buf[0] = TOKEN_CLIPBOARD_TEXT;
|
||||
memcpy(&buf[1], text.data(), text.size());
|
||||
m_client->Send2Server((char*)buf.data(), buf.size());
|
||||
NSLog(@">>> Clipboard GET: %zu bytes text", text.size());
|
||||
} else {
|
||||
// 返回空剪贴板
|
||||
uint8_t empty = TOKEN_CLIPBOARD_TEXT;
|
||||
m_client->Send2Server((char*)&empty, 1);
|
||||
NSLog(@">>> Clipboard GET: empty");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case COMMAND_GET_FILE:
|
||||
// Server requests file download: [cmd:1][targetDir\0][file1\0file2\0...\0]
|
||||
// Use V2 protocol to upload files
|
||||
@@ -303,7 +354,10 @@ void ScreenHandler::OnReceive(uint8_t* data, ULONG size)
|
||||
ptr += fileGbk.length() + 1;
|
||||
}
|
||||
|
||||
// TODO: If no file list, get from clipboard (ClipboardHandler not implemented yet)
|
||||
// 如果没有文件列表,从剪贴板获取
|
||||
if (files.empty()) {
|
||||
files = ClipboardHandler::GetFiles();
|
||||
}
|
||||
|
||||
if (!files.empty() && !targetDir.empty()) {
|
||||
NSLog(@">>> COMMAND_GET_FILE: %zu files -> %s", files.size(), targetDir.c_str());
|
||||
|
||||
Reference in New Issue
Block a user