connect to api only after login, add switching secret keys and inputting secret key during intro, fix filereplacements not working properly, adjust to the new web api

This commit is contained in:
Stanley Dimant
2022-06-29 22:40:17 +02:00
parent 2ff224243a
commit 95f7e5f867
11 changed files with 206 additions and 93 deletions

View File

@@ -16,7 +16,7 @@ namespace MareSynchronos.UI
private readonly WindowSystem _windowSystem;
private bool _readFirstPage = false;
public event EventHandler? FinishedRegistration;
public event SwitchUi? SwitchFromIntroToMainUi;
public void Dispose()
{
@@ -157,7 +157,7 @@ namespace MareSynchronos.UI
ImGui.Text("Service registration");
ImGui.SetWindowFontScale(1.0f);
ImGui.Separator();
if (_pluginConfiguration.ClientSecret.ContainsKey(_pluginConfiguration.ApiUri))
if (_pluginConfiguration.ClientSecret.ContainsKey(_pluginConfiguration.ApiUri) && _uiShared.ShowClientSecret)
{
ImGui.Separator();
UiShared.TextWrapped(_pluginConfiguration.ClientSecret[_pluginConfiguration.ApiUri]);
@@ -176,7 +176,7 @@ namespace MareSynchronos.UI
ImGui.Separator();
if (ImGui.Button("Finish##finishIntro"))
{
FinishedRegistration?.Invoke(null, EventArgs.Empty);
SwitchFromIntroToMainUi?.Invoke();
IsOpen = false;
}
}
@@ -190,7 +190,7 @@ namespace MareSynchronos.UI
"to verify who you are. It is directly tied to the UID you will be receiving. In case of loss, you will have to re-register an account.");
UiShared.TextWrapped("Do not ever, under any circumstances, share your secret key to anyone! Likewise do not share your Mare Synchronos plugin configuration to anyone!");
ImGui.PopStyleColor();
_uiShared.DrawServiceSelection();
_uiShared.DrawServiceSelection(() => SwitchFromIntroToMainUi?.Invoke(), true);
}
}
}

View File

