SystemTrayMenu/Business/App.cs
2020-05-06 02:39:38 +02:00

46 lines
1.5 KiB
C#

using Microsoft.Win32;
using System;
using System.Windows.Forms;
using SystemTrayMenu.Business;
using SystemTrayMenu.DataClasses;
using SystemTrayMenu.Helper;
using SystemTrayMenu.UserInterface;
using SystemTrayMenu.Utilities;
namespace SystemTrayMenu
{
internal class App : IDisposable
{
private readonly MenuNotifyIcon menuNotifyIcon = new MenuNotifyIcon();
private Menus menus = new Menus();
public App()
{
Scaling.Initialize();
FolderOptions.Initialize();
Screen screen = Screen.PrimaryScreen;
Statics.ScreenHeight = screen.Bounds.Height;
Statics.ScreenWidth = screen.Bounds.Width;
Statics.ScreenRight = screen.Bounds.Right;
Statics.TaskbarHeight = new WindowsTaskbar().Size.Height;
AppRestart.BeforeRestarting += Dispose;
SystemEvents.DisplaySettingsChanged += AppRestart.ByDisplaySettings;
menus.LoadStarted += menuNotifyIcon.LoadingStart;
menus.LoadStopped += menuNotifyIcon.LoadingStop;
menuNotifyIcon.Exit += Application.Exit;
menuNotifyIcon.Restart += AppRestart.ByMenuNotifyIcon;
menuNotifyIcon.Click += MenuNotifyIcon_Click;
void MenuNotifyIcon_Click() => menus.SwitchOpenClose(true);
menuNotifyIcon.OpenLog += Log.OpenLogFile;
menus.MainPreload();
}
public void Dispose()
{
menus.Dispose();
menuNotifyIcon.Dispose();
}
}
}