Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit e1b2d50
Author: Kien Nguyen <[email protected]>
Date:   Fri May 31 14:11:09 2019 +0900

    correct usage of await and null-conditional op

commit 66da510
Author: Kien Nguyen <[email protected]>
Date:   Fri May 31 11:26:43 2019 +0700

    README

commit 3eff408
Author: Kien Nguyen <[email protected]>
Date:   Fri May 31 12:42:59 2019 +0900

    working

commit 3e548d9
Author: Kien Nguyen <[email protected]>
Date:   Wed May 29 16:45:04 2019 +0900

    minor refactoring

commit dfd7bd3
Author: Kien Nguyen <[email protected]>
Date:   Thu May 23 13:32:45 2019 +0900

    add jsonrpc
  • Loading branch information
kiennq committed May 31, 2019
1 parent 7c4b091 commit 5f08c15
Show file tree
Hide file tree
Showing 7 changed files with 392 additions and 207 deletions.
41 changes: 18 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,40 @@ To know more about clipboard refer to [this article](https://docs.microsoft.com/
### Running as server process
In this mode, `csclip` will communicate with client process (normally text editor) via stdio.
Client process should watch `csclip` stdout for notification.
Both side will communicating via [`JsonRPC`](https://www.jsonrpc.org/)

``` shell
csclip server
```

Optionally, json data can be encoded in [base64](https://en.wikipedia.org/wiki/Base64)

``` shell
csclip server -e
```

#### Monitoring clipboard change
When running as server, `csclip` will monitoring clipboard change and notify client about newly copied text.
With that, newly copied text will always be available in client, and can be paste without querying the clipboard again.

Notification format:
Notification `paste`:

``` json
<message len>\r\n
{"command":"paste", "args":"<copied string>"}
{"method":"paste", "params":["<copied string>"]}
```

### Proactively getting text from clipboard
Client can proactively getting text from clipboard by sending this notification
Client can proactively getting text from clipboard by sending `get` request.

``` json
{"method":"get", "params":["<data format>"]}
```

`csclip` will response with

``` json
<message len>\r\n
{"command":"paste"}
{"result":"<requested data>"}
```

### Copy data to clipboard
Client can sent the following notification to `csclip` and get data to be copied to clipboard.
Client can sent `copy` notification to `csclip` to notify the data should be copied to clipboard.

``` json
<message len>\r\n
{"command":"copy", "data":[{"cf":,"data":},{}]}
{"method":"copy", "params":[[{"cf": "<data format>", "data": "<data to put into clipboard>"},{}]]}
```

### Delay copying to clipboard
Expand All @@ -80,22 +78,19 @@ This happens a lot when user copy some texts that can be hightlight using html (
In that case, client can put those data formats to clipboard latter by leave the `data` field for those formats to `null`

``` json
<message len>\r\n
{"command":"copy", "data":[{"cf":,"data":},{}]}
{"method":"copy", "params":[[{"cf": "<data format>", "data":null},{}]]}
```

When other application request those data formats, `csclip` will notify client
When other application request those data formats, `csclip` will send `get` request to client.

``` json
<message len>\r\n
{"command":"get", "args":"<format id string>"}
{"method":"get", "params":["<data format>"]}
```

Upon receving that, client should render the required format and notify back to `csclip`
Upon receving that, client should render the required format and response back the result to `csclip`

``` json
<message len>\r\n
{"command":"put", "data":[{"cf":"<format id string>","data":}]}
{"result":"<requested data>"}
```

Please refer to [multiclip-mode](https://github.com/kiennq/highlight2clipboard) for example of client implementation.
47 changes: 47 additions & 0 deletions csclip.test/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.5.0" newVersion="4.1.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.Pipelines" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Nerdbank.Streams" publicKeyToken="cac503e1823ce71c" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.VisualStudio.Threading" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-16.0.0.0" newVersion="16.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
1 change: 1 addition & 0 deletions csclip.test/csclip.test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
Expand Down
48 changes: 46 additions & 2 deletions csclip/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.5.0" newVersion="4.1.5.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.Pipelines" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Nerdbank.Streams" publicKeyToken="cac503e1823ce71c" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.VisualStudio.Threading" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-16.0.0.0" newVersion="16.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Loading

0 comments on commit 5f08c15

Please sign in to comment.