Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further AutoPlay improvements #444

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/AmbientSounds.Uwp/Controls/SoundItemControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
Command="{x:Bind ViewModel.RenameCommand, Mode=OneWay}"
Icon="Rename"
Visibility="{x:Bind ViewModel.IsMix, Mode=OneWay}" />
<AppBarButton
x:Uid="CopyIDAppBarButton"
Command="{x:Bind ViewModel.CopyMixIDCommand, Mode=OneWay}"
Icon="Copy"
Visibility="{x:Bind ViewModel.IsMix, Mode=OneWay}" />
<AppBarButton Click="OnEditHomePageClicked" Label="{x:Bind strings:Resources.EditHomePage}">
<AppBarButton.Icon>
<FontIcon FontFamily="{StaticResource FluentUIGlyphs}" Glyph="{StaticResource GlyphEditHome}" />
Expand Down
37 changes: 31 additions & 6 deletions src/AmbientSounds.Uwp/Services/ProtocolLaunchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
using CommunityToolkit.Diagnostics;
using System;
using System.Collections.Generic;
using AmbientSounds.Constants;
using JeniusApps.Common.Telemetry;
using Windows.ApplicationModel.DataTransfer;
using Windows.System;
using JeniusApps.Common.Tools.Uwp;
using Microsoft.Extensions.DependencyInjection;

#nullable enable

Expand All @@ -19,24 +15,32 @@ public class ProtocolLaunchController
private readonly IShareService _shareService;
private readonly ITelemetry _telemetry;
private readonly INavigator _navigator;
private readonly ISoundService _soundService;
private readonly ISoundMixService _soundMixService;

private const string AutoPlayKey = "autoPlay";

public ProtocolLaunchController(
IMixMediaPlayerService player,
IShareService shareService,
ITelemetry telemetry,
INavigator navigator)
INavigator navigator,
ISoundService soundService,
ISoundMixService soundMixService)
{
Guard.IsNotNull(player);
Guard.IsNotNull(shareService);
Guard.IsNotNull(telemetry);
Guard.IsNotNull(navigator);
Guard.IsNotNull(soundService);
Guard.IsNotNull(soundMixService);

_player = player;
_shareService = shareService;
_telemetry = telemetry;
_navigator = navigator;
_soundService = soundService;
_soundMixService = soundMixService;
}

public void ProcessShareProtocolArguments(string arguments)
Expand All @@ -52,12 +56,33 @@ public void ProcessShareProtocolArguments(string arguments)
public async void ProcessAutoPlayProtocolArguments(string arguments)
{
bool minimize = false;

string mixID = "";

if (arguments.Contains("minimize"))
{
minimize = true;
}

if (arguments.Contains("mix"))
{
int mixStart = arguments.IndexOf("mix=") + 4;
int mixEnd = arguments.IndexOf('&', mixStart);

if (mixEnd == -1) // If there's no &, take the rest of the string (smart moment here)
{
mixID = arguments.Substring(mixStart);
}
else
{
mixID = arguments.Substring(mixStart, mixEnd - mixStart);
}
if (_player != null) {
_player.SetMixId(mixID);
_player.RemoveAll();
await _player?.ToggleSoundsAsync(await _soundService.GetLocalSoundsAsync((await _soundService.GetLocalSoundAsync(mixID)).SoundIds), parentMixId: mixID);
}
}

_player?.Play();

if (minimize)
Expand Down
3 changes: 3 additions & 0 deletions src/AmbientSounds.Uwp/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1035,4 +1035,7 @@
<data name="FreeTrialTipTitle" xml:space="preserve">
<value>Free trial available</value>
</data>
<data name="CopyIDAppBarButton.Label" xml:space="preserve">
<value>Copy mix ID</value>
</data>
</root>
110 changes: 109 additions & 1 deletion src/AmbientSounds.Uwp/Strings/pl-PL/Resources.resw
Original file line number Diff line number Diff line change
@@ -1,5 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
Expand Down Expand Up @@ -761,7 +866,7 @@
<value>Oops! Nie mogliśmy znaleźć tego dźwięku. Zobaczymy, czy uda nam się go dodać w przyszłości</value>
</data>
<data name="SearchText" xml:space="preserve">
<value>Szukać</value>
<value>Szukaj</value>
</data>
<data name="QuickResumeTitle" xml:space="preserve">
<value>Szybkie wznawianie</value>
Expand Down Expand Up @@ -927,4 +1032,7 @@
<data name="FreeTrialTipTitle" xml:space="preserve">
<value>Dostępna bezpłatna wersja próbna</value>
</data>
<data name="CopyIDAppBarButton.Label" xml:space="preserve">
<value>Kopiuj ID miksu</value>
</data>
</root>
4 changes: 2 additions & 2 deletions src/AmbientSounds/Factories/SoundVmFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using AmbientSounds.Models;
using AmbientSounds.Services;
using AmbientSounds.Tools;
using AmbientSounds.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using CommunityToolkit.Diagnostics;
Expand Down Expand Up @@ -71,7 +70,8 @@ public SoundViewModel GetSoundVm(Sound s)
_serviceProvider.GetRequiredService<IPresenceService>(),
_serviceProvider.GetRequiredService<IDispatcherQueue>(),
_serviceProvider.GetRequiredService<IOnlineSoundRepository>(),
_serviceProvider.GetRequiredService<IAssetLocalizer>());
_serviceProvider.GetRequiredService<IAssetLocalizer>(),
_serviceProvider.GetRequiredService<IClipboard>());
vm.Initialize();
return vm;
}
Expand Down
18 changes: 17 additions & 1 deletion src/AmbientSounds/ViewModels/SoundViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public partial class SoundViewModel : ObservableObject
private readonly IPresenceService _presenceService;
private readonly IDispatcherQueue _dispatcherQueue;
private readonly IAssetLocalizer _assetLocalizer;
private readonly IClipboard _clipboard;
private Progress<double>? _downloadProgress;

[ObservableProperty]
Expand Down Expand Up @@ -71,7 +72,8 @@ public SoundViewModel(
IPresenceService presenceService,
IDispatcherQueue dispatcherQueue,
IOnlineSoundRepository onlineSoundRepo,
IAssetLocalizer assetLocalizer)
IAssetLocalizer assetLocalizer,
IClipboard clipboard)
{
_sound = s;
_soundMixService = soundMixService;
Expand All @@ -86,6 +88,7 @@ public SoundViewModel(
_dispatcherQueue = dispatcherQueue;
_onlineSoundRepo = onlineSoundRepo;
_assetLocalizer = assetLocalizer;
_clipboard = clipboard;
}

public IAsyncRelayCommand<IList<string>>? MixUnavailableCommand { get; set; }
Expand Down Expand Up @@ -237,6 +240,19 @@ private void OnProgressChanged(object sender, double e)
}
}

/// <summary>
/// Copies the mix ID to the clipboard.
/// </summary>
[RelayCommand]
private void CopyMixID()
{
if (IsMix)
{
_clipboard.CopyToClipboard(Id);
}
}


/// <summary>
/// Loads this sound into the player and plays it.
/// </summary>
Expand Down