Files
SimpleRemoter/macos/ActivityHistory.h
T
yuanyuanxianganddeepseek-flash 06b93f7bdb Feat(client): complete the macOS feature set (phase 0 and 1)
Phase 0 makes implementations that already existed reachable. macOS now
declares TERMINAL, SCREEN_CLIPBOARD, PROCESS and C2C_RECV_ACK; PROCESS is a
new bit and Linux declares it too. SystemManager was dead code -- its
constructor took a second argument and it did not derive IOCPManager, so the
sub-connection skeleton could never instantiate it -- and now matches the
createHandler/OnReceive contract, so COMMAND_SYSTEM really spawns a
sub-connection (proc_listpids, SIGKILL). DataProcess always gets a NULL user,
so main.mm keeps a g_pMainClient handle and the V2 C2C receiver finally
answers TOKEN_C2C_RECV_RESULT. The server asks for SupportsTerminal() on MAC
for exec_command / terminal_* and for SupportsProcess() for kill_process, so
an old build gets "client is too old" instead of a command nobody answers;
kToolPlatforms and mcp/tools.json follow. http_probe stays win/lnx: the
terminal works on macOS, but the probe uses GNU-only base64 -w.

Phase 1 is POSIX parity. ScreenPreview captures through CGDisplayCreateImage,
scales and ships BGRX for the server to encode, and the capability is only
declared when preflight or a real capture says the display is readable.
ActivityHistory samples the frontmost layer-0 window once a second and prints
the same records as Windows and Linux. COMMAND_SCREEN_KEYFRAME_REQ is now
consumed by Linux (x264 IDR) and macOS (VideoToolbox force keyframe): the
receive thread raises a flag, the capture thread -- which owns the encoder --
consumes it and puts it back if the frame never went out. The macOS quality
level persists in NSUserDefaults because main.mm rewrites config.conf.

Linux client and Debug x64 server rebuild green; check_platform_table PASS.
Not built or run on a Mac.

Co-Authored-By: deepseek-flash
2026-11-14 13:30:50 +01:00

56 lines
2.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
// macOS 客户端的「历史活动」采样器(服务端 COMMAND_QUERY_ACTIVITY → TOKEN_REPORT_ACTIVITY)。
//
// 后台每秒采样一次前台窗口(CGWindowListCopyWindowInfo 取最前面的 layer 0 窗口),
// 输出格式与 Windows/Linux 端完全一致,服务端 CActivityDialog 与 MCP
// get_activity_history 都只按行切分纯文本,不需要改:
// [2026-11-14 10:00:00] [Safari - GitHub] 12s
// 停留不足 5 秒的一闪而过不记录;同一条记录里的窗口标题会跟着更新
// (浏览器切标签页标题常变,但窗口没换,仍算同一段停留)。
//
// 与 Windows/Linux 一样各平台独立实现:Linux 那份要 X11,macOS 这份要 CGWindowList +
// NSWorkspace,共用的只有输出格式。
#include <atomic>
#include <deque>
#include <mutex>
#include <string>
#include <thread>
class MacActivityHistory
{
public:
static MacActivityHistory& Instance();
// 启动后台采样线程(幂等)。应当在进程启动后尽早调用,历史从那一刻开始攒;
// 查询时才启动的话,第一次查到的永远是空表。
void Start();
// 进程退出时收线程;可以再次 Start(与 Linux 端一样保留这个能力)
void Stop();
// 最新在前,每行一条;进行中的窗口(驻留已达阈值)排在最前
std::string Dump() const;
// 还没有够 5 秒的记录时的说明,避免对话框全空
static std::string EmptyText();
private:
MacActivityHistory() = default;
~MacActivityHistory() { Stop(); }
MacActivityHistory(const MacActivityHistory&) = delete;
MacActivityHistory& operator=(const MacActivityHistory&) = delete;
void Loop();
private:
mutable std::mutex m_mutex;
std::deque<std::string> m_records; // 已完成记录,最新在前
std::string m_curTitle;
std::string m_curStartTime;
int m_curDwellSec = 0;
std::atomic<bool> m_running{ false };
std::atomic<bool> m_started{ false };
std::thread m_thread;
};