Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 561811cd1f | |||
| 0c0c72be9f |
@@ -6,6 +6,12 @@ using Dalamud.Plugin.Services;
|
||||
using SpotifyHonorific.Windows;
|
||||
using SpotifyHonorific.Activities;
|
||||
using SpotifyHonorific.Updaters;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using System.Numerics;
|
||||
|
||||
namespace SpotifyHonorific;
|
||||
|
||||
@@ -70,6 +76,87 @@ public sealed class Plugin : IDalamudPlugin
|
||||
Config.Save();
|
||||
Updater.Stop();
|
||||
}
|
||||
else if (subcommand == "set")
|
||||
{
|
||||
var splitArgs = args.Trim().Split(' ', 2, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
|
||||
if (splitArgs.Length != 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var setArgs = splitArgs[1].Split('|', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
|
||||
bool? prefix = null;
|
||||
Vector3? color = null;
|
||||
Vector3? glow = null;
|
||||
|
||||
foreach (var a in setArgs)
|
||||
{
|
||||
|
||||
var arg = a.ToLower();
|
||||
|
||||
var colorArg = arg.Skip(arg.StartsWith('#') ? 1 : 0).ToArray();
|
||||
|
||||
if (colorArg.Length == 6 && colorArg.All(chr => chr is >= '0' and <= '9' or >= 'a' and <= 'f'))
|
||||
{
|
||||
|
||||
if (color != null && glow != null)
|
||||
{
|
||||
ChatGui.PrintError($"Duplicate Option in Set: '{a}'", "SpotifyHonorific");
|
||||
return;
|
||||
}
|
||||
|
||||
var rHex = string.Join(null, colorArg.Skip(0).Take(2));
|
||||
var gHex = string.Join(null, colorArg.Skip(2).Take(2));
|
||||
var bHex = string.Join(null, colorArg.Skip(4).Take(2));
|
||||
|
||||
|
||||
if (byte.TryParse(rHex, NumberStyles.HexNumber, NumberFormatInfo.InvariantInfo, out var r) &&
|
||||
byte.TryParse(gHex, NumberStyles.HexNumber, NumberFormatInfo.InvariantInfo, out var g) &&
|
||||
byte.TryParse(bHex, NumberStyles.HexNumber, NumberFormatInfo.InvariantInfo, out var b))
|
||||
{
|
||||
|
||||
var c = new Vector3(r / 255f, g / 255f, b / 255f);
|
||||
if (color == null)
|
||||
{
|
||||
color = c;
|
||||
continue;
|
||||
}
|
||||
|
||||
glow = c;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (arg is "p" or "prefix" or "pre")
|
||||
{
|
||||
if (prefix != null)
|
||||
{
|
||||
ChatGui.PrintError($"Duplicate Option in Set: '{a}'", "SpotifyHonorific");
|
||||
return;
|
||||
}
|
||||
|
||||
prefix = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg is "s" or "suffix")
|
||||
{
|
||||
if (prefix != null)
|
||||
{
|
||||
ChatGui.PrintError($"Duplicate Option in Set: '{a}'", "SpotifyHonorific");
|
||||
return;
|
||||
}
|
||||
prefix = false;
|
||||
continue;
|
||||
}
|
||||
ChatGui.PrintError($"Invalid Option in Set: '{a}'", "SpotifyHonorific");
|
||||
return;
|
||||
}
|
||||
|
||||
Config.ActivityConfigs.First().Color = color;
|
||||
Config.ActivityConfigs.First().Glow = glow;
|
||||
Config.ActivityConfigs.First().IsPrefix = prefix ?? false;
|
||||
ChatGui.Print("Updated Title", "SpotifyHonorific");
|
||||
}
|
||||
else
|
||||
{
|
||||
ChatGui.Print(CommandHelpMessage);
|
||||
|
||||
@@ -8,6 +8,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
|
||||
@@ -147,25 +149,63 @@ public class Updater : IDisposable
|
||||
try
|
||||
{
|
||||
var spotifyProcesses = Process.GetProcessesByName("Spotify");
|
||||
var trackTitles = new List<string>();
|
||||
|
||||
foreach (var process in spotifyProcesses)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(process.MainWindowTitle) &&
|
||||
process.MainWindowTitle != "Spotify" &&
|
||||
process.MainWindowTitle != "Spotify Premium" &&
|
||||
process.MainWindowTitle != "Spotify Free")
|
||||
EnumWindows((hWnd, lParam) =>
|
||||
{
|
||||
return process.MainWindowTitle;
|
||||
}
|
||||
uint processId;
|
||||
GetWindowThreadProcessId(hWnd, out processId);
|
||||
|
||||
if (processId == process.Id)
|
||||
{
|
||||
var title = GetWindowTitle(hWnd);
|
||||
if (!string.IsNullOrEmpty(title) &&
|
||||
title != "Spotify" &&
|
||||
title != "Spotify Premium" &&
|
||||
title != "Spotify Free" &&
|
||||
title.Contains(" - "))
|
||||
{
|
||||
trackTitles.Add(title);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}, IntPtr.Zero);
|
||||
}
|
||||
|
||||
return trackTitles.OrderByDescending(t => t.Length).FirstOrDefault();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
PluginLog.Debug($"Error getting Spotify track: {ex.Message}");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string GetWindowTitle(IntPtr hWnd)
|
||||
{
|
||||
const int nChars = 256;
|
||||
var buff = new StringBuilder(nChars);
|
||||
if (GetWindowTextW(hWnd, buff, nChars) > 0)
|
||||
{
|
||||
return buff.ToString();
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
|
||||
private static extern int GetWindowTextW(IntPtr hWnd, StringBuilder text, int count);
|
||||
|
||||
private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
|
||||
|
||||
private bool MediaActivitiesEqual(MediaActivity? a, MediaActivity? b)
|
||||
{
|
||||
if (a == null && b == null) return true;
|
||||
|
||||
Reference in New Issue
Block a user