2020-07-07 07:15:45 +12:00
|
|
|
|
// <copyright file="App.cs" company="PlaceholderCompany">
|
|
|
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
|
|
|
// </copyright>
|
2019-07-15 02:46:11 +12:00
|
|
|
|
namespace SystemTrayMenu
|
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
using System;
|
|
|
|
|
using System.Windows.Forms;
|
2020-07-08 03:05:19 +12:00
|
|
|
|
using Microsoft.Win32;
|
2020-07-07 07:15:45 +12:00
|
|
|
|
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
|
2019-07-15 02:46:11 +12:00
|
|
|
|
{
|
2020-07-07 07:15:45 +12:00
|
|
|
|
private readonly AppNotifyIcon menuNotifyIcon = new AppNotifyIcon();
|
2020-05-14 05:14:51 +12:00
|
|
|
|
private readonly Menus menus = new Menus();
|
2020-08-06 01:33:45 +12:00
|
|
|
|
private readonly TaskbarForm taskbarForm = null;
|
2020-03-16 04:06:18 +13:00
|
|
|
|
|
2020-05-06 12:39:38 +12:00
|
|
|
|
public App()
|
2019-07-15 02:46:11 +12:00
|
|
|
|
{
|
2020-03-17 09:05:52 +13:00
|
|
|
|
AppRestart.BeforeRestarting += Dispose;
|
|
|
|
|
SystemEvents.DisplaySettingsChanged += AppRestart.ByDisplaySettings;
|
2020-04-30 23:22:47 +12:00
|
|
|
|
menus.LoadStarted += menuNotifyIcon.LoadingStart;
|
|
|
|
|
menus.LoadStopped += menuNotifyIcon.LoadingStop;
|
2020-03-24 00:24:16 +13:00
|
|
|
|
menuNotifyIcon.Exit += Application.Exit;
|
2020-03-17 09:05:52 +13:00
|
|
|
|
menuNotifyIcon.Restart += AppRestart.ByMenuNotifyIcon;
|
2020-05-01 22:41:35 +12:00
|
|
|
|
menuNotifyIcon.Click += MenuNotifyIcon_Click;
|
2020-05-14 05:14:51 +12:00
|
|
|
|
void 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();
|
2020-08-06 01:33:45 +12:00
|
|
|
|
if (!Properties.Settings.Default.HideTaskbarForm)
|
2020-07-07 07:15:45 +12:00
|
|
|
|
{
|
2020-08-06 01:33:45 +12:00
|
|
|
|
taskbarForm = new TaskbarForm();
|
|
|
|
|
taskbarForm.Activated += TasbkarItemActivated;
|
|
|
|
|
void TasbkarItemActivated(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SetStateNormal();
|
|
|
|
|
taskbarForm.Activate();
|
|
|
|
|
taskbarForm.Focus();
|
|
|
|
|
menus.SwitchOpenCloseByTaskbarItem();
|
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
|
2020-08-06 01:33:45 +12:00
|
|
|
|
taskbarForm.Resize += TaskbarForm_Resize;
|
|
|
|
|
taskbarForm.FormClosed += TaskbarForm_FormClosed;
|
|
|
|
|
static void TaskbarForm_FormClosed(object sender, FormClosedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Application.Exit();
|
|
|
|
|
}
|
2020-06-29 01:57:40 +12:00
|
|
|
|
|
2020-08-06 01:33:45 +12:00
|
|
|
|
taskbarForm.Deactivate += TaskbarForm_Deactivate;
|
|
|
|
|
void TaskbarForm_Resize(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
SetStateNormal();
|
|
|
|
|
}
|
2020-07-07 07:15:45 +12:00
|
|
|
|
}
|
2020-06-27 21:01:12 +12:00
|
|
|
|
|
2020-07-07 07:15:45 +12:00
|
|
|
|
DllImports.NativeMethods.User32ShowInactiveTopmost(taskbarForm);
|
2019-07-15 02:46:11 +12:00
|
|
|
|
}
|
2020-06-29 06:20:19 +12:00
|
|
|
|
|
2020-07-08 03:05:19 +12:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2020-08-06 01:33:45 +12:00
|
|
|
|
taskbarForm?.Dispose();
|
2020-07-08 03:05:19 +12:00
|
|
|
|
menus.Dispose();
|
|
|
|
|
menuNotifyIcon.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-29 05:06:44 +12:00
|
|
|
|
private void TaskbarForm_Deactivate(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-06-29 06:20:19 +12:00
|
|
|
|
SetStateNormal();
|
2020-06-29 05:06:44 +12:00
|
|
|
|
}
|
2020-03-09 01:21:15 +13:00
|
|
|
|
|
2020-06-29 06:20:19 +12:00
|
|
|
|
/// <summary>
|
2020-07-07 07:15:45 +12:00
|
|
|
|
/// This ensures that next click on taskbaritem works as activate event/click event.
|
2020-06-29 06:20:19 +12:00
|
|
|
|
/// </summary>
|
|
|
|
|
private void SetStateNormal()
|
|
|
|
|
{
|
|
|
|
|
if (Form.ActiveForm == taskbarForm)
|
|
|
|
|
{
|
|
|
|
|
taskbarForm.WindowState = FormWindowState.Normal;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-15 02:46:11 +12:00
|
|
|
|
}
|
2019-07-05 05:04:14 +12:00
|
|
|
|
}
|