forked from antonpup/Aurora
-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
layouts: consider lightsync for CL LEDs, detect chroma and lightsync state changes
- Loading branch information
Aytackydln
committed
May 3, 2024
1 parent
b10fd76
commit 3db7abd
Showing
17 changed files
with
235 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
Project-Aurora/Project-Aurora/Modules/Razer/ChromaSdkManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using AuroraRgb.Modules.ProcessMonitor; | ||
using RazerSdkReader; | ||
|
||
namespace AuroraRgb.Modules.Razer; | ||
|
||
public class ChromaSdkStateChangedEventArgs(ChromaReader? chromaReader) : EventArgs | ||
{ | ||
public ChromaReader? ChromaReader => chromaReader; | ||
} | ||
|
||
public sealed class ChromaSdkManager : IDisposable | ||
{ | ||
private const string RzServiceProcessName = "rzsdkservice.exe"; | ||
|
||
public event EventHandler<ChromaSdkStateChangedEventArgs>? StateChanged; | ||
|
||
public ChromaReader? ChromaReader { get; private set; } | ||
|
||
internal async Task Initialize() | ||
{ | ||
try | ||
{ | ||
var chromaReader = TryLoadChroma(); | ||
ChromaReader = chromaReader; | ||
StateChanged?.Invoke(this, new ChromaSdkStateChangedEventArgs(ChromaReader)); | ||
} | ||
catch (Exception exc) | ||
{ | ||
Global.logger.Fatal(exc, "RazerSdkManager failed to load!"); | ||
} | ||
|
||
var runningProcessMonitor = await ProcessesModule.RunningProcessMonitor; | ||
runningProcessMonitor.ProcessStarted += RunningProcessMonitorOnProcessStarted; | ||
runningProcessMonitor.ProcessStopped += RunningProcessMonitorOnProcessStopped; | ||
} | ||
|
||
private void RunningProcessMonitorOnProcessStarted(object? sender, ProcessStarted e) | ||
{ | ||
if (e.ProcessName != RzServiceProcessName) | ||
{ | ||
return; | ||
} | ||
|
||
Global.logger.Information("Chroma service opened. Enabling Chroma integration..."); | ||
|
||
var chromaReader = TryLoadChroma(); | ||
ChromaReader = chromaReader; | ||
StateChanged?.Invoke(this, new ChromaSdkStateChangedEventArgs(ChromaReader)); | ||
} | ||
|
||
private void RunningProcessMonitorOnProcessStopped(object? sender, ProcessStopped e) | ||
{ | ||
if (e.ProcessName != RzServiceProcessName) | ||
{ | ||
return; | ||
} | ||
|
||
if (ChromaReader == null) | ||
{ | ||
return; | ||
} | ||
|
||
Global.logger.Information("Chroma service is closed. Disabling Chroma integration..."); | ||
|
||
ChromaReader.Dispose(); | ||
ChromaReader = null; | ||
StateChanged?.Invoke(this, new ChromaSdkStateChangedEventArgs(null)); | ||
} | ||
|
||
private static ChromaReader TryLoadChroma() | ||
{ | ||
var chromaReader = new ChromaReader(); | ||
chromaReader.Exception += RazerSdkReaderOnException; | ||
RzHelper.Initialize(chromaReader); | ||
|
||
chromaReader.Start(); | ||
return chromaReader; | ||
} | ||
|
||
private static void RazerSdkReaderOnException(object? sender, RazerSdkReaderException e) | ||
{ | ||
Global.logger.Error(e, "Chroma Reader Error"); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (ChromaReader == null) | ||
{ | ||
return; | ||
} | ||
|
||
ChromaReader.Dispose(); | ||
ChromaReader = null; | ||
} | ||
} |
Oops, something went wrong.