Update file watcher for Luna.
Some checks are pending
.NET Build / build (push) Waiting to run

This commit is contained in:
Ottermandias 2025-10-24 15:44:26 +02:00
parent c47d920961
commit d79e687162
4 changed files with 32 additions and 22 deletions

2
Luna

@ -1 +1 @@
Subproject commit 8fc11b993d8504982acd95b8d39e6ee7046c1347
Subproject commit c764db88097c88cd49f2bed4f60268d617f97fdb

@ -1 +1 @@
Subproject commit 182cca56a49411430233d73d7a8a6bb3d983f8f0
Subproject commit cf3d868eeeb4ea3ea728ae15a8d09ec127ce80e9

View file

@ -1,15 +1,14 @@
using OtterGui.Services;
using Luna;
using Penumbra.Mods.Manager;
namespace Penumbra.Services;
public class FileWatcher : IDisposable, IService
{
// TODO: use ConcurrentSet when it supports comparers in Luna.
private readonly ConcurrentDictionary<string, byte> _pending = new(StringComparer.OrdinalIgnoreCase);
private readonly ModImportManager _modImportManager;
private readonly MessageService _messageService;
private readonly Configuration _config;
private readonly ConcurrentSet<string> _pending = new(StringComparer.OrdinalIgnoreCase);
private readonly ModImportManager _modImportManager;
private readonly MessageService _messageService;
private readonly Configuration _config;
private bool _pausedConsumer;
private FileSystemWatcher? _fsw;
@ -89,6 +88,7 @@ public class FileWatcher : IDisposable, IService
_cts.Cancel();
_cts = null;
}
_consumer = null;
}
@ -125,13 +125,13 @@ public class FileWatcher : IDisposable, IService
}
private void OnPath(object? sender, FileSystemEventArgs e)
=> _pending.TryAdd(e.FullPath, 0);
=> _pending.TryAdd(e.FullPath);
private async Task ConsumerLoopAsync(CancellationToken token)
{
while (true)
{
var (path, _) = _pending.FirstOrDefault();
var path = _pending.FirstOrDefault<string>();
if (path is null || _pausedConsumer)
{
await Task.Delay(500, token).ConfigureAwait(false);
@ -152,7 +152,7 @@ public class FileWatcher : IDisposable, IService
}
finally
{
_pending.TryRemove(path, out _);
_pending.TryRemove(path);
}
}
}

View file

@ -1,39 +1,49 @@
using Dalamud.Bindings.ImGui;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Interface.ImGuiNotification;
using Dalamud.Interface.ImGuiNotification.EventArgs;
using OtterGui.Text;
using ImSharp;
using Penumbra.Mods.Manager;
namespace Penumbra.Services;
public class InstallNotification(ModImportManager modImportManager, string filePath) : OtterGui.Classes.MessageService.IMessage
public class InstallNotification(ModImportManager modImportManager, string filePath) : Luna.IMessage
{
public string Message
=> "A new mod has been found!";
public NotificationType NotificationType
=> NotificationType.Info;
public uint NotificationDuration
=> uint.MaxValue;
public string NotificationMessage
=> "A new mod has been found!";
public TimeSpan NotificationDuration
=> TimeSpan.MaxValue;
public string NotificationTitle { get; } = Path.GetFileNameWithoutExtension(filePath);
public string LogMessage
=> $"A new mod has been found: {Path.GetFileName(filePath)}";
public SeString ChatMessage
=> SeString.Empty;
public StringU8 StoredMessage
=> StringU8.Empty;
public StringU8 StoredTooltip
=> StringU8.Empty;
public void OnNotificationActions(INotificationDrawArgs args)
{
var region = ImGui.GetContentRegionAvail();
var buttonSize = new Vector2((region.X - ImGui.GetStyle().ItemSpacing.X) / 2, 0);
if (ImUtf8.ButtonEx("Install"u8, ""u8, buttonSize))
var region = Im.ContentRegion.Available;
var buttonSize = new Vector2((region.X - Im.Style.ItemSpacing.X) / 2, 0);
if (Im.Button("Install"u8, buttonSize))
{
modImportManager.AddUnpack(filePath);
args.Notification.DismissNow();
}
ImGui.SameLine();
if (ImUtf8.ButtonEx("Ignore"u8, ""u8, buttonSize))
if (Im.Button("Ignore"u8, buttonSize))
args.Notification.DismissNow();
}
}