Skip to content

Commit

Permalink
Added novnc clipboard support (#641)
Browse files Browse the repository at this point in the history
- Works with Proxmox 8.1
  - Requires vm to have SPICE guest tools enabled
  - Must be manually enabled via API or CLI for each vm (qm set <id> -vga clipboard=vnc)
  • Loading branch information
sei-aschlackman authored Feb 19, 2024
1 parent a8d8ae7 commit 91e03e7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/app/components/novnc/novnc.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class NovncComponent implements OnChanges, AfterViewInit {
this.novncService.setSecurityFailureListener(
this.securityFailure.bind(this),
);
this.novncService.setClipboardListener(this.clipboardEvent.bind(this));
}

connected(e) {
Expand All @@ -99,4 +100,9 @@ export class NovncComponent implements OnChanges, AfterViewInit {
securityFailure(e) {
console.log(e);
}

async clipboardEvent(e) {
console.log(e);
await navigator.clipboard.writeText(e.detail.text);
}
}
3 changes: 3 additions & 0 deletions src/app/components/options-bar2/options-bar2.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<button mat-menu-item (click)="ctrlAltDel()">
Send Ctrl-Alt-Del
</button>
<button mat-menu-item (click)="sendClipboardText()">
Paste to Clipboard
</button>
</mat-menu>
</mat-menu>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/app/components/options-bar2/options-bar2.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ export class OptionsBar2Component implements OnInit {
public ctrlAltDel() {
this.vmService.sendCtrlAltDel(this.vm.id);
}

public sendClipboardText() {
this.vmService.sendClipboardText(this.vm.id);
}
}
8 changes: 8 additions & 0 deletions src/app/services/novnc/novnc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ export class NoVNCService {
this.rfb.addEventListener('securityfailure', func);
}

public setClipboardListener(func: Function) {
this.rfb.addEventListener('clipboard', func);
}

public sendCtrlAltDel() {
this.rfb.sendCtrlAltDel();
}

public sendClipboardText(text: string) {
this.rfb.clipboardPasteFrom(text);
}
}
4 changes: 4 additions & 0 deletions src/app/services/proxmox/proxmox.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ export class ProxmoxService {
public sendCtrlAltDel() {
this.novncService.sendCtrlAltDel();
}

public sendClipboardText(text: string) {
this.novncService.sendClipboardText(text);
}
}
12 changes: 12 additions & 0 deletions src/app/state/vm/vm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,16 @@ export class VmService {
break;
}
}

async sendClipboardText(id: string) {
const vm = this.vmQuery.getEntity(id);

const text = await navigator.clipboard.readText();

switch (vm.type) {
case 'Proxmox':
this.proxmoxService.sendClipboardText(text);
break;
}
}
}

0 comments on commit 91e03e7

Please sign in to comment.