Skip to content

Commit 00f16a2

Browse files
committed
Fix: better clipboard sync behavior options
1 parent 346a6c6 commit 00f16a2

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

PowerRemoteDesktop_Server/PowerRemoteDesktop_Server.psm1

+20-7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ enum TransportMode {
6666
Base64 = 2
6767
}
6868

69+
enum ClipboardMode {
70+
Receive = 1
71+
Send = 2
72+
Both = 3
73+
}
74+
6975
function Write-Banner
7076
{
7177
<#
@@ -1454,6 +1460,9 @@ $global:IngressEventScriptBlock = {
14541460
# Clipboard Update
14551461
"ClipboardUpdated"
14561462
{
1463+
if ($Param.Clipboard -eq "Disabled" -or $Param.Clipboard -eq "Send")
1464+
{ continue }
1465+
14571466
if (-not ($aEvent.PSobject.Properties.name -match "Text"))
14581467
{ continue }
14591468

@@ -1650,7 +1659,7 @@ $global:EgressEventScriptBlock = {
16501659
{
16511660
$eventTriggered = $false
16521661

1653-
if ($Param.SynchronizeClipboard)
1662+
if ($Param.Clipboard -eq "Both" -or $Param.Clipboard -eq "Send")
16541663
{
16551664
# IDEA: Check for existing clipboard change event or implement a custom clipboard
16561665
# change detector using "WM_CLIPBOARDUPDATE" for example (WITHOUT INLINE C#)
@@ -1820,9 +1829,12 @@ function Invoke-RemoteDesktopServer
18201829
0 = Lowest quality.
18211830
100 = Highest quality.
18221831
1823-
.PARAMETER DisableClipboard
1824-
This option disable Clipboard synchronization with remote peer. By default Clipboard synchronization
1825-
is enabled and will synchronize only if both Viewer and Server have Clipboard synchronization enabled.
1832+
.PARAMETER Clipboard
1833+
Define clipboard synchronization rules:
1834+
- "Disabled": Completely disable clipboard synchronization.
1835+
- "Receive": Update local clipboard with remote clipboard only.
1836+
- "Send": Send local clipboard to remote peer.
1837+
- "Both": Clipboards are fully synchronized between Viewer and Server.
18261838
#>
18271839

18281840
param (
@@ -1841,7 +1853,7 @@ function Invoke-RemoteDesktopServer
18411853

18421854
[int] $ImageQuality = 100,
18431855

1844-
[switch] $DisableClipboard
1856+
[ClipboardMode] $Clipboard
18451857
)
18461858

18471859

@@ -1969,7 +1981,8 @@ function Invoke-RemoteDesktopServer
19691981

19701982
# Create Runspace #2 for Incoming Events.
19711983
$param = New-Object -TypeName PSCustomObject -Property @{
1972-
Reader = $clientEvents.Reader
1984+
Reader = $clientEvents.Reader
1985+
Clipboard = $Clipboard
19731986
}
19741987

19751988
$newRunspace = (New-RunSpace -ScriptBlock $global:IngressEventScriptBlock -Param $param)
@@ -1978,7 +1991,7 @@ function Invoke-RemoteDesktopServer
19781991
# Create Runspace #3 for Outgoing Events
19791992
$param = New-Object -TypeName PSCustomObject -Property @{
19801993
Writer = $clientEvents.Writer
1981-
SynchronizeClipboard = -not $DisableClipboard
1994+
Clipboard = $Clipboard
19821995
}
19831996

19841997
$newRunspace = (New-RunSpace -ScriptBlock $global:EgressEventScriptBlock -Param $param)

PowerRemoteDesktop_Viewer/PowerRemoteDesktop_Viewer.psm1

+20-6
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ $global:EphemeralTrustedServers = @()
6767
$global:LocalStoragePath = "HKCU:\SOFTWARE\PowerRemoteDesktop_Viewer"
6868
$global:LocalStoragePath_TrustedServers = -join($global:LocalStoragePath, "\TrustedServers")
6969

70+
enum ClipboardMode {
71+
Disabled = 1
72+
Receive = 2
73+
Send = 3
74+
Both = 4
75+
}
76+
7077
function Write-Banner
7178
{
7279
<#
@@ -1152,6 +1159,9 @@ $global:IngressEventScriptBlock = {
11521159

11531160
"ClipboardUpdated"
11541161
{
1162+
if ($Param.Clipboard -eq "Disabled" -or $Param.Clipboard -eq "Send")
1163+
{ continue }
1164+
11551165
if (-not ($aEvent.PSobject.Properties.name -match "Text"))
11561166
{ continue }
11571167

@@ -1226,7 +1236,7 @@ $global:EgressEventScriptBlock = {
12261236
{
12271237
$eventTriggered = $false
12281238

1229-
if ($Param.SynchronizeClipboard)
1239+
if ($Param.Clipboard -eq "Both" -or $Param.Clipboard -eq "Send")
12301240
{
12311241
# IDEA: Check for existing clipboard change event or implement a custom clipboard
12321242
# change detector using "WM_CLIPBOARDUPDATE" for example (WITHOUT INLINE C#)
@@ -1401,9 +1411,12 @@ function Invoke-RemoteDesktopViewer
14011411
.PARAMETER DisableVerbosity
14021412
Disable verbosity (not recommended)
14031413
1404-
.PARAMETER DisableClipboard
1405-
This option disable Clipboard synchronization with remote peer. By default Clipboard synchronization
1406-
is enabled and will synchronize only if both Viewer and Server have Clipboard synchronization enabled.
1414+
.PARAMETER Clipboard
1415+
Define clipboard synchronization rules:
1416+
- "Disabled": Completely disable clipboard synchronization.
1417+
- "Receive": Update local clipboard with remote clipboard only.
1418+
- "Send": Send local clipboard to remote peer.
1419+
- "Both": Clipboards are fully synchronized between Viewer and Server.
14071420
14081421
.EXAMPLE
14091422
Invoke-RemoteDesktopViewer -ServerAddress "192.168.0.10" -ServerPort "2801" -SecurePassword (ConvertTo-SecureString -String "s3cr3t!" -AsPlainText -Force)
@@ -1421,7 +1434,7 @@ function Invoke-RemoteDesktopViewer
14211434
[String] $Password,
14221435

14231436
[switch] $DisableVerbosity,
1424-
[switch] $DisableClipboard
1437+
[ClipboardMode] $Clipboard = "Both"
14251438
)
14261439

14271440
[System.Collections.Generic.List[PSCustomObject]]$runspaces = @()
@@ -1819,6 +1832,7 @@ function Invoke-RemoteDesktopViewer
18191832
$param = New-Object -TypeName PSCustomObject -Property @{
18201833
Client = $session.ClientEvents
18211834
VirtualDesktopSyncHash = $virtualDesktopSyncHash
1835+
Clipboard = $Clipboard
18221836
}
18231837

18241838
$newRunspace = (New-RunSpace -ScriptBlock $global:IngressEventScriptBlock -Param $param)
@@ -1829,7 +1843,7 @@ function Invoke-RemoteDesktopViewer
18291843

18301844
$param = New-Object -TypeName PSCustomObject -Property @{
18311845
OutputEventSyncHash = $outputEventSyncHash
1832-
SynchronizeClipboard = -not $DisableClipboard
1846+
Clipboard = $Clipboard
18331847
}
18341848

18351849
$newRunspace = (New-RunSpace -ScriptBlock $global:EgressEventScriptBlock -Param $param)

0 commit comments

Comments
 (0)