Public Access
112 lines
3.2 KiB
C#
112 lines
3.2 KiB
C#
using MeetingAssistant.LaunchProfiles;
|
|
using MeetingAssistant.Recording;
|
|
|
|
namespace MeetingAssistant.Taskbar;
|
|
|
|
public enum MeetingTaskbarAction
|
|
{
|
|
EditRules,
|
|
StartRecording,
|
|
StopRecording,
|
|
AbortRecording,
|
|
SwitchProfile,
|
|
Exit
|
|
}
|
|
|
|
public sealed record MeetingTaskbarMenu(
|
|
RecordingProcessState State,
|
|
string Tooltip,
|
|
IReadOnlyList<MeetingTaskbarMenuItem> Items);
|
|
|
|
public sealed record MeetingTaskbarMenuItem(
|
|
string Text,
|
|
MeetingTaskbarAction Action,
|
|
string? ProfileName = null);
|
|
|
|
public static class MeetingTaskbarMenuBuilder
|
|
{
|
|
public static MeetingTaskbarMenu Build(
|
|
RecordingStatus status,
|
|
IReadOnlyList<LaunchProfile> launchProfiles)
|
|
{
|
|
var items = new List<MeetingTaskbarMenuItem>
|
|
{
|
|
new("Settings and logs", MeetingTaskbarAction.EditRules)
|
|
};
|
|
|
|
if (status.IsRecording)
|
|
{
|
|
items.Add(new MeetingTaskbarMenuItem(
|
|
"Stop meeting recording and transcribe",
|
|
MeetingTaskbarAction.StopRecording));
|
|
items.Add(new MeetingTaskbarMenuItem(
|
|
"Cancel meeting recording and discard",
|
|
MeetingTaskbarAction.AbortRecording));
|
|
|
|
foreach (var profile in launchProfiles.Where(profile => !IsActiveProfile(profile, status)))
|
|
{
|
|
items.Add(new MeetingTaskbarMenuItem(
|
|
AppendHotkey($"Switch to {profile.Name}", profile.Options.Hotkey.Toggle),
|
|
MeetingTaskbarAction.SwitchProfile,
|
|
profile.Name));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (var profile in launchProfiles)
|
|
{
|
|
items.Add(new MeetingTaskbarMenuItem(
|
|
AppendHotkey($"Start meeting recording ({profile.Name})", profile.Options.Hotkey.Toggle),
|
|
MeetingTaskbarAction.StartRecording,
|
|
profile.Name));
|
|
}
|
|
}
|
|
|
|
items.Add(new MeetingTaskbarMenuItem(
|
|
"Exit",
|
|
MeetingTaskbarAction.Exit));
|
|
|
|
return new MeetingTaskbarMenu(
|
|
status.State,
|
|
BuildTooltip(status),
|
|
items);
|
|
}
|
|
|
|
private static string BuildTooltip(RecordingStatus status)
|
|
{
|
|
return status.State switch
|
|
{
|
|
RecordingProcessState.Recording => string.IsNullOrWhiteSpace(status.LaunchProfile)
|
|
? "Meeting Assistant - recording"
|
|
: $"Meeting Assistant - recording ({status.LaunchProfile})",
|
|
RecordingProcessState.Summarizing => "Meeting Assistant - summarizing",
|
|
_ => "Meeting Assistant - idle"
|
|
};
|
|
}
|
|
|
|
private static bool IsActiveProfile(
|
|
LaunchProfile profile,
|
|
RecordingStatus status)
|
|
{
|
|
return string.Equals(
|
|
profile.Name,
|
|
status.LaunchProfile,
|
|
StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
private static string AppendHotkey(string text, string hotkey)
|
|
{
|
|
return string.IsNullOrWhiteSpace(hotkey)
|
|
? text
|
|
: $"{text}\t{hotkey.Trim()}";
|
|
}
|
|
}
|
|
|
|
public static class MeetingTaskbarExitPolicy
|
|
{
|
|
public static bool RequiresConfirmation(RecordingStatus status)
|
|
{
|
|
return status.State != RecordingProcessState.Idle;
|
|
}
|
|
}
|