Fix formatting and some warnings

This commit is contained in:
Stone_Red
2024-05-16 19:37:18 +02:00
parent a9bd9c8854
commit 657dbffcd0
3 changed files with 122 additions and 125 deletions
+9 -9
View File
@@ -1,17 +1,18 @@
using Markdowser.ViewModels;
using System.Collections.Generic;
namespace Markdowser.Utilities
{
public class CacheService
{
private Dictionary<string, ContentViewModelBase> cache = new Dictionary<string, ContentViewModelBase>();
namespace Markdowser.Utilities;
public class CacheService
{
private readonly Dictionary<string, ContentViewModelBase> cache = [];
public ContentViewModelBase? Get(string url)
{
if (cache.ContainsKey(url))
if (cache.TryGetValue(url, out ContentViewModelBase? value))
{
return cache[url];
return value;
}
else
{
@@ -23,5 +24,4 @@ using System.Collections.Generic;
{
cache[url] = content;
}
}
}
}
@@ -104,7 +104,6 @@ public partial class MainWindowViewModel : ViewModelBase
public ICommand Browse => ReactiveCommand.Create(() => FetchUrl(true));
public ICommand Reload => ReactiveCommand.Create(() => FetchUrl(false));
public ICommand Back => ReactiveCommand.Create(() =>
{
if (GlobalState.BackHistory.Count > 0)
@@ -199,8 +198,8 @@ public partial class MainWindowViewModel : ViewModelBase
return Uri.TryCreate(uriString, UriKind.Absolute, out uri) && (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps);
}
private void FetchUrl(bool useCache = true)
{
private void FetchUrl(bool useCache = true)
{
if (IsBusy)
{
WindowNotificationManager.Show(new Notification("Busy", "The browser is currently busy.", NotificationType.Warning));
@@ -244,8 +243,8 @@ private void FetchUrl(bool useCache = true)
try
{
ContentViewModelBase cachedContent = cacheService.Get(Url);
if (cachedContent != null && useCache)
ContentViewModelBase? cachedContent = cacheService.Get(Url);
if (cachedContent is not null && useCache)
{
Content = cachedContent;
}
@@ -315,6 +314,5 @@ private void FetchUrl(bool useCache = true)
IsBusy = false;
}
});
}
}
}
+1 -2
View File
@@ -83,9 +83,8 @@
<Grid IsEnabled="{Binding !IsBusy}" ColumnDefinitions="Auto, Auto, Auto, Auto, *, Auto">
<Button Grid.Column="0" i:Attached.Icon="fa-solid fa-caret-left" IsEnabled="{Binding BackEnabled}" Command="{Binding Back}" />
<Button Grid.Column="1" i:Attached.Icon="fa-solid fa-caret-right" IsEnabled="{Binding ForwardEnabled}" Command="{Binding Forward}" />
<Button Grid.Column="2" i:Attached.Icon="fa-solid fa-rotate-right" Command="{Binding Browse}" />
<Button Grid.Column="2" i:Attached.Icon="fa-solid fa-rotate-right" Command="{Binding Reload}" />
<Button Grid.Column="3" i:Attached.Icon="fa-solid fa-house" Command="{StaticResource HomeCommand}" />
<Button Grid.Column="4" i:Attached.Icon="fa-solid fa-sync" Command="{Binding Reload}" />
<Grid Grid.Column="4">
<TextBox IsVisible="{Binding !IsBusy}" Watermark="Search or type a URL" Text="{Binding Url}" BorderThickness="0">