diff options
| -rw-r--r-- | Erable/DiscordRPC.cs | 56 | ||||
| -rw-r--r-- | Erable/Erable.csproj | 7 | ||||
| -rw-r--r-- | Erable/Program.cs | 25 | ||||
| -rw-r--r-- | Erable/ViewModels/MainWindowViewModel.cs | 16 | ||||
| -rw-r--r-- | Erable/Views/About.axaml | 17 | ||||
| -rw-r--r-- | Erable/Views/About.axaml.cs | 30 | ||||
| -rw-r--r-- | Erable/Views/MainWindow.axaml | 7 | ||||
| -rw-r--r-- | Erable/Views/MainWindow.axaml.cs | 9 | ||||
| -rw-r--r-- | Sirop.Backend/Playback.cs | 11 | ||||
| -rw-r--r-- | Sirop.Backend/Sirop.Backend.csproj | 1 |
10 files changed, 160 insertions, 19 deletions
diff --git a/Erable/DiscordRPC.cs b/Erable/DiscordRPC.cs new file mode 100644 index 0000000..0237934 --- /dev/null +++ b/Erable/DiscordRPC.cs @@ -0,0 +1,56 @@ +using System; +using DiscordRPC; +using DiscordRPC.Logging; + +namespace Erable +{ + public class DiscordRpc + { + +//Called when your application first starts. +//For example, just before your main loop, on OnEnable for unity. + public static void Initialize() + { + /* + Create a Discord client + NOTE: If you are using Unity3D, you must use the full constructor and define + the pipe connection. + */ + var client = new DiscordRpcClient("808844258038644747") + { + Logger = new ConsoleLogger() {Level = LogLevel.Warning} + }; + + //Set the logger + + //Subscribe to events + client.OnReady += (sender, e) => + { + Console.WriteLine("Connected to Discord..."); + Console.WriteLine("Received Ready from user {0}", e.User.Username); + }; + #if DEBUG + client.OnPresenceUpdate += (sender, e) => + { + Console.WriteLine("Received Update! {0}", e.Presence); + }; + #endif + + //Connect to the RPC + client.Initialize(); + + //Set the rich presence + //Call this as many times as you want and anywhere in your code. + client.SetPresence(new RichPresence() + { + Details = "Playing Nothing", + State = "RPC is being implemented!", + Assets = new Assets() + { + LargeImageKey = "erable_logo", + LargeImageText = "Erable Audio Player" + } + }); + } + } +}
\ No newline at end of file diff --git a/Erable/Erable.csproj b/Erable/Erable.csproj index fa7cecb..88b6034 100644 --- a/Erable/Erable.csproj +++ b/Erable/Erable.csproj @@ -37,9 +37,16 @@ <PackageReference Include="Avalonia.Desktop" Version="0.10.0" />
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.0" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.0" />
+ <PackageReference Include="DiscordRichPresence" Version="1.0.175" />
<PackageReference Include="Dotnet.Bundle" Version="0.9.13" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Sirop.Backend\Sirop.Backend.csproj" />
</ItemGroup>
+ <ItemGroup>
+ <Compile Update="Views\About.axaml.cs">
+ <DependentUpon>About.axaml</DependentUpon>
+ <SubType>Code</SubType>
+ </Compile>
+ </ItemGroup>
</Project>
diff --git a/Erable/Program.cs b/Erable/Program.cs index f461a79..9999bee 100644 --- a/Erable/Program.cs +++ b/Erable/Program.cs @@ -1,6 +1,5 @@ using System;
using Avalonia;
-using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.ReactiveUI;
namespace Erable
@@ -13,13 +12,29 @@ namespace Erable public static void Main(string[] args)
{
Console.WriteLine("Erable: Audio Player by Alee Productions");
- Console.WriteLine("Running on .NET " + Environment.Version + ", and " + Environment.OSVersion);
+
+ AppDomain.CurrentDomain.UnhandledException += ErrorHandler;
+
#if DEBUG
- Console.WriteLine("Opening MainWindow...");
+ Console.WriteLine("Running on .NET " + Environment.Version + ", and " + Environment.OSVersion);
+ Console.WriteLine("Opening window...");
#endif
- try { BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); }catch (Exception ex) { Console.WriteLine(ex); }
- }
+
+ DiscordRpc.Initialize();
+
+ BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
+
+ }
+ static void ErrorHandler(object sender, UnhandledExceptionEventArgs e)
+ {
+ Console.WriteLine("Oh no! An error has occurred!");
+ Console.WriteLine("OS Version: " + Environment.OSVersion);
+ Console.WriteLine(".NET Version: " + Environment.Version);
+ Console.WriteLine("Report this to the developers...");
+ Console.WriteLine("Did this crashed? " + e.IsTerminating);
+ }
+
// Avalonia configuration, don't remove; also used by visual designer.
static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
diff --git a/Erable/ViewModels/MainWindowViewModel.cs b/Erable/ViewModels/MainWindowViewModel.cs index 899b49c..c99dfc2 100644 --- a/Erable/ViewModels/MainWindowViewModel.cs +++ b/Erable/ViewModels/MainWindowViewModel.cs @@ -11,8 +11,15 @@ namespace Erable.ViewModels public void PlayFunction()
{
- Thread t = new (Playback.PlayAudio);
- t.Start();
+ try
+ {
+ Thread t = new(Playback.PlayAudio);
+ t.Start();
+ }
+ catch(Exception ex)
+ {
+ MessageBox.Show(new MainWindow(), ex.ToString(), "Error", MessageBox.MessageBoxButtons.Ok);
+ }
}
public void StopFunction()
@@ -48,10 +55,9 @@ namespace Erable.ViewModels MessageBox.Show(new MainWindow(), "Hello world", "Test Title", MessageBox.MessageBoxButtons.Ok);
}
- public void Quit()
+ public void ExceptionButton()
{
- Environment.Exit(0);
+ throw new Exception();
}
-
}
}
diff --git a/Erable/Views/About.axaml b/Erable/Views/About.axaml new file mode 100644 index 0000000..7d6017f --- /dev/null +++ b/Erable/Views/About.axaml @@ -0,0 +1,17 @@ +<Window xmlns="https://github.com/avaloniaui"
+ 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"
+ mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="150"
+ x:Class="Erable.Views.About"
+ Width="600"
+ Height="150"
+ Icon="/Assets/erable.png"
+ Title="About Erable">
+ <StackPanel Margin="10">
+ <TextBlock HorizontalAlignment="Center" FontSize="30">About Erable 0.1 Pre-Alpha</TextBlock>
+ <TextBlock HorizontalAlignment="Center" FontSize="20">© Copyright 2021, Alee Productions</TextBlock>
+ <TextBlock HorizontalAlignment="Center" FontSize="20">Licensed with GPL-3.0</TextBlock>
+ <TextBlock HorizontalAlignment="Center" FontSize="20">Report Bugs at https://git.io/JtrAO</TextBlock>
+ </StackPanel>
+</Window>
diff --git a/Erable/Views/About.axaml.cs b/Erable/Views/About.axaml.cs new file mode 100644 index 0000000..d3d2846 --- /dev/null +++ b/Erable/Views/About.axaml.cs @@ -0,0 +1,30 @@ +using System;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Input;
+using Avalonia.Markup.Xaml;
+
+namespace Erable.Views
+{
+ public class About : Window
+ {
+
+ public About()
+ {
+ InitializeComponent();
+#if DEBUG
+ this.AttachDevTools();
+#endif
+ }
+
+ private void InitializeComponent()
+ {
+ AvaloniaXamlLoader.Load(this);
+ }
+
+ private void InputElement_OnPointerPressed(object? sender, PointerPressedEventArgs e)
+ {
+ Environment.Exit(0);
+ }
+ }
+}
\ No newline at end of file diff --git a/Erable/Views/MainWindow.axaml b/Erable/Views/MainWindow.axaml index de6c5b7..ca78244 100644 --- a/Erable/Views/MainWindow.axaml +++ b/Erable/Views/MainWindow.axaml @@ -19,17 +19,18 @@ <MenuItem Header="_File">
<MenuItem Header="_Open..."/>
<Separator/>
- <MenuItem Header="_Exit" PointerPressed="InputElement_OnPointerPressed"/>
+ <MenuItem Header="_Exit" PointerPressed="Exit_OnPointerPressed"/>
</MenuItem>
<MenuItem Header="_Help">
- <MenuItem Header="_About"/>
+ <MenuItem Header="_About" PointerPressed="About_OnPointerPressed"/>
</MenuItem>
</Menu>
</DockPanel>
<Button Name="PlayButton" Width="80" Command="{Binding PlayFunction}" >Play</Button>
<Button Name="StopButton" Width="80" Command="{Binding StopFunction}">Stop</Button>
<Button Name="BrowseButton" Width="80" Command="{Binding BrowseFunction }" >Browse</Button>
- <!--<Button Name="MessageBoxTest" Width="80" Command="{Binding MsgBoxTest }" >Message Box Test</Button>-->
+ <Button Name="ExceptionButton" Width="80" Command="{Binding ExceptionButton}">Exception</Button>
+ <Button Name="MessageBoxTest" Width="80" Command="{Binding MsgBoxTest }" >Message Box Test</Button>
<Slider Name="AudioSlider"/>
</StackPanel>
</Window>
diff --git a/Erable/Views/MainWindow.axaml.cs b/Erable/Views/MainWindow.axaml.cs index 78cde38..f849f26 100644 --- a/Erable/Views/MainWindow.axaml.cs +++ b/Erable/Views/MainWindow.axaml.cs @@ -21,9 +21,16 @@ namespace Erable.Views AvaloniaXamlLoader.Load(this);
}
- private void InputElement_OnPointerPressed(object? sender, PointerPressedEventArgs e)
+ private void Exit_OnPointerPressed(object? sender, PointerPressedEventArgs e)
{
Environment.Exit(0);
}
+
+ private void About_OnPointerPressed(object? sender, PointerPressedEventArgs e)
+ {
+ About about = new();
+ about.ShowDialog(this);
+
+ }
}
}
\ No newline at end of file diff --git a/Sirop.Backend/Playback.cs b/Sirop.Backend/Playback.cs index a073ce3..7670193 100644 --- a/Sirop.Backend/Playback.cs +++ b/Sirop.Backend/Playback.cs @@ -1,6 +1,7 @@ +using System; using Gst; -namespace Sirop.Backend.Audio +namespace Sirop.Backend { public static class Playback { @@ -9,18 +10,18 @@ namespace Sirop.Backend.Audio Application.Init(); // Build the pipeline var pipeline = Parse.Launch("playbin uri=file:///home/andrew/Music/4616-werq-by-kevin-macleod.mp3"); - // Start playing pipeline.SetState(State.Playing); // Wait until error or EOS var bus = pipeline.Bus; - var msg = bus.TimedPopFiltered (Constants.CLOCK_TIME_NONE, MessageType.Eos | MessageType.Error); + var msg = bus.TimedPopFiltered(Constants.CLOCK_TIME_NONE, MessageType.Eos | MessageType.Error); // Free resources - pipeline.SetState (State.Null); + pipeline.SetState(State.Null); + - } + } public static void StopAudio() { diff --git a/Sirop.Backend/Sirop.Backend.csproj b/Sirop.Backend/Sirop.Backend.csproj index a321d62..130264f 100644 --- a/Sirop.Backend/Sirop.Backend.csproj +++ b/Sirop.Backend/Sirop.Backend.csproj @@ -8,6 +8,7 @@ <ItemGroup> <PackageReference Include="gstreamer-sharp-netcore" Version="0.0.8" /> + <PackageReference Include="LiteDB" Version="5.0.10" /> </ItemGroup> </Project> |
