public ToolbarViewModel(PocketStrafeBootStrapper ps) { Updater = ps.AppCastUpdater; DnsServer = ps.DnsServer; DeviceManager = ps.DeviceManager; // IP address this.WhenAnyValue(x => x.DnsServer.Address, x => x.DnsServer.Port, (addr, p) => string.Format(addr + " : " + p.ToString())) .Where((addr, p) => addr.Length > 1 && p != 0) .ToProperty(this, x => x.IpAddress, out _IpAddress); // Updater this.WhenAnyValue(x => x.Updater.UpdateAvailable) .ToProperty(this, x => x.UpdateAvailable, out _UpdateAvailable); this.WhenAnyValue(x => x.Updater.UpdateAvailable, x => x.Updater.UpdateOnShutdown, (available, shutdown) => shutdown ? "AlarmCheck" : available ? "Download" : "Minus") .ToProperty(this, x => x.UpdateIcon, out _UpdateIcon); this.WhenAnyValue(x => x.Updater.UpdateAvailable, x => x.Updater.UpdateOnShutdown, (available, shutdown) => shutdown ? "Update when closed" : available ? "Update is available" : "Up to date") .ToProperty(this, x => x.UpdateToolTip, out _UpdateToolTip); DownloadUpdate = ReactiveCommand.CreateFromTask(DownloadUpdateImpl); FlipX = ReactiveCommand.CreateFromTask(async _ => await Task.Run(() => DeviceManager.FlipAxis(OutputDeviceAxis.AxisX))); FlipY = ReactiveCommand.CreateFromTask(async _ => await Task.Run(() => DeviceManager.FlipAxis(OutputDeviceAxis.AxisY))); VJoyConfig = ReactiveCommand.CreateFromTask(VJoyConfigImpl); VJoyMonitor = ReactiveCommand.CreateFromTask(VJoyMonitorImpl); ViewLogFile = ReactiveCommand.CreateFromTask(ViewLogFileImpl); }
public InputSettingsViewModel(PocketStrafeBootStrapper ps) { DeviceManager = ps.DeviceManager; DnsServer = ps.DnsServer; // Primary device DNS service (implies that Bonjour wasn't installed) this.WhenAnyValue(x => x.DnsServer.BonjourInstalled, x => !x) .ToProperty(this, x => x.BonjourNotInstalled, out _BonjourNotInstalled); // Primary device DNS service this.WhenAnyValue(x => x.DnsServer.DeviceCount, x => x > 0) .ToProperty(this, x => x.PrimaryDevice, out _PrimaryDevice); // Secondary device DNS service this.WhenAnyValue(x => x.DnsServer.DeviceCount, x => x > 1) .ToProperty(this, x => x.SecondaryDevice, out _SecondaryDevice); // Device Manager // Xbox controller intercepted this.WhenAnyValue(x => x.DeviceManager.InterceptXInputDevice) .ToProperty(this, x => x.XboxController, out _XboxController); // Pausing this.WhenAnyValue(x => x.DeviceManager.IsPaused) .ToProperty(this, x => x.IsPaused, out _IsPaused); this.WhenAnyValue(x => x.IsPaused, x => x ? "Resume" : "Pause") .ToProperty(this, x => x.PauseButtonText, out _PauseButtonText); this.WhenAnyValue(x => x.IsPaused, x => x ? "Play" : "Pause") .ToProperty(this, x => x.PauseButtonIcon, out _PauseButtonIcon); PlayPause = ReactiveCommand.CreateFromTask(PlayPauseImpl); InterceptXInputDevice = ReactiveCommand.CreateFromTask <bool>(async wasChecked => { if (wasChecked) { await Task.Run(() => DeviceManager.AcquireXInputDevice()); } else { DeviceManager.InterceptXInputDevice = false; } }); AddRemoveSecondaryDevice = ReactiveCommand.CreateFromTask(AddRemoveSecondaryDeviceImpl); AddRemoveSecondaryDevice.ThrownExceptions.Subscribe(ex => log.Error("AddRemoveSecondaryDevice\n" + ex)); BonjourInfo = ReactiveCommand.CreateFromTask(_ => Task.Run(() => DnsServer.ShowBonjourDialog())); }
public OutputSettingsViewModel(PocketStrafeBootStrapper ps) { DeviceManager = ps.DeviceManager; DnsServer = ps.DnsServer; ScpVBus = new ScpVBus(); this.WhenAnyValue(x => x.ScpVBus.InstallSuccess) .Where(x => x) .Subscribe(x => { log.Info("ScpVBis Installation Succeeded"); ShowRestartMessage(); }); // Changing output device this.WhenAnyValue(x => x.DeviceManager.OutputDevice, d => d.Type == OutputDeviceType.Keyboard) .ToProperty(this, x => x.KeyboardOutput, out _KeyboardOutput); this.WhenAnyValue(x => x.DeviceManager.OutputDevice, d => d.Type == OutputDeviceType.vJoy) .ToProperty(this, x => x.VJoyOutput, out _VJoyOutput); this.WhenAnyValue(x => x.DeviceManager.OutputDevice, d => d.Type == OutputDeviceType.vXbox) .ToProperty(this, x => x.XboxOutput, out _XboxOutput); this.WhenAnyValue(x => x.DeviceManager.OutputDevice, d => d.Type == OutputDeviceType.OpenVRInject) .ToProperty(this, x => x.VrOutput, out _VrOutput); this.WhenAnyValue(x => x.DeviceManager.OutputDevice, d => d.Type == OutputDeviceType.OpenVREmulator) .ToProperty(this, x => x.OpenVrOutput, out _OpenVrOutput); // Current vDevice ID this.WhenAnyValue(x => x.DeviceManager.OutputDevice.Id) .ToProperty(this, x => x.CurrentDeviceID, out _CurrentDeviceID); // Coupled output this.WhenAnyValue(x => x.DeviceManager.OutputDevice.Coupled) .ToProperty(this, x => x.CoupledOutput, out _CoupledOutput); this.WhenAnyValue(x => x.CoupledOutput, x => x ? "Coupled" : "Decoupled") .ToProperty(this, x => x.CoupledText, out _CoupledText); // Keybind this.WhenAnyValue(x => x.DeviceManager.Keyboard.Keybind) .Do(x => Keybind = x) .Subscribe(); // Filter list of enabled devices to VJoyDevices list this.WhenAnyValue(x => x.DeviceManager.VJoy.EnabledDevices, x => x.ToList()) .ToProperty(this, x => x.VJoyDevices, out _VJoyDevices); // Set *DevicesExist property based on *Devices lists having values this.WhenAnyValue(x => x.VJoyDevices, x => x.Count > 0) .ToProperty(this, x => x.VJoyDevicesExist, out _vJoyDevicesExist); this.WhenAnyValue(x => x.DeviceManager.VXbox.EnabledDevices, x => x.Count() > 0) .ToProperty(this, x => x.XboxDevicesExist, out _XboxDevicesExist); // No*Devices is the inverse of *DevicesExist this.WhenAnyValue(x => x.VJoyDevicesExist, x => !x) .ToProperty(this, x => x.NoVJoyDevices, out _NoVJoyDevices); this.WhenAnyValue(x => x.XboxDevicesExist, x => !x) .ToProperty(this, x => x.NoXboxDevices, out _NoXboxDevices); // When the user changes VJoy ID, but hasn't acquired it yet, set VJoyDevice changed to true this.WhenAnyValue(x => x.CurrentVJoyDevice) .Skip(2) .Do(_ => VJoyDeviceChanged = true) .Subscribe(); // When CFW changes the current device ID to a vJoy id (1-16), set VJoyDeviceChanged to false this.WhenAnyValue(x => x.CurrentDeviceID, x => x > 0 && x < 17) .Do(_ => VJoyDeviceChanged = false) .Subscribe(); // Handling user changing Keybind in a similar way this.WhenAnyValue(x => x.Keybind) .Skip(1) // skip initial value set by model .Do(x => KeybindChanged = !string.IsNullOrWhiteSpace(x)) .Subscribe(); // Xbox controller LED image this.WhenAnyValue(x => x.CurrentDeviceID) .Select(x => XboxLedImagePath((int)x)) .ToProperty(this, x => x.XboxLedImage, out _XboxLedImage); this.WhenAnyValue(x => x.CurrentDeviceID) .Do(x => Console.WriteLine(x)) .Subscribe(); // Commands // KeyboardMode = ReactiveCommand.CreateFromTask(async _ => { await Task.Run(() => DeviceManager.GetNewOutputDevice(OutputDeviceType.Keyboard)); }); ChangeKeybind = ReactiveCommand.CreateFromTask(ChangeKeybindImpl); VJoyMode = ReactiveCommand.CreateFromTask <int>(async(id) => { await Task.Run(() => { DeviceManager.GetNewOutputDevice(OutputDeviceType.vJoy, id: (uint)id); DeviceManager.VJoy.GetEnabledDevices(); }); }); AcquireVJoyDevice = ReactiveCommand.CreateFromTask(AcquireVJoyDeviceImpl); XboxMode = ReactiveCommand.CreateFromTask(async _ => { await Task.Run(() => DeviceManager.GetNewOutputDevice(OutputDeviceType.vXbox)); }); VrMode = ReactiveCommand.CreateFromTask(async _ => { await Task.Run(() => DeviceManager.GetNewOutputDevice(OutputDeviceType.OpenVRInject)); }); VrMode.ThrownExceptions.Subscribe(ex => MessageBox.Show(ex.Message)); OpenVrEmulatorMode = ReactiveCommand.CreateFromTask(async _ => { await Task.Run(() => DeviceManager.GetNewOutputDevice(OutputDeviceType.OpenVREmulator)); }); CoupledDecoupled = ReactiveCommand.CreateFromTask(CoupledDecoupledImpl); VJoyInfo = ReactiveCommand.CreateFromTask(async _ => await Task.Run(() => VJoyInfoDialog.ShowVJoyInfoDialog())); VXboxInfo = ReactiveCommand.CreateFromTask(async _ => await Task.Run(() => ShowScpVbusDialog())); VXboxInfo.ThrownExceptions.Subscribe(ex => log.Error(ex.Message)); SteamVRInfo = ReactiveCommand.CreateFromTask(async _ => await Task.Run(() => ShowSteamVrDialog())); JoyCplCommand = ReactiveCommand.CreateFromTask(async _ => await Task.Run(() => Process.Start("joy.cpl"))); UnplugAllXboxCommand = ReactiveCommand.CreateFromTask(UnplugAllXboxImpl); RunningProcs = new ReactiveList <Process>(); RefreshProcs = ReactiveCommand.CreateFromTask(async() => { var procs = await Task.Run(() => { return(ProcessInspector.GetProcesses().OrderBy(x => x.ProcessName)); }); RunningProcs.Clear(); foreach (var p in procs) { RunningProcs.Add(p); } }); RefreshProcs.ThrownExceptions .Subscribe(ex => log.Error("RefreshProcs: " + ex)); RefreshProcs.IsExecuting .Throttle(TimeSpan.FromMilliseconds(250)) .ToProperty(this, x => x.ProcsRefreshing, out _ProcsRefreshing); this.WhenAnyValue(x => x.ProcsRefreshing, x => !x) .ToProperty(this, x => x.ProcsDoneRefreshing, out _ProcsDoneRefreshing); Observable.Return(Unit.Default) .InvokeCommand(RefreshProcs); InjectedProcs = new ReactiveList <Process>(); InjectedProcs.ItemsAdded .Select(_ => InjectedProcs.Select(p => p.Id).ToList().Contains(SelectedProc.Id)) .Do(x => InjectedIntoSelected = x) .Subscribe(); this.WhenAnyValue(x => x.SelectedProc) .Do(p => log.Debug("selected " + p)).Subscribe(); var canInject = this .WhenAnyValue(x => x.SelectedProc).Select(p => p != null); InjectProc = ReactiveCommand.CreateFromTask(InjectProcImpl, canInject); InjectProc.ThrownExceptions .Do(ex => MessageBox.Show(ex.Message, "Woops!", MessageBoxButton.OK)) .Subscribe(); this.WhenAnyValue(x => x.Injected) .Select(x => x ? "Release" : "Inject") .ToProperty(this, x => x.InjectText, out _InjectText); UpdateHookInterface = ReactiveCommand.CreateFromTask(UpdateHookInterfaceImpl); UpdateHookInterface.ThrownExceptions .Do(_ => ViveBindingsChanged = true) .Subscribe(ex => log.Debug("UpdateHookInterface error: " + ex)); this.WhenAnyValue( x => x.SelectedControllerTouchIndex, x => x.SelectedViveControllerButtonIndex, x => x.SelectedControllerHandIndex, (t, b, h) => Unit.Default) //.Do(x => ViveBindingsChanged = true) //.Subscribe(); .InvokeCommand(this, x => x.UpdateHookInterface); this.WhenAnyValue(x => x.Injected) .Select(x => !x) .ToProperty(this, x => x.NotInjected, out _NotInjected); Injected = false; }