TeamsNetphoneLink/TeamsNetphoneLinkWPF/App.xaml.cs
2025-03-25 22:43:13 +01:00

79 lines
2.7 KiB
C#

using Azure.Identity.Broker;
using Microsoft.Identity.Client;
using Microsoft.Identity.Client.NativeInterop;
using System;
using System.Configuration;
using System.Data;
using System.Printing;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using TeamsNetphoneLink.WPF;
using TeamsNetphoneLink.WPF.MVVM;
namespace TeamsNetphoneLink
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool AllocConsole();
public App()
{
#if DEBUG
// Konsole für Debugging-Zwecke öffnen
AllocConsole();
#endif
// Initialisierung der Anwendungskomponenten
InitializeApplication();
}
private void InitializeApplication()
{
UpdateCheck.UpgradeSettingsIfRequired();
// Erstellen der benötigten Instanzen
var TeamsLocalAPI = new Teams.TeamsLocalAPI();
var Netphone = new Netphone.NetPhoneEvents();
var TeamsGraph = new Teams.TeamsGraph();
var dashboardViewModel = new DashboardViewModel();
var LogEntries = new LogViewModel();
var finishPanelViewModel = new FinishPanelViewModel();
var latestTag = UpdateCheck.GetLatestReleaseTagAsync().GetAwaiter().GetResult();
var currentTag = UpdateCheck.GetCurrentVersion();
dashboardViewModel.VersionText = currentTag;
// Erstellen der Synchronisationsinstanz
var sync = new Syncronisation(Netphone, TeamsLocalAPI, TeamsGraph, dashboardViewModel, LogEntries, finishPanelViewModel);
// Erstellen und Anzeigen des Dashboard-Fensters
var dashboard = new WPF.DashboardWindow(sync);
dashboard.Show();
if (UpdateCheck.IsVersionLower(currentTag, latestTag))
{
UpdateCheck.UpdateAvailable = true;
dashboardViewModel.VersionText = String.Format("Version {0} verfügbar!", latestTag);
dashboardViewModel.VersionBackground = new SolidColorBrush(Colors.Orange);
// Erstellen und Anzeigen des Update-Fensters
var updateWindow = new WPF.UpdateWindow(currentTag, latestTag);
updateWindow.Show();
}
// Asynchrone Initialisierung von Netphone und TeamsLocalAPI
sync.InitializeTeamsGraphAsync();
sync.InitializeNetphoneAsync();
sync.InitializeTeamsLocalAPIAsync();
}
}
}