Repository navigation
Expand file tree
/
Copy pathsettings-debug-panel-launcher.component.ts
More file actions
159 lines (150 loc) · 5.29 KB
/
Copy pathsettings-debug-panel-launcher.component.ts
File metadata and controls
159 lines (150 loc) · 5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import { DOCUMENT } from '@angular/common';
import {
Component,
inject,
input,
OnInit,
signal,
viewChild,
} from '@angular/core';
import { MatMenuModule, MatMenuTrigger } from '@angular/material/menu';
import { AsyncHandler } from 'libs/common/src/lib/async-handler.class';
import { HotkeysService } from 'libs/common/src/lib/hotkeys.service';
import { type HashMap } from 'libs/common/src/lib/types';
import { BindingDebugPanelComponent } from './binding-debug-panel.component';
import { DebugConsoleComponent } from './debug-console.component';
import { IconComponent } from './icon.component';
import { SettingsDebugPanelComponent } from './settings-debug-panel.component';
type DebugPanel = 'settings' | 'bindings' | 'console';
@Component({
selector: 'settings-debug-panel-launcher',
host: { '(document:contextmenu)': 'onContextMenu($event)' },
imports: [
MatMenuModule,
SettingsDebugPanelComponent,
BindingDebugPanelComponent,
DebugConsoleComponent,
IconComponent,
],
template: `
<button
type="button"
class="absolute bottom-0 left-0 z-999 h-px w-px"
aria-label="Open debugging tools"
[matMenuTriggerFor]="debug_menu"
#menu_trigger="matMenuTrigger"
(contextmenu)="openMenu($event, menu_trigger)"
>
</button>
<mat-menu #debug_menu="matMenu" yPosition="above">
<div
class="flex w-64 items-center justify-center pb-2 text-sm opacity-60"
>
Debugging Panels
</div>
<button mat-menu-item (click)="openPanel('settings')">
<div class="flex items-center gap-2">
<icon>discover_tune</icon>
<div>Settings</div>
</div>
</button>
<button mat-menu-item (click)="openPanel('bindings')">
<div class="flex items-center gap-2">
<icon>linked_services</icon>
<div>Driver bindings</div>
</div>
</button>
<button mat-menu-item (click)="openPanel('console')">
<div class="flex items-center gap-2">
<icon>terminal_2</icon>
<div>Console</div>
</div>
</button>
</mat-menu>
@defer (when panel() === 'settings') {
@if (panel() === 'settings') {
<settings-debug-panel
[show]="true"
(showChange)="panel.set(null)"
[schema]="schema()"
/>
}
}
@defer (when panel() === 'bindings') {
@if (panel() === 'bindings') {
<binding-debug-panel
[show]="true"
(showChange)="panel.set(null)"
[hotkeysEnabled]="false"
/>
}
}
@defer (when panel() === 'console') {
@if (panel() === 'console') {
<debug-console
[show]="true"
(showChange)="panel.set(null)"
[hotkeysEnabled]="false"
/>
}
}
`,
styles: [``],
})
export class SettingsDebugPanelLauncherComponent
extends AsyncHandler
implements OnInit
{
private readonly _hotkey = inject(HotkeysService);
private readonly _document = inject(DOCUMENT);
private readonly _menu_trigger = viewChild.required(MatMenuTrigger);
private _schema_request?: Promise<void>;
public readonly loadSchema = input<() => Promise<HashMap>>();
public readonly schema = signal<HashMap | null>(null);
public readonly panel = signal<DebugPanel | null>(null);
public ngOnInit(): void {
const shortcuts: [DebugPanel, string[]][] = [
['settings', ['Control', 'Alt', 'Shift', 'KeyS']],
['bindings', ['Control', 'Alt', 'Shift', 'KeyB']],
['console', ['Control', 'Backquote']],
];
for (const [panel, keys] of shortcuts) {
this.subscription(
panel,
this._hotkey.listen(keys, () => {
if (this.panel() === panel) this.panel.set(null);
else this.openPanel(panel);
}),
);
}
}
/** Observe the corner without placing a pointer target over app controls. */
public onContextMenu(event: MouseEvent): void {
const height = this._document.documentElement.clientHeight;
if (
event.clientX < 0 ||
event.clientX > 32 ||
event.clientY < height - 32 ||
event.clientY > height
)
return;
this.openMenu(event, this._menu_trigger());
}
public openMenu(event: MouseEvent, trigger: MatMenuTrigger): void {
event.preventDefault();
trigger.openMenu();
}
public openPanel(panel: DebugPanel): void {
this.panel.set(panel);
if (panel === 'settings') {
this._schema_request ??= this.loadSettingsSchema();
}
}
private async loadSettingsSchema(): Promise<void> {
try {
this.schema.set((await this.loadSchema()?.()) ?? null);
} catch {
this.schema.set(null);
}
}
}