Skip to content

Commit

Permalink
Rely on github api instead of root version file
Browse files Browse the repository at this point in the history
  • Loading branch information
MolotovCherry committed Nov 15, 2023
1 parent c627c9c commit 7b55760
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Virtual Display Driver Control/Common/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum Material {

public static class SettingsProvider {
public static IAppSettings Initialize() {
var jsonPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "VirtualDisplayDriver", "appsettings.json");
var jsonPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "VirtualDisplayDriver", "settings.json");

return new ConfigurationBuilder<IAppSettings>()
.UseJsonFile(jsonPath)
Expand Down
17 changes: 10 additions & 7 deletions Virtual Display Driver Control/Views/SettingsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.UI.Xaml.Controls;
using System;
using System.ComponentModel;
using System.Net.Http;
using Virtual_Display_Driver_Control.Common;
using Virtual_Display_Driver_Control.Helpers;
using Windows.System;
Expand Down Expand Up @@ -154,11 +153,12 @@ string UpdateCheck {

bool needsUpdate = false;
bool checkedUpdate = false;
private static readonly HttpClient client = new HttpClient();
string releaseUrl = "";
private static readonly Octokit.GitHubClient client = new Octokit.GitHubClient(new Octokit.ProductHeaderValue("VirtualDisplayDriverControl"));
private async void updates_Click(object sender, RoutedEventArgs e) {
// update check was already done and succeeded, so launch uri
if (needsUpdate) {
await Launcher.LaunchUriAsync(new Uri("https://github.com/MolotovCherry/virtual-display-rs/releases/latest"));
await Launcher.LaunchUriAsync(new Uri(releaseUrl));
return;
}

Expand All @@ -169,20 +169,23 @@ private async void updates_Click(object sender, RoutedEventArgs e) {
// otherwise, do the update check instead

try {
string reply = await client.GetStringAsync("https://raw.githubusercontent.com/MolotovCherry/virtual-display-rs/master/version");
var release = await client.Repository.Release.GetLatest("MolotovCherry", "virtual-display-rs");

Version data = Version.Parse(reply);
var tag = release.TagName[1..6];
releaseUrl = release.HtmlUrl;

Version data = Version.Parse(tag);

var major = uint.Parse(GitVersionInformation.Major);
var minor = uint.Parse(GitVersionInformation.Minor);
var patch = uint.Parse(GitVersionInformation.Patch);

if (data.Major > major || data.Minor > minor || data.Build > patch) {
UpdateCheck = $"Update is available: v{reply}";
UpdateCheck = $"Update is available: v{tag}";
needsUpdate = true;
checkedUpdate = true;
} else {
UpdateCheck = $"No update is available; latest version is: v{reply}";
UpdateCheck = $"No update is available";
needsUpdate = false;
checkedUpdate = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<PackageReference Include="CSharpFunctionalExtensions" Version="2.40.3" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.231008000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" />
<PackageReference Include="Octokit" Version="9.0.0" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
<PackageReference Include="GitVersion.MsBuild" Version="5.10.3">
<PrivateAssets>all</PrivateAssets>
Expand Down
1 change: 0 additions & 1 deletion version

This file was deleted.

0 comments on commit 7b55760

Please sign in to comment.