Initial commit.
This commit is contained in:
127
Wino.Mail/Views/Settings/AboutPage.xaml
Normal file
127
Wino.Mail/Views/Settings/AboutPage.xaml
Normal file
File diff suppressed because one or more lines are too long
12
Wino.Mail/Views/Settings/AboutPage.xaml.cs
Normal file
12
Wino.Mail/Views/Settings/AboutPage.xaml.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Wino.Views.Abstract;
|
||||
|
||||
namespace Wino.Views.Settings
|
||||
{
|
||||
public sealed partial class AboutPage : AboutPageAbstract
|
||||
{
|
||||
public AboutPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
105
Wino.Mail/Views/Settings/MessageListPage.xaml
Normal file
105
Wino.Mail/Views/Settings/MessageListPage.xaml
Normal file
File diff suppressed because one or more lines are too long
12
Wino.Mail/Views/Settings/MessageListPage.xaml.cs
Normal file
12
Wino.Mail/Views/Settings/MessageListPage.xaml.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Wino.Views.Abstract;
|
||||
|
||||
namespace Wino.Views.Settings
|
||||
{
|
||||
public sealed partial class MessageListPage : MessageListPageAbstract
|
||||
{
|
||||
public MessageListPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
306
Wino.Mail/Views/Settings/PersonalizationPage.xaml
Normal file
306
Wino.Mail/Views/Settings/PersonalizationPage.xaml
Normal file
File diff suppressed because one or more lines are too long
12
Wino.Mail/Views/Settings/PersonalizationPage.xaml.cs
Normal file
12
Wino.Mail/Views/Settings/PersonalizationPage.xaml.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Wino.Views.Abstract;
|
||||
|
||||
namespace Wino.Views.Settings
|
||||
{
|
||||
public sealed partial class PersonalizationPage : PersonalizationPageAbstract
|
||||
{
|
||||
public PersonalizationPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
115
Wino.Mail/Views/Settings/ReadingPanePage.xaml
Normal file
115
Wino.Mail/Views/Settings/ReadingPanePage.xaml
Normal file
File diff suppressed because one or more lines are too long
12
Wino.Mail/Views/Settings/ReadingPanePage.xaml.cs
Normal file
12
Wino.Mail/Views/Settings/ReadingPanePage.xaml.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Wino.Views.Abstract;
|
||||
|
||||
namespace Wino.Views.Settings
|
||||
{
|
||||
public sealed partial class ReadingPanePage : ReadingPanePageAbstract
|
||||
{
|
||||
public ReadingPanePage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
97
Wino.Mail/Views/Settings/SettingOptionsPage.xaml
Normal file
97
Wino.Mail/Views/Settings/SettingOptionsPage.xaml
Normal file
File diff suppressed because one or more lines are too long
19
Wino.Mail/Views/Settings/SettingOptionsPage.xaml.cs
Normal file
19
Wino.Mail/Views/Settings/SettingOptionsPage.xaml.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Wino.Views.Abstract;
|
||||
|
||||
namespace Wino.Views.Settings
|
||||
{
|
||||
public sealed partial class SettingOptionsPage : SettingOptionsPageAbstract
|
||||
{
|
||||
public SettingOptionsPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public override void OnLanguageChanged()
|
||||
{
|
||||
base.OnLanguageChanged();
|
||||
|
||||
Bindings.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
284
Wino.Mail/Views/Settings/SignatureManagementPage.xaml
Normal file
284
Wino.Mail/Views/Settings/SignatureManagementPage.xaml
Normal file
@@ -0,0 +1,284 @@
|
||||
<abstract:SignatureManagementPageAbstract
|
||||
x:Class="Wino.Views.Settings.SignatureManagementPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:abstract="using:Wino.Views.Abstract"
|
||||
xmlns:helpers="using:Wino.Helpers"
|
||||
xmlns:domain="using:Wino.Core.Domain"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
|
||||
xmlns:controls="using:Wino.Controls"
|
||||
xmlns:controls1="using:CommunityToolkit.WinUI.Controls"
|
||||
xmlns:reader="using:Wino.Core.Domain.Models.Reader"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid RowSpacing="12">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Wino Pivot -->
|
||||
<controls:WinoPivotControl
|
||||
IsEnabled="{x:Bind ViewModel.IsSignatureEnabled, Mode=OneWay}"
|
||||
ItemsSource="{x:Bind ViewModel.ToolbarSections}"
|
||||
SelectedItem="{x:Bind ViewModel.SelectedToolbarSection, Mode=TwoWay}"
|
||||
SelectorPipeColor="{ThemeResource NavigationViewSelectionIndicatorForeground}">
|
||||
<controls:WinoPivotControl.DataTemplate>
|
||||
<DataTemplate x:DataType="reader:EditorToolbarSection">
|
||||
<TextBlock Text="{x:Bind Title}" />
|
||||
</DataTemplate>
|
||||
</controls:WinoPivotControl.DataTemplate>
|
||||
</controls:WinoPivotControl>
|
||||
|
||||
<StackPanel
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center"
|
||||
Spacing="12"
|
||||
Orientation="Horizontal">
|
||||
<Button Content="{x:Bind domain:Translator.Buttons_Save}" Command="{x:Bind ViewModel.SaveSignatureCommand}" />
|
||||
<ToggleButton Content="{x:Bind domain:Translator.SettingsEnableSignature}" IsChecked="{x:Bind ViewModel.IsSignatureEnabled, Mode=TwoWay}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- Editor Options -->
|
||||
<ScrollViewer
|
||||
Grid.Row="1"
|
||||
VerticalAlignment="Top"
|
||||
IsEnabled="{x:Bind ViewModel.IsSignatureEnabled, Mode=OneWay}"
|
||||
VerticalScrollMode="Disabled"
|
||||
HorizontalScrollBarVisibility="Hidden"
|
||||
HorizontalScrollMode="Enabled">
|
||||
<Grid Padding="8,0">
|
||||
<!-- Format Panel -->
|
||||
<Grid x:Name="FormatPanel" Visibility="{x:Bind helpers:XamlHelpers.IsFormatSection(ViewModel.SelectedToolbarSection), Mode=OneWay}">
|
||||
<StackPanel Orientation="Horizontal" Spacing="12">
|
||||
<ToggleButton
|
||||
x:Name="BoldButton"
|
||||
Height="32"
|
||||
Click="BoldButtonClicked">
|
||||
<ToggleButton.Content>
|
||||
<Viewbox Width="16">
|
||||
<PathIcon Data="{StaticResource BoldPathIcon}" />
|
||||
</Viewbox>
|
||||
</ToggleButton.Content>
|
||||
</ToggleButton>
|
||||
<ToggleButton
|
||||
x:Name="ItalicButton"
|
||||
Height="32"
|
||||
Click="ItalicButtonClicked">
|
||||
<ToggleButton.Content>
|
||||
<Viewbox Width="16">
|
||||
<PathIcon Data="{StaticResource ItalicPathIcon}" />
|
||||
</Viewbox>
|
||||
</ToggleButton.Content>
|
||||
</ToggleButton>
|
||||
<ToggleButton
|
||||
x:Name="UnderlineButton"
|
||||
Height="32"
|
||||
Click="UnderlineButtonClicked">
|
||||
<ToggleButton.Content>
|
||||
<Viewbox Width="16">
|
||||
<PathIcon Data="{StaticResource UnderlinePathIcon}" />
|
||||
</Viewbox>
|
||||
</ToggleButton.Content>
|
||||
</ToggleButton>
|
||||
<ToggleButton
|
||||
x:Name="StrokeButton"
|
||||
Height="32"
|
||||
Click="StrokeButtonClicked">
|
||||
<ToggleButton.Content>
|
||||
<Viewbox Width="16">
|
||||
<PathIcon Data="{StaticResource StrikePathIcon}" />
|
||||
</Viewbox>
|
||||
</ToggleButton.Content>
|
||||
</ToggleButton>
|
||||
|
||||
<AppBarSeparator />
|
||||
|
||||
<ToggleButton
|
||||
x:Name="BulletListButton"
|
||||
Height="32"
|
||||
Click="BulletListButtonClicked">
|
||||
<ToggleButton.Content>
|
||||
<Viewbox Width="16">
|
||||
<PathIcon Data="{StaticResource BulletedListPathIcon}" />
|
||||
</Viewbox>
|
||||
</ToggleButton.Content>
|
||||
</ToggleButton>
|
||||
|
||||
<ToggleButton
|
||||
x:Name="OrderedListButton"
|
||||
Height="32"
|
||||
Click="OrderedListButtonClicked">
|
||||
<ToggleButton.Content>
|
||||
<Viewbox Width="16">
|
||||
<PathIcon Data="{StaticResource OrderedListPathIcon}" />
|
||||
</Viewbox>
|
||||
</ToggleButton.Content>
|
||||
</ToggleButton>
|
||||
|
||||
<Button
|
||||
x:Name="DecreaseIndentButton"
|
||||
Height="32"
|
||||
Click="DecreaseIndentClicked">
|
||||
<Button.Content>
|
||||
<Viewbox Width="16">
|
||||
<PathIcon Data="{StaticResource DecreaseIndentPathIcon}" />
|
||||
</Viewbox>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
x:Name="IncreaseIndentButton"
|
||||
Height="32"
|
||||
Click="IncreaseIndentClicked">
|
||||
<Button.Content>
|
||||
<Viewbox Width="16">
|
||||
<PathIcon Data="{StaticResource IncreaseIndentPathIcon}" />
|
||||
</Viewbox>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
|
||||
<AppBarSeparator />
|
||||
|
||||
<ToggleButton
|
||||
x:Name="DirectionButton"
|
||||
Height="32"
|
||||
Click="DirectionButtonClicked">
|
||||
<ToggleButton.Content>
|
||||
<Viewbox Width="16">
|
||||
<PathIcon Data="{StaticResource ParagraphPathIcon}" />
|
||||
</Viewbox>
|
||||
</ToggleButton.Content>
|
||||
</ToggleButton>
|
||||
|
||||
<ComboBox
|
||||
x:Name="AlignmentListView"
|
||||
Width="120"
|
||||
Height="32"
|
||||
VerticalAlignment="Center"
|
||||
SelectionChanged="AlignmentChanged">
|
||||
<ComboBoxItem Tag="left">
|
||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||
<Viewbox Width="16">
|
||||
<PathIcon Data="{StaticResource AlignLeftPathIcon}" />
|
||||
</Viewbox>
|
||||
<TextBlock VerticalAlignment="Center" Text="{x:Bind domain:Translator.Left}" />
|
||||
</StackPanel>
|
||||
</ComboBoxItem>
|
||||
|
||||
<ComboBoxItem Tag="center">
|
||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||
<Viewbox Width="16">
|
||||
<PathIcon Data="{StaticResource AlignCenterPathIcon}" />
|
||||
</Viewbox>
|
||||
<TextBlock VerticalAlignment="Center" Text="{x:Bind domain:Translator.Center}" />
|
||||
</StackPanel>
|
||||
</ComboBoxItem>
|
||||
|
||||
<ComboBoxItem Tag="right">
|
||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||
<Viewbox Width="16">
|
||||
<PathIcon Data="{StaticResource AlignRightPathIcon}" />
|
||||
</Viewbox>
|
||||
<TextBlock VerticalAlignment="Center" Text="{x:Bind domain:Translator.Right}" />
|
||||
</StackPanel>
|
||||
</ComboBoxItem>
|
||||
|
||||
<ComboBoxItem Tag="justify">
|
||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||
<Viewbox Width="16">
|
||||
<PathIcon Data="{StaticResource AlignJustifyPathIcon}" />
|
||||
</Viewbox>
|
||||
<TextBlock VerticalAlignment="Center" Text="{x:Bind domain:Translator.Justify}" />
|
||||
</StackPanel>
|
||||
</ComboBoxItem>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- Insert Panel -->
|
||||
<Grid x:Name="InsertPanel" Visibility="{x:Bind helpers:XamlHelpers.IsInsertSection(ViewModel.SelectedToolbarSection), Mode=OneWay}">
|
||||
<StackPanel Orientation="Horizontal" Spacing="12">
|
||||
<Button
|
||||
x:Name="AddImageButton"
|
||||
Height="32"
|
||||
Click="AddImageClicked">
|
||||
<Button.Content>
|
||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||
<Viewbox Width="16" VerticalAlignment="Center">
|
||||
<PathIcon Data="{StaticResource AddPhotoPathIcon}" />
|
||||
</Viewbox>
|
||||
<TextBlock Text="{x:Bind domain:Translator.Photos}" />
|
||||
</StackPanel>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
x:Name="EmojiButton"
|
||||
Height="32"
|
||||
Click="EmojiButtonClicked">
|
||||
<Button.Content>
|
||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||
<Viewbox Width="16" VerticalAlignment="Center">
|
||||
<PathIcon Data="{StaticResource EmojiPathIcon}" />
|
||||
</Viewbox>
|
||||
<TextBlock Text="{x:Bind domain:Translator.Emoji}" />
|
||||
</StackPanel>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
x:Name="LinkButton"
|
||||
Height="32"
|
||||
Click="LinkButtonClicked">
|
||||
<Button.Flyout>
|
||||
<Flyout x:Name="HyperlinkFlyout">
|
||||
<StackPanel Width="250" Spacing="6">
|
||||
<TextBox x:Name="HyperlinkTextBox" Header="Text" />
|
||||
<TextBox
|
||||
x:Name="LinkUrlTextBox"
|
||||
Header="Link"
|
||||
PlaceholderText="https://" />
|
||||
<Button
|
||||
x:Name="AddHyperlinkButton"
|
||||
Margin="0,6"
|
||||
HorizontalAlignment="Stretch"
|
||||
Click="HyperlinkAddClicked"
|
||||
Content="{x:Bind domain:Translator.AddHyperlink}" />
|
||||
</StackPanel>
|
||||
</Flyout>
|
||||
</Button.Flyout>
|
||||
<Button.Content>
|
||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||
<Viewbox Width="16" VerticalAlignment="Center">
|
||||
<PathIcon Data="{StaticResource AddLinkPathIcon}" />
|
||||
</Viewbox>
|
||||
<TextBlock Text="Link" />
|
||||
</StackPanel>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
|
||||
<muxc:WebView2
|
||||
x:Name="Chromium"
|
||||
Grid.Row="2"
|
||||
Margin="0,0,0,250"
|
||||
BorderBrush="LightGray"
|
||||
BorderThickness="1"
|
||||
Visibility="{x:Bind ViewModel.IsSignatureEnabled, Mode=OneWay}" />
|
||||
</Grid>
|
||||
</abstract:SignatureManagementPageAbstract>
|
||||
319
Wino.Mail/Views/Settings/SignatureManagementPage.xaml.cs
Normal file
319
Wino.Mail/Views/Settings/SignatureManagementPage.xaml.cs
Normal file
@@ -0,0 +1,319 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using Newtonsoft.Json;
|
||||
using Windows.UI.ViewManagement.Core;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Messages.Mails;
|
||||
using Wino.Views.Abstract;
|
||||
|
||||
namespace Wino.Views.Settings
|
||||
{
|
||||
public sealed partial class SignatureManagementPage : SignatureManagementPageAbstract, IRecipient<HtmlRenderingRequested>
|
||||
{
|
||||
private TaskCompletionSource<bool> DOMLoadedTask = new TaskCompletionSource<bool>();
|
||||
|
||||
public bool IsComposerDarkMode
|
||||
{
|
||||
get { return (bool)GetValue(IsComposerDarkModeProperty); }
|
||||
set { SetValue(IsComposerDarkModeProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsComposerDarkModeProperty = DependencyProperty.Register(nameof(IsComposerDarkMode), typeof(bool), typeof(SignatureManagementPage), new PropertyMetadata(false, OnIsComposerDarkModeChanged));
|
||||
|
||||
public SignatureManagementPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
|
||||
// Environment.SetEnvironmentVariable("WEBVIEW2_DEFAULT_BACKGROUND_COLOR", "00FFFFFF");
|
||||
}
|
||||
|
||||
protected override void OnNavigatedFrom(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedFrom(e);
|
||||
|
||||
Chromium.CoreWebView2Initialized -= ChromiumInitialized;
|
||||
|
||||
if (Chromium.CoreWebView2 != null)
|
||||
{
|
||||
Chromium.CoreWebView2.DOMContentLoaded -= DOMLoaded;
|
||||
Chromium.CoreWebView2.WebMessageReceived -= ScriptMessageRecieved;
|
||||
}
|
||||
}
|
||||
|
||||
protected override async void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
|
||||
Chromium.CoreWebView2Initialized -= ChromiumInitialized;
|
||||
Chromium.CoreWebView2Initialized += ChromiumInitialized;
|
||||
|
||||
await Chromium.EnsureCoreWebView2Async();
|
||||
|
||||
ViewModel.GetHTMLBodyFunction = new Func<Task<string>>(async () =>
|
||||
{
|
||||
var quillContent = await InvokeScriptSafeAsync("GetHTMLContent();");
|
||||
|
||||
return JsonConvert.DeserializeObject<string>(quillContent);
|
||||
});
|
||||
|
||||
ViewModel.GetTextBodyFunction = new Func<Task<string>>(() => InvokeScriptSafeAsync("GetTextContent();"));
|
||||
|
||||
var underlyingThemeService = App.Current.Services.GetService<IUnderlyingThemeService>();
|
||||
|
||||
IsComposerDarkMode = underlyingThemeService.IsUnderlyingThemeDark();
|
||||
}
|
||||
|
||||
private async void HyperlinkAddClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await InvokeScriptSafeAsync($"addHyperlink('{LinkUrlTextBox.Text}')");
|
||||
|
||||
LinkUrlTextBox.Text = string.Empty;
|
||||
HyperlinkFlyout.Hide();
|
||||
}
|
||||
|
||||
private async void BoldButtonClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await InvokeScriptSafeAsync("document.getElementById('boldButton').click();");
|
||||
}
|
||||
|
||||
private async void ItalicButtonClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await InvokeScriptSafeAsync("document.getElementById('italicButton').click();");
|
||||
}
|
||||
|
||||
private async void UnderlineButtonClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await InvokeScriptSafeAsync("document.getElementById('underlineButton').click();");
|
||||
}
|
||||
|
||||
private async void StrokeButtonClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await InvokeScriptSafeAsync("document.getElementById('strikeButton').click();");
|
||||
}
|
||||
|
||||
private async void BulletListButtonClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await InvokeScriptSafeAsync("document.getElementById('bulletListButton').click();");
|
||||
}
|
||||
|
||||
private async void OrderedListButtonClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await InvokeScriptSafeAsync("document.getElementById('orderedListButton').click();");
|
||||
}
|
||||
|
||||
private async void IncreaseIndentClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await InvokeScriptSafeAsync("document.getElementById('increaseIndentButton').click();");
|
||||
}
|
||||
|
||||
private async void DecreaseIndentClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await InvokeScriptSafeAsync("document.getElementById('decreaseIndentButton').click();");
|
||||
}
|
||||
|
||||
private async void DirectionButtonClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await InvokeScriptSafeAsync("document.getElementById('directionButton').click();");
|
||||
}
|
||||
|
||||
private async void AlignmentChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
var selectedItem = AlignmentListView.SelectedItem as ComboBoxItem;
|
||||
var alignment = selectedItem.Tag.ToString();
|
||||
|
||||
switch (alignment)
|
||||
{
|
||||
case "left":
|
||||
await InvokeScriptSafeAsync("document.getElementById('ql-align-left').click();");
|
||||
break;
|
||||
case "center":
|
||||
await InvokeScriptSafeAsync("document.getElementById('ql-align-center').click();");
|
||||
break;
|
||||
case "right":
|
||||
await InvokeScriptSafeAsync("document.getElementById('ql-align-right').click();");
|
||||
break;
|
||||
case "justify":
|
||||
await InvokeScriptSafeAsync("document.getElementById('ql-align-justify').click();");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string> ExecuteScriptFunctionAsync(string functionName, params object[] parameters)
|
||||
{
|
||||
string script = functionName + "(";
|
||||
for (int i = 0; i < parameters.Length; i++)
|
||||
{
|
||||
script += JsonConvert.SerializeObject(parameters[i]);
|
||||
if (i < parameters.Length - 1)
|
||||
{
|
||||
script += ", ";
|
||||
}
|
||||
}
|
||||
script += ");";
|
||||
|
||||
return await Chromium.ExecuteScriptAsync(script);
|
||||
}
|
||||
|
||||
private async Task<string> InvokeScriptSafeAsync(string function)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await Chromium.ExecuteScriptAsync(function);
|
||||
}
|
||||
catch (Exception) { }
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private async void AddImageClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await InvokeScriptSafeAsync("document.getElementById('addImageButton').click();");
|
||||
}
|
||||
|
||||
private async Task FocusEditorAsync()
|
||||
{
|
||||
await InvokeScriptSafeAsync("quill.focus();");
|
||||
|
||||
Chromium.Focus(FocusState.Keyboard);
|
||||
Chromium.Focus(FocusState.Programmatic);
|
||||
}
|
||||
|
||||
private async void EmojiButtonClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CoreInputView.GetForCurrentView().TryShow(CoreInputViewKind.Emoji);
|
||||
|
||||
await FocusEditorAsync();
|
||||
}
|
||||
|
||||
private async Task<string> TryGetSelectedTextAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
return await Chromium.ExecuteScriptAsync("getSelectedText();");
|
||||
}
|
||||
catch (Exception) { }
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private async void LinkButtonClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Get selected text from Quill.
|
||||
|
||||
HyperlinkTextBox.Text = await TryGetSelectedTextAsync();
|
||||
}
|
||||
|
||||
private async Task UpdateEditorThemeAsync()
|
||||
{
|
||||
await DOMLoadedTask.Task;
|
||||
|
||||
if (IsComposerDarkMode)
|
||||
{
|
||||
await InvokeScriptSafeAsync("DarkReader.enable();");
|
||||
}
|
||||
else
|
||||
{
|
||||
await InvokeScriptSafeAsync("DarkReader.disable();");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RenderInternalAsync(string htmlBody)
|
||||
{
|
||||
await DOMLoadedTask.Task;
|
||||
|
||||
await UpdateEditorThemeAsync();
|
||||
|
||||
if (string.IsNullOrEmpty(htmlBody))
|
||||
{
|
||||
await ExecuteScriptFunctionAsync("RenderHTML", " ");
|
||||
}
|
||||
else
|
||||
{
|
||||
await ExecuteScriptFunctionAsync("RenderHTML", htmlBody);
|
||||
|
||||
await FocusEditorAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async void ChromiumInitialized(Microsoft.UI.Xaml.Controls.WebView2 sender, Microsoft.UI.Xaml.Controls.CoreWebView2InitializedEventArgs args)
|
||||
{
|
||||
var editorBundlePath = (await ViewModel.NativeAppService.GetQuillEditorBundlePathAsync()).Replace("full.html", string.Empty);
|
||||
|
||||
Chromium.CoreWebView2.SetVirtualHostNameToFolderMapping("app.reader", editorBundlePath, CoreWebView2HostResourceAccessKind.Allow);
|
||||
Chromium.Source = new Uri("https://app.reader/full.html");
|
||||
|
||||
Chromium.CoreWebView2.DOMContentLoaded -= DOMLoaded;
|
||||
Chromium.CoreWebView2.DOMContentLoaded += DOMLoaded;
|
||||
|
||||
Chromium.CoreWebView2.WebMessageReceived -= ScriptMessageRecieved;
|
||||
Chromium.CoreWebView2.WebMessageReceived += ScriptMessageRecieved;
|
||||
}
|
||||
|
||||
private static async void OnIsComposerDarkModeChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
if (obj is ComposePage page)
|
||||
{
|
||||
await page.UpdateEditorThemeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private void ScriptMessageRecieved(CoreWebView2 sender, CoreWebView2WebMessageReceivedEventArgs args)
|
||||
{
|
||||
var change = JsonConvert.DeserializeObject<string>(args.WebMessageAsJson);
|
||||
|
||||
bool isEnabled = change.EndsWith("ql-active");
|
||||
|
||||
if (change.StartsWith("ql-bold"))
|
||||
BoldButton.IsChecked = isEnabled;
|
||||
else if (change.StartsWith("ql-italic"))
|
||||
ItalicButton.IsChecked = isEnabled;
|
||||
else if (change.StartsWith("ql-underline"))
|
||||
UnderlineButton.IsChecked = isEnabled;
|
||||
else if (change.StartsWith("ql-strike"))
|
||||
StrokeButton.IsChecked = isEnabled;
|
||||
else if (change.StartsWith("orderedListButton"))
|
||||
OrderedListButton.IsChecked = isEnabled;
|
||||
else if (change.StartsWith("bulletListButton"))
|
||||
BulletListButton.IsChecked = isEnabled;
|
||||
else if (change.StartsWith("ql-direction"))
|
||||
DirectionButton.IsChecked = isEnabled;
|
||||
else if (change.StartsWith("ql-align-left"))
|
||||
{
|
||||
AlignmentListView.SelectionChanged -= AlignmentChanged;
|
||||
AlignmentListView.SelectedIndex = 0;
|
||||
AlignmentListView.SelectionChanged += AlignmentChanged;
|
||||
}
|
||||
else if (change.StartsWith("ql-align-center"))
|
||||
{
|
||||
AlignmentListView.SelectionChanged -= AlignmentChanged;
|
||||
AlignmentListView.SelectedIndex = 1;
|
||||
AlignmentListView.SelectionChanged += AlignmentChanged;
|
||||
}
|
||||
else if (change.StartsWith("ql-align-right"))
|
||||
{
|
||||
AlignmentListView.SelectionChanged -= AlignmentChanged;
|
||||
AlignmentListView.SelectedIndex = 2;
|
||||
AlignmentListView.SelectionChanged += AlignmentChanged;
|
||||
}
|
||||
else if (change.StartsWith("ql-align-justify"))
|
||||
{
|
||||
AlignmentListView.SelectionChanged -= AlignmentChanged;
|
||||
AlignmentListView.SelectedIndex = 3;
|
||||
AlignmentListView.SelectionChanged += AlignmentChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void DOMLoaded(CoreWebView2 sender, CoreWebView2DOMContentLoadedEventArgs args) => DOMLoadedTask.TrySetResult(true);
|
||||
|
||||
public async void Receive(HtmlRenderingRequested message)
|
||||
{
|
||||
await RenderInternalAsync(message.HtmlBody);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user