Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into feat/#31-2
Browse files Browse the repository at this point in the history
  • Loading branch information
herring101 committed Feb 24, 2024
2 parents 1de3c7c + 20eb8cf commit 1542959
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
34 changes: 33 additions & 1 deletion KoeBook/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using KoeBook.Core.Contracts.Services;
using KoeBook.Core.Models;
using KoeBook.Services;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Windows.Storage.Pickers;
using WinRT.Interop;
Expand All @@ -27,7 +28,14 @@ public sealed partial class MainViewModel : ObservableRecipient
[NotifyCanExecuteChangedFor(nameof(StartProcessCommand))]
private string? _ebookUrl;

private bool CanExecuteStartProcess => EbookFilePath is not null || !string.IsNullOrEmpty(EbookUrl);
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(ErrorTextVisibility))]
[NotifyPropertyChangedFor(nameof(CanExecuteStartProcess))]
private bool _ebookIsValid = true;

public Visibility ErrorTextVisibility => EbookIsValid ? Visibility.Collapsed : Visibility.Visible;

private bool CanExecuteStartProcess => EbookFilePath is not null || !string.IsNullOrEmpty(EbookUrl) && EbookIsValid;

[ObservableProperty]
private bool _skipEdit = true;
Expand Down Expand Up @@ -135,4 +143,28 @@ static async void CoreAsync(ILocalSettingsService settingsService, bool skipEdit
await settingsService.SaveSettingAsync(SkipEditSettingsKey, skipEdit);
}
}

partial void OnEbookUrlChanged(string? value)
{
EbookIsValid = IsValid(value);

static bool IsValid(string? value)
{
if (string.IsNullOrEmpty(value))
return true;
ReadOnlySpan<string> allowedOrigins = [
"https://www.aozora.gr.jp"
];

try
{
var uri = new Uri(value);
return allowedOrigins.Contains(uri.GetLeftPart(UriPartial.Authority));
}
catch (UriFormatException)
{
return false;
}
}
}
}
10 changes: 8 additions & 2 deletions KoeBook/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@
</StackPanel>-->

<StackPanel>
<TextBlock Text="青空文庫を読み上げる"/>
<TextBlock Text="Webページを読み上げる (青空文庫のみ対応)"/>
<TextBox
Text="{x:Bind ViewModel.EbookUrl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
BeforeTextChanging="{x:Bind ViewModel.BeforeTextChanging}"
Margin="{StaticResource XSmallTopMargin}" />
Margin="{StaticResource XSmallTopMargin}"
PlaceholderText="https://www.aozora.gr.jp/cards/000035/files/1567_14913.html"/>
<TextBlock
Visibility="{x:Bind ViewModel.ErrorTextVisibility, Mode=OneWay}"
Text="青空文庫のURLを入力してください"
Style="{ThemeResource CaptionTextBlockStyle}"
Foreground="{ThemeResource SystemErrorTextColor}"/>
</StackPanel>

<Button
Expand Down

0 comments on commit 1542959

Please sign in to comment.