-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGettingStartedModelView.cs
More file actions
123 lines (103 loc) · 4.07 KB
/
Copy pathGettingStartedModelView.cs
File metadata and controls
123 lines (103 loc) · 4.07 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using ReactiveUI;
using Sextant;
using Shared.Misc;
using Shared.Services;
namespace PackageInstaller.Core.ModelViews;
public class GettingStartedModelView : ReactiveObject, IViewModel, INavigable
{
private readonly ILauncher _launcher;
private readonly Interaction<Unit, PickFileOutput> _pickFileInteraction;
private readonly IParameterViewStackService _viewStackService;
private readonly IKnownFolders _knownFolders;
private readonly IApplicationLifeCycle _lifeCycle;
public GettingStartedModelView(
ILauncher launcher,
IParameterViewStackService viewStackService,
IKnownFolders knownFolders,
IApplicationLifeCycle lifeCycle
)
{
_launcher = launcher;
_viewStackService = viewStackService;
_knownFolders = knownFolders;
_lifeCycle = lifeCycle;
_pickFileInteraction = new Interaction<Unit, PickFileOutput>(RxApp.MainThreadScheduler);
PickFilesCommand = ReactiveCommand.CreateFromTask(PickFilesAsync);
LaunchExplorerCommand = ReactiveCommand.CreateFromTask(LaunchExplorerAsync);
LaunchWithFileCommand = ReactiveCommand.CreateFromTask<string?>(LaunchWithFileAsync);
ExitCommand = ReactiveCommand.Create(() => _lifeCycle.Exit(0));
OpenDefaultAppsSettingsPageCommand = ReactiveCommand.CreateFromTask(
_launcher.LaunchDefaultAppsSettingsPageAsync
);
_userShouldCheckFileHandlerRegistrations = false;
}
private async Task LaunchWithFileAsync(string? filePath)
{
if (filePath != null)
{
var navParams = new PreparationViewModel.NavigationParameter()
{
Arguments = new[] { filePath }
};
_viewStackService
.PushPage<PreparationViewModel>(navParams.ToNavigationParameter())
.Subscribe();
}
}
private Task LaunchExplorerAsync()
{
return _launcher.LaunchFolderAsync(_knownFolders.GetPath(KnownFolder.Downloads));
}
private async Task PickFilesAsync()
{
var output = await PickFileInteraction.Handle(Unit.Default);
if (output.PickedFilePath != null)
{
var navParams = new PreparationViewModel.NavigationParameter()
{
Arguments = new[] { output.PickedFilePath }
};
_viewStackService
.PushPage<PreparationViewModel>(navParams.ToNavigationParameter())
.Subscribe();
}
}
public ReactiveCommand<Unit, Unit> PickFilesCommand { get; }
public ReactiveCommand<Unit, Unit> LaunchExplorerCommand { get; }
public ReactiveCommand<string?, Unit> LaunchWithFileCommand { get; }
public ReactiveCommand<Unit, Unit> ExitCommand { get; }
public ReactiveCommand<Unit, Unit> OpenDefaultAppsSettingsPageCommand { get; }
bool _userShouldCheckFileHandlerRegistrations;
public bool UserShouldCheckFileHandlerRegistrations
{
get { return _userShouldCheckFileHandlerRegistrations; }
private set
{
this.RaiseAndSetIfChanged(ref _userShouldCheckFileHandlerRegistrations, value);
}
}
public string Id { get; } = nameof(GettingStartedModelView);
public Interaction<Unit, PickFileOutput> PickFileInteraction => _pickFileInteraction;
public IObservable<Unit> WhenNavigatedTo(INavigationParameter parameter)
{
return Observable.Return(Unit.Default);
}
public IObservable<Unit> WhenNavigatedFrom(INavigationParameter parameter)
{
return Observable.Return(Unit.Default);
}
public IObservable<Unit> WhenNavigatingTo(INavigationParameter parameter)
{
return ProcessAsync().ToObservable(RxApp.MainThreadScheduler);
}
public async Task ProcessAsync()
{
await Task.Delay(10).ConfigureAwait(true);
UserShouldCheckFileHandlerRegistrations = !await _launcher
.VerifyThatAllFileTypeAssociationsAreRegisteredAsync()
.ConfigureAwait(true);
}
}