示例#1
0
        public static async Task <PersistentState> LoadAsync()
        {
            var currentDirectory = Path.GetDirectoryName((Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly()).Location);
            var statePath        = Path.Combine(currentDirectory, "ghub-mute-state.json");

            var stream = new FileStream(statePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, 4096, FileOptions.SequentialScan);
            var state  = new PersistentState(stream);
            await state.LoadInternalAsync();

            return(state);
        }
示例#2
0
 public AudioController(PersistentState state)
 {
     _state = state;
 }
示例#3
0
        static async Task <int> Main(string[] args)
        {
            using var state = await PersistentState.LoadAsync();

            var audioController       = new AudioController(state);
            AudioCaptureStatus?status = null;

            var capturingColors = new Option <string>(
                new[] { "--cc", "--capture-colors" },
                getDefaultValue: () => "50,0,25;100,0,10",
                description: "Mouse colors when mics are capturing audio"
                );

            var muteColors = new Option <string>(
                new[] { "--mc", "--mute-colors" },
                getDefaultValue: () => "100,100,0;0,40,60",
                description: "Mouse colors when mics are muted"
                );

            var toggleCommand = new Command("toggle", "Toggles the mute state")
            {
                Handler = CommandHandler.Create(() =>
                {
                    status = audioController.Toggle();
                })
            };
            var muteCommand = new Command("mute", "Forces the input devices to be muted")
            {
                Handler = CommandHandler.Create(() =>
                {
                    status = audioController.Mute();
                })
            };
            var unmuteCommand = new Command("unmute", "Forces the muted input devices to become unmuted")
            {
                Handler = CommandHandler.Create(() =>
                {
                    status = audioController.Unmute();
                })
            };
            var checkCommand = new Command("check", "Checks the mute status of audio devices")
            {
                Handler = CommandHandler.Create(() =>
                {
                    status = audioController.Check();
                })
            };

            var rootCommand = new RootCommand
            {
                toggleCommand,
                muteCommand,
                unmuteCommand,
                checkCommand,
                capturingColors,
                muteColors
            };

            rootCommand.Description = "Works with G-Hub to control microphone inputs";
            rootCommand.Handler     = toggleCommand.Handler;

            try
            {
                var invokeResult = rootCommand.Invoke(args, new WinConsole());

                var saveTask = state.SaveChangesAsync();

                if (status.HasValue)
                {
                    var mouseController = new MouseController();

                    var parseResult = rootCommand.Parse(args);
                    mouseController.CapturingColors = LogiColor.ParseMultiple(parseResult.ValueForOption(capturingColors));
                    mouseController.MutedColors     = LogiColor.ParseMultiple(parseResult.ValueForOption(muteColors));
                    mouseController.Show(status.GetValueOrDefault());
                }

                await saveTask;

                return(invokeResult);
            }
            finally
            {
                MouseController.Shutdown();
                WinConsole.Cleanup();
            }
        }