1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 09:43:46 +00:00

Merge upstream/master

This commit is contained in:
Darth Affe 2016-06-14 20:32:16 +02:00
commit 83c64d6cc3
20 changed files with 339 additions and 119 deletions

View File

@ -148,6 +148,10 @@
<HintPath>..\packages\CUE.NET.1.0.3\lib\net45\CUE.NET.dll</HintPath> <HintPath>..\packages\CUE.NET.1.0.3\lib\net45\CUE.NET.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="DynamicExpresso.Core, Version=1.3.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\DynamicExpresso.Core.1.3.1.0\lib\net40\DynamicExpresso.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="GongSolutions.Wpf.DragDrop, Version=0.1.4.3, Culture=neutral, PublicKeyToken=d19974ea350ccea1, processorArchitecture=MSIL"> <Reference Include="GongSolutions.Wpf.DragDrop, Version=0.1.4.3, Culture=neutral, PublicKeyToken=d19974ea350ccea1, processorArchitecture=MSIL">
<HintPath>..\packages\gong-wpf-dragdrop.0.1.4.3\lib\net40\GongSolutions.Wpf.DragDrop.dll</HintPath> <HintPath>..\packages\gong-wpf-dragdrop.0.1.4.3\lib\net40\GongSolutions.Wpf.DragDrop.dll</HintPath>
<Private>True</Private> <Private>True</Private>
@ -205,10 +209,6 @@
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression" /> <Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" /> <Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Linq.Dynamic, Version=1.0.5840.25917, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\System.Linq.Dynamic.1.0.6\lib\net40\System.Linq.Dynamic.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.Serialization" /> <Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" /> <Reference Include="System.Web" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />

View File

@ -46,18 +46,20 @@ namespace Artemis.DeviceProviders.Corsair
var visual = new DrawingVisual(); var visual = new DrawingVisual();
using (var c = visual.RenderOpen()) using (var c = visual.RenderOpen())
c.DrawRectangle(brush, null, rect); c.DrawRectangle(brush, null, rect);
var img = ImageUtilities.DrawinVisualToBitmap(visual, rect);
var ledIndex = 0; using (var img = ImageUtilities.DrawinVisualToBitmap(visual, rect))
// Color each LED according to one of the pixels
foreach (var corsairLed in CueSDK.HeadsetSDK.Leds)
{ {
corsairLed.Color = ledIndex == 0
? img.GetPixel(0, 0)
: img.GetPixel((ledIndex + 1)*20 - 1, (ledIndex + 1)*20 - 1);
ledIndex++;
}
var ledIndex = 0;
// Color each LED according to one of the pixels
foreach (var corsairLed in CueSDK.HeadsetSDK.Leds)
{
corsairLed.Color = ledIndex == 0
? img.GetPixel(0, 0)
: img.GetPixel((ledIndex + 1)*20 - 1, (ledIndex + 1)*20 - 1);
ledIndex++;
}
}
// Flush is required for headset to work reliably on CUE2 for some reason // Flush is required for headset to work reliably on CUE2 for some reason
CueSDK.HeadsetSDK.Update(true); CueSDK.HeadsetSDK.Update(true);
} }

View File

@ -46,18 +46,19 @@ namespace Artemis.DeviceProviders.Corsair
var visual = new DrawingVisual(); var visual = new DrawingVisual();
using (var c = visual.RenderOpen()) using (var c = visual.RenderOpen())
c.DrawRectangle(brush, null, rect); c.DrawRectangle(brush, null, rect);
var img = ImageUtilities.DrawinVisualToBitmap(visual, rect);
var ledIndex = 0; using (var img = ImageUtilities.DrawinVisualToBitmap(visual, rect))
// Color each LED according to one of the pixels
foreach (var corsairLed in CueSDK.MouseSDK.Leds)
{ {
corsairLed.Color = ledIndex == 0 var ledIndex = 0;
? img.GetPixel(0, 0) // Color each LED according to one of the pixels
: img.GetPixel((ledIndex + 1)*20 - 1, (ledIndex + 1)*20 - 1); foreach (var corsairLed in CueSDK.MouseSDK.Leds)
ledIndex++; {
corsairLed.Color = ledIndex == 0
? img.GetPixel(0, 0)
: img.GetPixel((ledIndex + 1)*20 - 1, (ledIndex + 1)*20 - 1);
ledIndex++;
}
} }
CueSDK.MouseSDK.Update(); CueSDK.MouseSDK.Update();
} }

