mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2025-02-18 08:56:20 +01:00
Added Stop and Start menu item to tray icon. Fixed ambiguity of temp thread objects in ControlService.
This commit is contained in:
parent
5fb140c91b
commit
4c4a6f5ba6
@ -1,17 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
using System.Media;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using static DS4Windows.Global;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using static DS4Windows.Global;
|
||||||
using Nefarius.ViGEm.Client;
|
using Nefarius.ViGEm.Client;
|
||||||
using Nefarius.ViGEm.Client.Targets;
|
|
||||||
using Nefarius.ViGEm.Client.Targets.Xbox360;
|
|
||||||
using Nefarius.ViGEm.Client.Targets.DualShock4;
|
|
||||||
|
|
||||||
namespace DS4Windows
|
namespace DS4Windows
|
||||||
{
|
{
|
||||||
@ -40,6 +34,7 @@ namespace DS4Windows
|
|||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
Thread tempThread;
|
Thread tempThread;
|
||||||
|
Thread tempBusThread;
|
||||||
public List<string> affectedDevs = new List<string>()
|
public List<string> affectedDevs = new List<string>()
|
||||||
{
|
{
|
||||||
@"HID\VID_054C&PID_05C4",
|
@"HID\VID_054C&PID_05C4",
|
||||||
@ -154,7 +149,7 @@ namespace DS4Windows
|
|||||||
|
|
||||||
//sp.Stream = DS4WinWPF.Properties.Resources.EE;
|
//sp.Stream = DS4WinWPF.Properties.Resources.EE;
|
||||||
// Cause thread affinity to not be tied to main GUI thread
|
// Cause thread affinity to not be tied to main GUI thread
|
||||||
tempThread = new Thread(() => {
|
tempBusThread = new Thread(() => {
|
||||||
//_udpServer = new UdpServer(GetPadDetailForIdx);
|
//_udpServer = new UdpServer(GetPadDetailForIdx);
|
||||||
busThrRunning = true;
|
busThrRunning = true;
|
||||||
|
|
||||||
@ -174,9 +169,9 @@ namespace DS4Windows
|
|||||||
Monitor.Wait(busThrLck);
|
Monitor.Wait(busThrLck);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
tempThread.Priority = ThreadPriority.Normal;
|
tempBusThread.Priority = ThreadPriority.Normal;
|
||||||
tempThread.IsBackground = true;
|
tempBusThread.IsBackground = true;
|
||||||
tempThread.Start();
|
tempBusThread.Start();
|
||||||
//while (_udpServer == null)
|
//while (_udpServer == null)
|
||||||
//{
|
//{
|
||||||
// Thread.SpinWait(500);
|
// Thread.SpinWait(500);
|
||||||
@ -353,17 +348,12 @@ namespace DS4Windows
|
|||||||
{
|
{
|
||||||
Thread.SpinWait(500);
|
Thread.SpinWait(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tempThread = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopViGEm()
|
private void stopViGEm()
|
||||||
{
|
{
|
||||||
if (tempThread != null)
|
|
||||||
{
|
|
||||||
tempThread.Interrupt();
|
|
||||||
tempThread.Join();
|
|
||||||
tempThread = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vigemTestClient != null)
|
if (vigemTestClient != null)
|
||||||
{
|
{
|
||||||
vigemTestClient.Dispose();
|
vigemTestClient.Dispose();
|
||||||
|
@ -252,6 +252,7 @@ Properties.Resources.DS4Update, MessageBoxButton.YesNo, MessageBoxImage.Question
|
|||||||
trayIconVM.ProfileSelected += TrayIconVM_ProfileSelected;
|
trayIconVM.ProfileSelected += TrayIconVM_ProfileSelected;
|
||||||
trayIconVM.RequestMinimize += TrayIconVM_RequestMinimize;
|
trayIconVM.RequestMinimize += TrayIconVM_RequestMinimize;
|
||||||
trayIconVM.RequestOpen += TrayIconVM_RequestOpen;
|
trayIconVM.RequestOpen += TrayIconVM_RequestOpen;
|
||||||
|
trayIconVM.RequestServiceChange += TrayIconVM_RequestServiceChange;
|
||||||
autoProfControl.AutoDebugChanged += AutoProfControl_AutoDebugChanged;
|
autoProfControl.AutoDebugChanged += AutoProfControl_AutoDebugChanged;
|
||||||
autoprofileChecker.RequestServiceChange += AutoprofileChecker_RequestServiceChange;
|
autoprofileChecker.RequestServiceChange += AutoprofileChecker_RequestServiceChange;
|
||||||
autoProfileHolder.AutoProfileColl.CollectionChanged += AutoProfileColl_CollectionChanged;
|
autoProfileHolder.AutoProfileColl.CollectionChanged += AutoProfileColl_CollectionChanged;
|
||||||
@ -287,6 +288,11 @@ Suspend support not enabled.", true);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void TrayIconVM_RequestServiceChange(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
ChangeService();
|
||||||
|
}
|
||||||
|
|
||||||
private void LogItems_CollectionChanged(object sender,
|
private void LogItems_CollectionChanged(object sender,
|
||||||
System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using DS4Windows;
|
using DS4Windows;
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ namespace DS4WinWPF.DS4Forms.ViewModels
|
|||||||
public const string ballonTitle = "DS4Windows";
|
public const string ballonTitle = "DS4Windows";
|
||||||
public static string trayTitle = $"DS4Windows v{Global.exeversion}";
|
public static string trayTitle = $"DS4Windows v{Global.exeversion}";
|
||||||
private ContextMenu contextMenu;
|
private ContextMenu contextMenu;
|
||||||
|
private MenuItem changeServiceItem;
|
||||||
|
|
||||||
public string TooltipText { get => tooltipText;
|
public string TooltipText { get => tooltipText;
|
||||||
set
|
set
|
||||||
@ -44,6 +46,7 @@ namespace DS4WinWPF.DS4Forms.ViewModels
|
|||||||
public event EventHandler RequestShutdown;
|
public event EventHandler RequestShutdown;
|
||||||
public event EventHandler RequestOpen;
|
public event EventHandler RequestOpen;
|
||||||
public event EventHandler RequestMinimize;
|
public event EventHandler RequestMinimize;
|
||||||
|
public event EventHandler RequestServiceChange;
|
||||||
|
|
||||||
private ReaderWriterLockSlim _colLocker = new ReaderWriterLockSlim();
|
private ReaderWriterLockSlim _colLocker = new ReaderWriterLockSlim();
|
||||||
private List<ControllerHolder> controllerList = new List<ControllerHolder>();
|
private List<ControllerHolder> controllerList = new List<ControllerHolder>();
|
||||||
@ -61,6 +64,10 @@ namespace DS4WinWPF.DS4Forms.ViewModels
|
|||||||
this.controlService = service;
|
this.controlService = service;
|
||||||
contextMenu = new ContextMenu();
|
contextMenu = new ContextMenu();
|
||||||
iconSource = Global.UseWhiteIcon ? ICON_WHITE : ICON_COLOR;
|
iconSource = Global.UseWhiteIcon ? ICON_WHITE : ICON_COLOR;
|
||||||
|
changeServiceItem = new MenuItem() { Header = "Start",
|
||||||
|
FontWeight = FontWeights.Bold };
|
||||||
|
changeServiceItem.Click += ChangeControlServiceItem_Click;
|
||||||
|
changeServiceItem.IsEnabled = false;
|
||||||
|
|
||||||
PopulateControllerList();
|
PopulateControllerList();
|
||||||
PopulateToolText();
|
PopulateToolText();
|
||||||
@ -74,6 +81,7 @@ namespace DS4WinWPF.DS4Forms.ViewModels
|
|||||||
service.PreServiceStop += ClearToolText;
|
service.PreServiceStop += ClearToolText;
|
||||||
service.PreServiceStop += UnhookEvents;
|
service.PreServiceStop += UnhookEvents;
|
||||||
service.PreServiceStop += ClearControllerList;
|
service.PreServiceStop += ClearControllerList;
|
||||||
|
service.RunningChanged += Service_RunningChanged;
|
||||||
service.HotplugController += Service_HotplugController;
|
service.HotplugController += Service_HotplugController;
|
||||||
/*tester.StartControllers += HookBatteryUpdate;
|
/*tester.StartControllers += HookBatteryUpdate;
|
||||||
tester.StartControllers += StartPopulateText;
|
tester.StartControllers += StartPopulateText;
|
||||||
@ -83,6 +91,16 @@ namespace DS4WinWPF.DS4Forms.ViewModels
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Service_RunningChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
string temp = controlService.running ? "Stop" : "Start";
|
||||||
|
App.Current.Dispatcher.BeginInvoke((Action)(() =>
|
||||||
|
{
|
||||||
|
changeServiceItem.Header = temp;
|
||||||
|
changeServiceItem.IsEnabled = true;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
private void ClearControllerList(object sender, EventArgs e)
|
private void ClearControllerList(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
_colLocker.EnterWriteLock();
|
_colLocker.EnterWriteLock();
|
||||||
@ -173,6 +191,8 @@ namespace DS4WinWPF.DS4Forms.ViewModels
|
|||||||
|
|
||||||
items.Add(item);
|
items.Add(item);
|
||||||
items.Add(new Separator());
|
items.Add(new Separator());
|
||||||
|
item = changeServiceItem;
|
||||||
|
items.Add(item);
|
||||||
item = new MenuItem() { Header = "Open" };
|
item = new MenuItem() { Header = "Open" };
|
||||||
item.Click += OpenMenuItem_Click;
|
item.Click += OpenMenuItem_Click;
|
||||||
items.Add(item);
|
items.Add(item);
|
||||||
@ -188,6 +208,12 @@ namespace DS4WinWPF.DS4Forms.ViewModels
|
|||||||
items.Add(item);
|
items.Add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ChangeControlServiceItem_Click(object sender, System.Windows.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
changeServiceItem.IsEnabled = false;
|
||||||
|
RequestServiceChange?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
private void OpenProgramFolderItem_Click(object sender, System.Windows.RoutedEventArgs e)
|
private void OpenProgramFolderItem_Click(object sender, System.Windows.RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Process.Start(Global.exedirpath);
|
Process.Start(Global.exedirpath);
|
||||||
@ -348,7 +374,10 @@ namespace DS4WinWPF.DS4Forms.ViewModels
|
|||||||
{
|
{
|
||||||
contextMenu.Items.Clear();
|
contextMenu.Items.Clear();
|
||||||
ItemCollection items = contextMenu.Items;
|
ItemCollection items = contextMenu.Items;
|
||||||
MenuItem item = new MenuItem() { Header = "Open" };
|
MenuItem item;
|
||||||
|
item = changeServiceItem;
|
||||||
|
items.Add(item);
|
||||||
|
item = new MenuItem() { Header = "Open" };
|
||||||
item.Click += OpenMenuItem_Click;
|
item.Click += OpenMenuItem_Click;
|
||||||
items.Add(item);
|
items.Add(item);
|
||||||
item = new MenuItem() { Header = "Minimize" };
|
item = new MenuItem() { Header = "Minimize" };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user