mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Allow saving third party repos without unnecesary "plus" press
This commit is contained in:
parent
ac2d522415
commit
efa8f06dc7
1 changed files with 40 additions and 21 deletions
|
|
@ -46,6 +46,13 @@ internal class ThirdRepoSettingsEntry : SettingsEntry
|
||||||
|
|
||||||
public override void Save()
|
public override void Save()
|
||||||
{
|
{
|
||||||
|
var hasPendingRepo = !string.IsNullOrWhiteSpace(this.thirdRepoTempUrl);
|
||||||
|
var addedPendingRepo = this.TryAddTempRepo();
|
||||||
|
if (!addedPendingRepo && hasPendingRepo)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Service<DalamudConfiguration>.Get().ThirdRepoList =
|
Service<DalamudConfiguration>.Get().ThirdRepoList =
|
||||||
[.. this.thirdRepoList.Select(x => x.Clone())];
|
[.. this.thirdRepoList.Select(x => x.Clone())];
|
||||||
|
|
||||||
|
|
@ -235,27 +242,7 @@ internal class ThirdRepoSettingsEntry : SettingsEntry
|
||||||
ImGui.NextColumn();
|
ImGui.NextColumn();
|
||||||
if (!string.IsNullOrEmpty(this.thirdRepoTempUrl) && ImGuiComponents.IconButton(FontAwesomeIcon.Plus))
|
if (!string.IsNullOrEmpty(this.thirdRepoTempUrl) && ImGuiComponents.IconButton(FontAwesomeIcon.Plus))
|
||||||
{
|
{
|
||||||
this.thirdRepoTempUrl = this.thirdRepoTempUrl.TrimEnd();
|
this.TryAddTempRepo();
|
||||||
if (this.thirdRepoList.Any(r => string.Equals(r.Url, this.thirdRepoTempUrl, StringComparison.InvariantCultureIgnoreCase)))
|
|
||||||
{
|
|
||||||
this.thirdRepoAddError = Loc.Localize("DalamudThirdRepoExists", "Repo already exists.");
|
|
||||||
Task.Delay(5000).ContinueWith(t => this.thirdRepoAddError = string.Empty);
|
|
||||||
}
|
|
||||||
else if (!ValidThirdPartyRepoUrl(this.thirdRepoTempUrl))
|
|
||||||
{
|
|
||||||
this.thirdRepoAddError = Loc.Localize("DalamudThirdRepoNotUrl", "The entered address is not a valid URL.\nDid you mean to enter it as a DevPlugin in the fields above instead?");
|
|
||||||
Task.Delay(5000).ContinueWith(t => this.thirdRepoAddError = string.Empty);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.thirdRepoList.Add(new ThirdPartyRepoSettings
|
|
||||||
{
|
|
||||||
Url = this.thirdRepoTempUrl,
|
|
||||||
IsEnabled = true,
|
|
||||||
});
|
|
||||||
this.thirdRepoListChanged = true;
|
|
||||||
this.thirdRepoTempUrl = string.Empty;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.Columns(1);
|
ImGui.Columns(1);
|
||||||
|
|
@ -269,4 +256,36 @@ internal class ThirdRepoSettingsEntry : SettingsEntry
|
||||||
private static bool ValidThirdPartyRepoUrl(string url)
|
private static bool ValidThirdPartyRepoUrl(string url)
|
||||||
=> Uri.TryCreate(url, UriKind.Absolute, out var uriResult)
|
=> Uri.TryCreate(url, UriKind.Absolute, out var uriResult)
|
||||||
&& (uriResult.Scheme == Uri.UriSchemeHttps || uriResult.Scheme == Uri.UriSchemeHttp);
|
&& (uriResult.Scheme == Uri.UriSchemeHttps || uriResult.Scheme == Uri.UriSchemeHttp);
|
||||||
|
|
||||||
|
private bool TryAddTempRepo()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(this.thirdRepoTempUrl))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
this.thirdRepoTempUrl = this.thirdRepoTempUrl.Trim();
|
||||||
|
if (this.thirdRepoList.Any(r => string.Equals(r.Url, this.thirdRepoTempUrl, StringComparison.InvariantCultureIgnoreCase)))
|
||||||
|
{
|
||||||
|
this.thirdRepoAddError = Loc.Localize("DalamudThirdRepoExists", "Repo already exists.");
|
||||||
|
Task.Delay(5000).ContinueWith(t => this.thirdRepoAddError = string.Empty);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ValidThirdPartyRepoUrl(this.thirdRepoTempUrl))
|
||||||
|
{
|
||||||
|
this.thirdRepoAddError = Loc.Localize("DalamudThirdRepoNotUrl", "The entered address is not a valid URL.\nDid you mean to enter it as a DevPlugin in the fields above instead?");
|
||||||
|
Task.Delay(5000).ContinueWith(t => this.thirdRepoAddError = string.Empty);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.thirdRepoList.Add(new ThirdPartyRepoSettings
|
||||||
|
{
|
||||||
|
Url = this.thirdRepoTempUrl,
|
||||||
|
IsEnabled = true,
|
||||||
|
});
|
||||||
|
this.thirdRepoListChanged = true;
|
||||||
|
this.thirdRepoTempUrl = string.Empty;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue