Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
784 lines (696 loc) · 31.3 KB
/
Copy pathProgram.cs
File metadata and controls
784 lines (696 loc) · 31.3 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
using Spectre.Console;
using QuestControl.Models;
using QuestControl.Services;
namespace QuestControl;
public static class Program
{
private static readonly AdbService Adb = new();
private static readonly ColorConfigService ColorConfig = new();
private static readonly ScrcpyAudioService AudioService = new();
private static AdbDevice? _activeDevice;
public static async Task Main(string[] args)
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
// Ensure runtime audio process is killed if user exits or Ctrl+C
AppDomain.CurrentDomain.ProcessExit += (_, _) => AudioService.StopAudioBroadcast();
Console.CancelKeyPress += (_, e) =>
{
AudioService.StopAudioBroadcast();
e.Cancel = false;
};
if (args.Length > 0)
{
await HandleCommandLineArgsAsync(args);
return;
}
await RunInteractiveLoopAsync();
}
#region Direct Command-Line Mode
private static async Task HandleCommandLineArgsAsync(string[] args)
{
var cmd = args[0].ToLowerInvariant().TrimStart('-', '/');
// Color commands don't need an ADB device
if (cmd is "color" or "colors")
{
HandleColorCommand(args);
return;
}
var devices = await Adb.GetDevicesAsync();
if (devices.Count == 0 && cmd != "help" && cmd != "--help" && cmd != "-h")
{
AnsiConsole.MarkupLine("[red]Error: No Quest device detected via ADB.[/]");
return;
}
var dev = devices.FirstOrDefault(d => d.IsOnline) ?? devices.FirstOrDefault();
string serial = dev?.Serial ?? "";
switch (cmd)
{
case "status":
case "s":
await PrintStatusAsync(serial, dev);
break;
case "kill":
case "stop":
case "k":
string targetKill = args.Length > 1 ? args[1] : (await Adb.GetForegroundAppAsync(serial) ?? "");
if (string.IsNullOrWhiteSpace(targetKill))
{
AnsiConsole.MarkupLine("[yellow]No active application running to kill.[/]");
return;
}
AnsiConsole.MarkupLine($"[grey]Stopping [bold]{Markup.Escape(targetKill)}[/]...[/]");
var (kSuccess, kMsg) = await Adb.ForceStopAppAsync(serial, targetKill);
AnsiConsole.MarkupLine(kSuccess ? $"[green]✓ {Markup.Escape(kMsg)}[/]" : $"[red]✗ {Markup.Escape(kMsg)}[/]");
break;
case "restart":
case "r":
string targetRestart = args.Length > 1 ? args[1] : (await Adb.GetForegroundAppAsync(serial) ?? "");
if (string.IsNullOrWhiteSpace(targetRestart))
{
AnsiConsole.MarkupLine("[yellow]No active application running to restart.[/]");
return;
}
AnsiConsole.MarkupLine($"[grey]Restarting [bold]{Markup.Escape(targetRestart)}[/]...[/]");
var (rSuccess, rMsg) = await Adb.RestartAppAsync(serial, targetRestart);
AnsiConsole.MarkupLine(rSuccess ? $"[green]✓ {Markup.Escape(rMsg)}[/]" : $"[red]✗ {Markup.Escape(rMsg)}[/]");
break;
case "run":
case "launch":
case "start":
if (args.Length < 2)
{
AnsiConsole.MarkupLine("[red]Usage: questctl run <package_name>[/]");
return;
}
string targetRun = args[1];
AnsiConsole.MarkupLine($"[grey]Launching [bold]{Markup.Escape(targetRun)}[/]...[/]");
var (runSuccess, runMsg) = await Adb.LaunchAppAsync(serial, targetRun);
AnsiConsole.MarkupLine(runSuccess ? $"[green]✓ {Markup.Escape(runMsg)}[/]" : $"[red]✗ {Markup.Escape(runMsg)}[/]");
break;
case "list":
case "ls":
bool showAll = args.Contains("--all") || args.Contains("-a");
var pkgs = await Adb.GetInstalledPackagesAsync(serial, showAll);
AnsiConsole.MarkupLine($"[cyan]Installed Packages ({pkgs.Count}):[/]");
foreach (var p in pkgs)
{
AnsiConsole.MarkupLine($" • [white]{Markup.Escape(p)}[/]");
}
break;
case "audio":
case "a":
HandleAudioCommand(serial, dev, args);
break;
case "install":
case "i":
if (args.Length < 2)
{
AnsiConsole.MarkupLine("[red]Usage: questctl install <path_to_apk>[/]");
return;
}
string apkPath = args[1];
if (!File.Exists(apkPath))
{
AnsiConsole.MarkupLine($"[red]File not found: {Markup.Escape(apkPath)}[/]");
return;
}
AnsiConsole.MarkupLine($"[grey]Installing {Markup.Escape(Path.GetFileName(apkPath))}...[/]");
var (iSuccess, iMsg) = await Adb.InstallApkAsync(serial, apkPath);
AnsiConsole.MarkupLine(iSuccess ? $"[green]✓ {Markup.Escape(iMsg)}[/]" : $"[red]✗ {Markup.Escape(iMsg)}[/]");
break;
case "tcpip":
case "port5555":
var (pSuccess, pMsg) = await Adb.SwitchToTcpip5555Async(serial);
AnsiConsole.MarkupLine(pSuccess ? $"[green]✓ {pMsg}[/]" : $"[red]✗ {pMsg}[/]");
break;
case "reboot":
var (rbSuccess, rbMsg) = await Adb.RebootDeviceAsync(serial);
AnsiConsole.MarkupLine(rbSuccess ? $"[green]✓ {rbMsg}[/]" : $"[red]✗ {rbMsg}[/]");
break;
case "help":
case "--help":
case "-h":
default:
PrintHelp();
break;
}
}
private static void HandleAudioCommand(string serial, AdbDevice? dev, string[] args)
{
if (args.Length > 1 && args[1] is "--set-path" or "-p")
{
if (args.Length < 3)
{
AnsiConsole.MarkupLine("[red]Usage: questctl audio --set-path <path_to_scrcpy.exe>[/]");
return;
}
AudioService.SetCustomScrcpyPath(args[2]);
AnsiConsole.MarkupLine($"[green]✓ Saved scrcpy path: {Markup.Escape(args[2])}[/]");
return;
}
bool dup = args.Contains("--dup") || args.Contains("-d");
RunAudioSession(serial, dev?.DisplayName ?? serial, dup);
}
private static void RunAudioSession(string serial, string deviceName, bool duplicateOnHeadset)
{
var scrcpy = AudioService.ResolveScrcpyPath();
if (string.IsNullOrWhiteSpace(scrcpy))
{
AnsiConsole.MarkupLine("[yellow]⚠ scrcpy.exe not found automatically.[/]");
var path = AnsiConsole.Ask<string>("Enter path to [cyan]scrcpy.exe[/]:").Trim().Trim('"', '\'');
if (!File.Exists(path))
{
AnsiConsole.MarkupLine($"[red]File not found: {Markup.Escape(path)}[/]");
return;
}
AudioService.SetCustomScrcpyPath(path);
}
AnsiConsole.MarkupLine($"[grey]Starting runtime audio broadcast for [bold cyan]{Markup.Escape(deviceName)}[/]...[/]");
var (ok, msg) = AudioService.StartAudioBroadcast(serial, duplicateOnHeadset);
if (!ok)
{
AnsiConsole.MarkupLine($"[red]✗ {Markup.Escape(msg)}[/]");
return;
}
var grid = new Grid();
grid.AddColumn();
grid.AddRow(new Markup($"[grey]Headset:[/] [bold cyan]{Markup.Escape(deviceName)}[/]"));
grid.AddRow(new Markup($"[grey]Mode:[/] [white]{(duplicateOnHeadset ? "Duplicate (Headset + PC Speakers)" : "PC Speakers Only (Headset Redirected)")}[/]"));
grid.AddRow(new Markup("[grey]Status:[/] [bold green]● Live Audio Broadcasting[/]"));
grid.AddRow(new Markup("[grey]Scope:[/] [italic]Runtime-only. When stopped, headset audio returns to normal.[/]"));
var panel = new Panel(grid)
{
Header = new PanelHeader("[bold white]🔊 Audio Broadcast Active[/]"),
Border = BoxBorder.Rounded,
Padding = new Padding(1, 0, 1, 0)
};
AnsiConsole.Write(panel);
AnsiConsole.WriteLine();
AnsiConsole.MarkupLine("[yellow]Press any key or Ctrl+C to STOP audio broadcast...[/]");
Console.ReadKey(true);
AudioService.StopAudioBroadcast();
AnsiConsole.MarkupLine("[green]✓ Audio broadcast stopped. Headset audio restored to normal.[/]");
}
private static void HandleColorCommand(string[] args)
{
string subCmd = args.Length > 1 ? args[1].ToLowerInvariant() : "list";
if (subCmd is "--set-path" or "-p" or "set-path")
{
if (args.Length < 3)
{
AnsiConsole.MarkupLine("[red]Usage: questctl color --set-path <path_to_simple.webplatform>[/]");
return;
}
var (sOk, sMsg) = ColorConfig.SetCustomConstantsPath(args[2]);
AnsiConsole.MarkupLine(sOk ? $"[green]✓ {Markup.Escape(sMsg)}[/]" : $"[red]✗ {Markup.Escape(sMsg)}[/]");
return;
}
switch (subCmd)
{
case "list":
case "ls":
PrintColorTable();
break;
case "add":
case "set":
if (args.Length < 4)
{
AnsiConsole.MarkupLine("[red]Usage: questctl color add <IP_or_suffix> <color>[/]");
AnsiConsole.MarkupLine("[grey]Colors: blue, green, orange, purple, yellow, black[/]");
return;
}
var (addOk, addMsg) = ColorConfig.AddMapping(args[2], args[3]);
AnsiConsole.MarkupLine(addOk ? $"[green]✓ {Markup.Escape(addMsg)}[/]" : $"[red]✗ {Markup.Escape(addMsg)}[/]");
break;
case "reset":
var (resetOk, resetMsg) = ColorConfig.ResetMappings();
AnsiConsole.MarkupLine(resetOk ? $"[green]✓ {Markup.Escape(resetMsg)}[/]" : $"[red]✗ {Markup.Escape(resetMsg)}[/]");
break;
default:
AnsiConsole.MarkupLine("[red]Unknown color command. Usage: questctl color [list | add <ip> <color> | reset | --set-path <dir>][/]");
break;
}
}
private static void PrintColorTable()
{
var path = ColorConfig.FindConstantsPath();
if (path == null)
{
var warnPanel = new Panel(new Markup("[yellow]⚠ Could not find simple.webplatform src/common/constants.ts[/]\n[grey]Use 'Set simple.webplatform path' to link your webplatform directory.[/]"))
{
Header = new PanelHeader("[bold red]Constants File Not Found[/]"),
Border = BoxBorder.Rounded
};
AnsiConsole.Write(warnPanel);
return;
}
var map = ColorConfig.ReadMappings();
var table = new Table().Border(TableBorder.Rounded);
table.AddColumn("[grey]IP Suffix[/]");
table.AddColumn("[grey]Color[/]");
table.AddColumn("[grey]Type[/]");
var sortedKeys = map.Keys.OrderBy(k => int.TryParse(k, out var n) ? n : int.MaxValue);
foreach (var key in sortedKeys)
{
var color = map[key];
bool isDef = ColorConfigService.DefaultMap.TryGetValue(key, out var defColor) && defColor.Equals(color, StringComparison.OrdinalIgnoreCase);
string colorMarkup = GetColorMarkup(color);
string typeMarkup = isDef ? "[grey]Default[/]" : "[cyan]Custom[/]";
table.AddRow($"[bold white].{Markup.Escape(key)}[/]", colorMarkup, typeMarkup);
}
AnsiConsole.Write(new Panel(table)
{
Header = new PanelHeader($"[bold]Headset Color Mappings ({Markup.Escape(path)})[/]"),
Border = BoxBorder.Rounded
});
}
private static string GetColorMarkup(string color)
{
return color.ToLowerInvariant() switch
{
"blue" => "[blue]● Blue[/]",
"green" => "[green]● Green[/]",
"orange" => "[darkorange]● Orange[/]",
"purple" => "[magenta]● Purple[/]",
"yellow" => "[yellow]● Yellow[/]",
"black" => "[white]● Black[/]",
_ => $"[grey]● {Markup.Escape(color)}[/]"
};
}
private static void PrintHelp()
{
var panel = new Panel(
new Markup(
"[bold cyan]questctl[/] - Meta Quest Terminal Controller & Audio Broadcaster\n\n" +
"[yellow]Usage:[/] questctl [[command]] [[options]]\n\n" +
"[green]Application & Stream Commands:[/] \n" +
" [white]questctl[/] Open interactive terminal menu\n" +
" [white]questctl status[/] Show current device and foreground app\n" +
" [white]questctl audio[/] Broadcast headset audio to PC speakers (runtime only)\n" +
" [white]questctl audio --dup[/] Broadcast audio to PC and keep headset sound on\n" +
" [white]questctl audio --set-path <exe>[/] Set path to scrcpy.exe\n" +
" [white]questctl restart [[pkg]][/] Restart current app (or specified pkg)\n" +
" [white]questctl kill [[pkg]][/] Terminate current app (or specified pkg)\n" +
" [white]questctl run <pkg>[/] Launch an APK on the Quest\n" +
" [white]questctl list [[--all]][/] List installed APKs\n" +
" [white]questctl install <file.apk>[/] Sideload an APK file\n" +
" [white]questctl tcpip[/] Reset headset to port 5555 (adb tcpip 5555)\n" +
" [white]questctl reboot[/] Reboot the headset\n\n" +
"[green]Color Configuration Commands:[/] \n" +
" [white]questctl color list[/] View current IP color mappings\n" +
" [white]questctl color add <ip> <color>[/] Add or update IP mapping (e.g. 5 orange)\n" +
" [white]questctl color reset[/] Reset mappings to default (101-106)\n"
)
)
{
Header = new PanelHeader("[bold]Quest Control CLI[/]"),
Border = BoxBorder.Rounded
};
AnsiConsole.Write(panel);
}
private static async Task PrintStatusAsync(string serial, AdbDevice? dev)
{
string fg = await Adb.GetForegroundAppAsync(serial) ?? "VR Shell / Home";
var table = new Table().Border(TableBorder.Rounded);
table.AddColumn("[grey]Property[/]");
table.AddColumn("[grey]Value[/]");
table.AddRow("[white]Device[/]", $"[bold cyan]{Markup.Escape(dev?.DisplayName ?? serial)}[/]");
table.AddRow("[white]Foreground App[/]", fg.Contains("VR Shell") ? $"[yellow]{Markup.Escape(fg)}[/]" : $"[bold green]{Markup.Escape(fg)}[/]");
AnsiConsole.Write(table);
}
#endregion
#region Interactive Terminal TUI Mode
private static async Task RunInteractiveLoopAsync()
{
while (true)
{
AnsiConsole.Clear();
RenderHeader();
var devices = await Adb.GetDevicesAsync();
if (devices.Count == 0)
{
AnsiConsole.MarkupLine("[yellow]⚠ No Quest device detected via ADB.[/]");
AnsiConsole.MarkupLine("[grey]Ensure USB debugging is enabled and the headset is connected.[/]\n");
var noDeviceChoice = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("[grey]Select an option:[/]")
.AddChoices(
"🔄 Refresh devices",
"🎨 Configure Headset Colors (IP Mappings)",
"🚪 Exit"
)
);
if (noDeviceChoice.Contains("Refresh")) continue;
if (noDeviceChoice.Contains("Configure Headset Colors"))
{
InteractiveColorMenu();
continue;
}
break;
}
// Pick active device if multiple or not set
if (_activeDevice == null || !devices.Any(d => d.Serial == _activeDevice.Serial))
{
_activeDevice = devices.FirstOrDefault(d => d.IsOnline) ?? devices[0];
}
else
{
_activeDevice = devices.First(d => d.Serial == _activeDevice.Serial);
}
string fgApp = _activeDevice.IsOnline
? (await Adb.GetForegroundAppAsync(_activeDevice.Serial) ?? "Home / VR Shell")
: $"Device is {_activeDevice.Status}";
bool isCustomApp = _activeDevice.IsOnline && !fgApp.Contains("VR Shell") && !fgApp.Contains("Home");
// Render current status panel
var grid = new Grid();
grid.AddColumn();
grid.AddRow(new Markup($"[grey]Device:[/] [bold cyan]{Markup.Escape(_activeDevice.DisplayName)}[/]"));
if (_activeDevice.IsOnline)
{
grid.AddRow(new Markup($"[grey]Active App:[/] {(isCustomApp ? $"[bold green]🟢 {Markup.Escape(fgApp)}[/]" : $"[yellow]⚪ {Markup.Escape(fgApp)}[/]")}"));
}
else
{
grid.AddRow(new Markup($"[grey]Active App:[/] [red]🔴 {_activeDevice.Status} (Cannot communicate with device)[/]"));
}
var statusPanel = new Panel(grid)
{
Header = new PanelHeader("[bold white]Active Quest State[/]"),
Border = BoxBorder.Rounded,
Padding = new Padding(1, 0, 1, 0)
};
AnsiConsole.Write(statusPanel);
AnsiConsole.WriteLine();
// Menu choices
var menu = new SelectionPrompt<string>()
.Title("[bold grey]Select an action:[/]")
.PageSize(15);
if (_activeDevice.IsOnline)
{
if (isCustomApp)
{
menu.AddChoice($"🔄 Restart Active App ({fgApp})");
menu.AddChoice($"⏹ Terminate Active App ({fgApp})");
}
menu.AddChoice("🔊 Broadcast Audio to PC (Audio Only)");
menu.AddChoice("▶ Launch Another App (Search installed APKs)");
menu.AddChoice("📋 List All Installed APKs");
menu.AddChoice("⚡ Install APK File");
menu.AddChoice("🔌 Reset Headset to Port 5555 (adb tcpip 5555)");
}
else
{
menu.AddChoice($"❌ Disconnect this offline device ({_activeDevice.Serial})");
}
menu.AddChoice("🎨 Configure Headset Colors (IP Mappings)");
if (devices.Count > 1)
{
menu.AddChoice("🔀 Switch Active Device");
}
if (devices.Any(d => !d.IsOnline))
{
menu.AddChoice("🧹 Disconnect All Offline Devices");
}
if (_activeDevice.IsOnline)
{
menu.AddChoice("🔁 Reboot Headset");
}
menu.AddChoice("🔄 Refresh Status");
menu.AddChoice("🚪 Exit");
var selection = AnsiConsole.Prompt(menu);
if (selection.Contains("Restart Active App"))
{
await ExecuteActionAsync($"Restarting {fgApp}...", () => Adb.RestartAppAsync(_activeDevice.Serial, fgApp));
}
else if (selection.Contains("Terminate Active App"))
{
await ExecuteActionAsync($"Stopping {fgApp}...", () => Adb.ForceStopAppAsync(_activeDevice.Serial, fgApp));
}
else if (selection.Contains("Broadcast Audio to PC"))
{
InteractiveAudioMenu(_activeDevice.Serial, _activeDevice.DisplayName);
}
else if (selection.Contains("Launch Another App"))
{
await InteractiveLaunchAppAsync(_activeDevice.Serial);
}
else if (selection.Contains("List All Installed APKs"))
{
await InteractiveListAppsAsync(_activeDevice.Serial);
}
else if (selection.Contains("Install APK File"))
{
await InteractiveInstallApkAsync(_activeDevice.Serial);
}
else if (selection.Contains("Reset Headset to Port 5555"))
{
await ExecuteActionAsync($"Switching {_activeDevice.Serial} to port 5555...", () => Adb.SwitchToTcpip5555Async(_activeDevice.Serial));
}
else if (selection.Contains("Disconnect this offline device"))
{
await ExecuteActionAsync($"Disconnecting {_activeDevice.Serial}...", () => Adb.DisconnectDeviceAsync(_activeDevice.Serial));
_activeDevice = null;
}
else if (selection.Contains("Disconnect All Offline Devices"))
{
await ExecuteActionAsync("Cleaning up offline devices...", async () =>
{
int count = 0;
foreach (var d in devices.Where(x => !x.IsOnline))
{
await Adb.DisconnectDeviceAsync(d.Serial);
count++;
}
_activeDevice = null;
return (true, $"Cleaned up {count} offline device connection(s).");
});
}
else if (selection.Contains("Configure Headset Colors"))
{
InteractiveColorMenu();
}
else if (selection.Contains("Switch Active Device"))
{
var devChoice = AnsiConsole.Prompt(
new SelectionPrompt<AdbDevice>()
.Title("Select Quest device:")
.UseConverter(dev => Markup.Escape(dev.DisplayName))
.AddChoices(devices)
);
_activeDevice = devChoice;
}
else if (selection.Contains("Reboot Headset"))
{
if (AnsiConsole.Confirm("[yellow]Are you sure you want to reboot the headset?[/]", false))
{
await ExecuteActionAsync("Rebooting...", () => Adb.RebootDeviceAsync(_activeDevice.Serial));
}
}
else if (selection.Contains("Refresh Status"))
{
continue;
}
else if (selection.Contains("Exit"))
{
break;
}
}
}
private static void RenderHeader()
{
var rule = new Rule("[bold cyan]🥽 Meta Quest Controller (questctl)[/]")
{
Justification = Justify.Left
};
AnsiConsole.Write(rule);
AnsiConsole.WriteLine();
}
private static async Task ExecuteActionAsync(string statusText, Func<Task<(bool Success, string Message)>> action)
{
(bool success, string msg) = await AnsiConsole.Status()
.Spinner(Spinner.Known.Dots)
.StartAsync(statusText, async _ => await action());
if (success)
{
AnsiConsole.MarkupLine($"[green]✓ {Markup.Escape(msg)}[/]");
}
else
{
AnsiConsole.MarkupLine($"[red]✗ {Markup.Escape(msg)}[/]");
}
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
Console.ReadKey(true);
}
private static async Task InteractiveLaunchAppAsync(string serial)
{
List<string> pkgs = [];
await AnsiConsole.Status()
.Spinner(Spinner.Known.Dots)
.StartAsync("Fetching installed apps...", async _ =>
{
pkgs = await Adb.GetInstalledPackagesAsync(serial, includeSystem: false);
});
if (pkgs.Count == 0)
{
AnsiConsole.MarkupLine("[yellow]No 3rd-party APKs found on device.[/]");
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
Console.ReadKey(true);
return;
}
var prompt = new SelectionPrompt<string>()
.Title("[cyan]Select an APK to launch[/] [grey](type to filter)[/]:")
.PageSize(15)
.EnableSearch()
.AddChoices(pkgs);
prompt.AddChoice("[red]< Cancel >[/]");
var selectedPkg = AnsiConsole.Prompt(prompt);
if (selectedPkg.Contains("< Cancel >"))
return;
await ExecuteActionAsync($"Launching {selectedPkg}...", () => Adb.LaunchAppAsync(serial, selectedPkg));
}
private static async Task InteractiveListAppsAsync(string serial)
{
bool showSystem = AnsiConsole.Confirm("Include system packages?", false);
List<string> pkgs = [];
HashSet<string> running = [];
await AnsiConsole.Status()
.Spinner(Spinner.Known.Dots)
.StartAsync("Fetching package list...", async _ =>
{
pkgs = await Adb.GetInstalledPackagesAsync(serial, showSystem);
running = await Adb.GetRunningPackagesAsync(serial);
});
var table = new Table().Border(TableBorder.Rounded);
table.AddColumn("[grey]#[/]");
table.AddColumn("[grey]Status[/]");
table.AddColumn("[grey]Package Name[/]");
for (int i = 0; i < pkgs.Count; i++)
{
string p = pkgs[i];
bool isRun = running.Contains(p);
string status = isRun ? "[green]● Running[/]" : "[grey]○ Stopped[/]";
table.AddRow($"[grey]{i + 1}[/]", status, $"[white]{Markup.Escape(p)}[/]");
}
AnsiConsole.Write(table);
AnsiConsole.MarkupLine("\n[grey]Press any key to return to menu...[/]");
Console.ReadKey(true);
}
private static async Task InteractiveInstallApkAsync(string serial)
{
var path = AnsiConsole.Ask<string>("Enter path to [cyan].apk[/] file:").Trim().Trim('"', '\'');
if (!File.Exists(path))
{
AnsiConsole.MarkupLine($"[red]File not found: {Markup.Escape(path)}[/]");
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
Console.ReadKey(true);
return;
}
await ExecuteActionAsync($"Installing {Path.GetFileName(path)}...", () => Adb.InstallApkAsync(serial, path));
}
private static void InteractiveAudioMenu(string serial, string deviceName)
{
var choice = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("[bold grey]Select Audio Broadcast Mode (Runtime only):[/]")
.AddChoices(
"🔊 Broadcast to PC Speakers (Redirect from Headset)",
"🎧 Broadcast to PC AND Keep Headset Audio (Duplicate)",
"⚙ Set custom scrcpy.exe path",
"↩ Back to Main Menu"
)
);
if (choice.Contains("Redirect from Headset"))
{
RunAudioSession(serial, deviceName, duplicateOnHeadset: false);
}
else if (choice.Contains("Duplicate"))
{
RunAudioSession(serial, deviceName, duplicateOnHeadset: true);
}
else if (choice.Contains("Set custom scrcpy"))
{
var path = AnsiConsole.Ask<string>("Enter path to [cyan]scrcpy.exe[/]:").Trim().Trim('"', '\'');
if (File.Exists(path))
{
AudioService.SetCustomScrcpyPath(path);
AnsiConsole.MarkupLine($"[green]✓ Saved scrcpy path: {Markup.Escape(path)}[/]");
}
else
{
AnsiConsole.MarkupLine($"[red]File not found: {Markup.Escape(path)}[/]");
}
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
Console.ReadKey(true);
}
}
private static void InteractiveColorMenu()
{
while (true)
{
AnsiConsole.Clear();
RenderHeader();
PrintColorTable();
AnsiConsole.WriteLine();
var choice = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("[bold grey]Color Configuration Options:[/]")
.AddChoices(
"➕ Add or Update IP Mapping",
"🔄 Reset to Defaults (101-106)",
"⚙ Set simple.webplatform path",
"↩ Return to Main Menu"
)
);
if (choice.Contains("Add or Update"))
{
if (ColorConfig.FindConstantsPath() == null)
{
PromptForWebplatformPath();
if (ColorConfig.FindConstantsPath() == null) continue;
}
var rawIp = AnsiConsole.Ask<string>("Enter IP address or last octet (e.g. [cyan]192.168.137.5[/] or [cyan]5[/]):").Trim();
var color = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("Select color:")
.AddChoices(ColorConfigService.ColorClasses.Keys)
);
var (ok, msg) = ColorConfig.AddMapping(rawIp, color);
AnsiConsole.MarkupLine(ok ? $"[green]✓ {Markup.Escape(msg)}[/]" : $"[red]✗ {Markup.Escape(msg)}[/]");
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
Console.ReadKey(true);
}
else if (choice.Contains("Reset to Defaults"))
{
if (ColorConfig.FindConstantsPath() == null)
{
PromptForWebplatformPath();
if (ColorConfig.FindConstantsPath() == null) continue;
}
if (AnsiConsole.Confirm("[yellow]Are you sure you want to reset all color mappings to defaults (101-106)?[/]", false))
{
var (ok, msg) = ColorConfig.ResetMappings();
AnsiConsole.MarkupLine(ok ? $"[green]✓ {Markup.Escape(msg)}[/]" : $"[red]✗ {Markup.Escape(msg)}[/]");
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
Console.ReadKey(true);
}
}
else if (choice.Contains("Set simple.webplatform path"))
{
PromptForWebplatformPath();
}
else
{
break;
}
}
}
private static void PromptForWebplatformPath()
{
var input = AnsiConsole.Ask<string>("Enter path to [cyan]simple.webplatform[/] folder (e.g. D:\\Git\\simple.webplatform):").Trim().Trim('"', '\'');
var (ok, msg) = ColorConfig.SetCustomConstantsPath(input);
AnsiConsole.MarkupLine(ok ? $"[green]✓ {Markup.Escape(msg)}[/]" : $"[red]✗ {Markup.Escape(msg)}[/]");
AnsiConsole.MarkupLine("[grey]Press any key to continue...[/]");
Console.ReadKey(true);
}
#endregion
}