From ac64ae305abfc75cde1a715ead405beb9aad9648 Mon Sep 17 00:00:00 2001 From: Crauzer <18646077+Crauzer@users.noreply.github.com> Date: Wed, 12 Apr 2023 22:35:07 +0200 Subject: [PATCH] move MainLayout code section --- Obsidian/Shared/MainLayout.razor | 82 ---------------------- Obsidian/Shared/MainLayout.razor.cs | 105 ++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 82 deletions(-) create mode 100644 Obsidian/Shared/MainLayout.razor.cs diff --git a/Obsidian/Shared/MainLayout.razor b/Obsidian/Shared/MainLayout.razor index 1b799fd..47f6f13 100644 --- a/Obsidian/Shared/MainLayout.razor +++ b/Obsidian/Shared/MainLayout.razor @@ -87,85 +87,3 @@ - -@code { - [Inject] public Config Config { get; set; } - [Inject] public IDialogService DialogService { get; set; } - [Inject] public IJSRuntime Js { get; set; } - [Inject] public ISnackbar Snackbar { get; set; } - - public AppTheme Theme { get; } = new(); - - public string UpdateUrl { get; set; } - - private bool _isLoadingHashtable; - private bool _isReady; - - private void OnHashtableLoadingStart() - { - this._isLoadingHashtable = true; - } - - private async Task OnHashtableLoadingFinished() - { - this._isLoadingHashtable = false; - - if (string.IsNullOrEmpty(this.Config.GameDataDirectory) && !this.Config.DoNotRequireGameDirectory) - await this.DialogService.Show().Result; - - this._isReady = true; - } - - private void OpenSettings() - { - this.DialogService.Show(); - } - - private async Task SubmitBugReport() - { - await this.Js.InvokeVoidAsync("useCmd", @"explorer ""https://github.com/Crauzer/Obsidian/issues/new?assignees=&labels=bug%2C+triage&template=bug_report.md&title=%5BBUG%5D+%2A%2ABug+report+title+here%2A%2A"""); - } - - private async Task GoToGithub() - { - await this.Js.InvokeVoidAsync("useCmd", @"explorer ""https://github.com/Crauzer/Obsidian"""); - } - - private async Task GoToNewRelease() - { - await this.Js.InvokeVoidAsync("useCmd", @$"explorer ""{this.UpdateUrl}"""); - } - - private async Task CheckForUpdate() - { - Log.Information("Checking for new update"); - try - { - GitHubClient gitClient = new GitHubClient(new ProductHeaderValue("Obsidian")); - IReadOnlyList releases = await gitClient.Repository.Release.GetAll("Crauzer", "Obsidian"); - Release newestRelease = releases[0]; - - SemVersion latestReleaseSemver = SemVersion.Parse(newestRelease.TagName, SemVersionStyles.Strict); - - if (latestReleaseSemver.IsPrerelease is false - && latestReleaseSemver.ComparePrecedenceTo(Program.VERSION) > 0 - ) - { - Log.Information($"Found new update: {latestReleaseSemver}"); - this.UpdateUrl = newestRelease.HtmlUrl; - } - } - catch (Exception exception) - { - SnackbarUtils.ShowSoftError(this.Snackbar, exception); - } - } - - protected override async Task OnAfterRenderAsync(bool firstRender) - { - if (firstRender) - await CheckForUpdate(); - - await base.OnAfterRenderAsync(firstRender); - } -} diff --git a/Obsidian/Shared/MainLayout.razor.cs b/Obsidian/Shared/MainLayout.razor.cs new file mode 100644 index 0000000..37d1fea --- /dev/null +++ b/Obsidian/Shared/MainLayout.razor.cs @@ -0,0 +1,105 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using MudBlazor; +using Obsidian.Data; +using Obsidian.Shared.Dialogs; +using Obsidian.Utils; +using Octokit; +using Semver; +using Serilog; + +namespace Obsidian.Shared; + +public partial class MainLayout +{ + [Inject] + public Config Config { get; set; } + + [Inject] + public IDialogService DialogService { get; set; } + + [Inject] + public IJSRuntime Js { get; set; } + + [Inject] + public ISnackbar Snackbar { get; set; } + + public AppTheme Theme { get; } = new(); + + public string UpdateUrl { get; set; } + + private bool _isLoadingHashtable; + private bool _isReady; + + private void OnHashtableLoadingStart() => this._isLoadingHashtable = true; + + private async Task OnHashtableLoadingFinished() + { + this._isLoadingHashtable = false; + + if ( + string.IsNullOrEmpty(this.Config.GameDataDirectory) + && !this.Config.DoNotRequireGameDirectory + ) + await this.DialogService.Show().Result; + + this._isReady = true; + } + + private void OpenSettings() => this.DialogService.Show(); + + private async Task SubmitBugReport() => + await this.Js.InvokeVoidAsync( + "useCmd", + @"explorer ""https://github.com/Crauzer/Obsidian/issues/new?assignees=&labels=bug%2C+triage&template=bug_report.md&title=%5BBUG%5D+%2A%2ABug+report+title+here%2A%2A""" + ); + + private async Task GoToGithub() => + await this.Js.InvokeVoidAsync( + "useCmd", + @"explorer ""https://github.com/Crauzer/Obsidian""" + ); + + private async Task GoToNewRelease() => + await this.Js.InvokeVoidAsync("useCmd", @$"explorer ""{this.UpdateUrl}"""); + + private async Task CheckForUpdate() + { + Log.Information("Checking for new update"); + try + { + GitHubClient gitClient = new(new ProductHeaderValue("Obsidian")); + IReadOnlyList releases = await gitClient.Repository.Release.GetAll( + "Crauzer", + "Obsidian" + ); + Release newestRelease = releases[0]; + + SemVersion latestReleaseSemver = SemVersion.Parse( + newestRelease.TagName, + SemVersionStyles.Strict + ); + + if ( + latestReleaseSemver.IsPrerelease is false + && latestReleaseSemver.ComparePrecedenceTo(Program.VERSION) > 0 + ) + { + Log.Information($"Found new update: {latestReleaseSemver}"); + this.UpdateUrl = newestRelease.HtmlUrl; + } + } + catch (Exception exception) + { + SnackbarUtils.ShowSoftError(this.Snackbar, exception); + } + } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + await CheckForUpdate(); + + await base.OnAfterRenderAsync(firstRender); + } +}