1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-12-24 16:27:23 +01:00

Rename DiscordService to be a bit more future-proof. Fix flickering when showing community link.

This commit is contained in:
Nick Blakely 2020-08-16 03:08:49 -07:00
parent bb376e1f63
commit 6d46fa2875
12 changed files with 79 additions and 65 deletions

View File

@ -0,0 +1,9 @@
namespace Giants.DataContract.V1
{
public class CommunityStatus
{
public string CommunityAppName { get; set; }
public string CommunityAppUri { get; set; }
}
}

View File

@ -1,7 +0,0 @@
namespace Giants.DataContract.V1
{
public class DiscordStatus
{
public string DiscordUri { get; set; }
}
}

View File

@ -34,7 +34,7 @@
this.btnPlay = new Giants.Launcher.ImageButton();
this.updateProgressBar = new System.Windows.Forms.ProgressBar();
this.txtProgress = new System.Windows.Forms.Label();
this.DiscordLabel = new System.Windows.Forms.LinkLabel();
this.CommunityLabel = new System.Windows.Forms.LinkLabel();
((System.ComponentModel.ISupportInitialize)(this.btnExit)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.btnOptions)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.btnPlay)).BeginInit();
@ -108,19 +108,21 @@
this.txtProgress.Text = "ProgressText";
this.txtProgress.Visible = false;
//
// DiscordLabel
// CommunityLabel
//
this.DiscordLabel.AutoSize = true;
this.DiscordLabel.BackColor = System.Drawing.Color.Transparent;
this.DiscordLabel.LinkColor = System.Drawing.Color.Aquamarine;
this.DiscordLabel.Location = new System.Drawing.Point(12, 9);
this.DiscordLabel.Name = "DiscordLabel";
this.DiscordLabel.Size = new System.Drawing.Size(69, 13);
this.DiscordLabel.TabIndex = 12;
this.DiscordLabel.TabStop = true;
this.DiscordLabel.Text = "DiscordLabel";
this.DiscordLabel.Visible = false;
this.DiscordLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.DiscordLabel_LinkClicked);
this.CommunityLabel.ActiveLinkColor = System.Drawing.Color.DodgerBlue;
this.CommunityLabel.AutoSize = true;
this.CommunityLabel.BackColor = System.Drawing.Color.Transparent;
this.CommunityLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.CommunityLabel.LinkColor = System.Drawing.Color.DodgerBlue;
this.CommunityLabel.Location = new System.Drawing.Point(12, 9);
this.CommunityLabel.Name = "CommunityLabel";
this.CommunityLabel.Size = new System.Drawing.Size(112, 17);
this.CommunityLabel.TabIndex = 12;
this.CommunityLabel.TabStop = true;
this.CommunityLabel.Text = "CommunityLabel";
this.CommunityLabel.Visible = false;
this.CommunityLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.DiscordLabel_LinkClicked);
//
// LauncherForm
//
@ -131,7 +133,7 @@
this.CancelButton = this.btnExit;
this.ClientSize = new System.Drawing.Size(800, 500);
this.ControlBox = false;
this.Controls.Add(this.DiscordLabel);
this.Controls.Add(this.CommunityLabel);
this.Controls.Add(this.txtProgress);
this.Controls.Add(this.updateProgressBar);
this.Controls.Add(this.btnExit);
@ -161,7 +163,7 @@
private ImageButton btnExit;
private System.Windows.Forms.ProgressBar updateProgressBar;
private System.Windows.Forms.Label txtProgress;
private System.Windows.Forms.LinkLabel DiscordLabel;
private System.Windows.Forms.LinkLabel CommunityLabel;
}
}

View File

