1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-20 20:34:08 +02:00

Refactor error page

This commit is contained in:
chylex 2021-12-22 10:05:01 +01:00
parent fd634379d7
commit 13f8f12ac8
Signed by: chylex
GPG Key ID: 4DE42C8F19A80548
3 changed files with 19 additions and 24 deletions
Browser
Resources/Content/error
TweetDuck.csproj

View File

@ -23,7 +23,6 @@ namespace TweetDuck.Browser {
sealed class TweetDeckBrowser : IDisposable { sealed class TweetDeckBrowser : IDisposable {
private static UserConfig Config => Program.Config.User; private static UserConfig Config => Program.Config.User;
private const string ErrorUrl = "http://td/error";
private const string NamespaceTweetDeck = "tweetdeck"; private const string NamespaceTweetDeck = "tweetdeck";
public bool Ready { get; private set; } public bool Ready { get; private set; }
@ -167,10 +166,6 @@ private void browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e) {
CefScriptExecutor.RunBootstrap(frame, "update"); CefScriptExecutor.RunBootstrap(frame, "update");
} }
if (url == ErrorUrl) {
resourceHandlers.Unregister(ErrorUrl);
}
} }
private void browser_LoadError(object sender, LoadErrorEventArgs e) { private void browser_LoadError(object sender, LoadErrorEventArgs e) {
@ -178,16 +173,10 @@ private void browser_LoadError(object sender, LoadErrorEventArgs e) {
return; return;
} }
if (!e.FailedUrl.StartsWith("http://td/", StringComparison.Ordinal)) { if (!e.FailedUrl.StartsWith("td://", StringComparison.Ordinal)) {
string errorPage = Program.Resources.LoadSilent("pages/error.html"); string errorName = Enum.GetName(typeof(CefErrorCode), e.ErrorCode);
string errorTitle = StringUtils.ConvertPascalCaseToScreamingSnakeCase(errorName ?? string.Empty);
if (errorPage != null) { browser.Load("td://resources/error/error.html#" + Uri.EscapeDataString(errorTitle));
string errorName = Enum.GetName(typeof(CefErrorCode), e.ErrorCode);
string errorTitle = StringUtils.ConvertPascalCaseToScreamingSnakeCase(errorName ?? string.Empty);
resourceHandlers.Register(ErrorUrl, ResourceHandlers.ForString(errorPage.Replace("{err}", errorTitle)));
browser.Load(ErrorUrl);
}
} }
} }

View File

@ -1,7 +1,9 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en">
<head> <head>
<style type="text/css"> <title>TweetDuck Error</title>
<meta charset="UTF-8">
<style>
body { body {
color: #e1e8ed; color: #e1e8ed;
background-color: #1c6399; background-color: #1c6399;
@ -16,9 +18,10 @@
display: table; display: table;
} }
center { main {
display: table-cell; display: table-cell;
vertical-align: middle; vertical-align: middle;
text-align: center;
} }
h1 { h1 {
@ -39,11 +42,14 @@
</style> </style>
</head> </head>
<body> <body>
<center> <main>
<h1>Connection Error</h1> <h1>Connection Error</h1>
<p>{err}</p> <p id="error"></p>
<button onclick="location.href = 'https://tweetdeck.twitter.com'; [].forEach.call(document.getElementsByTagName('button'), e => e.style.visibility = 'hidden')">Retry</button> <button onclick="location.href = 'https://tweetdeck.twitter.com'; Array.from(document.getElementsByTagName('button')).forEach(e => e.style.visibility = 'hidden');">Retry</button>
<button onclick="window.close()">Exit</button> <button onclick="window.close();">Exit</button>
</center> </main>
<script type="text/javascript">
document.getElementById("error").innerText = decodeURIComponent(location.hash.slice(1));
</script>
</body> </body>
</html> </html>

View File

@ -322,6 +322,7 @@
<ItemGroup> <ItemGroup>
<None Include="app.config" /> <None Include="app.config" />
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="Resources\Content\error\error.html" />
<None Include="Resources\Images\avatar.png" /> <None Include="Resources\Images\avatar.png" />
<None Include="Resources\Images\icon-muted.ico" /> <None Include="Resources\Images\icon-muted.ico" />
<None Include="Resources\Images\icon-small.ico" /> <None Include="Resources\Images\icon-small.ico" />
@ -355,7 +356,6 @@
<None Include="Resources\PostCefUpdate.ps1" /> <None Include="Resources\PostCefUpdate.ps1" />
<None Include="Resources\Scripts\imports\scripts\plugins.base.js" /> <None Include="Resources\Scripts\imports\scripts\plugins.base.js" />
<None Include="Resources\Scripts\notification.js" /> <None Include="Resources\Scripts\notification.js" />
<None Include="Resources\Scripts\pages\error.html" />
<None Include="Resources\Scripts\pages\example.html" /> <None Include="Resources\Scripts\pages\example.html" />
<None Include="Resources\Scripts\plugins.browser.js" /> <None Include="Resources\Scripts\plugins.browser.js" />
<None Include="Resources\Scripts\plugins.notification.js" /> <None Include="Resources\Scripts\plugins.notification.js" />