-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
98 lines (84 loc) · 3 KB
/
Copy pathApp.xaml.cs
File metadata and controls
98 lines (84 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.IO;
using System.Reflection;
using System.Windows;
using Desktoper.Lib;
using Desktoper.Services;
using System.Windows.Forms;
namespace Desktoper
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
{
internal static readonly string WorkingDir;
internal static readonly string ConfigPath;
internal const string Name = "Desktoper";
private NotifyIcon TrayIcon;
static App()
{
WorkingDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly()?.Location) ?? throw new ArgumentNullException(nameof(WorkingDir));
ConfigPath = Path.Combine(WorkingDir, "config.json");
}
public static WindowManager WindowManager { get; } = new WindowManager();
protected override void OnStartup(StartupEventArgs e)
{
this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
base.OnStartup(e);
InitConfig();
var trayMenu = new ContextMenu();
trayMenu.MenuItems.Add("Replicate apps", (sender, args) => WindowManager.ReplicateApps());
trayMenu.MenuItems.Add("Exit", (sender, args) => this.Shutdown());
TrayIcon = new NotifyIcon()
{
Text = "Desktoper",
Icon = System.Drawing.Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location),
ContextMenu = trayMenu,
Visible = true,
};
TrayIcon.DoubleClick += (sender, args) =>
{
if (this.MainWindow != null)
{
this.MainWindow.Close();
this.MainWindow = null;
Win32Window.TrimWorkingSet();
return;
}
this.MainWindow = new MainWindow();
this.MainWindow.Show();
};
}
private void InitConfig()
{
Config.Load();
WindowManager.Execute(Config.Current.IsListening);
Config.Current.PropertyChanged += (sender, args) =>
{
if(args.PropertyName != nameof(Config.Current.IsListening)) return;
WindowManager.Execute(Config.Current.IsListening);
};
if (!Config.Current.StartMinimized)
{
this.MainWindow = new MainWindow();
this.MainWindow.Show();
}
if (Config.Current.ReplicatePresetOnStartup)
{
WindowManager.ReplicateApps();
}
if (Config.Current.StartMinimized)
{
Win32Window.TrimWorkingSet();
}
}
protected override void OnExit(ExitEventArgs e)
{
Config.FlushNow();
WindowManager.Dispose();
TrayIcon.Dispose();
base.OnExit(e);
}
}
}