View File

@ -1,5 +1,4 @@
using System.Drawing; using System.Drawing;
using System.Threading;
using System.Windows; using System.Windows;
using Artemis.Properties; using Artemis.Properties;
using Artemis.Utilities; using Artemis.Utilities;
@ -14,7 +13,6 @@ namespace Artemis.DeviceProviders.Corsair
{ {
public class CorsairRGB : KeyboardProvider public class CorsairRGB : KeyboardProvider
{ {
public ILogger Logger { get; set; }
private CorsairKeyboard _keyboard; private CorsairKeyboard _keyboard;
private ImageBrush _keyboardBrush; private ImageBrush _keyboardBrush;
@ -28,19 +26,11 @@ namespace Artemis.DeviceProviders.Corsair
"If needed, you can select a different keyboard in Artemis under settings."; "If needed, you can select a different keyboard in Artemis under settings.";
} }
public ILogger Logger { get; set; }
public override bool CanEnable() public override bool CanEnable()
{ {
// This will skip the check-loop if the SDK is initialized return CueSDK.IsSDKAvailable(CorsairDeviceType.Keyboard);
if (CueSDK.IsInitialized)
return CueSDK.IsSDKAvailable(CorsairDeviceType.Keyboard);
for (var tries = 0; tries < 9; tries++)
{
if (CueSDK.IsSDKAvailable(CorsairDeviceType.Keyboard))
return true;
Thread.Sleep(2000);
}
return false;
} }
/// <summary> /// <summary>

View File

@ -1,4 +1,5 @@
using System.Windows.Media; using System.Threading.Tasks;
using System.Windows.Media;
namespace Artemis.DeviceProviders namespace Artemis.DeviceProviders
{ {
@ -29,6 +30,15 @@ namespace Artemis.DeviceProviders
/// Disables the device /// Disables the device
/// </summary> /// </summary>
public abstract void Disable(); public abstract void Disable();
/// <summary>
/// Tries to enable the device and updates CanUse accordingly asynchronously
/// </summary>
/// <returns></returns>
public Task<bool> TryEnableAsync()
{
return Task.Run(() => TryEnable());
}
} }
public enum DeviceType public enum DeviceType

View File

@ -1,6 +1,9 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Threading;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using MahApps.Metro.Controls.Dialogs;
using Brush = System.Windows.Media.Brush; using Brush = System.Windows.Media.Brush;
using Size = System.Windows.Size; using Size = System.Windows.Size;
@ -18,7 +21,6 @@ namespace Artemis.DeviceProviders
public int Height { get; set; } public int Height { get; set; }
public int Width { get; set; } public int Width { get; set; }
public string CantEnableText { get; set; } public string CantEnableText { get; set; }
public PreviewSettings PreviewSettings { get; set; } public PreviewSettings PreviewSettings { get; set; }
public abstract bool CanEnable(); public abstract bool CanEnable();
@ -39,6 +41,52 @@ namespace Artemis.DeviceProviders
public Rect KeyboardRectangle(int scale) => new Rect(new Size(Width*scale, Height*scale)); public Rect KeyboardRectangle(int scale) => new Rect(new Size(Width*scale, Height*scale));
/// <summary>
/// Runs CanEnable asynchronously multiple times until successful, cancelled or max tries reached
/// </summary>
/// <param name="dialog"></param>
/// <returns></returns>
public Task<bool> CanEnableAsync(ProgressDialogController dialog)
{
return Task.Run(() =>
{
for (var tries = 1; tries <= 10; tries++)
{
// Dialog interaction
if (dialog != null)
{
// Stop if cancelled by user
if (dialog.IsCanceled)
{
dialog.SetIndeterminate();
return false;
}
// Updated progress to indicate how much tries are left
dialog.SetProgress(0.1*tries);
}
if (CanEnable())
{
dialog?.SetIndeterminate();
return true;
}
Thread.Sleep(2000);
}
dialog?.SetIndeterminate();
return false;
});
}
/// <summary>
/// Runs CanEnable asynchronously
/// </summary>
/// <param name="dialog"></param>
/// <returns></returns>
public Task EnableAsync(ProgressDialogController dialog)
{
return Task.Run(() => Enable());
}
public override void UpdateDevice(Brush brush) public override void UpdateDevice(Brush brush)
{ {
throw new NotImplementedException("KeyboardProvider doesn't implement UpdateDevice, use DrawBitmap instead."); throw new NotImplementedException("KeyboardProvider doesn't implement UpdateDevice, use DrawBitmap instead.");
@ -46,7 +94,8 @@ namespace Artemis.DeviceProviders
public override bool TryEnable() public override bool TryEnable()
{ {
throw new NotImplementedException("KeyboardProvider doesn't implement TryEnable, use CanEnable instead."); throw new NotImplementedException(
"KeyboardProvider doesn't implement TryEnable, use CanEnableAsync instead.");
} }
} }

View File

@ -1,11 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Artemis.DeviceProviders; using Artemis.DeviceProviders;
using Artemis.Events; using Artemis.Events;
using Artemis.Services; using Artemis.Services;
using Artemis.Settings; using Artemis.Settings;
using Caliburn.Micro; using Caliburn.Micro;
using MahApps.Metro.Controls.Dialogs;
using Ninject; using Ninject;
using Ninject.Extensions.Logging; using Ninject.Extensions.Logging;
@ -64,8 +67,14 @@ namespace Artemis.Managers
/// Enables the given keyboard /// Enables the given keyboard
/// </summary> /// </summary>
/// <param name="keyboardProvider"></param> /// <param name="keyboardProvider"></param>
public void EnableKeyboard(KeyboardProvider keyboardProvider) public async void EnableKeyboard(KeyboardProvider keyboardProvider)
{ {
if (ChangingKeyboard)
return;
// Store the old keyboard so it can be used in the event we're raising later
var oldKeyboard = ActiveKeyboard;
lock (this) lock (this)
{ {
ChangingKeyboard = true; ChangingKeyboard = true;
@ -79,9 +88,6 @@ namespace Artemis.Managers
return; return;
} }
// Store the old keyboard so it can be used in the event we're raising later
var oldKeyboard = ActiveKeyboard;
var wasNull = false; var wasNull = false;
if (ActiveKeyboard == null) if (ActiveKeyboard == null)
{ {
@ -89,43 +95,62 @@ namespace Artemis.Managers
ActiveKeyboard = keyboardProvider; ActiveKeyboard = keyboardProvider;
} }
_logger.Debug("Enabling keyboard: {0}", keyboardProvider.Name);
if (!wasNull) if (!wasNull)
ReleaseActiveKeyboard(); ReleaseActiveKeyboard();
// Disable everything if there's no active keyboard found
if (!keyboardProvider.CanEnable())
{
DialogService.ShowErrorMessageBox(keyboardProvider.CantEnableText);
ActiveKeyboard = null;
General.Default.LastKeyboard = null;
General.Default.Save();
_logger.Warn("Failed enabling keyboard: {0}", keyboardProvider.Name);
ChangingKeyboard = false;
return;
}
ActiveKeyboard = keyboardProvider;
ActiveKeyboard.Enable();
General.Default.LastKeyboard = ActiveKeyboard.Name;
General.Default.Save();
EnableUsableDevices();
ChangingKeyboard = false;
_events.PublishOnUIThread(new ActiveKeyboardChanged(oldKeyboard, ActiveKeyboard));
_logger.Debug("Enabled keyboard: {0}", keyboardProvider.Name);
} }
_logger.Debug("Enabling keyboard: {0}", keyboardProvider.Name);
// Create a dialog to let the user know Artemis hasn't frozen
ProgressDialogController dialog = null;
if (DialogService.GetActiveWindow() != null)
{
dialog = await DialogService.ShowProgressDialog("Enabling keyboard",
$"Checking if keyboard '{keyboardProvider.Name}' can be enabled...", true);
// May seem a bit cheesy, but it's tidier to have the animation finish
await Task.Delay(500);
}
dialog?.SetIndeterminate();
var canEnable = await keyboardProvider.CanEnableAsync(dialog);
if (!canEnable)
{
if (dialog != null)
await dialog.CloseAsync();
DialogService.ShowErrorMessageBox(keyboardProvider.CantEnableText);
ActiveKeyboard = null;
General.Default.LastKeyboard = null;
General.Default.Save();
_logger.Warn("Failed enabling keyboard: {0}", keyboardProvider.Name);
ChangingKeyboard = false;
return;
}
dialog?.SetMessage($"Enabling keyboard: {keyboardProvider.Name}...");
ActiveKeyboard = keyboardProvider;
await ActiveKeyboard.EnableAsync(dialog);
General.Default.LastKeyboard = ActiveKeyboard.Name;
General.Default.Save();
EnableUsableDevices();
_events.PublishOnUIThread(new ActiveKeyboardChanged(oldKeyboard, ActiveKeyboard));
_logger.Debug("Enabled keyboard: {0}", keyboardProvider.Name);
if (dialog != null)
await dialog.CloseAsync();
ChangingKeyboard = false;
} }
private void EnableUsableDevices() private void EnableUsableDevices()
{ {
foreach (var mouseProvider in MiceProviders) foreach (var mouseProvider in MiceProviders)
mouseProvider.TryEnable(); mouseProvider.TryEnableAsync();
foreach (var headsetProvider in HeadsetProviders) foreach (var headsetProvider in HeadsetProviders)
headsetProvider.TryEnable(); headsetProvider.TryEnableAsync();
} }
/// <summary> /// <summary>

