Repository navigation
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
64 lines (53 loc) · 1.84 KB
/
Copy pathApp.xaml.cs
File metadata and controls
64 lines (53 loc) · 1.84 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
using Microsoft.UI.Xaml;
using Lexorio.Services;
using Lexorio.ViewModels;
namespace Lexorio;
public partial class App : Application
{
private Window? _window;
private HotkeyService? _hotkeyService;
private Microsoft.UI.Dispatching.DispatcherQueueTimer? _pruneTimer;
public static MainViewModel? ViewModel { get; private set; }
public App()
{
InitializeComponent();
}
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
if (Environment.GetCommandLineArgs().Any(a => string.Equals(a, "--smoke", StringComparison.OrdinalIgnoreCase)))
{
Environment.Exit(SmokeCheck.Run());
return;
}
var settingsStore = new SettingsStore();
var historyStore = new HistoryStore();
var openAi = new OpenAiClient();
var autostart = new AutostartService();
_hotkeyService = new HotkeyService();
var dispatcher = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
var selectionCapture = new SelectionCaptureService(dispatcher);
ViewModel = new MainViewModel(
settingsStore,
historyStore,
openAi,
autostart,
selectionCapture,
_hotkeyService);
_ = historyStore.LoadAsync();
_pruneTimer = dispatcher.CreateTimer();
_pruneTimer.Interval = TimeSpan.FromHours(1);
_pruneTimer.Tick += (_, _) => historyStore.Prune();
_pruneTimer.Start();
var mainWindow = new MainWindow(ViewModel, _hotkeyService);
_window = mainWindow;
mainWindow.Activate();
if (!ViewModel.NeedsApiKey)
{
mainWindow.HideToTray();
}
else
{
ViewModel.SelectedTabIndex = 3;
}
}
}