@ -24,16 +24,18 @@ namespace Giants.Launcher
private readonly HttpClient httpClient;
private readonly VersionClient versionHttpClient;
private readonly DiscordClient discordHttpClient;
private readonly CommunityClient communityHttpClient;
private string commandLine = String.Empty;
private string gamePath = null;
private Updater updater;
private string discordUri;
private string communityAppUri;
public LauncherForm()
{
this.InitializeComponent();
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
// Set window title
this.Text = GameName;
@ -42,8 +44,8 @@ namespace Giants.Launcher
this.versionHttpClient = new VersionClient(this.httpClient);
this.versionHttpClient.BaseUrl = BaseUrl;
this.discordHttpClient = new DiscordClient(this.httpClient);
this.discordHttpClient.BaseUrl = BaseUrl;
this.communityHttpClient = new CommunityClient(this.httpClient);
this.communityHttpClient.BaseUrl = BaseUrl;
}
private void btnExit_Click(object sender, EventArgs e)
@ -138,11 +140,11 @@ namespace Giants.Launcher
{
try
{
var status = await this.discordHttpClient.GetDiscordStatusAsync();
var status = await this.communityHttpClient.GetDiscordStatusAsync();
this.discordUri = status.DiscordUri;
this.DiscordLabel.Text = Resources.DiscordLabel;
this.DiscordLabel.Visible = true;
this.communityAppUri = status.CommunityAppUri;
this.CommunityLabel.Text = string.Format(Resources.CommunityLabel, status.CommunityAppName);
this.CommunityLabel.Visible = true;
}
catch (Exception)
{
@ -273,19 +275,19 @@ namespace Giants.Launcher
private void DiscordLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (string.IsNullOrEmpty(this.discordUri))
if (string.IsNullOrEmpty(this.communityAppUri))
{
return;
}
var uri = new Uri(this.discordUri);
var uri = new Uri(this.communityAppUri);
if (uri.Scheme != "https")
{
// For security, reject any non-HTTPS or local file system URIs
return;
}
Process.Start(this.discordUri);
Process.Start(this.communityAppUri);
}
}
}

View File