View File

@ -134,7 +134,7 @@ namespace Artemis.Managers
if (loopManager != null && !loopManager.Running) if (loopManager != null && !loopManager.Running)
{ {
_logger.Debug("Starting LoopManager for effect change"); _logger.Debug("Starting LoopManager for effect change");
loopManager.Start(); loopManager.StartAsync();
} }
_logger.Debug("Changed active effect to: {0}", effectModel.Name); _logger.Debug("Changed active effect to: {0}", effectModel.Name);

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using System.Timers; using System.Timers;
using Ninject.Extensions.Logging; using Ninject.Extensions.Logging;
using Brush = System.Windows.Media.Brush; using Brush = System.Windows.Media.Brush;
@ -42,7 +43,12 @@ namespace Artemis.Managers
_keyboardBitmap?.Dispose(); _keyboardBitmap?.Dispose();
} }
public void Start() public Task StartAsync()
{
return Task.Run(() => Start());
}
private void Start()
{ {
if (Running) if (Running)
return; return;

View File

@ -46,7 +46,6 @@ namespace Artemis.Managers
ProgramEnabled = false; ProgramEnabled = false;
Running = false; Running = false;
// TODO: Dependency inject utilities? // TODO: Dependency inject utilities?
KeyboardHook = new KeyboardHook(); KeyboardHook = new KeyboardHook();
@ -79,12 +78,12 @@ namespace Artemis.Managers
{ {
_logger.Debug("Shutting down MainManager"); _logger.Debug("Shutting down MainManager");
_processTimer.Stop(); _processTimer?.Stop();
_processTimer.Dispose(); _processTimer?.Dispose();
LoopManager.Stop(); LoopManager?.Stop();
EffectManager.ActiveEffect.Dispose(); EffectManager?.ActiveEffect?.Dispose();
GameStateWebServer.Stop(); GameStateWebServer?.Stop();
PipeServer.Stop(); PipeServer?.Stop();
} }
/// <summary> /// <summary>
@ -94,7 +93,7 @@ namespace Artemis.Managers
{ {
_logger.Debug("Enabling program"); _logger.Debug("Enabling program");
ProgramEnabled = true; ProgramEnabled = true;
LoopManager.Start(); LoopManager.StartAsync();
_events.PublishOnUIThread(new ToggleEnabled(ProgramEnabled)); _events.PublishOnUIThread(new ToggleEnabled(ProgramEnabled));
} }

View File

@ -68,7 +68,7 @@ namespace Artemis.Managers
} }
// LoopManager might be running, this method won't do any harm in that case. // LoopManager might be running, this method won't do any harm in that case.
_loopManager.Start(); _loopManager.StartAsync();
if (!ReferenceEquals(ProfilePreviewModel.Profile, activePreview.ProfileEditor.SelectedProfile)) if (!ReferenceEquals(ProfilePreviewModel.Profile, activePreview.ProfileEditor.SelectedProfile))
ProfilePreviewModel.Profile = activePreview.ProfileEditor.SelectedProfile; ProfilePreviewModel.Profile = activePreview.ProfileEditor.SelectedProfile;

