Skip to content

Commit

Permalink
Share your clipboard. Text, Screenshot, File are supported.
Browse files Browse the repository at this point in the history
  • Loading branch information
daviidwang committed Nov 7, 2023
0 parents commit a6f621f
Show file tree
Hide file tree
Showing 38 changed files with 1,665 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# .github/workflows/release.yml
name: goreleaser

on:
push:
# run only against tags
tags:
- "*"

permissions:
contents: write
# packages: write
# issues: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v4
with:
go-version: stable
# More assembly might be required: Docker logins, GPG, etc.
# It all depends on your needs.
- uses: goreleaser/goreleaser-action@v5
with:
# either 'goreleaser' (default) or 'goreleaser-pro':
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro'
# distribution:
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.gcopy
dist/
49 changes: 49 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines bellow are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
# - go generate ./...

builds:
- env:
- CGO_ENABLED=0
main: ./cmd
goos:
- linux
- windows
- darwin
goarch:
- amd64
# - arm
# - arm64

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip

# changelog:
# sort: asc
# filters:
# exclude:
# - "^docs:"
# - "^test:"
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023-2024 Weiyang Wang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
both:
go run cmd/gcopy.go --role=server,client --token=helloworld --debug
server:
go run cmd/gcopy.go --role=server --token=helloworld --debug
client:
go run cmd/gcopy.go --role=client --token=helloworld --debug
release:
goreleaser release --snapshot --clean
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<p align="center">
<img alt="GCopy Logo" src="docs/gcopy.png" height="120" />
<p align="center">Share your clipboard. Text, Screenshot, File are supported.</p>
</p>

---

A clipboard synchronization tool that powered by Golang.

**`Text`, `Screenshot`, `File` are supported**

This is a tool to synchronize clipboards between different operating systems.

Every second, the Client pushes or pulls clipboard content from Server.

## Simplest usage

If you have two device, they are in the same LAN.

on first device:

```
/path/to/gcopy --role=server,client
```

the other:

```
/path/to/gcopy --role=client --token=<output-token> --server=<server-ip>:3375
```

## Tow usage mode

### server&client <-> clients

This mode requires one device to simultaneously act as both the server and client. These clients must be on the same LAN and should be able to access each other.

![](docs/mode1.png)

Refer to the simplest usage

### clients <-> server <-> clients

In this mode, it is more flexible but requires a minimum of three devices, with one of them serving as the server. Clients do not need to be able to access each other, but it is required that clients can access the server.

![](docs/mode2.png)

server:

```
/path/to/gcopy --role=server
```

on first device:

```
/path/to/gcopy --role=client --token=<output-token> --server=<server-ip>:3375
```

the other:

```
/path/to/gcopy --role=client --token=<output-token> --server=<server-ip>:3375
```

## Read more

- [The work mechanism](docs/mechanism.md)

## Limitations

- Only tested on windows 10 & macOS Monterey
- It can only synchronize one file at a time

## Community

You have questions, need support and or just want to talk about GCopy?

Here are ways to get in touch with the community:

Email: [email protected]

Wechat:

<img width="200" src="docs/wechat-lllaoj.png">
55 changes: 55 additions & 0 deletions cmd/gcopy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"fmt"
"os"
"strings"
"sync"

"github.com/llaoj/gcopy/internal/client"
"github.com/llaoj/gcopy/internal/config"
"github.com/llaoj/gcopy/internal/server"
"github.com/sirupsen/logrus"
)

func main() {
fmt.Println(`
__ _ ___ ___ _ __ _ _
/ _ |/ __/ _ \| '_ \| | | |
| (_| | (_| (_) | |_) | |_| |
\__, |\___\___/| .__/ \__, |
__/ | | | __/ |
|___/ |_| |___/ `)
fmt.Println()

cfg := config.Get()
log := logrus.New()
log.SetOutput(os.Stdout)
if cfg.Debug {
log.SetLevel(logrus.TraceLevel)
} else {
log.SetLevel(logrus.InfoLevel)
}
log.Debugf("config: %+v", cfg)

var wg sync.WaitGroup
if strings.Contains(cfg.Role, "server") {
srv, err := server.NewServer(log)
if err != nil {
log.Fatal(err)
}
wg.Add(1)
go srv.Run(&wg)
}

if strings.Contains(cfg.Role, "client") {
cli, err := client.NewClient(log)
if err != nil {
log.Fatal(err)
}
wg.Add(1)
go cli.Run(&wg)
}

wg.Wait()
}
Binary file added docs/client.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/clipboard-struct.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gcopy-social.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gcopy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 111 additions & 0 deletions docs/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
## 背景

