-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from BoiHanny/Dev-Master
Dev master
- Loading branch information
Showing
33 changed files
with
1,737 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Application | ||
x:Class="MagicChatboxV2.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:MagicChatboxV2"> | ||
<Application.Resources /> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System.Windows; | ||
using MagicChatboxV2.Services; | ||
using MagicChatboxV2.Helpers; | ||
using MagicChatboxV2.Extensions; | ||
using System.Reflection; | ||
using Serilog; | ||
using System.Windows.Threading; | ||
using MagicChatboxV2.UIVM.Windows; | ||
|
||
namespace MagicChatboxV2 | ||
{ | ||
public partial class App : Application | ||
{ | ||
private IServiceProvider serviceProvider; | ||
public delegate PrimaryInterface PrimaryInterfaceFactory(); | ||
|
||
|
||
public App() | ||
{ | ||
// Configure the logger | ||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.WriteTo.Console() | ||
.WriteTo.File("logs/application.log", rollingInterval: RollingInterval.Day) | ||
.CreateLogger(); | ||
|
||
// Set the shutdown mode to explicit | ||
Current.ShutdownMode = ShutdownMode.OnExplicitShutdown; | ||
|
||
// Handle unhandled exceptions in the Dispatcher | ||
DispatcherUnhandledException += App_DispatcherUnhandledException; | ||
|
||
// Handle unhandled exceptions in the AppDomain | ||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; | ||
} | ||
|
||
// Handler for unhandled exceptions in the Dispatcher | ||
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) | ||
{ | ||
// Log the exception | ||
Log.Error(e.Exception, "An unhandled Dispatcher exception occurred"); | ||
|
||
// Show a custom error dialog with the exception details | ||
var errorDialog = new CustomErrorDialog(e.Exception.Message, e.Exception.StackTrace); | ||
errorDialog.ShowDialog(); | ||
|
||
// Mark the exception as handled | ||
e.Handled = true; | ||
} | ||
|
||
// Handler for unhandled exceptions in the AppDomain | ||
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) | ||
{ | ||
// Log the exception | ||
Log.Error((Exception)e.ExceptionObject, "An unhandled Domain exception occurred"); | ||
|
||
// Show a custom error dialog with the exception details | ||
var errorDialog = new CustomErrorDialog(((Exception)e.ExceptionObject).Message, ((Exception)e.ExceptionObject).StackTrace); | ||
errorDialog.ShowDialog(); | ||
} | ||
|
||
// Configure and build the service provider | ||
private IServiceProvider ConfigureServices() | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
// Register services and modules as before | ||
services.AddSingleton<VRChatMonitorService>(); | ||
services.AddSingleton<SystemTrayService>(); | ||
services.AddSingleton<StartupHelper>(); | ||
services.AddModules(Assembly.GetExecutingAssembly()); | ||
|
||
|
||
|
||
// Register ModuleManagerService | ||
services.AddSingleton<ModuleManagerService>(); | ||
|
||
services.AddSingleton<PrimaryInterface>(); | ||
services.AddSingleton<PrimaryInterfaceFactory>(serviceProvider => () => serviceProvider.GetRequiredService<PrimaryInterface>()); | ||
|
||
|
||
return services.BuildServiceProvider(); | ||
} | ||
|
||
|
||
protected override void OnStartup(StartupEventArgs e) | ||
{ | ||
base.OnStartup(e); | ||
serviceProvider = ConfigureServices(); | ||
|
||
// Get the StartupHelper service from the service provider | ||
var startupHelper = serviceProvider.GetService<StartupHelper>(); | ||
|
||
// Start the application logic using the StartupHelper | ||
startupHelper?.Start(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Windows; | ||
|
||
[assembly: ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System.Reflection; | ||
|
||
namespace MagicChatboxV2.Extensions | ||
{ | ||
public static class ServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddModules(this IServiceCollection services, Assembly assembly) | ||
{ | ||
// Find all types in the assembly that implement IModule and are class types | ||
var moduleTypes = assembly.GetTypes() | ||
.Where(t => typeof(UIVM.Models.IModule).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract); | ||
|
||
// Register each found module type with the services collection | ||
foreach (var type in moduleTypes) | ||
{ | ||
services.AddTransient(typeof(UIVM.Models.IModule), type); | ||
} | ||
|
||
return services; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using MagicChatboxV2.Services; | ||
using MagicChatboxV2.UIVM.Windows; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Serilog; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using static MagicChatboxV2.App; | ||
|
||
namespace MagicChatboxV2.Helpers | ||
{ | ||
public class StartupHelper | ||
{ | ||
private readonly IServiceProvider serviceProvider; | ||
private readonly PrimaryInterfaceFactory _mainWindowFactory; | ||
private LoadingWindow loadingWindow; | ||
|
||
public StartupHelper(IServiceProvider serviceProvider, PrimaryInterfaceFactory mainWindowFactory) | ||
{ | ||
this.serviceProvider = serviceProvider; | ||
this._mainWindowFactory = mainWindowFactory; | ||
} | ||
|
||
// Start method to initiate the startup process | ||
public void Start() | ||
{ | ||
try | ||
{ | ||
ShowLoadingWindow(); | ||
InitializeServices(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Error(ex, "Error during service initialization"); | ||
MessageBox.Show($"Failed to initialize services: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); | ||
CloseLoadingWindow(); | ||
Application.Current.Shutdown(); | ||
return; | ||
} | ||
|
||
CloseLoadingWindow(); | ||
|
||
try | ||
{ | ||
var vrChatService = serviceProvider.GetService<VRChatMonitorService>(); | ||
vrChatService.OnVRChatStarted += OnVRChatStarted; | ||
vrChatService.StartMonitoring(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Error(ex, "Failed to start VRChat monitoring"); | ||
MessageBox.Show($"Failed to start VRChat monitoring: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); | ||
|
||
} | ||
} | ||
|
||
// Show the loading window | ||
private void ShowLoadingWindow() | ||
{ | ||
Application.Current.Dispatcher.Invoke(() => | ||
{ | ||
loadingWindow = new LoadingWindow(); | ||
loadingWindow.Show(); | ||
}); | ||
} | ||
|
||
// Initialize the services | ||
private void InitializeServices() | ||
{ | ||
UpdateProgress(0, "Initializing System Tray..."); | ||
var trayService = serviceProvider.GetService<SystemTrayService>(); | ||
trayService.InitializeTrayIcon(); | ||
UpdateProgress(50, "System Tray Initialized."); | ||
|
||
UpdateProgress(100, "Initialization Complete."); | ||
} | ||
|
||
// Update the progress of the loading window | ||
private void UpdateProgress(double progress, string status) | ||
{ | ||
Application.Current.Dispatcher.Invoke(() => | ||
{ | ||
loadingWindow.UpdateProgress(progress, status); | ||
}); | ||
} | ||
|
||
// Close the loading window | ||
private void CloseLoadingWindow() | ||
{ | ||
Application.Current.Dispatcher.Invoke(() => | ||
{ | ||
loadingWindow.Close(); | ||
}); | ||
} | ||
|
||
// Event handler for when VRChat is started | ||
private void OnVRChatStarted() | ||
{ | ||
Application.Current.Dispatcher.Invoke(() => | ||
{ | ||
var mainWindow = _mainWindowFactory(); | ||
if (!mainWindow.IsVisible) | ||
{ | ||
mainWindow.Show(); | ||
} | ||
else | ||
{ | ||
mainWindow.Activate(); | ||
} | ||
}); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>WinExe</OutputType> | ||
<TargetFramework>net7.0-windows</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<UseWPF>true</UseWPF> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="UIVM\Images\MagicOSC_icon.png" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" /> | ||
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | ||
<PackageReference Include="Serilog" Version="3.1.1" /> | ||
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" /> | ||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Resource Include="UIVM\Images\MagicOSC_icon.png" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="UIVM\Pages\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Window | ||
x:Class="MagicChatboxV2.PrimaryInterface" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:MagicChatboxV2" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
Title="MainWindow" | ||
Width="800" | ||
Height="450" | ||
mc:Ignorable="d"> | ||
<StackPanel> | ||
<TextBlock | ||
x:Name="GetFormattedOutput" | ||
Width="200" | ||
Margin="10,10,0,0" | ||
HorizontalAlignment="Left" | ||
VerticalAlignment="Top" | ||
Text="TextBlock" | ||
TextWrapping="Wrap" /> | ||
<Button Name="GET" Click="GET_Click" Content="GET" Margin="10,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75"/> | ||
<Button Name="disposemodules" Click="disposemodules_Click" Content="Dispose Modules" Margin="10,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75"/> | ||
<Button Name="startmodules" Click="startmodules_Click" Content="Dispose Modules" Margin="10,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75"/> | ||
</StackPanel> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using MagicChatboxV2.Services; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System.ComponentModel; | ||
using System.Text; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Documents; | ||
using System.Windows.Input; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using System.Windows.Navigation; | ||
using System.Windows.Shapes; | ||
|
||
namespace MagicChatboxV2 | ||
{ | ||
/// <summary> | ||
/// Interaction logic for MainWindow.xaml | ||
/// </summary> | ||
public partial class PrimaryInterface : Window | ||
{ | ||
private readonly ModuleManagerService _moduleManagerService; | ||
|
||
// Constructor injection of ModuleManagerService | ||
public PrimaryInterface(ModuleManagerService moduleManagerService) | ||
{ | ||
InitializeComponent(); | ||
_moduleManagerService = moduleManagerService; | ||
} | ||
|
||
private void GET_Click(object sender, RoutedEventArgs e) | ||
{ | ||
// Retrieve formatted outputs from all active modules and display them | ||
var formattedOutputs = _moduleManagerService.GetFormattedOutputs(); | ||
// Assuming you want to display these outputs in a TextBlock or similar control | ||
// For demonstration, updating the Button content; adjust based on your UI design | ||
GetFormattedOutput.Text = formattedOutputs; | ||
} | ||
|
||
protected override void OnClosing(CancelEventArgs e) | ||
{ | ||
e.Cancel = true; // Cancel the closing | ||
this.Hide(); // Hide the window instead of closing it | ||
base.OnClosing(e); | ||
} | ||
|
||
private void disposemodules_Click(object sender, RoutedEventArgs e) | ||
{ | ||
_moduleManagerService.DisposeModules(); | ||
} | ||
|
||
private void startmodules_Click(object sender, RoutedEventArgs e) | ||
{ | ||
_moduleManagerService.InitializeModules(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.