View File

@ -1,12 +1,19 @@
using System.Collections.Generic; using System;
using System.Linq.Dynamic;
using Artemis.Models.Interfaces; using Artemis.Models.Interfaces;
using Artemis.Utilities; using Artemis.Utilities;
using DynamicExpresso;
namespace Artemis.Models.Profiles namespace Artemis.Models.Profiles
{ {
public class LayerConditionModel public class LayerConditionModel
{ {
private readonly Interpreter _interpreter;
public LayerConditionModel()
{
_interpreter = new Interpreter();
}
public string Field { get; set; } public string Field { get; set; }
public string Value { get; set; } public string Value { get; set; }
public string Operator { get; set; } public string Operator { get; set; }
@ -22,15 +29,29 @@ namespace Artemis.Models.Profiles
return false; return false;
// Put the subject in a list, allowing Dynamic Linq to be used. // Put the subject in a list, allowing Dynamic Linq to be used.
var subjectList = new List<T> {(T) subject};
bool res;
if (Type == "String") if (Type == "String")
res = subjectList.Where($"{Field}.ToLower() {Operator} @0", Value.ToLower()).Any(); {
else if (Type == "Enum") return _interpreter.Eval<bool>($"subject.{Field}.ToLower() {Operator} value",
res = subjectList.Where($"{Field} {Operator} \"{Value}\"").Any(); new Parameter("subject", typeof(T), subject),
else new Parameter("value", Value.ToLower()));
res = subjectList.Where($"{Field} {Operator} {Value}").Any(); }
return res;
Parameter rightParam = null;
switch (Type)
{
case "Enum":
var enumType = _interpreter.Eval<Type>($"subject.{Field}.GetType()", new Parameter("subject", typeof(T), subject));
rightParam = new Parameter("value", Enum.Parse(enumType, Value));
break;
case "Boolean":
rightParam = new Parameter("value", bool.Parse(Value));
break;
case "Int32":
rightParam = new Parameter("value", int.Parse(Value));
break;
}
return _interpreter.Eval<bool>($"subject.{Field} {Operator} value", new Parameter("subject", typeof(T), subject), rightParam);
} }
} }
} }

