Add link to plaza.one, hopefully fixed some bugs with the async stuff, UI now pays attention to maintenance mode, library now differentiates between maintenance and non-maintenance-related problems
This commit is contained in:
parent
058f3b1467
commit
736eccf306
|
@ -29,7 +29,7 @@
|
|||
<Label x:Name="lbTitle" Content="リサフランク420 / 現代のコンピュ" HorizontalAlignment="Left" Margin="2,6,0,0" VerticalAlignment="Top" FontSize="12" FontWeight="Bold" Grid.ColumnSpan="2" Grid.Column="1"/>
|
||||
<Label x:Name="lbArtist" Content="MACプラス Macintosh Plus" HorizontalAlignment="Left" Margin="2,28,0,0" VerticalAlignment="Top" FontSize="11" Grid.Column="1"/>
|
||||
<Label x:Name="lbAlbum" Content="フローラルの専門店 Floral Shoppe" HorizontalAlignment="Left" Margin="2,45,0,0" VerticalAlignment="Top" FontStyle="Italic" FontSize="10" Grid.Column="1" Grid.ColumnSpan="2"/>
|
||||
<Slider x:Name="slDuration" Margin="0,87,0,0" VerticalAlignment="Top" IsEnabled="False" Grid.ColumnSpan="2" Height="18" Grid.Column="1"/>
|
||||
<Slider x:Name="slDuration" Margin="0,87,0,0" VerticalAlignment="Top" IsEnabled="False" Grid.ColumnSpan="2" Height="18" Grid.Column="1" AutoToolTipPlacement="TopLeft"/>
|
||||
<Label x:Name="lbElapsed" Content="00:00" HorizontalAlignment="Left" Margin="0,99,0,0" VerticalAlignment="Top" FontStyle="Italic" FontSize="9" Grid.Column="1"/>
|
||||
<Label x:Name="lbTime" Content="00:00" Margin="0,99,0,0" VerticalAlignment="Top" HorizontalAlignment="Right" FontStyle="Italic" FontSize="9" Grid.Column="2"/>
|
||||
<Button x:Name="btLike" Content="❤" ToolTip="Like this track" HorizontalAlignment="Right" Margin="0,40,2,0" Width="22" Height="20" VerticalAlignment="Top" FontSize="10" Grid.Column="2" Click="BtLike_Click"/>
|
||||
|
@ -38,6 +38,9 @@
|
|||
<Label x:Name="lbDislikeCt" Content="0" HorizontalAlignment="Right" Margin="0,60.5,22,0" VerticalAlignment="Top" Grid.Column="2" Grid.ColumnSpan="2"/>
|
||||
<Image x:Name="imLogin" Source="{DynamicResource imUsr}" IsHitTestVisible="False" Panel.ZIndex="1" Width="18" Height="18" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,17,3,0" Grid.Column="2"/>
|
||||
<Button x:Name="btLogin" Content="" ToolTip="Log into Nightwave Plaza" HorizontalAlignment="Right" Margin="0,16,2,0" Width="22" Height="20" VerticalAlignment="Top" FontSize="9" Grid.Column="2" Click="BtLogin_Click"/>
|
||||
<TextBlock ToolTip="Visit Nightwave Plaza! If you don't have an account, you can make one there!" FontSize="10" FontStyle="Italic" Grid.Column="2" Grid.Row="0" Margin="0,0,2,13" HorizontalAlignment="Right" VerticalAlignment="Bottom" Foreground="#FF5A5A5A">
|
||||
<Hyperlink NavigateUri="https://plaza.one" RequestNavigate="Hyperlink_RequestNavigate" Foreground="{Binding Parent.Foreground, RelativeSource={RelativeSource Self}}" TextDecorations="{x:Null}" Cursor="ArrowCD" TargetName="Nightwave Plaza">plaza.one</Hyperlink>
|
||||
</TextBlock>
|
||||
<DockPanel Grid.ColumnSpan="5" Margin="0,0,0,0" Grid.Row="1">
|
||||
<StatusBar x:Name="statusBar" Margin="0,0,0,-2" DockPanel.Dock="Bottom" VerticalAlignment="Bottom" BorderBrush="#FFDFDFDF" BorderThickness="1" Height="28" VerticalContentAlignment="Bottom">
|
||||
<StatusBarItem HorizontalAlignment="Left">
|
||||
|
|
|
@ -54,7 +54,18 @@ namespace WinPlaza {
|
|||
SetStatus($"Logged in as {await plaza.GetUser()}");
|
||||
}
|
||||
private async void DgtRefresh(bool Force = false) {
|
||||
Nightwave.Status s=await plaza.Broadcast(Force);
|
||||
Status s=await plaza.Broadcast(Force);
|
||||
if(s.FaultOccurred||s.InMaintenance) {
|
||||
if(s.InMaintenance)
|
||||
SetStatus("Nightwave Plaza is currently in maintenance mode.");
|
||||
else
|
||||
SetStatus("Ran into a problem while fetching now-playing.");
|
||||
return;
|
||||
}
|
||||
if(s.ArtworkUri == null || s.Duration == 0) {
|
||||
Console.WriteLine("why is async so hard");
|
||||
throw new Exception("Something went real weird, woah. Time to Crash!");
|
||||
}
|
||||
slDuration.Value = s.CalculatedElapsed;
|
||||
sbListeners.Text = $"{s.Listeners} listeners";
|
||||
lbLikeCt.Content = s.Likes;
|
||||
|
@ -69,7 +80,7 @@ namespace WinPlaza {
|
|||
slDuration.Maximum = s.Duration;
|
||||
lbTime.Content = $"{(s.Duration / 60).ToString("D")}:{(s.Duration % 60).ToString("D2")}";
|
||||
if(LastArtwork != s.ArtworkUri) {
|
||||
if(tGfx.Enabled)
|
||||
if(btPlayPause.IsChecked == true)
|
||||
SetStatus("Playing");
|
||||
LikedCTrack = false;
|
||||
art.Source = new BitmapImage(new Uri(s.ArtworkUri));
|
||||
|
@ -139,8 +150,8 @@ namespace WinPlaza {
|
|||
if(buf != IntPtr.Zero && len == 0 && usr.ToInt32() == BufferReqs)
|
||||
SetStatus(Marshal.PtrToStringAnsi(buf));
|
||||
}
|
||||
private void EvtRefresh(object sender, ElapsedEventArgs e) =>
|
||||
Dispatcher.BeginInvoke(new dgtBool(DgtRefresh), false);
|
||||
private async void EvtRefresh(object sender, ElapsedEventArgs e) =>
|
||||
await Dispatcher.BeginInvoke(new dgtBool(DgtRefresh), false);
|
||||
private async void EvtLogon(object sender, ElapsedEventArgs e) =>
|
||||
await Dispatcher.BeginInvoke(new dgtNoParam(DgtStartupLogon));
|
||||
private void EvtAudio(object sender, ElapsedEventArgs e) =>
|
||||
|
@ -223,6 +234,10 @@ namespace WinPlaza {
|
|||
btPlayPause.IsChecked = !btPlayPause.IsChecked;
|
||||
private void TbMute_Click(object sender, EventArgs e) =>
|
||||
sbMute.IsChecked = !sbMute.IsChecked;
|
||||
private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e) {
|
||||
_ = System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(e.Uri.AbsoluteUri));
|
||||
e.Handled = true;
|
||||
}
|
||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
|
||||
tRefresh.Stop();
|
||||
if(AudioInit) {
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
|
||||
<WebPage>index.html</WebPage>
|
||||
<OpenBrowserOnPublish>false</OpenBrowserOnPublish>
|
||||
<ApplicationRevision>3</ApplicationRevision>
|
||||
<ApplicationRevision>4</ApplicationRevision>
|
||||
<ApplicationVersion>1.5.0.%2a</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<CreateDesktopShortcut>true</CreateDesktopShortcut>
|
||||
|
@ -73,7 +73,7 @@
|
|||
<GenerateManifests>true</GenerateManifests>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignManifests>true</SignManifests>
|
||||
<SignManifests>false</SignManifests>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject>WinPlaza.App</StartupObject>
|
||||
|
@ -91,9 +91,6 @@
|
|||
<Reference Include="ManagedBass, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ManagedBass.2.0.4\lib\net45\ManagedBass.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ManagedBass.Opus, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ManagedBass.Opus.2.0.0\lib\netstandard1.4\ManagedBass.Opus.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Meziantou.Framework.Win32.CredentialManager, Version=1.3.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Meziantou.Framework.Win32.CredentialManager.1.3.4\lib\net461\Meziantou.Framework.Win32.CredentialManager.dll</HintPath>
|
||||
</Reference>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="ManagedBass" version="2.0.4" targetFramework="net472" />
|
||||
<package id="ManagedBass.Opus" version="2.0.0" targetFramework="net472" />
|
||||
<package id="Meziantou.Framework.Win32.CredentialManager" version="1.3.4" targetFramework="net472" />
|
||||
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net472" />
|
||||
</packages>
|
|
@ -47,6 +47,23 @@ namespace libplaza {
|
|||
}
|
||||
internal class PlazaInMaintenanceException : Exception { }
|
||||
internal class PlazaUnavailableException : Exception { }
|
||||
public class Status {
|
||||
public bool InMaintenance;
|
||||
public bool FaultOccurred;
|
||||
public string Title;
|
||||
public string Artist;
|
||||
public string Album;
|
||||
public string ArtworkUri;
|
||||
public int Elapsed;
|
||||
public int Duration;
|
||||
public long Since;
|
||||
public int ServerTimeOffset;
|
||||
public int CalculatedElapsed =>
|
||||
(int)(DateTimeOffset.Now.ToUnixTimeSeconds() - ServerTimeOffset - Since) + Elapsed;
|
||||
public int Likes;
|
||||
public int Dislikes;
|
||||
public int Listeners;
|
||||
}
|
||||
public class Nightwave {
|
||||
public int MinRefreshTime=10;
|
||||
private long tsLastRefresh=0;
|
||||
|
@ -57,26 +74,7 @@ namespace libplaza {
|
|||
Like,
|
||||
Favourite
|
||||
}
|
||||
public enum BroadcastStatus {
|
||||
OffAir,
|
||||
OnAir
|
||||
}
|
||||
public struct Status {
|
||||
public string Title;
|
||||
public string Artist;
|
||||
public string Album;
|
||||
public string ArtworkUri;
|
||||
public int Elapsed;
|
||||
public int Duration;
|
||||
public long Since;
|
||||
public int ServerTimeOffset;
|
||||
public int CalculatedElapsed;
|
||||
public int Likes;
|
||||
public int Dislikes;
|
||||
public int Listeners;
|
||||
}
|
||||
private Status _bc;
|
||||
public BroadcastStatus Broadcasting=BroadcastStatus.OffAir;
|
||||
public Nightwave() {
|
||||
_hcl.BaseAddress = new Uri(PlazaApi.ApiBase);
|
||||
_hcl.Timeout = TimeSpan.FromSeconds(2);
|
||||
|
@ -85,36 +83,26 @@ namespace libplaza {
|
|||
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
|
||||
}
|
||||
public async Task<Status> Broadcast(bool Force = false) {
|
||||
_bc.CalculatedElapsed = (int)(DateTimeOffset.Now.ToUnixTimeSeconds() - _bc.ServerTimeOffset - _bc.Since) + _bc.Elapsed;
|
||||
if(!Force && tsLastRefresh + MinRefreshTime >= DateTimeOffset.Now.ToUnixTimeSeconds() && _bc.CalculatedElapsed < _bc.Duration)
|
||||
return _bc;
|
||||
try {
|
||||
Status _=await GetNightwaveAsync();
|
||||
Broadcasting = BroadcastStatus.OnAir;
|
||||
_bc = _;
|
||||
} catch(PlazaInMaintenanceException) {
|
||||
Broadcasting = BroadcastStatus.OffAir;
|
||||
} catch(PlazaUnavailableException) {
|
||||
Broadcasting = BroadcastStatus.OffAir;
|
||||
} catch(Exception) { //TODO make this more reliable?
|
||||
Broadcasting = BroadcastStatus.OffAir;
|
||||
}
|
||||
await Update();
|
||||
tsLastRefresh = DateTimeOffset.Now.ToUnixTimeSeconds();
|
||||
return _bc;
|
||||
}
|
||||
public async void Update() {
|
||||
public async Task Update() {
|
||||
try {
|
||||
Status _=await GetNightwaveAsync();
|
||||
Broadcasting = BroadcastStatus.OnAir;
|
||||
_.InMaintenance = false;
|
||||
_.FaultOccurred = false;
|
||||
_bc = _;
|
||||
} catch(PlazaInMaintenanceException) {
|
||||
Broadcasting = BroadcastStatus.OffAir;
|
||||
} catch(PlazaUnavailableException) {
|
||||
Broadcasting = BroadcastStatus.OffAir;
|
||||
_bc.InMaintenance = true;
|
||||
_bc.FaultOccurred = false;
|
||||
} catch(Exception) { //TODO make this more reliable?
|
||||
Broadcasting = BroadcastStatus.OffAir;
|
||||
_bc.FaultOccurred = true;
|
||||
}
|
||||
}
|
||||
public async void EvtUpdate() => await Update();
|
||||
public async Task<Status> GetNightwaveAsync() {
|
||||
Status status;
|
||||
HttpResponseMessage _r=await _hcl.GetAsync("/status");
|
||||
|
@ -130,7 +118,6 @@ namespace libplaza {
|
|||
Artist = j.playback.artist,
|
||||
Elapsed = j.playback.position,
|
||||
Duration = j.playback.length,
|
||||
CalculatedElapsed = (int)(DateTimeOffset.Now.ToUnixTimeSeconds() - j.playback.updated) + j.playback.position,
|
||||
Since = j.playback.updated,
|
||||
Likes = j.playback.likes,
|
||||
Dislikes = j.playback.hates,
|
||||
|
@ -138,7 +125,6 @@ namespace libplaza {
|
|||
ServerTimeOffset = (int)(DateTimeOffset.Now.ToUnixTimeSeconds() - _r.Headers.Date.Value.ToUnixTimeSeconds()),
|
||||
ArtworkUri = $"{PlazaApi.ArtworkBase}{j.playback.artwork}"
|
||||
};
|
||||
status.CalculatedElapsed = (int)(DateTimeOffset.Now.ToUnixTimeSeconds() - status.ServerTimeOffset - j.playback.updated) + j.playback.position;
|
||||
return status;
|
||||
}
|
||||
public async Task<bool> CastVote(Vote v) {
|
||||
|
|
Loading…
Reference in New Issue