@ -80,11 +80,11 @@ namespace Giants.Launcher {
}
/// <summary>
/// Looks up a localized string similar to Join the community on Discord!.
/// Looks up a localized string similar to Join the community on {0}!.
/// </summary>
internal static string DiscordLabel {
internal static string CommunityLabel {
get {
return ResourceManager.GetString("DiscordLabel", resourceCulture);
return ResourceManager.GetString("CommunityLabel", resourceCulture);
}
}

View File

@ -199,7 +199,7 @@
<data name="OptionSamples" xml:space="preserve">
<value>{0} Samples</value>
</data>
<data name="DiscordLabel" xml:space="preserve">
<value>Join the community on Discord!</value>
<data name="CommunityLabel" xml:space="preserve">
<value>Join the community on {0}!</value>
</data>
</root>

View File

@ -17,7 +17,7 @@
services.AddSingleton<IMemoryCache, MemoryCache>();
services.AddSingleton<IUpdaterStore, CosmosDbUpdaterStore>();
services.AddSingleton<IUpdaterService, UpdaterService>();
services.AddSingleton<IDiscordService, DiscordService>();
services.AddSingleton<ICommunityService, CommunityService>();
services.AddHostedService<InitializerService>();
services.AddHostedService<ServerRegistryCleanupService>();

View File

@ -2,11 +2,11 @@
{
using Microsoft.Extensions.Configuration;
public class DiscordService : IDiscordService
public class CommunityService : ICommunityService
{
private readonly IConfiguration configuration;
public DiscordService(IConfiguration configuration)
public CommunityService(IConfiguration configuration)
{
this.configuration = configuration;
}

View File

@ -1,6 +1,6 @@
namespace Giants.Services
{
public interface IDiscordService
public interface ICommunityService
{
string GetDiscordUri();
}

View File

@ -342,13 +342,13 @@ namespace Giants.WebApi.Clients
}
[System.CodeDom.Compiler.GeneratedCode("NSwag", "13.7.0.0 (NJsonSchema v10.1.24.0 (Newtonsoft.Json v11.0.0.0))")]
public partial class DiscordClient
public partial class CommunityClient
{
private string _baseUrl = "https://localhost:44304";
private System.Net.Http.HttpClient _httpClient;
private System.Lazy<Newtonsoft.Json.JsonSerializerSettings> _settings;
public DiscordClient(System.Net.Http.HttpClient httpClient)
public CommunityClient(System.Net.Http.HttpClient httpClient)
{
_httpClient = httpClient;
_settings = new System.Lazy<Newtonsoft.Json.JsonSerializerSettings>(CreateSerializerSettings);
@ -375,17 +375,17 @@ namespace Giants.WebApi.Clients
partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response);
/// <exception cref="ApiException">A server side error occurred.</exception>
public System.Threading.Tasks.Task<DiscordStatus> GetDiscordStatusAsync()
public System.Threading.Tasks.Task<CommunityStatus> GetDiscordStatusAsync()
{
return GetDiscordStatusAsync(System.Threading.CancellationToken.None);
}
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <exception cref="ApiException">A server side error occurred.</exception>
public async System.Threading.Tasks.Task<DiscordStatus> GetDiscordStatusAsync(System.Threading.CancellationToken cancellationToken)
public async System.Threading.Tasks.Task<CommunityStatus> GetDiscordStatusAsync(System.Threading.CancellationToken cancellationToken)
{
var urlBuilder_ = new System.Text.StringBuilder();
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Discord");
urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Community");
var client_ = _httpClient;
try
@ -415,7 +415,7 @@ namespace Giants.WebApi.Clients
var status_ = (int)response_.StatusCode;
if (status_ == 200)
{
var objectResponse_ = await ReadObjectResponseAsync<DiscordStatus>(response_, headers_).ConfigureAwait(false);
var objectResponse_ = await ReadObjectResponseAsync<CommunityStatus>(response_, headers_).ConfigureAwait(false);
if (objectResponse_.Object == null)
{
throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null);
@ -857,10 +857,13 @@ namespace Giants.WebApi.Clients
}
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.24.0 (Newtonsoft.Json v11.0.0.0)")]
public partial class DiscordStatus
public partial class CommunityStatus
{
[Newtonsoft.Json.JsonProperty("discordUri", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string DiscordUri { get; set; }
[Newtonsoft.Json.JsonProperty("communityAppName", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string CommunityAppName { get; set; }
[Newtonsoft.Json.JsonProperty("communityAppUri", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string CommunityAppUri { get; set; }
}

View File

@ -68,19 +68,19 @@
}
}
},
"/api/Discord": {
"/api/Community": {
"get": {
"tags": [
"Discord"
"Community"
],
"operationId": "Discord_GetDiscordStatus",
"operationId": "Community_GetDiscordStatus",
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DiscordStatus"
"$ref": "#/components/schemas/CommunityStatus"
}
}
}
@ -281,11 +281,15 @@
}
}
},
"DiscordStatus": {
"CommunityStatus": {
"type": "object",
"additionalProperties": false,
"properties": {
"discordUri": {
"communityAppName": {
"type": "string",
"nullable": true
},
"communityAppUri": {
"type": "string",
"nullable": true
}

View File

@ -6,22 +6,23 @@
[ApiController]
[Route("api/[controller]")]
public class DiscordController : ControllerBase
public class CommunityController : ControllerBase
{
private readonly IDiscordService discordService;
private readonly ICommunityService discordService;
public DiscordController(
IDiscordService discordService)
public CommunityController(
ICommunityService communityService)
{
this.discordService = discordService;
this.discordService = communityService;
}
[HttpGet]
public DiscordStatus GetDiscordStatus()
public CommunityStatus GetDiscordStatus()
{
return new DiscordStatus
return new CommunityStatus
{
DiscordUri = this.discordService.GetDiscordUri()
CommunityAppName = "Discord",
CommunityAppUri = this.discordService.GetDiscordUri()
};
}
}