View File

@ -8,14 +8,17 @@ namespace Artemis.Modules.Effects.WindowsProfile
{ {
Spotify = new Spotify(); Spotify = new Spotify();
Cpu = new CpuDataModel(); Cpu = new CpuDataModel();
Performance = new PerformanceDataModel();
} }
public CpuDataModel Cpu { get; set; } public CpuDataModel Cpu { get; set; }
public PerformanceDataModel Performance { get; set; }
public Spotify Spotify { get; set; } public Spotify Spotify { get; set; }
} }
public class CpuDataModel public class CpuDataModel
{ {
public int TotalUsage { get; set; }
public int Core1Usage { get; set; } public int Core1Usage { get; set; }
public int Core2Usage { get; set; } public int Core2Usage { get; set; }
public int Core3Usage { get; set; } public int Core3Usage { get; set; }
@ -26,6 +29,11 @@ namespace Artemis.Modules.Effects.WindowsProfile
public int Core8Usage { get; set; } public int Core8Usage { get; set; }
} }
public class PerformanceDataModel
{
public int RAMUsage { get; set; }
}
public class Spotify public class Spotify
{ {
public bool Running { get; set; } public bool Running { get; set; }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Artemis.Managers; using Artemis.Managers;
@ -11,14 +12,60 @@ using SpotifyAPI.Local;
namespace Artemis.Modules.Effects.WindowsProfile namespace Artemis.Modules.Effects.WindowsProfile
{ {
internal static class PerformanceInfo
{
[DllImport("psapi.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetPerformanceInfo([Out] out PerformanceInformation performanceInformation, [In] int size);
public static long GetPhysicalAvailableMemoryInMiB()
{
var pi = new PerformanceInformation();
if (GetPerformanceInfo(out pi, Marshal.SizeOf(pi)))
{
return Convert.ToInt64(pi.PhysicalAvailable.ToInt64()*pi.PageSize.ToInt64()/1048576);
}
return -1;
}
public static long GetTotalMemoryInMiB()
{
var pi = new PerformanceInformation();
if (GetPerformanceInfo(out pi, Marshal.SizeOf(pi)))
{
return Convert.ToInt64(pi.PhysicalTotal.ToInt64()*pi.PageSize.ToInt64()/1048576);
}
return -1;
}
[StructLayout(LayoutKind.Sequential)]
public struct PerformanceInformation
{
public int Size;
public IntPtr CommitTotal;
public IntPtr CommitLimit;
public IntPtr CommitPeak;
public IntPtr PhysicalTotal;
public IntPtr PhysicalAvailable;
public IntPtr SystemCache;
public IntPtr KernelTotal;
public IntPtr KernelPaged;
public IntPtr KernelNonPaged;
public IntPtr PageSize;
public int HandlesCount;
public int ProcessCount;
public int ThreadCount;
}
}
public class WindowsProfileModel : EffectModel public class WindowsProfileModel : EffectModel
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private List<PerformanceCounter> _cores; private List<PerformanceCounter> _cores;
private int _cpuFrames; private int _cpuFrames;
private PerformanceCounter _overallCpu;
private SpotifyLocalAPI _spotify; private SpotifyLocalAPI _spotify;
private bool _spotifySetupBusy; private bool _spotifySetupBusy;
private bool _triedCpuFix;
public WindowsProfileModel(ILogger logger, MainManager mainManager, WindowsProfileSettings settings) public WindowsProfileModel(ILogger logger, MainManager mainManager, WindowsProfileSettings settings)
: base(mainManager, new WindowsProfileDataModel()) : base(mainManager, new WindowsProfileDataModel())
@ -63,17 +110,17 @@ namespace Artemis.Modules.Effects.WindowsProfile
_cores.Add(null); _cores.Add(null);
coreCount++; coreCount++;
} }
_overallCpu = GetOverallPerformanceCounter();
} }
catch (InvalidOperationException) catch (InvalidOperationException)
{ {
_logger.Warn("Failed to setup CPU information, try running \"lodctr /R\" as administrator."); _logger.Warn("Failed to setup CPU information, try running \"lodctr /R\" as administrator.");
} }
} }
private void UpdateCpu(WindowsProfileDataModel dataModel) private void UpdateCpu(WindowsProfileDataModel dataModel)
{ {
if (_cores == null) if (_cores == null || _overallCpu == null)
return; return;
// CPU is only updated every 15 frames, the performance counter gives 0 if updated too often // CPU is only updated every 15 frames, the performance counter gives 0 if updated too often
@ -100,6 +147,16 @@ namespace Artemis.Modules.Effects.WindowsProfile
dataModel.Cpu.Core7Usage = (int) _cores[6].NextValue(); dataModel.Cpu.Core7Usage = (int) _cores[6].NextValue();
if (_cores[7] != null) if (_cores[7] != null)
dataModel.Cpu.Core8Usage = (int) _cores[7].NextValue(); dataModel.Cpu.Core8Usage = (int) _cores[7].NextValue();
//From Ted - Let's get overall RAM and CPU usage here
dataModel.Cpu.TotalUsage = (int) _overallCpu.NextValue();
var phav = PerformanceInfo.GetPhysicalAvailableMemoryInMiB();
var tot = PerformanceInfo.GetTotalMemoryInMiB();
var percentFree = phav/(decimal) tot*100;
var percentOccupied = 100 - percentFree;
dataModel.Performance.RAMUsage = (int) percentOccupied;
} }
public override List<LayerModel> GetRenderLayers(bool renderMice, bool renderHeadsets) public override List<LayerModel> GetRenderLayers(bool renderMice, bool renderHeadsets)
@ -107,6 +164,18 @@ namespace Artemis.Modules.Effects.WindowsProfile
return Profile.GetRenderLayers<WindowsProfileDataModel>(DataModel, renderMice, renderHeadsets, false); return Profile.GetRenderLayers<WindowsProfileDataModel>(DataModel, renderMice, renderHeadsets, false);
} }
public static PerformanceCounter GetOverallPerformanceCounter()
{
var cpuCounter = new PerformanceCounter
{
CategoryName = "Processor",
CounterName = "% Processor Time",
InstanceName = "_Total"
};
return cpuCounter;
}
public static List<PerformanceCounter> GetPerformanceCounters() public static List<PerformanceCounter> GetPerformanceCounters()
{ {
var performanceCounters = new List<PerformanceCounter>(); var performanceCounters = new List<PerformanceCounter>();

View File

@ -81,7 +81,7 @@ namespace Artemis.Modules.Overlays.VolumeDisplay
public override void RenderOverlay(Graphics keyboard, ref Brush mouse, ref Brush headset, bool renderMice, public override void RenderOverlay(Graphics keyboard, ref Brush mouse, ref Brush headset, bool renderMice,
bool renderHeadsets) bool renderHeadsets)
{ {
if (VolumeDisplay != null && VolumeDisplay.Ttl >= 1) if (MainManager.DeviceManager.ActiveKeyboard != null && VolumeDisplay != null && VolumeDisplay.Ttl >= 1)
VolumeDisplay.Draw(keyboard); VolumeDisplay.Draw(keyboard);
} }
} }

