Skip to content

Commit

Permalink
Merge pull request #23 from Difegue/dev
Browse files Browse the repository at this point in the history
1.6.0
  • Loading branch information
Difegue committed Mar 13, 2021
2 parents 1a62d5b + f46f4a0 commit 1756f25
Show file tree
Hide file tree
Showing 44 changed files with 477 additions and 388 deletions.
Binary file modified Screenshots/Screen1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/Screen2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/Screen3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/Screen4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/Screen5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/Screen6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/ScreenXbox.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 11 additions & 7 deletions Sources/FluentMPC/FluentMPC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CodeProject.ObjectPool">
<Version>5.0.1</Version>
<Version>5.0.2</Version>
</PackageReference>
<PackageReference Include="ksemenenko.ColorThief">
<Version>1.1.1.4</Version>
Expand All @@ -146,16 +146,19 @@
<Version>6.2.9</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp">
<Version>6.1.1</Version>
<Version>7.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
<Version>6.1.1</Version>
<Version>7.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Animations">
<Version>6.1.1</Version>
<Version>7.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls">
<Version>6.1.1</Version>
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Behaviors">
<Version>7.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.Core">
<Version>7.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.UI.Xaml">
<Version>2.5.0</Version>
Expand All @@ -164,7 +167,7 @@
<Version>2.0.1</Version>
</PackageReference>
<PackageReference Include="System.Drawing.Common">
<Version>5.0.0</Version>
<Version>5.0.2</Version>
</PackageReference>
<PackageReference Include="WriteableBitmapEx">
<Version>1.6.7</Version>
Expand Down Expand Up @@ -198,6 +201,7 @@
<Compile Include="Activation\DefaultActivationHandler.cs" />
<Compile Include="Services\BackgroundTaskService.cs" />
<Compile Include="Services\DialogService.cs" />
<Compile Include="Services\DispatcherService.cs" />
<Compile Include="Services\SystemMediaControlsService.cs" />
<Compile Include="Services\LiveTileService.cs" />
<Compile Include="Services\LiveTileService.Structure.cs" />
Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentMPC/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Identity
Name="StylophoneDebug"
Publisher="CN=B2F6FFCA-07C7-479C-AC33-2C75463C7DCE"
Version="1.5.0.0" />
Version="1.6.0.0" />

<mp:PhoneIdentity PhoneProductId="6aab9ef0-77d1-4922-a9da-497e36a34491" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

Expand Down
2 changes: 1 addition & 1 deletion Sources/FluentMPC/Package.tt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<#@ output extension=".appxmanifest" #>
<#@ parameter type="System.String" name="BuildConfiguration" #>
<#
string version = "1.5.0.0";
string version = "1.6.0.0";

// Get configuration name at Build time
string configName = Host.ResolveParameterValue("-", "-", "BuildConfiguration");
Expand Down
32 changes: 17 additions & 15 deletions Sources/FluentMPC/Services/AlbumArtService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ColorThiefDotNet;
using FluentMPC.Helpers;
using FluentMPC.ViewModels.Items;
using Microsoft.Toolkit.Uwp;
using Microsoft.Toolkit.Uwp.Helpers;
using MpcNET.Commands.Database;
using MpcNET.Types;
Expand All @@ -14,6 +15,7 @@
using Windows.Graphics.Imaging;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.System;
using Windows.UI.Core;
using Windows.UI.Xaml.Media.Imaging;

