feat: Basic general context menu
All checks were successful
Queue Release Build / prepare (push) Successful in 14s
Deploy Web Apps / deploy (push) Successful in 14m39s
Queue Release Build / build-linux (push) Successful in 40m59s
Queue Release Build / build-windows (push) Successful in 28m59s
Queue Release Build / finalize (push) Successful in 1m58s
All checks were successful
Queue Release Build / prepare (push) Successful in 14s
Deploy Web Apps / deploy (push) Successful in 14m39s
Queue Release Build / build-linux (push) Successful in 40m59s
Queue Release Build / build-windows (push) Successful in 28m59s
Queue Release Build / finalize (push) Successful in 1m58s
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import {
|
||||
Component,
|
||||
OnInit,
|
||||
OnDestroy,
|
||||
inject,
|
||||
signal
|
||||
} from '@angular/core';
|
||||
import { ElectronBridgeService } from '../../core/platform/electron/electron-bridge.service';
|
||||
import { ContextMenuComponent } from '../../shared';
|
||||
import type { ContextMenuParams } from '../../core/platform/electron/electron-api.models';
|
||||
|
||||
@Component({
|
||||
selector: 'app-native-context-menu',
|
||||
standalone: true,
|
||||
imports: [ContextMenuComponent],
|
||||
templateUrl: './native-context-menu.component.html'
|
||||
})
|
||||
export class NativeContextMenuComponent implements OnInit, OnDestroy {
|
||||
params = signal<ContextMenuParams | null>(null);
|
||||
|
||||
private readonly electronBridge = inject(ElectronBridgeService);
|
||||
private cleanup: (() => void) | null = null;
|
||||
|
||||
ngOnInit(): void {
|
||||
const api = this.electronBridge.getApi();
|
||||
|
||||
if (!api?.onContextMenu) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.cleanup = api.onContextMenu((incoming) => {
|
||||
const hasContent = incoming.isEditable
|
||||
|| !!incoming.selectionText
|
||||
|| !!incoming.linkURL
|
||||
|| (incoming.mediaType === 'image' && !!incoming.srcURL);
|
||||
|
||||
this.params.set(hasContent ? incoming : null);
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.cleanup?.();
|
||||
this.cleanup = null;
|
||||
}
|
||||
|
||||
close(): void {
|
||||
this.params.set(null);
|
||||
}
|
||||
|
||||
execCommand(command: string): void {
|
||||
document.execCommand(command);
|
||||
this.close();
|
||||
}
|
||||
|
||||
copyLink(): void {
|
||||
const url = this.params()?.linkURL;
|
||||
|
||||
if (url) {
|
||||
navigator.clipboard.writeText(url).catch(() => {});
|
||||
}
|
||||
|
||||
this.close();
|
||||
}
|
||||
|
||||
copyImage(): void {
|
||||
const srcURL = this.params()?.srcURL;
|
||||
const api = this.electronBridge.getApi();
|
||||
|
||||
if (srcURL && api?.copyImageToClipboard) {
|
||||
api.copyImageToClipboard(srcURL).catch(() => {});
|
||||
}
|
||||
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user