f21fa5b5e8
Commilitia Drop:自托管的跨设备剪贴板同步与点对点文件传输。 - 后端 Go(chi / SQLite WAL / SSE Hub / WebRTC signaling + 状态机 / Relay ring buffer),编译进单个 distroless 镜像(前端 go:embed)。 - 前端 React + TanStack Router + Zustand,自实现 SSE + WebRTC P2P,NAT 受阻时回退服务端中继;聚珍(Juzhen)CJK 综合排版。 - 桌面端 Wails v2(macOS / Windows),瘦客户端复用 web。 - 鉴权 OIDC PKCE(自建 Casdoor 等),refresh_token 信封加密存系统密钥库;iOS Shortcut 用 HS256 scoped token。 架构文档与变更记录见 docs 分支(PROJECT_BRIEF / FRONTEND_DESIGN / CHANGELOG)。 本次为公开发布初始提交:完整开发历史(含部署细节)留存于私有归档,公开仓库自此干净起步。
68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
//go:build windows
|
|
|
|
package platform
|
|
|
|
import (
|
|
"context"
|
|
|
|
"golang.design/x/clipboard"
|
|
)
|
|
|
|
// windowsClipboard is the Windows Source backed by golang.design/x/clipboard
|
|
// (pure syscall, no cgo): it watches the clipboard for local copies via
|
|
// GetClipboardSequenceNumber polling and writes plain text back.
|
|
type windowsClipboard struct {
|
|
ready bool
|
|
}
|
|
|
|
// NewClipboardSource returns the platform clipboard Source (Windows). If the
|
|
// clipboard can't be initialised it degrades to an inert source so the rest of
|
|
// the sync wiring still runs.
|
|
func NewClipboardSource() Source {
|
|
return &windowsClipboard{ready: clipboard.Init() == nil}
|
|
}
|
|
|
|
func (c *windowsClipboard) Watch(ctx context.Context) <-chan ClipboardEvent {
|
|
out := make(chan ClipboardEvent)
|
|
go func() {
|
|
defer close(out)
|
|
if !c.ready {
|
|
<-ctx.Done()
|
|
return
|
|
}
|
|
changes := clipboard.Watch(ctx, clipboard.FmtText)
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case data, ok := <-changes:
|
|
if !ok {
|
|
return
|
|
}
|
|
if data.Format != clipboard.FmtText || len(data.Bytes) == 0 {
|
|
continue
|
|
}
|
|
// golang.design/x/clipboard surfaces only the text — the Windows
|
|
// privacy formats (ExcludeClipboardContentFromMonitorProcessing /
|
|
// CanUploadToCloudClipboard) aren't exposed, so Sensitive stays
|
|
// false and the server's 5-min TTL is the backstop. A raw
|
|
// EnumClipboardFormats check is a possible follow-up.
|
|
select {
|
|
case out <- ClipboardEvent{Text: string(data.Bytes)}:
|
|
case <-ctx.Done():
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}()
|
|
return out
|
|
}
|
|
|
|
func (c *windowsClipboard) Write(text string) error {
|
|
if !c.ready {
|
|
return nil
|
|
}
|
|
clipboard.Write(clipboard.FmtText, []byte(text))
|
|
return nil
|
|
}
|