Merge pull request #887 from wabbajack-tools/downloader-icons

Add favicons to login manager
This commit is contained in:
Timothy Baldridge 2020-05-29 08:41:02 -07:00 committed by GitHub
commit 68205f384e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 7 deletions

View File

@ -556,6 +556,7 @@ namespace Wabbajack.Common
public static AbsolutePath RelativeTo(this string str, AbsolutePath path)
{
if (Path.IsPathRooted(str)) return (AbsolutePath)str;
return ((RelativePath)str).RelativeTo(path);
}

View File

@ -38,7 +38,7 @@ namespace Wabbajack.Lib.Downloaders
public string SiteName => "Bethesda.NET";
public IObservable<string> MetaInfo => Observable.Return(""); //"Wabbajack will start the game, then exit once you enter the Mods page";
public Uri SiteURL => new Uri("https://bethesda.net");
public Uri? IconUri { get; }
public Uri? IconUri => new Uri("https://bethesda.net/favicon.ico");
public BethesdaNetDownloader()
{

View File

@ -7,8 +7,8 @@ namespace Wabbajack.Lib.Downloaders
{
#region INeedsDownload
public override string SiteName => "TESALL";
public override Uri SiteURL => new Uri("http://tesall.ru");
public override Uri IconUri => new Uri("http://tesall.ru/favicon.ico");
public override Uri SiteURL => new Uri("https://tesall.ru");
public override Uri IconUri => new Uri("https://tesall.ru/favicon.ico");
#endregion
public TESAllDownloader() : base(new Uri("https://tesall.ru/index.php?app=core&module=global&section=login"),

View File

@ -1,12 +1,20 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.Lib;
using Wabbajack.Lib.Downloaders;
@ -21,6 +29,7 @@ namespace Wabbajack
{
Downloaders = DownloadDispatcher.Downloaders
.OfType<INeedsLogin>()
.OrderBy(x => x.SiteName)
.Select(x => new LoginTargetVM(x))
.ToList();
}
@ -37,10 +46,16 @@ namespace Wabbajack
public ReactiveCommand<Unit, Unit> TriggerCredentialsLogin;
private ImageSource _favicon = null;
public ImageSource Favicon { get => _favicon; set => RaiseAndSetIfChanged(ref _favicon, value); }
public LoginTargetVM(INeedsLogin login)
{
Login = login;
LoadImage();
if (login is INeedsLoginCredentials loginWithCredentials)
{
UsesCredentials = true;
@ -62,5 +77,30 @@ namespace Wabbajack
loginWindow.Show();
}, LoginWithCredentials.IsLoggedIn.Select(b => !b).ObserveOnGuiThread());
}
private void LoadImage()
{
Task.Run(async () =>
{
if (Login.IconUri == null) return;
using var img = await new Common.Http.Client().GetAsync(Login.IconUri, errorsAsExceptions:false);
if (!img.IsSuccessStatusCode) return;
var icoData = new MemoryStream(await img.Content.ReadAsByteArrayAsync());
var data = new Icon(icoData);
var ms = new MemoryStream();
data.ToBitmap().Save(ms, ImageFormat.Png);
ms.Position = 0;
var source = new BitmapImage();
source.BeginInit();
source.StreamSource = ms;
source.EndInit();
source.Freeze();
Favicon = source;
});
}
}
}

View File

@ -12,28 +12,34 @@
mc:Ignorable="d">
<Grid Height="30" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="32"/>
<ColumnDefinition Width="Auto" MinWidth="150" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image
Margin="4"
x:Name="Favicon"
Grid.Column="0"
VerticalAlignment="Center"/>
<TextBlock
x:Name="SiteNameText"
Grid.Column="0"
Grid.Column="1"
VerticalAlignment="Center" />
<Button
x:Name="LoginButton"
Grid.Column="1"
Grid.Column="2"
Margin="5"
Content="Login" />
<Button
x:Name="LogoutButton"
Grid.Column="2"
Grid.Column="3"
Margin="5"
Content="Logout" />
<TextBlock
x:Name="MetaText"
Grid.Column="3"
Grid.Column="4"
FontSize="14" />
</Grid>
</rxui:ReactiveUserControl>

View File

@ -12,6 +12,11 @@ namespace Wabbajack
InitializeComponent();
this.WhenActivated(disposable =>
{
this.WhenAny(x => x.ViewModel.Favicon)
.ObserveOnGuiThread()
.Subscribe(x => Favicon.Source = x)
.DisposeWith(disposable);
this.OneWayBindStrict(ViewModel, x => x.Login.SiteName, x => x.SiteNameText.Text)
.DisposeWith(disposable);