mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Get colors from active window executable icon (#490)
* Get colors from active window executable icon
This commit is contained in:
parent
31d8c345f5
commit
c3b34fd397
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
using Artemis.Plugins.Modules.General.DataModels.Windows;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Plugins.Modules.General.DataModels
|
||||
{
|
||||
@ -20,4 +21,14 @@ namespace Artemis.Plugins.Modules.General.DataModels
|
||||
public DateTimeOffset CurrentTime { get; set; }
|
||||
public TimeSpan TimeSinceMidnight { get; set; }
|
||||
}
|
||||
|
||||
public class IconColorsDataModel : DataModel
|
||||
{
|
||||
public SKColor Vibrant { get; set; }
|
||||
public SKColor LightVibrant { get; set; }
|
||||
public SKColor DarkVibrant { get; set; }
|
||||
public SKColor Muted { get; set; }
|
||||
public SKColor LightMuted { get; set; }
|
||||
public SKColor DarkMuted { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,18 @@
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
using Artemis.Core.Services;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Plugins.Modules.General.DataModels.Windows
|
||||
{
|
||||
public class WindowDataModel
|
||||
{
|
||||
public WindowDataModel(Process process)
|
||||
public WindowDataModel(Process process, IColorQuantizerService _quantizerService)
|
||||
{
|
||||
Process = process;
|
||||
WindowTitle = process.MainWindowTitle;
|
||||
@ -14,6 +20,27 @@ namespace Artemis.Plugins.Modules.General.DataModels.Windows
|
||||
|
||||
// Accessing MainModule requires admin privileges, this way does not
|
||||
ProgramLocation = process.GetProcessFilename();
|
||||
|
||||
// Get Icon colors
|
||||
if(File.Exists(ProgramLocation))
|
||||
{
|
||||
using MemoryStream mem = new MemoryStream();
|
||||
Icon.ExtractAssociatedIcon(ProgramLocation).Save(mem);
|
||||
mem.Seek(0, SeekOrigin.Begin);
|
||||
using SKBitmap skbm = SKBitmap.Decode(mem);
|
||||
mem.Close();
|
||||
|
||||
List<SKColor> skClrs = _quantizerService.Quantize(skbm.Pixels.ToList(), 256).ToList();
|
||||
Colors = new IconColorsDataModel
|
||||
{
|
||||
Vibrant = _quantizerService.FindColorVariation(skClrs, ColorType.Vibrant, true),
|
||||
LightVibrant = _quantizerService.FindColorVariation(skClrs, ColorType.LightVibrant, true),
|
||||
DarkVibrant = _quantizerService.FindColorVariation(skClrs, ColorType.DarkVibrant, true),
|
||||
Muted = _quantizerService.FindColorVariation(skClrs, ColorType.Muted, true),
|
||||
LightMuted = _quantizerService.FindColorVariation(skClrs, ColorType.LightMuted, true),
|
||||
DarkMuted = _quantizerService.FindColorVariation(skClrs, ColorType.DarkMuted, true),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[DataModelIgnore]
|
||||
@ -22,5 +49,6 @@ namespace Artemis.Plugins.Modules.General.DataModels.Windows
|
||||
public string WindowTitle { get; set; }
|
||||
public string ProcessName { get; set; }
|
||||
public string ProgramLocation { get; set; }
|
||||
public IconColorsDataModel Colors { get; set; }
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Modules;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Plugins.Modules.General.DataModels;
|
||||
using Artemis.Plugins.Modules.General.DataModels.Windows;
|
||||
using Artemis.Plugins.Modules.General.Utilities;
|
||||
@ -13,6 +14,12 @@ namespace Artemis.Plugins.Modules.General
|
||||
{
|
||||
public class GeneralModule : ProfileModule<GeneralDataModel>
|
||||
{
|
||||
private readonly IColorQuantizerService _quantizerService;
|
||||
|
||||
public GeneralModule(IColorQuantizerService quantizerService) {
|
||||
_quantizerService = quantizerService;
|
||||
}
|
||||
|
||||
public override void EnablePlugin()
|
||||
{
|
||||
DisplayName = "General";
|
||||
@ -51,7 +58,7 @@ namespace Artemis.Plugins.Modules.General
|
||||
{
|
||||
int processId = WindowUtilities.GetActiveProcessId();
|
||||
if (DataModel.ActiveWindow == null || DataModel.ActiveWindow.Process.Id != processId)
|
||||
DataModel.ActiveWindow = new WindowDataModel(Process.GetProcessById(processId));
|
||||
DataModel.ActiveWindow = new WindowDataModel(Process.GetProcessById(processId), _quantizerService);
|
||||
if (DataModel.ActiveWindow != null && string.IsNullOrWhiteSpace(DataModel.ActiveWindow.WindowTitle))
|
||||
DataModel.ActiveWindow.WindowTitle = Process.GetProcessById(WindowUtilities.GetActiveProcessId()).MainWindowTitle;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user