Expand Down Expand Up @@ -101,21 +103,21 @@ public static async Task<bool> IsAlbumArtCachedAsync(IMpdFile f)
/// <param name="albumArtWidth">Width of the final BitmapImage</param>
/// <param name="dispatcher">Dispatcher to use for the UI-bound options. Defaults to MainWindow.CoreWindow.Dispatcher.</param>
/// <returns>An AlbumArt object containing bitmap and color. Returns null if there was no albumart on the MPD server.</returns>
public async static Task<AlbumArt> GetAlbumArtAsync(IMpdFile f, bool calculateDominantColor, int albumArtWidth, CoreDispatcher dispatcher = null, CancellationToken token = default)
public async static Task<AlbumArt> GetAlbumArtAsync(IMpdFile f, bool calculateDominantColor, int albumArtWidth, DispatcherQueue dispatcherQueue = null, CancellationToken token = default)
{
if (dispatcher == null)
dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;
if (dispatcherQueue == null)
dispatcherQueue = DispatcherService.DispatcherQueue;

var result = new AlbumArt();

var bitmap = await GetAlbumBitmap(f, dispatcher, token);
var bitmap = await GetAlbumBitmap(f, dispatcherQueue, token);
if (bitmap != null)
{
result.ArtBitmap = await WriteableBitmapToBitmapImageAsync(bitmap, albumArtWidth, dispatcher);
result.ArtBitmap = await WriteableBitmapToBitmapImageAsync(bitmap, albumArtWidth, dispatcherQueue);

if (calculateDominantColor)
{
result.DominantColor = await GetDominantColor(bitmap, dispatcher);
result.DominantColor = await GetDominantColor(bitmap, dispatcherQueue);
}

return result;
Expand All @@ -133,7 +135,7 @@ private static string GetFileIdentifier(IMpdFile f)
return MiscHelpers.EscapeFilename(uniqueIdentifier);
}

private async static Task<WriteableBitmap> GetAlbumBitmap(IMpdFile f, CoreDispatcher dispatcher, CancellationToken token = default)
private async static Task<WriteableBitmap> GetAlbumBitmap(IMpdFile f, DispatcherQueue dispatcher, CancellationToken token = default)
{
WriteableBitmap result;
var foundUsableArt = false;
Expand Down Expand Up @@ -208,12 +210,12 @@ private async static Task<WriteableBitmap> GetAlbumBitmap(IMpdFile f, CoreDispat
return result;
}

private static async Task<QuantizedColor> GetDominantColor(WriteableBitmap art, CoreDispatcher dispatcher)
private static async Task<QuantizedColor> GetDominantColor(WriteableBitmap art, DispatcherQueue dispatcherQueue)
{
// Get dominant color of albumart
using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
{
await dispatcher.AwaitableRunAsync(async () =>
await dispatcherQueue.EnqueueAsync(async () =>
{
await art.Resize(50, 50, WriteableBitmapExtensions.Interpolation.NearestNeighbor).ToStreamAsJpeg(stream);
});
Expand All @@ -232,10 +234,10 @@ private static async Task SaveArtToFileAsync(string fileName, List<byte> data)
await pictureFolder.SaveFileAsync(data.ToArray(), fileName, CreationCollisionOption.ReplaceExisting);
}

private static async Task<BitmapImage> WriteableBitmapToBitmapImageAsync(WriteableBitmap art, int decodedPixelWidth, CoreDispatcher dispatcher)
private static async Task<BitmapImage> WriteableBitmapToBitmapImageAsync(WriteableBitmap art, int decodedPixelWidth, DispatcherQueue dispatcherQueue)
{
BitmapImage image = null;
await dispatcher.AwaitableRunAsync(async () =>
await dispatcherQueue.EnqueueAsync(async () =>
{
image = new BitmapImage();
Expand All @@ -254,7 +256,7 @@ await dispatcher.AwaitableRunAsync(async () =>
return image;
}

private static async Task<WriteableBitmap> LoadImageFromFile(string fileName, CoreDispatcher dispatcher)
private static async Task<WriteableBitmap> LoadImageFromFile(string fileName, DispatcherQueue dispatcherQueue)
{
try
{
Expand All @@ -264,7 +266,7 @@ private static async Task<WriteableBitmap> LoadImageFromFile(string fileName, Co
var readStream = await file.OpenReadAsync();

WriteableBitmap image = null;
await dispatcher.AwaitableRunAsync(async () => image = await BitmapFactory.FromStream(readStream));
await dispatcherQueue.EnqueueAsync(async () => image = await BitmapFactory.FromStream(readStream));

readStream.Dispose();
return image;
Expand All @@ -275,12 +277,12 @@ private static async Task<WriteableBitmap> LoadImageFromFile(string fileName, Co
}
}

private async static Task<WriteableBitmap> ImageFromBytes(byte[] bytes, CoreDispatcher dispatcher)
private async static Task<WriteableBitmap> ImageFromBytes(byte[] bytes, DispatcherQueue dispatcherQueue)
{
WriteableBitmap image = null;
using (var stream = new MemoryStream(bytes))
{
await dispatcher.AwaitableRunAsync(async () =>
await dispatcherQueue.EnqueueAsync(async () =>
{
image = await BitmapFactory.FromStream(stream);
Expand Down
9 changes: 4 additions & 5 deletions Sources/FluentMPC/Services/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
using System.Threading.Tasks;

using FluentMPC.Views;

using Microsoft.Toolkit.Uwp;
using Microsoft.Toolkit.Uwp.Helpers;

using Windows.ApplicationModel.Core;
using Windows.System;
using Windows.UI.Core;
using Windows.UI.Xaml.Controls;

Expand All @@ -22,9 +23,7 @@ public static class DialogService
public static async Task<string> ShowAddToPlaylistDialog(bool allowExistingPlaylists = true)
{
var dialog = new AddToPlaylistDialog(allowExistingPlaylists);
var result = ContentDialogResult.None;

await DispatcherHelper.ExecuteOnUIThreadAsync (async () => result = await dialog.ShowAsync());
var result = await DispatcherService.DispatcherQueue.EnqueueAsync(async () => await dialog.ShowAsync());

// Return new playlist name if checked, selected playlist otherwise
return result == ContentDialogResult.Primary ? dialog.AddNewPlaylist ? dialog.PlaylistName : dialog.SelectedPlaylist : null;
Expand All @@ -36,7 +35,7 @@ internal static async Task ShowFirstRunDialogIfAppropriateAsync()
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
CoreDispatcherPriority.Normal, async () =>
{
if (SystemInformation.IsFirstRun && !shown)
if (SystemInformation.Instance.IsFirstRun && !shown)
{
shown = true;
var dialog = new FirstRunDialog();
Expand Down
38 changes: 38 additions & 0 deletions Sources/FluentMPC/Services/DispatcherService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Microsoft.Toolkit.Uwp;
using System;
using System.Threading.Tasks;
using Windows.System;

namespace FluentMPC.Services
{
public static class DispatcherService
{
private static DispatcherQueue _queue;
public static DispatcherQueue DispatcherQueue
{
get
{
if (_queue == null)
{
throw new Exception("The DispatcherQueue hasn't been cached yet!");
}

return _queue;
}

set
{
_queue = value;
}
}

public static void Initialize()
{
// Get a DispatcherQueue instance for later use. This has to be called on the UI thread,
// but it can then be cached for later use and accessed from a background thread as well.
DispatcherQueue = DispatcherQueue.GetForCurrentThread();
}

public static Task ExecuteOnUIThreadAsync(Action function, DispatcherQueuePriority priority = DispatcherQueuePriority.Normal) => DispatcherQueue.EnqueueAsync(function, priority);
}
}
14 changes: 10 additions & 4 deletions Sources/FluentMPC/Services/MPDConnectionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,23 @@ public static async Task<PooledObjectWrapper<MpcConnection>> GetConnectionAsync(
/// </summary>
/// <typeparam name="T">Return type of the command</typeparam>
/// <param name="command">IMpcCommand to send</param>
/// <param name="dispatcher">CoreDispatcher, needed if you're executing commands in a state where the dispatcher can be a secondary one</param>
/// <returns>The command results, or default value.</returns>
public static async Task<T> SafelySendCommandAsync<T>(IMpcCommand<T> command, CoreDispatcher dispatcher = null)
public static async Task<T> SafelySendCommandAsync<T>(IMpcCommand<T> command)
{
try
{
using (var c = await GetConnectionAsync())
{
var response = await c.InternalResource.SendAsync(command);
if (!response.IsResponseValid) throw new Exception($"Invalid server response: {response}.");
if (!response.IsResponseValid)
{
// If we have an MpdError string, only show that as the error to avoid extra noise
var mpdError = response.Response?.Result?.MpdError;
if (mpdError != null)
throw new Exception(mpdError);
else
throw new Exception($"Invalid server response: {response}.");
}

return response.Response.Content;
}
Expand All @@ -152,7 +159,6 @@ public static async Task<T> SafelySendCommandAsync<T>(IMpcCommand<T> command, Co
{
try
{
if (dispatcher == null || dispatcher == CoreApplication.MainView.CoreWindow.Dispatcher) // Only invoke notificationservice on the main window
NotificationService.ShowInAppNotification($"Sending {command.GetType().Name} failed: {e.Message}", 0);
} catch
{
Expand Down
26 changes: 26 additions & 0 deletions Sources/FluentMPC/Services/ThemeSelectorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

using Windows.ApplicationModel.Core;
using Windows.Storage;
using Windows.UI;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;

namespace FluentMPC.Services
Expand Down Expand Up @@ -38,6 +40,30 @@ await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
if (Window.Current.Content is FrameworkElement frameworkElement)
{
frameworkElement.RequestedTheme = Theme;
// https://stackoverflow.com/questions/48201278/uwp-changing-titlebar-buttonforegroundcolor-with-themeresource
Color color;
var appTheme = Application.Current.RequestedTheme;
switch (Theme)
{
case ElementTheme.Default:
color = ((Color)Application.Current.Resources["SystemBaseHighColor"]);
break;
case ElementTheme.Light:
if (appTheme == ApplicationTheme.Light) { color = ((Color)Application.Current.Resources["SystemBaseHighColor"]); }
else { color = ((Color)Application.Current.Resources["SystemAltHighColor"]); }
break;
case ElementTheme.Dark:
if (appTheme == ApplicationTheme.Light) { color = ((Color)Application.Current.Resources["SystemAltHighColor"]); }
else { color = ((Color)Application.Current.Resources["SystemBaseHighColor"]); }
break;
default:
break;
}
ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar;
titleBar.ButtonForegroundColor = color;
}
});
}
Expand Down
Loading

0 comments on commit 1756f25

Please sign in to comment.