-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.xaml.cs
91 lines (79 loc) · 3.1 KB
/
App.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
using DcimIngester.Windows;
using Hardcodet.Wpf.TaskbarNotification;
using System;
using System.Drawing;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace DcimIngester
{
public partial class App : Application
{
private TaskbarIcon? taskbarIcon = null;
private MainWindow? mainWindow = null;
private Settings? settingsWindow = null;
private void Application_Startup(object sender, StartupEventArgs e)
{
taskbarIcon = new()
{
ToolTipText = "DCIM Ingester",
ContextMenu = (ContextMenu)FindResource("TrayContextMenu")
};
using (Stream stream = GetResourceStream(new Uri(
"pack://application:,,,/DcimIngester;component/Icon.ico")).Stream)
{
taskbarIcon.Icon = new Icon(stream);
}
taskbarIcon.Visibility = Visibility.Visible;
// Set destination to user's pictures directory on first launch
if (DcimIngester.Properties.Settings.Default.DestDirectory.Length == 0)
{
DcimIngester.Properties.Settings.Default.DestDirectory =
Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
DcimIngester.Properties.Settings.Default.Save();
}
mainWindow = new MainWindow();
// Need to show the window to get the Loaded event to trigger
mainWindow.Show();
mainWindow.Hide();
}
private void SettingsMenuItem_Click(object sender, RoutedEventArgs e)
{
if (settingsWindow == null)
{
settingsWindow = new Settings();
settingsWindow.Closed += (sender, e) => settingsWindow = null;
settingsWindow.Show();
}
else settingsWindow.Focus();
}
private void ExitMenuItem_Click(object sender, RoutedEventArgs e)
{
if (mainWindow!.ActiveIngestCount > 0)
{
// MessageBox immediately closes without using Task
Task.Run(() =>
{
if (MessageBox.Show("There are ingests in progress. Are you sure you want to exit?",
"DCIM Ingester", MessageBoxButton.YesNo, MessageBoxImage.Exclamation, MessageBoxResult.OK,
MessageBoxOptions.DefaultDesktopOnly) == MessageBoxResult.Yes)
{
Dispatcher.Invoke(() =>
{
// Icon stays visible after shutdown (until hovered over) without this
taskbarIcon!.Visibility = Visibility.Collapsed;
Shutdown();
});
}
});
}
else
{
// Icon stays visible after shutdown (until hovered over) without this
taskbarIcon!.Visibility = Visibility.Collapsed;
Shutdown();
}
}
}
}