Skip to content

Commit

Permalink
例外が発生して終了した場合、次に制限モードで起動するかを尋ねるようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
yuto-trd committed Aug 19, 2023
1 parent e9f8398 commit 88d1567
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/Beutl/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ IEnumerable<PageExtension> toAdd
_ = Dispatcher.UIThread.InvokeAsync(() => Pages.AddRange(viewModels.AsSpan()), DispatcherPriority.Background);
}

public Task RunSplachScreenTask(Func<IReadOnlyList<LocalPackage>, Task<bool>> showDialog)
public Task RunSplachScreenTask(Func<IReadOnlyList<LocalPackage>, Task<bool>> showDialog, bool restrictedMode)
{
return Task.Run(async () =>
{
Expand All @@ -394,7 +394,8 @@ public Task RunSplachScreenTask(Func<IReadOnlyList<LocalPackage>, Task<bool>> sh
LoadPrimitiveExtensions(provider, failures);
// .beutl/packages/ 内のパッケージを読み込む
LoadLocalPackages(manager, await manager.GetPackages(), failures);
if (!restrictedMode)
LoadLocalPackages(manager, await manager.GetPackages(), failures);
// .beutl/sideloads/ 内のパッケージを読み込む
if (manager.GetSideLoadPackages() is { Count: > 0 } sideloads
Expand Down
26 changes: 25 additions & 1 deletion src/Beutl/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,28 @@ protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
}
}

// 最後に実行したとき、例外が発生して終了した場合、
// 制限モード (拡張機能を読み込まない) で起動するかを尋ねる。
private async ValueTask<bool> AsksRunInRestrictedMode()
{
if (UnhandledExceptionHandler.LastExecutionExceptionWasThrown())
{
var dialog = new ContentDialog()
{
Title = Message.Looks_like_it_ended_with_an_error_last_time,
Content = Message.Ask_if_you_want_to_run_in_restricted_mode,
PrimaryButtonText = Strings.Yes,
CloseButtonText = Strings.No
};

return await dialog.ShowAsync() == ContentDialogResult.Primary;
}
else
{
return false;
}
}

private async void OnParentWindowOpened(object? sender, EventArgs e)
{
var topLevel = (TopLevel)sender!;
Expand All @@ -187,6 +209,8 @@ private async void OnParentWindowOpened(object? sender, EventArgs e)

if (DataContext is MainViewModel viewModel)
{
bool restrictedMode = await AsksRunInRestrictedMode();

Task splachScreenTask = viewModel.RunSplachScreenTask(async items =>
{
return await Dispatcher.UIThread.InvokeAsync(async () =>
Expand All @@ -205,7 +229,7 @@ private async void OnParentWindowOpened(object? sender, EventArgs e)
return await dialog.ShowAsync() == ContentDialogResult.Primary;
});
});
}, restrictedMode);

await splachScreenTask;
InitExtMenuItems(viewModel);
Expand Down

0 comments on commit 88d1567

Please sign in to comment.