mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
Add "startup behavior" to profiles
Choose between remember, always enable, always disable
This commit is contained in:
parent
08f959444b
commit
f4102db488
3 changed files with 115 additions and 41 deletions
|
|
@ -386,10 +386,19 @@ internal class ProfileManagerWidget
|
|||
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
|
||||
var enableAtBoot = profile.AlwaysEnableAtBoot;
|
||||
if (ImGui.Checkbox(Locs.AlwaysEnableAtBoot, ref enableAtBoot))
|
||||
ImGui.TextUnformatted(Locs.StartupBehavior);
|
||||
if (ImGui.BeginCombo("##startupBehaviorPicker", Locs.PolicyToLocalisedName(profile.StartupPolicy)))
|
||||
{
|
||||
profile.AlwaysEnableAtBoot = enableAtBoot;
|
||||
foreach (var policy in Enum.GetValues(typeof(ProfileModelV1.ProfileStartupPolicy)).Cast<ProfileModelV1.ProfileStartupPolicy>())
|
||||
{
|
||||
var name = Locs.PolicyToLocalisedName(policy);
|
||||
if (ImGui.Selectable(name, profile.StartupPolicy == policy))
|
||||
{
|
||||
profile.StartupPolicy = policy;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui.EndCombo();
|
||||
}
|
||||
|
||||
ImGuiHelpers.ScaledDummy(5);
|
||||
|
|
@ -554,6 +563,9 @@ internal class ProfileManagerWidget
|
|||
|
||||
private static class Locs
|
||||
{
|
||||
public static string StartupBehavior =>
|
||||
Loc.Localize("ProfileManagerStartupBehavior", "Startup behavior");
|
||||
|
||||
public static string TooltipEnableDisable =>
|
||||
Loc.Localize("ProfileManagerEnableDisableHint", "Enable/Disable this collection");
|
||||
|
||||
|
|
@ -567,9 +579,6 @@ internal class ProfileManagerWidget
|
|||
public static string NoPluginsInProfile =>
|
||||
Loc.Localize("ProfileManagerNoPluginsInProfile", "Collection has no plugins!");
|
||||
|
||||
public static string AlwaysEnableAtBoot =>
|
||||
Loc.Localize("ProfileManagerAlwaysEnableAtBoot", "Always enable when game starts");
|
||||
|
||||
public static string DeleteProfileHint => Loc.Localize("ProfileManagerDeleteProfile", "Delete this collection");
|
||||
|
||||
public static string CopyToClipboardHint =>
|
||||
|
|
@ -647,5 +656,22 @@ internal class ProfileManagerWidget
|
|||
|
||||
public static string NotInstalled(string name) =>
|
||||
Loc.Localize("ProfileManagerNotInstalled", "{0} (Not Installed)").Format(name);
|
||||
|
||||
public static string PolicyToLocalisedName(ProfileModelV1.ProfileStartupPolicy policy)
|
||||
{
|
||||
return policy switch
|
||||
{
|
||||
ProfileModelV1.ProfileStartupPolicy.RememberState => Loc.Localize(
|
||||
"ProfileManagerRememberState",
|
||||
"Remember state"),
|
||||
ProfileModelV1.ProfileStartupPolicy.AlwaysEnable => Loc.Localize(
|
||||
"ProfileManagerAlwaysEnableAtBoot",
|
||||
"Always enable at boot"),
|
||||
ProfileModelV1.ProfileStartupPolicy.AlwaysDisable => Loc.Localize(
|
||||
"ProfileManagerAlwaysDisableAtBoot",
|
||||
"Always disable at boot"),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(policy), policy, null),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,18 @@ internal class Profile
|
|||
this.modelV1 = model as ProfileModelV1 ??
|
||||
throw new ArgumentException("Model was null or unhandled version");
|
||||
|
||||
// Migrate "policy"
|
||||
if (this.modelV1.StartupPolicy == null)
|
||||
{
|
||||
#pragma warning disable CS0618
|
||||
this.modelV1.StartupPolicy = this.modelV1.AlwaysEnableOnBoot
|
||||
? ProfileModelV1.ProfileStartupPolicy.AlwaysEnable
|
||||
: ProfileModelV1.ProfileStartupPolicy.RememberState;
|
||||
#pragma warning restore CS0618
|
||||
|
||||
Service<DalamudConfiguration>.Get().QueueSave();
|
||||
}
|
||||
|
||||
// We don't actually enable plugins here, PM will do it on bootup
|
||||
if (isDefaultProfile)
|
||||
{
|
||||
|
|
@ -40,10 +52,18 @@ internal class Profile
|
|||
this.IsEnabled = this.modelV1.IsEnabled = true;
|
||||
this.Name = this.modelV1.Name = "DEFAULT";
|
||||
}
|
||||
else if (this.modelV1.AlwaysEnableOnBoot && isBoot)
|
||||
else if (isBoot)
|
||||
{
|
||||
this.IsEnabled = true;
|
||||
Log.Verbose("{Guid} set enabled because bootup", this.modelV1.Guid);
|
||||
if (this.modelV1.StartupPolicy == ProfileModelV1.ProfileStartupPolicy.AlwaysEnable)
|
||||
{
|
||||
this.IsEnabled = true;
|
||||
Log.Verbose("{Guid} set enabled because always enable", this.modelV1.Guid);
|
||||
}
|
||||
else if (this.modelV1.StartupPolicy == ProfileModelV1.ProfileStartupPolicy.AlwaysDisable)
|
||||
{
|
||||
this.IsEnabled = false;
|
||||
Log.Verbose("{Guid} set disabled because always disable", this.modelV1.Guid);
|
||||
}
|
||||
}
|
||||
else if (this.modelV1.IsEnabled)
|
||||
{
|
||||
|
|
@ -72,12 +92,12 @@ internal class Profile
|
|||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this profile shall always be enabled at boot.
|
||||
/// </summary>
|
||||
public bool AlwaysEnableAtBoot
|
||||
public ProfileModelV1.ProfileStartupPolicy StartupPolicy
|
||||
{
|
||||
get => this.modelV1.AlwaysEnableOnBoot;
|
||||
get => this.modelV1.StartupPolicy ?? ProfileModelV1.ProfileStartupPolicy.RememberState;
|
||||
set
|
||||
{
|
||||
this.modelV1.AlwaysEnableOnBoot = value;
|
||||
this.modelV1.StartupPolicy = value;
|
||||
Service<DalamudConfiguration>.Get().QueueSave();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,27 @@ namespace Dalamud.Plugin.Internal.Profiles;
|
|||
/// </summary>
|
||||
public class ProfileModelV1 : ProfileModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum representing the startup policy of a profile.
|
||||
/// </summary>
|
||||
public enum ProfileStartupPolicy
|
||||
{
|
||||
/// <summary>
|
||||
/// Remember the last state of the profile.
|
||||
/// </summary>
|
||||
RememberState,
|
||||
|
||||
/// <summary>
|
||||
/// Always enable the profile.
|
||||
/// </summary>
|
||||
AlwaysEnable,
|
||||
|
||||
/// <summary>
|
||||
/// Always disable the profile.
|
||||
/// </summary>
|
||||
AlwaysDisable,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the prefix of this version.
|
||||
/// </summary>
|
||||
|
|
@ -18,8 +39,15 @@ public class ProfileModelV1 : ProfileModel
|
|||
/// Gets or sets a value indicating whether or not this profile should always be enabled at boot.
|
||||
/// </summary>
|
||||
[JsonProperty("b")]
|
||||
[Obsolete("Superseded by StartupPolicy")]
|
||||
public bool AlwaysEnableOnBoot { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the policy to use when Dalamud is loading.
|
||||
/// </summary>
|
||||
[JsonProperty("p")]
|
||||
public ProfileStartupPolicy? StartupPolicy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not this profile is currently enabled.
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue