Skip to content

Commit

Permalink
small misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotr7 committed Jul 28, 2023
1 parent a8eb9ab commit 284960c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ internal void UpdateAppList(bool forced = false)
if (CurrentApp == null && !forced)
return;

if (forced)
_logger.Verbose("Running forced AppList update...");
else
_logger.Verbose("Running applist update to check for closed apps...");

RzAppListDataProvider applist = _manager.GetDataProvider<RzAppListDataProvider>();
applist.Update();
UpdateAppListData(applist);
Expand Down
2 changes: 1 addition & 1 deletion src/Artemis.Plugins.Modules.Discord/DiscordModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Artemis.Plugins.Modules.Discord;

[PluginFeature(Name = "Discord but different")]
[PluginFeature(Name = "Discord")]
public class DiscordModule : Module<DiscordDataModel>
{
public override List<IModuleActivationRequirement> ActivationRequirements { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Artemis.Plugins.Modules.Spotify"
mc:Ignorable="d" d:DesignWidth="450" d:DesignHeight="450"
x:DataType="local:SpotifyConfigurationDialogViewModel"
x:Class="Artemis.Plugins.Modules.Spotify.SpotifyConfigurationDialogView">
<Border Classes="card" Margin="8" >
<StackPanel Orientation="Vertical" HorizontalAlignment="Center">
Expand All @@ -11,14 +13,14 @@
Height="300"
Width="300" >
<Ellipse.Fill>
<ImageBrush Source="{Binding ProfilePicture}" />
<ImageBrush Source="{CompiledBinding ProfilePicture}" />
</Ellipse.Fill>
</Ellipse>

<TextBlock HorizontalAlignment="Center"
Margin="5"
FontSize="20"
Text="{Binding Username}"/>
Text="{CompiledBinding Username}"/>

<StackPanel Orientation="Horizontal">
<Button Margin="10"
Expand All @@ -27,7 +29,7 @@
HorizontalAlignment="Center"
Classes="AppBarButton icon-button"
Command="{Binding Login}"
IsEnabled="{Binding LogInVisibility}">
IsEnabled="{CompiledBinding LogInVisibility}">
LOGIN
</Button>

Expand All @@ -37,7 +39,7 @@
HorizontalAlignment="Center"
Classes="AppBarButton icon-button"
Command="{Binding Logout}"
IsEnabled="{Binding LogOutVisibility}">
IsEnabled="{CompiledBinding LogOutVisibility}">
LOGOUT
</Button>
</StackPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

Expand All @@ -22,31 +23,35 @@ public class SpotifyConfigurationDialogViewModel : PluginConfigurationViewModel
private static EmbedIOAuthServer Server => _server ??= new EmbedIOAuthServer(new Uri("http://localhost:5000/callback"), 5000);

private Bitmap? _profilePicture;

public Bitmap? ProfilePicture
{
get => _profilePicture;
set => this.RaiseAndSetIfChanged(ref _profilePicture, value);
set => RaiseAndSetIfChanged(ref _profilePicture, value);
}

private string? _username;

public string? Username
{
get => _username;
set => this.RaiseAndSetIfChanged(ref _username, value);
set => RaiseAndSetIfChanged(ref _username, value);
}

private bool _logInVisibility;

public bool LogInVisibility
{
get => _logInVisibility;
set => this.RaiseAndSetIfChanged(ref _logInVisibility, value);
set => RaiseAndSetIfChanged(ref _logInVisibility, value);
}

private bool _logOutVisibility;

public bool LogOutVisibility
{
get => _logOutVisibility;
set => this.RaiseAndSetIfChanged(ref _logOutVisibility, value);
set => RaiseAndSetIfChanged(ref _logOutVisibility, value);
}

private string? _verifier;
Expand All @@ -64,23 +69,23 @@ public SpotifyConfigurationDialogViewModel(Plugin plugin, PluginSettings setting

public async Task Login()
{
if (!_waitingForUser)
{
_waitingForUser = true;
(_verifier, _challenge) = PKCEUtil.GenerateCodes();
if (_waitingForUser)
return;

_waitingForUser = true;
(_verifier, _challenge) = PKCEUtil.GenerateCodes();

await Server.Start();
Server.AuthorizationCodeReceived += OnAuthorizationCodeReceived;
await Server.Start();
Server.AuthorizationCodeReceived += OnAuthorizationCodeReceived;

var request = new LoginRequest(Server.BaseUri, Constants.SPOTIFY_CLIENT_ID, LoginRequest.ResponseType.Code)
{
CodeChallenge = _challenge,
CodeChallengeMethod = "S256",
Scope = new List<string> { Scopes.UserReadCurrentlyPlaying, Scopes.UserReadPlaybackState }
};
_loginUrl = request.ToUri().ToString();

LoginRequest request = new LoginRequest(Server.BaseUri, Constants.SPOTIFY_CLIENT_ID, LoginRequest.ResponseType.Code)
{
CodeChallenge = _challenge,
CodeChallengeMethod = "S256",
Scope = new List<string> { Scopes.UserReadCurrentlyPlaying, Scopes.UserReadPlaybackState }
};
_loginUrl = request.ToUri().ToString();
}

if (_loginUrl is not null)
Utilities.OpenUrl(_loginUrl);
}
Expand All @@ -99,7 +104,7 @@ private async Task OnAuthorizationCodeReceived(object sender, AuthorizationCodeR
Server.AuthorizationCodeReceived -= OnAuthorizationCodeReceived;
await Server.Stop();

PKCETokenRequest tokenRequest = new PKCETokenRequest(Constants.SPOTIFY_CLIENT_ID, response.Code, Server.BaseUri, _verifier!);
var tokenRequest = new PKCETokenRequest(Constants.SPOTIFY_CLIENT_ID, response.Code, Server.BaseUri, _verifier!);

_token.Value = await new OAuthClient().RequestToken(tokenRequest);
_token.Save();
Expand All @@ -121,31 +126,42 @@ private void UpdateProfilePicture()
{
Dispatcher.UIThread.Post(async () =>
{
if (_dataModelExpansion.LoggedIn)
try
{
var user = await _dataModelExpansion.GetUserInfo();
if (user is null)
return;
Username = user.DisplayName;
//skiaSharp crashes on linux, fix later TODO
if (OperatingSystem.IsLinux())
return;
if (user.Images.Count < 1)
return;
try
if (_dataModelExpansion.LoggedIn)
{
ProfilePicture = new Bitmap(await _client.GetStreamAsync(user.Images[0].Url));
}
catch
{
ProfilePicture = new Bitmap(new FileStream(Plugin.ResolveRelativePath("no-user.png"), FileMode.Open, FileAccess.Read));
var user = await _dataModelExpansion.GetUserInfo();
if (user is null)
return;
Username = user.DisplayName;
//skiaSharp crashes on linux, fix later TODO
if (OperatingSystem.IsLinux())
return;
if (user.Images.Count < 1)
return;
try
{
var response = await _client.GetAsync(user.Images.Last().Url, HttpCompletionOption.ResponseContentRead);
var imageStream = await response.Content.ReadAsStreamAsync();
ProfilePicture = new Bitmap(imageStream);
}
catch (Exception e)
{
ProfilePicture = new Bitmap(new FileStream(Plugin.ResolveRelativePath("no-user.png"), FileMode.Open, FileAccess.Read));
}
return;
}
return;
}
Username = "Not logged in";
Username = "Not logged in";
}
catch (Exception e)
{
//failed to get user info, ignore
}
});
}
}

0 comments on commit 284960c

Please sign in to comment.