-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
53 lines (46 loc) · 1.52 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
using System;
using System.Windows;
namespace SpotifySongTracker {
public partial class MainWindow : Window {
TrayIcon trayIcon;
SpotifyTitleWatcher spotifyTitleWatcher = new SpotifyTitleWatcher();
public MainWindow() {
InitializeComponent();
LoadedConfig.RefreshConfig();
this.SetupTrayIcon();
OutputFileManager.SetupOutputFolder();
this.spotifyTitleWatcher.SpotifyWindowTitleChange += (string title, WindowTitleChangeType type) => {
this.Dispatcher.Invoke(() => {
CurrentlyPlaying.Content = title;
});
if (type == WindowTitleChangeType.PlayingTrack) {
OutputFileManager.UpdateOutputFromNewTrackTitle(title);
this.trayIcon.ResetToDefaultText();
} else {
this.trayIcon.SetText(title);
}
};
spotifyTitleWatcher.Start();
}
protected override void OnStateChanged(EventArgs e) {
if (this.WindowState == WindowState.Minimized) {
this.Hide();
}
base.OnStateChanged(e);
}
protected void SetupTrayIcon() {
this.Hide();
this.trayIcon = new TrayIcon();
this.trayIcon.RefreshConfigMenuItemClicked += () => LoadedConfig.RefreshConfig();
this.trayIcon.ExitMenuItemClicked += () => this.Close();
this.trayIcon.ShowMenuItemClicked += () => {
this.Show();
this.WindowState = WindowState.Normal;
};
this.trayIcon.TrayIconClicked += () => {
this.Show();
this.WindowState = WindowState.Normal;
};
}
}
}