@@ -13,17 +13,19 @@ using MareSynchronos.Utils;
namespace MareSynchronos.UI
{
public class PluginUi : Window, IDisposable
public delegate void SwitchUi();
public class MainUi : Window, IDisposable
{
private readonly Configuration _configuration;
private readonly WindowSystem _windowSystem;
private readonly ApiController _apiController;
private readonly UiShared _uiShared;
public event SwitchUi? SwitchFromMainUiToIntro;
public PluginUi(WindowSystem windowSystem,
public MainUi(WindowSystem windowSystem,
UiShared uiShared, Configuration configuration, ApiController apiController) : base("Mare Synchronos Settings", ImGuiWindowFlags.None)
{
Logger.Debug("Creating " + nameof(PluginUi));
Logger.Debug("Creating " + nameof(MainUi));
SizeConstraints = new WindowSizeConstraints()
{
@@ -40,7 +42,7 @@ namespace MareSynchronos.UI
public void Dispose()
{
Logger.Debug("Disposing " + nameof(PluginUi));
Logger.Debug("Disposing " + nameof(MainUi));
_windowSystem.RemoveWindow(this);
}
@@ -79,9 +81,24 @@ namespace MareSynchronos.UI
}
else
{
string error = _configuration.FullPause ? "Fully Paused" : "Service unavailable";
string error = _configuration.FullPause ? "Fully Paused" : _apiController.ServerAlive ? "Unauthorized" : "Service unavailable";
ImGui.TextColored(ImGuiColors.DalamudRed, $"No UID ({error})");
ImGui.SetWindowFontScale(1.0f);
if (_apiController.ServerAlive && !_configuration.FullPause)
{
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
UiShared.TextWrapped("Your account is not present on the service anymore or you are banned.");
ImGui.PopStyleColor();
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudYellow);
UiShared.TextWrapped("If you think your secret key is just invalid, use the following button to reset the local secret key to be able to re-register. If you continue to see this message after registering, tough luck, asshole.");
ImGui.PopStyleColor();
if (ImGui.Button("Reset Secret Key"))
{
_configuration.ClientSecret.Remove(_configuration.ApiUri);
_configuration.Save();
SwitchFromMainUiToIntro?.Invoke();
}
}
}
ImGui.Separator();
@@ -157,6 +174,7 @@ namespace MareSynchronos.UI
Task.Run(() => _apiController.DeleteAccount());
ImGui.CloseCurrentPopup();
_deleteAccountPopupModalShown = false;
SwitchFromMainUiToIntro?.Invoke();
}
ImGui.SameLine();
@@ -201,7 +219,7 @@ namespace MareSynchronos.UI
if (marePaused)
{
_uiShared.DrawServiceSelection();
_uiShared.DrawServiceSelection(() => SwitchFromMainUiToIntro?.Invoke());
}

View File

@@ -20,6 +20,7 @@ namespace MareSynchronos.UI
private readonly FileDialogManager _fileDialogManager;
private readonly Configuration _pluginConfiguration;
public long FileCacheSize => _fileCacheManager.FileCacheSize;
public bool ShowClientSecret = true;
public UiShared(IpcManager ipcManager, ApiController apiController, FileCacheManager fileCacheManager, FileDialogManager fileDialogManager, Configuration pluginConfiguration)
{
@@ -78,12 +79,12 @@ namespace MareSynchronos.UI
}
}
public void PrintServerState()
public void PrintServerState(bool isIntroUi = false)
{
var serverName = _apiController.ServerDictionary.ContainsKey(_pluginConfiguration.ApiUri)
? _apiController.ServerDictionary[_pluginConfiguration.ApiUri]
: _pluginConfiguration.ApiUri;
ImGui.Text("Service status of \"" + serverName + "\":");
ImGui.Text("Service " + serverName + ":");
ImGui.SameLine();
var color = _apiController.ServerAlive ? ImGuiColors.ParsedGreen : ImGuiColors.DalamudRed;
ImGui.TextColored(color, _apiController.ServerAlive ? "Available" : "Unavailable");
@@ -94,7 +95,7 @@ namespace MareSynchronos.UI
ImGui.SameLine();
ImGui.TextColored(ImGuiColors.ParsedGreen, _apiController.OnlineUsers.ToString());
ImGui.SameLine();
ImGui.Text("Users Online (server-wide)");
ImGui.Text("Users Online" + (!isIntroUi ? " (server-wide)" : string.Empty));
ImGui.SameLine();
ImGui.Text(")");
}
@@ -154,8 +155,9 @@ namespace MareSynchronos.UI
private int _serverSelectionIndex = 0;
private string _customServerName = "";
private string _customServerUri = "";
private bool _enterSecretKey = false;
public void DrawServiceSelection()
public void DrawServiceSelection(Action? callBackOnExit = null, bool isIntroUi = false)
{
string[] comboEntries = _apiController.ServerDictionary.Values.ToArray();
_serverSelectionIndex = Array.IndexOf(_apiController.ServerDictionary.Keys.ToArray(), _pluginConfiguration.ApiUri);
@@ -186,21 +188,50 @@ namespace MareSynchronos.UI
if (ImGui.Button(FontAwesomeIcon.Trash.ToIconString() + "##deleteService"))
{
_pluginConfiguration.CustomServerList.Remove(_pluginConfiguration.ApiUri);
_pluginConfiguration.ApiUri = ApiController.MainServiceUri;
_pluginConfiguration.ApiUri = _apiController.ServerDictionary.First().Key;
_pluginConfiguration.Save();
}
ImGui.PopFont();
}
PrintServerState();
if (ImGui.TreeNode("Add Custom Service"))
{
ImGui.SetNextItemWidth(250);
ImGui.InputText("Custom Service Name", ref _customServerName, 255);
ImGui.SetNextItemWidth(250);
ImGui.InputText("Custom Service Address", ref _customServerUri, 255);
if (ImGui.Button("Add Custom Service"))
{
if (!string.IsNullOrEmpty(_customServerUri)
&& !string.IsNullOrEmpty(_customServerName)
&& !_pluginConfiguration.CustomServerList.ContainsValue(_customServerName)
&& !_pluginConfiguration.CustomServerList.ContainsKey(_customServerUri))
{
_pluginConfiguration.CustomServerList[_customServerUri] = _customServerName;
_customServerUri = string.Empty;
_customServerName = string.Empty;
_pluginConfiguration.Save();
}
}
ImGui.TreePop();
}
PrintServerState(isIntroUi);
if (_apiController.ServerAlive && !_pluginConfiguration.ClientSecret.ContainsKey(_pluginConfiguration.ApiUri))
{
if (ImGui.Button("Register"))
if (!_enterSecretKey)
{
_pluginConfiguration.FullPause = false;
_pluginConfiguration.Save();
Task.Run(_apiController.Register);
if (ImGui.Button("Register"))
{
_pluginConfiguration.FullPause = false;
_pluginConfiguration.Save();
Task.Run(_apiController.Register);
ShowClientSecret = true;
callBackOnExit?.Invoke();
}
ImGui.SameLine();
}
}
else
@@ -217,28 +248,31 @@ namespace MareSynchronos.UI
}
}
if (ImGui.TreeNode("Custom Service"))
string checkboxText = _pluginConfiguration.ClientSecret.ContainsKey(_pluginConfiguration.ApiUri)
? "I want to switch accounts"
: "I already have an account";
ImGui.Checkbox(checkboxText, ref _enterSecretKey);
if (_enterSecretKey)
{
ImGui.SetNextItemWidth(250);
ImGui.InputText("Custom Service Name", ref _customServerName, 255);
ImGui.SetNextItemWidth(250);
ImGui.InputText("Custom Service Address", ref _customServerUri, 255);
if (ImGui.Button("Add Custom Service"))
ImGui.SetNextItemWidth(400);
ImGui.InputText("Enter Secret Key", ref _secretKey, 255);
ImGui.SameLine();
if (ImGui.Button("Save"))
{
if (!string.IsNullOrEmpty(_customServerUri)
&& !string.IsNullOrEmpty(_customServerName)
&& !_pluginConfiguration.CustomServerList.ContainsValue(_customServerName))
{
_pluginConfiguration.CustomServerList[_customServerUri] = _customServerName;
_customServerUri = string.Empty;
_customServerName = string.Empty;
_pluginConfiguration.Save();
}
_pluginConfiguration.ClientSecret[_pluginConfiguration.ApiUri] = _secretKey;
_pluginConfiguration.Save();
_secretKey = string.Empty;
Task.Run(_apiController.CreateConnections);
ShowClientSecret = false;
_enterSecretKey = false;
callBackOnExit?.Invoke();
}
ImGui.TreePop();
}
}
private string _secretKey = "";
public static void DrawHelpText(string helpText)
{
ImGui.SameLine();