-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
93 lines (79 loc) · 2.73 KB
/
MainWindow.xaml.cs
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
using CalendarHabitsApp.ViewModels;
using log4net;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows;
namespace CalendarHabitsApp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public MainViewModel viewModel;
public MainWindow()
{
viewModel = new MainViewModel();
viewModel.InitAsync().ContinueWith((t1) =>
{
if (viewModel.Settings.StartMinimized)
{
this.Dispatcher.Invoke(() =>
{
WindowState = WindowState.Minimized;
});
}
});
InitializeComponent();
DataContext = viewModel;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
viewModel.Save();
}
private void Window_StateChanged(object sender, EventArgs e)
{
switch (this.WindowState)
{
case WindowState.Maximized:
ShowInTaskbar = true;
break;
case WindowState.Minimized:
Hide();
ShowInTaskbar = false;
break;
case WindowState.Normal:
ShowInTaskbar = true;
break;
}
}
private void chkStartUp_Checked(object sender, RoutedEventArgs e)
{
InstallMeOnStartUp();
}
void InstallMeOnStartUp()
{
try
{
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
Assembly curAssembly = Assembly.GetExecutingAssembly();
//string appPath = curAssembly.Location.Replace(".dll", ".exe");
var process = Process.GetCurrentProcess(); // Or whatever method you are using
string appPath = process.MainModule.FileName;
//if (viewModel.Settings.StartMinimized)
//appPath += " --start-minimized";
if (chkStartUp.IsChecked.Value)
key.SetValue(curAssembly.GetName().Name, appPath);
else
key.DeleteValue(curAssembly.GetName().Name, false);
}
catch { }
}
}
}