View File

@ -32,7 +32,7 @@ namespace Artemis.Services
{ {
public class MetroDialogService : DialogService public class MetroDialogService : DialogService
{ {
private MetroWindow GetActiveWindow() public MetroWindow GetActiveWindow()
{ {
MetroWindow window = null; MetroWindow window = null;
@ -102,31 +102,29 @@ namespace Artemis.Services
}; };
if (initialDir != null) if (initialDir != null)
{
ofd.InitialDirectory = initialDir; ofd.InitialDirectory = initialDir;
}
if (Application.Current.MainWindow != null) res = Application.Current.MainWindow != null
{ ? ofd.ShowDialog(Application.Current.MainWindow)
res = ofd.ShowDialog(Application.Current.MainWindow); : ofd.ShowDialog();
}
else
{
res = ofd.ShowDialog();
}
if (res == true) if (res == true)
{
lPath = ofd.FileName; lPath = ofd.FileName;
}
else else
{
res = false; res = false;
}
}); });
path = lPath; path = lPath;
return res.Value; return res.Value;
} }
public Task<ProgressDialogController> ShowProgressDialog(string title, string message, bool isCancelable = false,
MetroDialogSettings settings = null)
{
var activeWindow = GetActiveWindow();
return activeWindow?.Dispatcher.Invoke(
() => activeWindow.ShowProgressAsync(title, message, isCancelable, settings));
}
} }
} }

