Skip to content

Commit

Permalink
Add option to write responses from web browser to log for debugging p…
Browse files Browse the repository at this point in the history
…urposes
  • Loading branch information
joshua-software-dev committed Aug 8, 2023
1 parent 6f581fa commit 025a235
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
11 changes: 10 additions & 1 deletion LMeter/src/Cactbot/TotallyNotCefCactbotHttpSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class TotallyNotCefCactbotHttpSource : IDisposable
private readonly IinactCactbotClient _iinactCactbotClient;
private readonly CancellationTokenSource _cancelTokenSource;
private readonly bool _enableAudio;
private readonly bool _enableVerboseResponseLogging;
private readonly HttpClient _httpClient;
private readonly HtmlParser _htmlParser;
private readonly string _httpUrl;
Expand All @@ -46,7 +47,8 @@ public TotallyNotCefCactbotHttpSource
bool bypassWebSocket,
string cactbotUrl,
ushort httpPort,
bool enableAudio
bool enableAudio,
bool enableVerboseResponseLogging
)
{
CactbotState = new ();
Expand All @@ -72,6 +74,7 @@ bool enableAudio

_cancelTokenSource = new ();
_enableAudio = enableAudio;
_enableVerboseResponseLogging = enableVerboseResponseLogging;
_htmlParser = new ();
_httpPort = httpPort;
_httpUrl = $"http://127.0.0.1:{httpPort}";
Expand Down Expand Up @@ -163,8 +166,14 @@ private async Task GetCactbotHtml()

var response = await _httpClient.GetAsync(_httpUrl, cancellationToken: _cancelTokenSource.Token);
if (response.Content == null) return;

var rawHtml = await response.Content.ReadAsStringAsync(_cancelTokenSource.Token);
if (rawHtml == null) return;
if (_enableVerboseResponseLogging)
{
PluginLog.LogInformation(rawHtml);
}

_parsedResponse = await _htmlParser.ParseDocumentAsync(rawHtml, _cancelTokenSource.Token);
CactbotState.UpdateState(_parsedResponse);
ConnectionState = TotallyNotCefConnectionState.Connected;
Expand Down
15 changes: 13 additions & 2 deletions LMeter/src/Config/CactbotConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class CactbotConfig : IConfigPage, IDisposable
public string CactbotUrl = MagicValues.DefaultCactbotUrl;
public int HttpPort = 8080;
public bool BypassCactbotWebSocketUsingIPC = true;
public bool LogAllResponsesFromBackgroundWebBrowser = false;

public bool RaidbossEnableAudio = true;
public int RaidbossInCombatPollingRate = 10;
Expand Down Expand Up @@ -74,7 +75,8 @@ public void SetNewCactbotUrl(bool forceStart)
BypassCactbotWebSocketUsingIPC,
CactbotUrl,
(ushort) HttpPort,
RaidbossEnableAudio
RaidbossEnableAudio,
LogAllResponsesFromBackgroundWebBrowser
);
this.Cactbot.StartBackgroundPollingThread(forceStart);
}
Expand Down Expand Up @@ -268,7 +270,7 @@ private void DrawConnectionSettings(Vector2 windowSize)
using var connectionScope = new DrawChildScope
(
"##ConnectionSettings",
windowSize with { X = windowSize.X * 0.94f, Y = 85 + (this.EnableConnection ? 166 : 0) },
windowSize with { X = windowSize.X * 0.94f, Y = 85 + (this.EnableConnection ? 225 : 0) },
true
);
if (!connectionScope.Success) return;
Expand Down Expand Up @@ -397,6 +399,15 @@ private void DrawConnectionSettings(Vector2 windowSize)
{
this.RaidbossOutOfCombatPollingRate = tempOutRate;
}

ImGui.Separator();
ImGui.Text("Connection Debug Options");
ImGui.Separator();
ImGui.Checkbox
(
"Log all responses from browser [WARNING: HIGH PERFORMANCE IMPACT]",
ref LogAllResponsesFromBackgroundWebBrowser
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Version/Version.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<PluginVersion>0.2.0.17</PluginVersion>
<PluginVersion>0.2.0.18</PluginVersion>
</PropertyGroup>
</Project>
4 changes: 4 additions & 0 deletions deps/txt/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version 0.2.0.18
- Add option to write all responses from background web browser to log file for
debugging purposes.

# Version 0.2.0.17
- More aggressively catch errors during basic handshake to ensure plugin never
crashes even when communicating with out of date background web browser
Expand Down
12 changes: 6 additions & 6 deletions repo.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"Name": "LMeter",
"Description": "Plugin to display ACT combat log data. Now with Cactbot integration!",
"InternalName": "LMeter",
"AssemblyVersion": "0.2.0.17",
"TestingAssemblyVersion": "0.2.0.17",
"AssemblyVersion": "0.2.0.18",
"TestingAssemblyVersion": "0.2.0.18",
"RepoUrl": "https://github.com/joshua-software-dev/LMeter",
"ApplicableVersion": "any",
"DalamudApiLevel": 8,
Expand All @@ -35,10 +35,10 @@
"DownloadCount": 0,
"LastUpdate": 0,
"LoadPriority": 69420,
"DownloadLinkInstall": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.17/latest.zip",
"DownloadLinkTesting": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.17/latest.zip",
"DownloadLinkUpdate": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.17/latest.zip",
"DownloadLinkInstall": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.18/latest.zip",
"DownloadLinkTesting": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.18/latest.zip",
"DownloadLinkUpdate": "https://github.com/joshua-software-dev/LMeter/releases/download/v0.2.0.18/latest.zip",
"IconUrl": "https://raw.githubusercontent.com/joshua-software-dev/LMeter/master/deps/img/icon.png",
"Changelog": "# Version 0.2.0.17\n- More aggressively catch errors during basic handshake to ensure plugin never\n crashes even when communicating with out of date background web browser\n versions."
"Changelog": "# Version 0.2.0.18\n- Add option to write all responses from background web browser to log file for\n debugging purposes."
}
]

0 comments on commit 025a235

Please sign in to comment.