-
Notifications
You must be signed in to change notification settings - Fork 528
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
99 lines (88 loc) · 3.2 KB
/
App.xaml.cs
File metadata and controls
99 lines (88 loc) · 3.2 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
99
using System;
using System.IO;
using System.Net;
using System.Reactive.Linq;
using System.Windows;
using Carnac.Logic;
using Carnac.Logic.KeyMonitor;
using Carnac.Logic.Models;
using Carnac.UI;
using Carnac.Utilities;
using SettingsProviderNet;
using Squirrel;
namespace Carnac
{
public partial class App
{
readonly SettingsProvider settingsProvider;
readonly IMessageProvider messageProvider;
readonly PopupSettings settings;
KeyShowView keyShowView;
CarnacTrayIcon trayIcon;
KeysController carnac;
#if !DEBUG
readonly string carnacUpdateUrl = "https://github.com/Code52/carnac";
#endif
public App()
{
settingsProvider = new SettingsProvider(new RoamingAppDataStorage("Carnac"));
settings = settingsProvider.GetSettings<PopupSettings>();
var keyProvider = new KeyProvider(InterceptKeys.Current, new PasswordModeService(), new DesktopLockEventService(), settingsProvider);
messageProvider = new MessageProvider(new ShortcutProvider(), keyProvider, settings);
}
protected override void OnStartup(StartupEventArgs e)
{
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
// Check if there was instance before this. If there was-close the current one.
if (ProcessUtilities.ThisProcessIsAlreadyRunning())
{
ProcessUtilities.SetFocusToPreviousInstance("Carnac");
Shutdown();
return;
}
trayIcon = new CarnacTrayIcon();
trayIcon.OpenPreferences += TrayIconOnOpenPreferences;
var keyShowViewModel = new KeyShowViewModel(settings);
keyShowView = new KeyShowView(keyShowViewModel);
keyShowView.Show();
carnac = new KeysController(keyShowViewModel.Messages, messageProvider, new ConcurrencyService(), settingsProvider);
carnac.Start();
#if !DEBUG
if (settings.AutoUpdate)
{
Observable
.Timer(TimeSpan.FromMinutes(5))
.Subscribe(async x =>
{
try
{
using (var mgr = UpdateManager.GitHubUpdateManager(carnacUpdateUrl))
{
await mgr.Result.UpdateApp();
}
}
catch
{
// Do something useful with the exception
}
});
}
#endif
base.OnStartup(e);
}
protected override void OnExit(ExitEventArgs e)
{
trayIcon.Dispose();
carnac.Dispose();
keyShowView.Dispose();
ProcessUtilities.DestroyMutex();
base.OnExit(e);
}
void TrayIconOnOpenPreferences()
{
var preferencesViewModel = new PreferencesViewModel(settingsProvider, new ScreenManager());
var preferencesView = new PreferencesView(preferencesViewModel);
preferencesView.Show();
}
}
}