diff --git a/Program.cs b/Program.cs index 4f798d4..cfb10db 100644 --- a/Program.cs +++ b/Program.cs @@ -7,9 +7,9 @@ public class BluetoothManager public static async Task Main(string[] args) { // Check if the correct command-line arguments are provided. - if (args.Length == 0 || (args[0].ToLower() != "on" && args[0].ToLower() != "off")) + if (args.Length == 0 || (args[0].ToLower() != "on" && args[0].ToLower() != "off" && args[0].ToLower() != "toggle")) { - Console.WriteLine("Usage: BluetoothSwitcher.exe [on|off]"); + Console.WriteLine("Usage: BluetoothSwitcher.exe [on|off|toggle]"); return; } @@ -28,14 +28,13 @@ public static async Task Main(string[] args) // Find the first radio that is a Bluetooth adapter. var bluetoothRadio = radios.FirstOrDefault(radio => radio.Kind == RadioKind.Bluetooth); - if (bluetoothRadio == null) { Console.WriteLine("No Bluetooth adapter was found."); return; } - // Process the "on" or "off" command. + // Process the "on", "off" or "toggle" command. string command = args[0].ToLower(); if (command == "on") { @@ -47,6 +46,12 @@ public static async Task Main(string[] args) await bluetoothRadio.SetStateAsync(RadioState.Off); Console.WriteLine("Bluetooth was turned off successfully."); } + else if (command == "toggle") + { + var newState = bluetoothRadio.State == RadioState.On ? RadioState.Off : RadioState.On; + await bluetoothRadio.SetStateAsync(newState); + Console.WriteLine($"Bluetooth was toggled to {(newState == RadioState.On ? "on" : "off")} successfully."); + } } catch (Exception ex) { @@ -54,4 +59,4 @@ public static async Task Main(string[] args) Console.WriteLine($"An error occurred: {ex.Message}"); } } -} \ No newline at end of file +}