Repository navigation
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
89 lines (75 loc) · 3.16 KB
/
Copy pathApp.xaml.cs
File metadata and controls
89 lines (75 loc) · 3.16 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
using ElliePdf.Dialogs;
using ElliePdf.Services;
using ElliePdf.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Xaml;
using Microsoft.Windows.AppLifecycle;
using Windows.ApplicationModel.Activation;
using Windows.Storage;
namespace ElliePdf;
public partial class App : Application
{
public static Window Window { get; private set; } = null!;
public static Microsoft.UI.Dispatching.DispatcherQueue DispatcherQueue { get; private set; } = null!;
public static nint WindowHandle =>
WinRT.Interop.WindowNative.GetWindowHandle(Window);
public static IServiceProvider Services { get; private set; } = null!;
public App()
{
var services = new ServiceCollection();
services.AddSingleton<IUserSettingsService, UserSettingsService>();
services.AddSingleton<IPdfService, PdfService>();
services.AddSingleton<IPdfPasswordPrompt, WinUiPdfPasswordPrompt>();
services.AddSingleton<IUnsavedChangesPrompt, WinUiUnsavedChangesPrompt>();
services.AddSingleton<IDocumentOpenService, DocumentOpenService>();
services.AddSingleton<IRecentFilesService, RecentFilesService>();
services.AddSingleton<IAnnotationStore, AnnotationStore>();
services.AddSingleton<IOverlayHistory, OverlayHistory>();
services.AddSingleton<IDocumentSaveService, DocumentSaveService>();
services.AddSingleton<IEditSaveService, EditSaveService>();
services.AddSingleton<ITabCloseService, TabCloseService>();
services.AddSingleton<IDocumentTabService, DocumentTabService>();
services.AddSingleton<SettingsViewModel>();
services.AddSingleton<DocumentCollectionViewModel>();
services.AddSingleton<ReaderViewModel>();
Services = services.BuildServiceProvider();
InitializeComponent();
}
protected override async void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
var settingsService = Services.GetRequiredService<IUserSettingsService>();
await settingsService.InitializeAsync();
Window = new MainWindow();
DispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
Helpers.ThemeHelper.Apply(settingsService.Settings.AppTheme);
Window.Activate();
_ = ProcessInitialActivationAsync();
}
private static async Task ProcessInitialActivationAsync()
{
if (Window is not MainWindow mainWindow)
{
return;
}
var activation = AppInstance.GetCurrent().GetActivatedEventArgs();
if (activation.Kind != ExtendedActivationKind.File)
{
return;
}
if (activation.Data is not FileActivatedEventArgs fileArgs)
{
return;
}
var filePaths = fileArgs.Files
.OfType<StorageFile>()
.Where(file => string.Equals(file.FileType, ".pdf", StringComparison.OrdinalIgnoreCase))
.Select(file => file.Path)
.Where(path => !string.IsNullOrWhiteSpace(path))
.ToArray();
if (filePaths.Length == 0)
{
return;
}
await mainWindow.OpenFilesAsync(filePaths);
}
}