SystemTrayMenu/Business/App.cs

49 lines
1.6 KiB
C#
Raw Normal View History

// <copyright file="App.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace SystemTrayMenu
{
using System;
using System.Windows.Forms;
using Microsoft.Win32;
using SystemTrayMenu.Business;
using SystemTrayMenu.UserInterface;
using SystemTrayMenu.Utilities;
/// <summary>
/// App contains the notifyicon, the taskbarform and the menus.
/// </summary>
2020-05-06 12:39:38 +12:00
internal class App : IDisposable
{
private readonly AppNotifyIcon menuNotifyIcon = new AppNotifyIcon();
2020-05-14 05:14:51 +12:00
private readonly Menus menus = new Menus();
2020-05-06 12:39:38 +12:00
public App()
{
2020-03-17 09:05:52 +13:00
AppRestart.BeforeRestarting += Dispose;
SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
2020-04-30 23:22:47 +12:00
menus.LoadStarted += menuNotifyIcon.LoadingStart;
menus.LoadStopped += menuNotifyIcon.LoadingStop;
menuNotifyIcon.Exit += Application.Exit;
2020-03-17 09:05:52 +13:00
menuNotifyIcon.Restart += AppRestart.ByMenuNotifyIcon;
menuNotifyIcon.Click += () => menus.SwitchOpenClose(true);
2020-03-17 02:45:19 +13:00
menuNotifyIcon.OpenLog += Log.OpenLogFile;
2020-04-30 23:22:47 +12:00
menus.MainPreload();
}
public void Dispose()
{
SystemEvents.DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged;
menus.Dispose();
menuNotifyIcon.Dispose();
}
private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
{
if (!menus.IsOpenCloseStateOpening())
{
AppRestart.ByDisplaySettings();
}
}
}
2019-07-05 05:04:14 +12:00
}