package main import ( "fmt" "os" "git.zaphyra.eu/airpodsctl/types" ) func (state State) toggleAncModeCommand(ancMode types.ANCMode) { device, err := state.Devices.Get(state.SelectedDevice) if err != nil { fmt.Fprintf(os.Stderr, "[setAncModeCommand] Error: Device '%s' is not connected!\n", state.SelectedDevice) os.Exit(1) } if device.ANCMode.Valid { if ancMode == types.ANCModeUnknown { switch device.ANCMode.Value { case types.ANCModeOff: ancMode = types.ANCModeTransparency case types.ANCModeTransparency: ancMode = types.ANCModeAdaptive case types.ANCModeAdaptive: ancMode = types.ANCModeOn case types.ANCModeOn: ancMode = types.ANCModeOff } } if err := state.SetANCMode(device, ancMode); err != nil { fmt.Fprintln(os.Stderr, "[setAncModeCommand] Error:", err) os.Exit(1) } if err := state.UpdateDevices(); err != nil { fmt.Fprintln(os.Stderr, "[setAncModeCommand] Error:", err) os.Exit(1) } device, _ = state.Devices.Get(state.SelectedDevice) response := fmt.Sprintf("Switched to ANC-Mode: %s", device.ANCMode.Value) state.SendNotify(response, 2, device.Name) fmt.Fprintf(os.Stdout, "[%s]: %s\n", device.Name, response) } else { fmt.Fprintf(os.Stderr, "Device '%s' doesn't support ANC!\n", device.Name) } os.Exit(0) }