View File

@ -167,7 +167,7 @@ namespace Artemis.ViewModels.Flyouts
if (keyboard != null) if (keyboard != null)
{ {
MainManager.DeviceManager.EnableKeyboard(keyboard); MainManager.DeviceManager.EnableKeyboard(keyboard);
MainManager.LoopManager.Start(); MainManager.LoopManager.StartAsync();
} }
else else
MainManager.DeviceManager.ReleaseActiveKeyboard(true); MainManager.DeviceManager.ReleaseActiveKeyboard(true);

View File

@ -1,4 +1,7 @@
using System.Linq; using System.Linq;
using System.Threading.Tasks;
using Artemis.Managers;
using Artemis.Services;
using Artemis.ViewModels.Abstract; using Artemis.ViewModels.Abstract;
using Artemis.ViewModels.Flyouts; using Artemis.ViewModels.Flyouts;
using Caliburn.Micro; using Caliburn.Micro;
@ -8,11 +11,16 @@ namespace Artemis.ViewModels
{ {
public sealed class ShellViewModel : Conductor<IScreen>.Collection.OneActive public sealed class ShellViewModel : Conductor<IScreen>.Collection.OneActive
{ {
private readonly DeviceManager _deviceManager;
private readonly MetroDialogService _dialogService;
private readonly BaseViewModel[] _viewModels; private readonly BaseViewModel[] _viewModels;
public ShellViewModel(IKernel kernel, IEventAggregator events, BaseViewModel[] viewModels) public ShellViewModel(IKernel kernel, IEventAggregator events, BaseViewModel[] viewModels,
DeviceManager deviceManager, MetroDialogService dialogService)
{ {
_viewModels = viewModels; _viewModels = viewModels;
_deviceManager = deviceManager;
_dialogService = dialogService;
events.Subscribe(this); events.Subscribe(this);

View File

@ -1,4 +1,7 @@
using System.Windows; using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Artemis.Events; using Artemis.Events;
using Artemis.Managers; using Artemis.Managers;
using Artemis.Services; using Artemis.Services;
@ -18,13 +21,14 @@ namespace Artemis.ViewModels
private bool _enabled; private bool _enabled;
private string _toggleText; private string _toggleText;
public SystemTrayViewModel(IWindowManager windowManager, IEventAggregator events, ShellViewModel shellViewModel, public SystemTrayViewModel(IWindowManager windowManager, IEventAggregator events, MetroDialogService dialogService, ShellViewModel shellViewModel,
MainManager mainManager) MainManager mainManager)
{ {
_windowManager = windowManager; _windowManager = windowManager;
_shellViewModel = shellViewModel; _shellViewModel = shellViewModel;
_checkedForUpdate = false; _checkedForUpdate = false;
DialogService = dialogService;
MainManager = mainManager; MainManager = mainManager;
events.Subscribe(this); events.Subscribe(this);
@ -34,14 +38,14 @@ namespace Artemis.ViewModels
ShowWindow(); ShowWindow();
} }
[Inject]
public MetroDialogService DialogService { get; set; } public MetroDialogService DialogService { get; set; }
public MainManager MainManager { get; set; } public MainManager MainManager { get; set; }
public bool CanShowWindow => !_shellViewModel.IsActive; public bool CanShowWindow => !_shellViewModel.IsActive;
public bool CanHideWindow => _shellViewModel.IsActive; public bool CanHideWindow => _shellViewModel.IsActive && !MainManager.DeviceManager.ChangingKeyboard;
public bool CanToggleEnabled => !MainManager.DeviceManager.ChangingKeyboard;
public bool Enabled public bool Enabled
{ {
@ -114,9 +118,39 @@ namespace Artemis.ViewModels
return; return;
_checkedForUpdate = true; _checkedForUpdate = true;
ShowKeyboardDialog();
Updater.CheckForUpdate(DialogService); Updater.CheckForUpdate(DialogService);
} }
private async void ShowKeyboardDialog()
{
while(!_shellViewModel.IsActive)
await Task.Delay(200);
NotifyOfPropertyChange(() => CanHideWindow);
NotifyOfPropertyChange(() => CanToggleEnabled);
var dialog = await DialogService.ShowProgressDialog("Enabling keyboard",
"Artemis is still busy trying to enable your last used keyboard. " +
"Please wait while the progress completes");
dialog.SetIndeterminate();
while (MainManager.DeviceManager.ChangingKeyboard)
await Task.Delay(10);
NotifyOfPropertyChange(() => CanHideWindow);
NotifyOfPropertyChange(() => CanToggleEnabled);
try
{
await dialog.CloseAsync();
}
catch (InvalidOperationException)
{
// Occurs when window is closed again, can't find a proper check for this
}
}
public void HideWindow() public void HideWindow()
{ {

View File

@ -5,6 +5,7 @@
<package id="Castle.Core" version="3.3.3" targetFramework="net452" /> <package id="Castle.Core" version="3.3.3" targetFramework="net452" />
<package id="Colore" version="4.0.0" targetFramework="net452" /> <package id="Colore" version="4.0.0" targetFramework="net452" />
<package id="CUE.NET" version="1.0.3" targetFramework="net452" /> <package id="CUE.NET" version="1.0.3" targetFramework="net452" />
<package id="DynamicExpresso.Core" version="1.3.1.0" targetFramework="net452" />
<package id="Extended.Wpf.Toolkit" version="2.7" targetFramework="net452" /> <package id="Extended.Wpf.Toolkit" version="2.7" targetFramework="net452" />
<package id="gong-wpf-dragdrop" version="0.1.4.3" targetFramework="net452" /> <package id="gong-wpf-dragdrop" version="0.1.4.3" targetFramework="net452" />
<package id="Hardcodet.NotifyIcon.Wpf" version="1.0.8" targetFramework="net452" /> <package id="Hardcodet.NotifyIcon.Wpf" version="1.0.8" targetFramework="net452" />
@ -20,7 +21,6 @@
<package id="NLog" version="4.3.4" targetFramework="net452" /> <package id="NLog" version="4.3.4" targetFramework="net452" />
<package id="NLog.Schema" version="4.3.4" targetFramework="net452" /> <package id="NLog.Schema" version="4.3.4" targetFramework="net452" />
<package id="SpotifyAPI-NET" version="2.9.0" targetFramework="net452" /> <package id="SpotifyAPI-NET" version="2.9.0" targetFramework="net452" />
<package id="System.Linq.Dynamic" version="1.0.6" targetFramework="net452" />
<package id="VirtualInput" version="1.0.1" targetFramework="net452" /> <package id="VirtualInput" version="1.0.1" targetFramework="net452" />
<package id="WpfExceptionViewer" version="1.0.0.0" targetFramework="net452" /> <package id="WpfExceptionViewer" version="1.0.0.0" targetFramework="net452" />
</packages> </packages>