Skip to content

Commit

Permalink
Merge pull request #144 from goatcorp/quickfire-cleanup-1
Browse files Browse the repository at this point in the history
  • Loading branch information
reiichi001 authored Sep 2, 2024
2 parents 48d54d7 + c0b647f commit 5878e7a
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 93 deletions.
6 changes: 1 addition & 5 deletions src/XIVLauncher.Core/Accounts/AccountSwitcherEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ public void UpdateProfileImage(DirectoryInfo storage)
}
else
{
using (var client = new HttpClient())
{
imageBytes = client.GetByteArrayAsync(uri).Result;
}

imageBytes = Program.HttpClient.GetByteArrayAsync(uri).Result;
File.WriteAllBytes(cacheFile, imageBytes);
}

Expand Down
9 changes: 3 additions & 6 deletions src/XIVLauncher.Core/Accounts/XivAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,8 @@ public static async Task<JObject> GetCharacterSearch(string name, string world)

public static async Task<dynamic> Get(string endpoint)
{
using (var client = new HttpClient())
{
var result = await client.GetStringAsync(URL + endpoint).ConfigureAwait(false);
var parsedObject = JObject.Parse(result);
return parsedObject;
}
var result = await Program.HttpClient.GetStringAsync(URL + endpoint).ConfigureAwait(false);
var parsedObject = JObject.Parse(result);
return parsedObject;
}
}
7 changes: 7 additions & 0 deletions src/XIVLauncher.Core/AppUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ public static string GetAssemblyVersion()
return fvi.FileVersion.ToString();
}

/// <summary>
/// Open a URL in the system's default browser.
/// </summary>
/// <remarks>
/// On Steam Deck this method will open the in-game overlay instead of a browser instance.
/// </remarks>
/// <param name="url">The URL to open.</param>
public static void OpenBrowser(string url)
{
if (Program.IsSteamDeckHardware && Program.Steam != null && Program.Steam.IsValid)
Expand Down
24 changes: 0 additions & 24 deletions src/XIVLauncher.Core/Components/Background.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,7 @@ public Background()
public override void Draw()
{
ImGui.SetCursorPos(new Vector2(0, ImGuiHelpers.ViewportSize.Y - bgTexture.Height));

ImGui.Image(bgTexture.ImGuiHandle, new Vector2(bgTexture.Width, bgTexture.Height));

/*
ImGui.SetCursorPos(new Vector2());
var vpSize = ImGuiHelpers.ViewportSize;
var width = vpSize.X;
var height = this.bgTexture.Height / (float)this.bgTexture.Width * width;
if (height < vpSize.Y)
{
height = vpSize.Y;
width = this.bgTexture.Width / (float)this.bgTexture.Height * height;
ImGui.SetCursorPosX((vpSize.X - width) / 2);
}
else
{
ImGui.SetCursorPosY((vpSize.Y - height) / 2);
}
ImGui.Image(this.bgTexture.ImGuiHandle, new Vector2(width, height));
*/

base.Draw();
}
}
14 changes: 0 additions & 14 deletions src/XIVLauncher.Core/Components/MainPage/ActionButtons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace XIVLauncher.Core.Components.MainPage;

