mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-14 13:16:16 -08:00
Merge pull request #974 from 4gray/agent/workspace-shortcuts-runtime-capabilities
refactor(workspace): use runtime shortcuts capability
This commit is contained in:
2 files changed
+31
-4
No files matched your search
+28
@@ -1,11 +1,13 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { Subject } from 'rxjs';
|
||||
import { RuntimeCapabilitiesService } from '@iptvnator/services';
|
||||
import { WorkspaceKeyboardShortcutsService } from './workspace-keyboard-shortcuts.service';
|
||||
|
||||
describe('WorkspaceKeyboardShortcutsService', () => {
|
||||
let afterClosed$: Subject<void>;
|
||||
let dialog: { open: jest.Mock };
|
||||
let runtime: { isElectron: boolean };
|
||||
let service: WorkspaceKeyboardShortcutsService;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -15,11 +17,13 @@ describe('WorkspaceKeyboardShortcutsService', () => {
|
||||
afterClosed: () => afterClosed$.asObservable(),
|
||||
}),
|
||||
};
|
||||
runtime = { isElectron: true };
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
WorkspaceKeyboardShortcutsService,
|
||||
{ provide: MatDialog, useValue: dialog },
|
||||
{ provide: RuntimeCapabilitiesService, useValue: runtime },
|
||||
],
|
||||
});
|
||||
|
||||
@@ -93,4 +97,28 @@ describe('WorkspaceKeyboardShortcutsService', () => {
|
||||
);
|
||||
expect(commandPaletteShortcut?.chords[0].keys[0].label).toBe('Ctrl');
|
||||
});
|
||||
|
||||
it('includes Electron-only shortcuts when runtime supports Electron', () => {
|
||||
service.openShortcutsDialog();
|
||||
|
||||
const dialogData = dialog.open.mock.calls[0][1].data;
|
||||
const itemIds = dialogData.groups.flatMap((group) =>
|
||||
group.items.map((item) => item.id)
|
||||
);
|
||||
|
||||
expect(itemIds).toContain('open-global-search');
|
||||
});
|
||||
|
||||
it('uses runtime capabilities for Electron-only shortcuts', () => {
|
||||
runtime.isElectron = false;
|
||||
|
||||
service.openShortcutsDialog();
|
||||
|
||||
const dialogData = dialog.open.mock.calls[0][1].data;
|
||||
const itemIds = dialogData.groups.flatMap((group) =>
|
||||
group.items.map((item) => item.id)
|
||||
);
|
||||
|
||||
expect(itemIds).not.toContain('open-global-search');
|
||||
});
|
||||
});
|
||||
+3
-4
@@ -6,6 +6,7 @@ import {
|
||||
isKeyboardShortcutHelpTrigger,
|
||||
isTypingInInput,
|
||||
} from '@iptvnator/portal/shared/util';
|
||||
import { RuntimeCapabilitiesService } from '@iptvnator/services';
|
||||
import {
|
||||
WorkspaceKeyboardShortcutsDialogComponent,
|
||||
WorkspaceKeyboardShortcutsDialogData,
|
||||
@@ -15,6 +16,7 @@ import {
|
||||
export class WorkspaceKeyboardShortcutsService {
|
||||
private readonly dialog = inject(MatDialog);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
private readonly runtime = inject(RuntimeCapabilitiesService);
|
||||
private readonly onDocumentKeydown = (event: KeyboardEvent): void =>
|
||||
this.handleKeydown(event);
|
||||
|
||||
@@ -49,7 +51,7 @@ export class WorkspaceKeyboardShortcutsService {
|
||||
data: {
|
||||
groups: getKeyboardShortcutGroups({
|
||||
isMac: platform === 'mac',
|
||||
isElectron: this.isElectron(),
|
||||
isElectron: this.runtime.isElectron,
|
||||
}),
|
||||
platformIcon:
|
||||
platform === 'mac' ? 'laptop_mac' : 'desktop_windows',
|
||||
@@ -93,7 +95,4 @@ export class WorkspaceKeyboardShortcutsService {
|
||||
return /Mac|iPhone|iPad|iPod/i.test(platform) ? 'mac' : 'other';
|
||||
}
|
||||
|
||||
private isElectron(): boolean {
|
||||
return typeof window !== 'undefined' && !!window.electron;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user