2022-10-23 11:02:31 +13:00
|
|
|
|
// <copyright file="App.xaml.cs" company="PlaceholderCompany">
|
|
|
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
|
|
|
// </copyright>
|
|
|
|
|
|
|
|
|
|
namespace SystemTrayMenu
|
|
|
|
|
{
|
|
|
|
|
using System;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Threading;
|
|
|
|
|
using SystemTrayMenu.Business;
|
2023-05-19 07:25:03 +12:00
|
|
|
|
using SystemTrayMenu.Helpers;
|
2023-04-17 00:17:33 +12:00
|
|
|
|
using SystemTrayMenu.Helpers.Updater;
|
2022-10-23 11:02:31 +13:00
|
|
|
|
using SystemTrayMenu.Properties;
|
|
|
|
|
using SystemTrayMenu.Utilities;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// App contains the notifyicon, the taskbarform and the menus.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class App : Application, IDisposable
|
|
|
|
|
{
|
|
|
|
|
private readonly Menus menus = new();
|
2023-05-19 07:25:03 +12:00
|
|
|
|
private JoystickHelper? joystickHelper;
|
2022-10-23 11:02:31 +13:00
|
|
|
|
private bool isDisposed;
|
|
|
|
|
|
|
|
|
|
public App()
|
|
|
|
|
{
|
|
|
|
|
AppRestart.BeforeRestarting += Dispose;
|
|
|
|
|
|
2023-05-16 08:34:17 +12:00
|
|
|
|
Activated += (_, _) => IsActiveApp = true;
|
|
|
|
|
Deactivated += (_, _) => IsActiveApp = false;
|
|
|
|
|
Startup += (_, _) =>
|
2022-10-23 11:02:31 +13:00
|
|
|
|
{
|
2023-05-19 07:25:03 +12:00
|
|
|
|
menus.Startup();
|
|
|
|
|
|
|
|
|
|
if (Settings.Default.SupportGamepad)
|
2023-05-16 08:34:17 +12:00
|
|
|
|
{
|
2023-05-19 07:25:03 +12:00
|
|
|
|
joystickHelper = new();
|
|
|
|
|
joystickHelper.KeyPressed += menus.KeyPressed;
|
2023-05-16 08:34:17 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Settings.Default.CheckForUpdates)
|
|
|
|
|
{
|
|
|
|
|
_ = Dispatcher.InvokeAsync(
|
|
|
|
|
() => GitHubUpdate.ActivateNewVersionFormOrCheckForUpdates(showWhenUpToDate: false),
|
|
|
|
|
DispatcherPriority.ApplicationIdle);
|
|
|
|
|
}
|
|
|
|
|
};
|
2022-10-23 11:02:31 +13:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-16 08:34:17 +12:00
|
|
|
|
internal static bool IsActiveApp { get; private set; }
|
2022-10-23 11:02:31 +13:00
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (!isDisposed)
|
|
|
|
|
{
|
2023-05-19 07:25:03 +12:00
|
|
|
|
if (joystickHelper != null)
|
|
|
|
|
{
|
|
|
|
|
joystickHelper.KeyPressed -= menus.KeyPressed;
|
|
|
|
|
joystickHelper.Dispose();
|
|
|
|
|
}
|
2022-10-23 11:02:31 +13:00
|
|
|
|
|
|
|
|
|
menus.Dispose();
|
|
|
|
|
|
|
|
|
|
isDisposed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|