public class ActionButtons : Component
{
public event Action? OnQueueButtonClicked;
public event Action? OnStatusButtonClicked;
public event Action? OnSettingsButtonClicked;

Expand All @@ -15,19 +14,6 @@ public override void Draw()
var btnSize = new Vector2(80) * ImGuiHelpers.GlobalScale;

ImGui.PushFont(FontManager.IconFont);

ImGui.BeginDisabled(this.OnQueueButtonClicked == null);
if (ImGui.Button(FontAwesomeIcon.Clock.ToIconString(), btnSize))
{
this.OnQueueButtonClicked?.Invoke();
}
ImGui.PushFont(FontManager.TextFont);
ImGuiHelpers.AddTooltip("Queue");
ImGui.PopFont();
ImGui.EndDisabled();

ImGui.SameLine();

ImGui.BeginDisabled(this.OnStatusButtonClicked == null);
if (ImGui.Button(FontAwesomeIcon.Globe.ToIconString(), btnSize))
{
Expand Down
3 changes: 1 addition & 2 deletions src/XIVLauncher.Core/Components/MainPage/NewsFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ public void ReloadNews()

this.banners = new TextureWrap[bannerList.Count];

var client = new HttpClient();

for (var i = 0; i < bannerList.Count; i++)
{
var textureBytes = await client.GetByteArrayAsync(this.bannerList[i].LsbBanner).ConfigureAwait(false);
var textureBytes = await Program.HttpClient.GetByteArrayAsync(this.bannerList[i].LsbBanner).ConfigureAwait(false);
this.banners[i] = TextureWrap.Load(textureBytes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class SettingsPage : Page
new SettingsTabPatching(),
new SettingsTabWine(),
new SettingsTabDalamud(),
new SettingsTabAutoStart(),
new SettingsTabAbout(),
new SettingsTabDebug(),
new SettingsTabTroubleshooting(),
Expand Down

This file was deleted.

7 changes: 4 additions & 3 deletions src/XIVLauncher.Core/FontManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ namespace XIVLauncher.Core;
public class FontManager
{
private const float FONT_GAMMA = 1.4f;
private const string TEXT_FONT_NAME = "NotoSansCJKjp-Regular.otf";
private const string ICON_FONT_NAME = "FontAwesome5FreeSolid.otf";

public static ImFontPtr TextFont { get; private set; }

public static ImFontPtr IconFont { get; private set; }

public unsafe void SetupFonts(float pxSize)
Expand All @@ -21,8 +22,8 @@ public unsafe void SetupFonts(float pxSize)
ImFontConfigPtr fontConfig = ImGuiNative.ImFontConfig_ImFontConfig();
fontConfig.PixelSnapH = true;

var fontDataText = AppUtil.GetEmbeddedResourceBytes("NotoSansCJKjp-Regular.otf");
var fontDataIcons = AppUtil.GetEmbeddedResourceBytes("FontAwesome5FreeSolid.otf");
var fontDataText = AppUtil.GetEmbeddedResourceBytes(TEXT_FONT_NAME);
var fontDataIcons = AppUtil.GetEmbeddedResourceBytes(ICON_FONT_NAME);

var fontDataTextPtr = Marshal.AllocHGlobal(fontDataText.Length);
Marshal.Copy(fontDataText, 0, fontDataTextPtr, fontDataText.Length);
Expand Down
1 change: 0 additions & 1 deletion src/XIVLauncher.Core/ImGuiBindings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down
1 change: 0 additions & 1 deletion src/XIVLauncher.Core/ImGuiHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace XIVLauncher.Core;
public static class ImGuiHelpers
{
public static Vector2 ViewportSize => ImGui.GetIO().DisplaySize;

public static float GlobalScale => ImGui.GetIO().FontGlobalScale;

public static void TextWrapped(string text)
Expand Down
8 changes: 3 additions & 5 deletions src/XIVLauncher.Core/LauncherApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class LauncherApp : Component
private string modalText = string.Empty;
private string modalTitle = string.Empty;
private string modalButtonText = string.Empty;
private Action modalButtonPressAction;
private Action modalButtonPressAction = null!;
private readonly ManualResetEvent modalWaitHandle = new(false);

#endregion
Expand All @@ -53,11 +53,9 @@ public LauncherState State
set
{
// If we are coming from the settings, we should reload the news, as the client language might have changed
switch (this.state)
if (this.state == LauncherState.Settings)
{
case LauncherState.Settings:
this.mainPage.ReloadNews();
break;
this.mainPage.ReloadNews();
}

this.state = value;
Expand Down
8 changes: 2 additions & 6 deletions src/XIVLauncher.Core/LauncherClientConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ public readonly struct LauncherClientConfig
public string? cutOffBootver { get; init; }
public uint flags { get; init; }

public static async Task<LauncherClientConfig> Fetch()
public static async Task<LauncherClientConfig> GetAsync()
{
try
{
using var client = new HttpClient()
{
Timeout = TimeSpan.FromSeconds(5),
};
return await client.GetFromJsonAsync<LauncherClientConfig>(LAUNCHER_CONFIG_URL).ConfigureAwait(false);
return await Program.HttpClient.GetFromJsonAsync<LauncherClientConfig>(LAUNCHER_CONFIG_URL).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand Down
9 changes: 7 additions & 2 deletions src/XIVLauncher.Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

namespace XIVLauncher.Core;

class Program
sealed class Program
{
private static Sdl2Window window = null!;
private static CommandList cl = null!;
Expand All @@ -46,6 +46,10 @@ class Program
public static DalamudOverlayInfoProxy DalamudLoadInfo { get; private set; } = null!;
public static CompatibilityTools CompatibilityTools { get; private set; } = null!;
public static ISecretProvider Secrets { get; private set; } = null!;
public static HttpClient HttpClient { get; private set; } = new()
{
Timeout = TimeSpan.FromSeconds(5)
};

private static readonly Vector3 ClearColor = new(0.1f, 0.1f, 0.1f);

Expand Down Expand Up @@ -302,7 +306,7 @@ private static void Main(string[] args)

needUpdate = CoreEnvironmentSettings.IsUpgrade ? true : needUpdate;

var launcherClientConfig = LauncherClientConfig.Fetch().GetAwaiter().GetResult();
var launcherClientConfig = LauncherClientConfig.GetAsync().GetAwaiter().GetResult();
launcherApp = new LauncherApp(storage, needUpdate, launcherClientConfig.frontierUrl, launcherClientConfig.cutOffBootver);

Invalidate(20);
Expand Down Expand Up @@ -353,6 +357,7 @@ private static void Main(string[] args)
gd.SwapBuffers(gd.MainSwapchain);
}

HttpClient.Dispose();
// Clean up Veldrid resources
gd.WaitForIdle();
bindings.Dispose();
Expand Down
Binary file removed src/XIVLauncher.Core/Resources/bg1.jpg
Binary file not shown.
5 changes: 1 addition & 4 deletions src/XIVLauncher.Core/UpdateCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ public static async Task<VersionCheckResult> CheckForUpdate()
{
try
{
using var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(5);

var response = await client.GetStringAsync(UPDATE_URL).ConfigureAwait(false);
var response = await Program.HttpClient.GetStringAsync(UPDATE_URL).ConfigureAwait(false);
var remoteVersion = Version.Parse(response);

var localVersion = Version.Parse(AppUtil.GetAssemblyVersion());
Expand Down
5 changes: 2 additions & 3 deletions src/XIVLauncher.Core/XIVLauncher.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,13 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Resources/FontAwesome5FreeSolid.otf"
<EmbeddedResource Include="Resources/fonts/FontAwesome5FreeSolid.otf"
LogicalName="FontAwesome5FreeSolid.otf" />
<EmbeddedResource Include="Resources/NotoSansCJKjp-Regular.otf"
<EmbeddedResource Include="Resources/fonts/NotoSansCJKjp-Regular.otf"
LogicalName="NotoSansCJKjp-Regular.otf" />

<EmbeddedResource Include="Resources/logo.png" LogicalName="logo.png" />

<EmbeddedResource Include="Resources/bg1.jpg" LogicalName="bg1.jpg" />
<EmbeddedResource Include="Resources/bg_logo.png" LogicalName="bg_logo.png" />

<EmbeddedResource Include="Resources/steamdeck_fts.png" LogicalName="steamdeck_fts.png" />
Expand Down

0 comments on commit 5878e7a

Please sign in to comment.