From aefa631ff3f648060f5c0fe5d51aee89e3898a85 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Tue, 9 Feb 2021 22:55:40 -0500 Subject: Discord RPC; About window --- Erable/DiscordRPC.cs | 56 ++++++++++++++++++++++++++++++++ Erable/Erable.csproj | 7 ++++ Erable/Program.cs | 25 +++++++++++--- Erable/ViewModels/MainWindowViewModel.cs | 16 ++++++--- Erable/Views/About.axaml | 17 ++++++++++ Erable/Views/About.axaml.cs | 30 +++++++++++++++++ Erable/Views/MainWindow.axaml | 7 ++-- Erable/Views/MainWindow.axaml.cs | 9 ++++- Sirop.Backend/Playback.cs | 11 ++++--- Sirop.Backend/Sirop.Backend.csproj | 1 + 10 files changed, 160 insertions(+), 19 deletions(-) create mode 100644 Erable/DiscordRPC.cs create mode 100644 Erable/Views/About.axaml create mode 100644 Erable/Views/About.axaml.cs 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 @@ + + + + About.axaml + Code + + 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() 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 @@ + + + About Erable 0.1 Pre-Alpha + © Copyright 2021, Alee Productions + Licensed with GPL-3.0 + Report Bugs at https://git.io/JtrAO + + 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 @@ - + - + - + + 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 @@ + -- cgit v1.2.3