在日常的办公中, 我们通常需要操作两台以上的电脑, 尤其是软件开发工程师.

假如, 你需要同时操作Windows电脑和MacOS电脑, 在这两个设备之间传递信息变得非常麻烦.
因为很多原因, 我找不到一个非常好的工具能共享两个不同操作系统的设备的剪切板.
当我拷贝了一段文字, 我需要在另外一台电脑上粘贴, 这通常非常困难.

现在的工具通常只支持文字, 但是截图, 文件不支持. 同时, 他们通常要求设备必须要在同一个局域网, 可以互相访问.
而且他们往往收费.

这很不好!

所以, 我开发了GCopy, 它解决了这些问题.
目前, 你可以在Windows电脑与MacOS电脑之间共享剪切板, 支持文字, 截图和文件.
它对网络没有太高的要求, 不同的设备可以在同一个局域网, 也可以不在.

## 下载和安装

访问 https://github.com/llaoj/gcopy/releases

按照您的操作系统下载对应的压缩包. 可执行文件就在压缩包中, 解压就可以执行.

## 简单用法

使用它的方法非常简单, 你只需要运行一个命令. 让我们看看吧.

假如, 你有两台电脑, 一台电脑安装了Windows, 另外一台电脑安装了MacOS, 他们在同一个局域网中, 可以互相访问.

我们在MacOS启动GCopy, 它同时是客户端和服务端.

```
$ /path/to/gcopy.exe --role=server,client
__ _ ___ ___ _ __ _ _
/ _ |/ __/ _ \| '_ \| | | |
| (_| | (_| (_) | |_) | |_| |
\__, |\___\___/| .__/ \__, |
__/ | | | __/ |
|___/ |_| |___/
The Server has started, start the clients:
/path/to/gcopy --role=client --server=192.168.137.186:3375 --token=51b2f5
...
```

可以看到GCopy已经启动, 并打印出了客户端启动命令.

我们在Windows上, 打开Powershell并输入上面打印出的命令并执行.

**注意:** 客户端命令中出现的`--server=192.168.137.186:3375`是服务端监听的地址, 它是GCopy自动发现的您设备的IP地址, `3375`是GCopy工作的端口号. 如果他们不好使, 您可以在启动服务端的时候, 通过手动指定`--listen=<ip:port>`来自定义服务端监听的地址.

这样, 这两台设备的剪切板就可以共享了.

试一试拷贝&粘贴吧!

## 高级用法

想像一下, 如果你的设备不在同一个局域网内, 他们之间不能互相连接.

这时, 你可能需要另一种启动方式.

首先我们需要一台服务器, 要求它是可以被你的设备访问的. 通常我们的服务器都是Linux操作系统, 我们需要在它上面启动GCopy的服务端.

```
$ /path/to/gcopy --role=server
__ _ ___ ___ _ __ _ _
/ _ |/ __/ _ \| '_ \| | | |
| (_| | (_| (_) | |_) | |_| |
\__, |\___\___/| .__/ \__, |
__/ | | | __/ |
|___/ |_| |___/
The Server has started, start the clients:
/path/to/gcopy --role=client --server=47.198.199.100:3375 --token=51b2f5
...
```

服务端启动成功, 并打印出了客户端启动命令, 下面我们在不同的设备上运行这个命令就行啦!

## 选项

```
/path/to/gcopy --help
__ _ ___ ___ _ __ _ _
/ _ |/ __/ _ \| '_ \| | | |
| (_| | (_| (_) | |_) | |_| |
\__, |\___\___/| .__/ \__, |
__/ | | | __/ |
|___/ |_| |___/
Usage of gcopy:
-debug
Enable debug mode
-listen string
The server will listen this ip and port, format: [ip]:port (default ":3375")
-role string
Include: server/client/server,client (default "client")
-server string
The client will communicate with the server through this ip and port (default "127.0.0.1:3375")
-token string
Identity authentication between client and server
```

- `--listen` 服务端监听地址, 客户端会将该地址配置到`--server`中, 并通过这个地址与服务端交互. GCopy会自动探测当前服务器的IP地址. 通常使用自动发现的IP是好用的, 但如果它不好使, 您可能需要手动指定, 可以使用这个选项.
- `--token` 服务端和客户端之间身份认证的密钥, 服务端在启动的时候会自动生成, 如果想手动指定, 可以使用这个选项.
- `--debug` 开启调试模式获取更多日志.
Loading

0 comments on commit a6f621f

Please sign in to comment.