Skip to content

Commit 4fb61a0

Browse files
committed
report new version in ui
1 parent dea04b3 commit 4fb61a0

File tree

4 files changed

+66
-22
lines changed

4 files changed

+66
-22
lines changed

src/IxMilia.BCad.Rpc/ContractGenerator.cs

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public void Run()
9595
AddInterface(typeof(DimensionStylesDialogParameters));
9696
AddInterface(typeof(DwgFileSettings));
9797
AddInterface(typeof(DxfFileSettings));
98+
AddInterface(typeof(VersionInformation));
9899

99100
// emit types
100101
var sb = new StringBuilder();

src/IxMilia.BCad.Rpc/ServerAgent.cs

+45-20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.IO;
55
using System.Linq;
6+
using System.Net.Http;
67
using System.Reflection;
78
using System.Threading.Tasks;
89
using IxMilia.BCad.Display;
@@ -34,7 +35,6 @@ public class ServerAgent
3435

3536
private bool _readyEventFired;
3637
public event EventHandler IsReady;
37-
private string _versionHtml = null;
3838

3939
public ServerAgent(LispWorkspace workspace, JsonRpc rpc)
4040
{
@@ -545,30 +545,55 @@ public void SetSetting(string name, string value)
545545
Workspace.SettingsService.SetValueFromString(name, value);
546546
}
547547

548-
public string GetVersionInformation()
548+
public async Task<VersionInformation> GetVersionInformation()
549549
{
550-
if (_versionHtml is null)
550+
// get currently running version
551+
var candidateAssemblyNames = new[]
551552
{
552-
// published app names
553-
var candidateAssemblyNames = new[]
554-
{
555-
"bcad.exe",
556-
"bcad.dll",
557-
"bcad"
558-
};
559-
var assemblyPath = candidateAssemblyNames
560-
.Select(name => Path.Combine(AppContext.BaseDirectory, name))
561-
.FirstOrDefault(File.Exists)
562-
?? Assembly.GetExecutingAssembly().Location; // fall back to using reflection
563-
var versionString = assemblyPath is { }
564-
? FileVersionInfo.GetVersionInfo(assemblyPath).ProductVersion
565-
: "<unknown>";
566-
_versionHtml = $"""
567-
Version: {versionString}<br />
553+
"bcad.exe",
554+
"bcad.dll",
555+
"bcad"
556+
};
557+
var assemblyPath = candidateAssemblyNames
558+
.Select(name => Path.Combine(AppContext.BaseDirectory, name))
559+
.FirstOrDefault(File.Exists)
560+
?? Assembly.GetExecutingAssembly().Location; // fall back to using reflection
561+
var versionString = assemblyPath is { }
562+
? FileVersionInfo.GetVersionInfo(assemblyPath).ProductVersion
563+
: "<unknown>";
564+
var plusIndex = versionString.IndexOf('+');
565+
var versionShortString = plusIndex >= 0
566+
? versionString.Substring(0, plusIndex)
567+
: versionString;
568+
569+
// get available version
570+
var versionUrl = "https://pkgs.ixmilia.com/bcad/version.txt";
571+
using var httpClient = new HttpClient();
572+
string availableVersion = null;
573+
try
574+
{
575+
availableVersion = (await httpClient.GetStringAsync(versionUrl)).Trim();
576+
}
577+
catch (Exception)
578+
{
579+
// couldn't query
580+
}
581+
582+
string upgradeString = null;
583+
if (availableVersion is not null && availableVersion != versionShortString)
584+
{
585+
upgradeString = $"""
586+
New version available: {availableVersion}</br />
587+
Please click "Close and update" to get the latest version.
568588
""";
569589
}
570590

571-
return _versionHtml;
591+
var aboutString = $"""
592+
Version: {versionString}<br />
593+
{upgradeString}
594+
""";
595+
var information = new VersionInformation(aboutString, versionShortString, availableVersion);
596+
return information;
572597
}
573598
}
574599
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace IxMilia.BCad.Rpc
2+
{
3+
public class VersionInformation
4+
{
5+
public string AboutString { get; }
6+
7+
public string CurrentVersion { get; }
8+
9+
public string AvailableVersion { get; }
10+
11+
public VersionInformation(string aboutString, string currentVersion, string availableVersion)
12+
{
13+
AboutString = aboutString;
14+
CurrentVersion = currentVersion;
15+
AvailableVersion = availableVersion;
16+
}
17+
}
18+
}

src/javascript-client/src/dialogs/aboutDialog.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ export class AboutDialog extends DialogBase {
88
constructor(dialogHandler: DialogHandler, readonly client: Client) {
99
super(dialogHandler, "about");
1010
this.content = <HTMLDivElement>document.getElementById('about-content');
11-
this.client.getVersionInformation().then(aboutHtml => {
11+
this.client.getVersionInformation().then(versionInformation => {
1212
// preload this once
13-
this.content.innerHTML = aboutHtml;
13+
this.content.innerHTML = versionInformation.AboutString;
1414
})
1515
}
1616

0 commit comments

Comments
 (0)