Files

61 lines
2.1 KiB
C#
Raw Permalink Normal View History

2026-08-11 23:03:55 +08:00
namespace LanMountainDesktop.AirAppSdk;
2026-08-11 23:03:55 +08:00
public static class AirAppRuntimeModes
{
public const string InProcess = "in-proc";
2026-08-11 23:03:55 +08:00
public const string InProcessAlt = "in-process";
public const string IsolatedBackground = "isolated-background";
public const string IsolatedWindow = "isolated-window";
2026-08-11 23:03:55 +08:00
public static bool TryParse(string? value, out AirAppRuntimeMode mode)
{
switch (value?.Trim().ToLowerInvariant())
{
case null:
case "":
case InProcess:
2026-08-11 23:03:55 +08:00
case InProcessAlt:
mode = AirAppRuntimeMode.InProcess;
return true;
case IsolatedBackground:
2026-08-11 23:03:55 +08:00
mode = AirAppRuntimeMode.IsolatedBackground;
return true;
case IsolatedWindow:
2026-08-11 23:03:55 +08:00
mode = AirAppRuntimeMode.IsolatedWindow;
return true;
default:
mode = default;
return false;
}
}
2026-08-11 23:03:55 +08:00
public static AirAppRuntimeMode Parse(string? value, string sourceName, string propertyName = "runtime.mode")
{
if (TryParse(value, out var mode))
{
return mode;
}
var candidate = string.IsNullOrWhiteSpace(value) ? "<empty>" : value.Trim();
throw new InvalidOperationException(
2026-08-11 23:03:55 +08:00
$"AirApp manifest '{sourceName}' declares unsupported runtime mode '{candidate}' in '{propertyName}'. " +
$"Supported values: '{InProcess}', '{IsolatedBackground}', '{IsolatedWindow}'.");
}
public static string NormalizeManifestValue(string? value, string sourceName, string propertyName = "runtime.mode")
{
return ToManifestValue(Parse(value, sourceName, propertyName));
}
2026-08-11 23:03:55 +08:00
public static string ToManifestValue(AirAppRuntimeMode mode)
{
return mode switch
{
2026-08-11 23:03:55 +08:00
AirAppRuntimeMode.InProcess => InProcess,
AirAppRuntimeMode.IsolatedBackground => IsolatedBackground,
AirAppRuntimeMode.IsolatedWindow => IsolatedWindow,
_ => throw new ArgumentOutOfRangeException(nameof(mode), mode, "Unsupported plugin runtime mode.")
};
}
}