* Separation of messages. Introducing Wino.Messages library. * Wino.Server and Wino.Packaging projects. Enabling full trust for UWP and app service connection manager basics. * Remove debug code. * Enable generating assembly info to deal with unsupported os platform warnings. * Fix server-client connection. * UIMessage communication. Single instancing for server and re-connection mechanism on suspension. * Removed IWinoSynchronizerFactory from UWP project. * Removal of background task service from core. * Delegating changes to UI and triggering new background synchronization. * Fix build error. * Moved core lib messages to Messaging project. * Better client-server communication. Handling of requests in the server. New synchronizer factory in the server. * WAM broker and MSAL token caching for OutlookAuthenticator. Handling account creation for Outlook. * WinoServerResponse basics. * Delegating protocol activation for Gmail authenticator. * Adding margin to searchbox to match action bar width. * Move libraries into lib folder. * Storing base64 encoded mime on draft creation instead of MimeMessage object. Fixes serialization/deserialization issue with S.T.Json * Scrollbar adjustments * WınoExpander for thread expander layout ıssue. * Handling synchronizer state changes. * Double init on background activation. * FIxing packaging issues and new Wino Mail launcher protocol for activation from full thrust process. * Remove debug deserialization. * Remove debug code. * Making sure the server connection is established when the app is launched. * Thrust -> Trust string replacement... * Rename package to Wino Mail * Enable translated values in the server. * Fixed an issue where toast activation can't find the clicked mail after the folder is initialized. * Revert debug code. * Change server background sync to every 3 minute and Inbox only synchronization. * Revert google auth changes. * App preferences page. * Changing tray icon visibility on preference change. * Start the server with invisible tray icon if set to invisible. * Reconnect button on the title bar. * Handling of toast actions. * Enable x86 build for server during packaging. * Get rid of old background tasks and v180 migration. * Terminate client when Exit clicked in server. * Introducing SynchronizationSource to prevent notifying UI after server tick synchronization. * Remove confirmAppClose restricted capability and unused debug code in manifest. * Closing the reconnect info popup when reconnect is clicked. * Custom RetryHandler for OutlookSynchronizer and separating client/server logs. * Running server on Windows startup. * Fix startup exe. * Fix for expander list view item paddings. * Force full sync on app launch instead of Inbox. * Fix draft creation. * Fix an issue with custom folder sync logic. * Reporting back account sync progress from server. * Fix sending drafts and missing notifications for imap. * Changing imap folder sync requirements. * Retain file count is set to 3. * Disabled swipe gestures temporarily due to native crash with SwipeControl * Save all attachments implementation. * Localization for save all attachments button. * Fix logging dates for logs. * Fixing ARM64 build. * Add ARM64 build config to packaging project. * Comment out OutOfProcPDB for ARM64. * Hnadling GONE response for Outlook folder synchronization.
387 lines
14 KiB
C#
387 lines
14 KiB
C#
using System;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
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 Wino.Core.Domain;
|
|
using Wino.Core.Domain.Entities;
|
|
using Wino.Core.Domain.Interfaces;
|
|
using Wino.Core.Domain.Models.Reader;
|
|
using Wino.Views.Settings;
|
|
|
|
namespace Wino.Dialogs
|
|
{
|
|
public sealed partial class SignatureEditorDialog : ContentDialog
|
|
{
|
|
private Func<Task<string>> _getHTMLBodyFunction;
|
|
private readonly TaskCompletionSource<bool> _domLoadedTask = new TaskCompletionSource<bool>();
|
|
|
|
private readonly INativeAppService _nativeAppService = App.Current.Services.GetService<INativeAppService>();
|
|
private readonly IFontService _fontService = App.Current.Services.GetService<IFontService>();
|
|
private readonly IPreferencesService _preferencesService = App.Current.Services.GetService<IPreferencesService>();
|
|
|
|
public AccountSignature Result;
|
|
|
|
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 SignatureEditorDialog()
|
|
{
|
|
InitializeComponent();
|
|
|
|
SignatureNameTextBox.Header = Translator.SignatureEditorDialog_SignatureName_TitleNew;
|
|
Environment.SetEnvironmentVariable("WEBVIEW2_DEFAULT_BACKGROUND_COLOR", "00FFFFFF");
|
|
Environment.SetEnvironmentVariable("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "--enable-features=OverlayScrollbar,msOverlayScrollbarWinStyle,msOverlayScrollbarWinStyleAnimation,FontAccess");
|
|
|
|
// TODO: Should be added additional logic to enable/disable primary button when webview content changed.
|
|
IsPrimaryButtonEnabled = true;
|
|
}
|
|
|
|
public SignatureEditorDialog(AccountSignature signatureModel)
|
|
{
|
|
InitializeComponent();
|
|
|
|
SignatureNameTextBox.Text = signatureModel.Name.Trim();
|
|
SignatureNameTextBox.Header = string.Format(Translator.SignatureEditorDialog_SignatureName_TitleEdit, signatureModel.Name);
|
|
|
|
Result = new AccountSignature
|
|
{
|
|
Id = signatureModel.Id,
|
|
Name = signatureModel.Name,
|
|
MailAccountId = signatureModel.MailAccountId,
|
|
HtmlBody = signatureModel.HtmlBody
|
|
};
|
|
Environment.SetEnvironmentVariable("WEBVIEW2_DEFAULT_BACKGROUND_COLOR", "00FFFFFF");
|
|
Environment.SetEnvironmentVariable("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "--enable-features=OverlayScrollbar,msOverlayScrollbarWinStyle,msOverlayScrollbarWinStyleAnimation");
|
|
|
|
// TODO: Should be added additional logic to enable/disable primary button when webview content changed.
|
|
IsPrimaryButtonEnabled = true;
|
|
}
|
|
|
|
private async void SignatureDialogOpened(ContentDialog sender, ContentDialogOpenedEventArgs args)
|
|
{
|
|
Chromium.CoreWebView2Initialized -= ChromiumInitialized;
|
|
Chromium.CoreWebView2Initialized += ChromiumInitialized;
|
|
|
|
await Chromium.EnsureCoreWebView2Async();
|
|
|
|
_getHTMLBodyFunction = new Func<Task<string>>(async () =>
|
|
{
|
|
var editorContent = await InvokeScriptSafeAsync("GetHTMLContent();");
|
|
|
|
return JsonConvert.DeserializeObject<string>(editorContent);
|
|
});
|
|
|
|
var underlyingThemeService = App.Current.Services.GetService<IUnderlyingThemeService>();
|
|
|
|
IsComposerDarkMode = underlyingThemeService.IsUnderlyingThemeDark();
|
|
|
|
await RenderInternalAsync(Result?.HtmlBody ?? string.Empty);
|
|
}
|
|
|
|
private void DialogClosed(ContentDialog sender, ContentDialogClosedEventArgs args)
|
|
{
|
|
Chromium.CoreWebView2Initialized -= ChromiumInitialized;
|
|
|
|
if (Chromium.CoreWebView2 != null)
|
|
{
|
|
Chromium.CoreWebView2.DOMContentLoaded -= DOMLoaded;
|
|
Chromium.CoreWebView2.WebMessageReceived -= ScriptMessageReceived;
|
|
}
|
|
}
|
|
|
|
private async void SaveClicked(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
|
{
|
|
var newSignature = Regex.Unescape(await _getHTMLBodyFunction());
|
|
|
|
if (Result == null)
|
|
{
|
|
Result = new AccountSignature
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
Name = SignatureNameTextBox.Text.Trim(),
|
|
HtmlBody = newSignature
|
|
};
|
|
}
|
|
else
|
|
{
|
|
Result.Name = SignatureNameTextBox.Text.Trim();
|
|
Result.HtmlBody = newSignature;
|
|
}
|
|
|
|
Hide();
|
|
}
|
|
|
|
private void CancelClicked(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
|
{
|
|
Hide();
|
|
}
|
|
|
|
private async void BoldButtonClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
await InvokeScriptSafeAsync("editor.execCommand('bold')");
|
|
}
|
|
|
|
private async void ItalicButtonClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
await InvokeScriptSafeAsync("editor.execCommand('italic')");
|
|
}
|
|
|
|
private async void UnderlineButtonClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
await InvokeScriptSafeAsync("editor.execCommand('underline')");
|
|
}
|
|
|
|
private async void StrokeButtonClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
await InvokeScriptSafeAsync("editor.execCommand('strikethrough')");
|
|
}
|
|
|
|
private async void BulletListButtonClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
await InvokeScriptSafeAsync("editor.execCommand('insertunorderedlist')");
|
|
}
|
|
|
|
private async void OrderedListButtonClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
await InvokeScriptSafeAsync("editor.execCommand('insertorderedlist')");
|
|
}
|
|
|
|
private async void IncreaseIndentClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
await InvokeScriptSafeAsync("editor.execCommand('indent')");
|
|
}
|
|
|
|
private async void DecreaseIndentClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
await InvokeScriptSafeAsync("editor.execCommand('outdent')");
|
|
}
|
|
|
|
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("editor.execCommand('justifyleft')");
|
|
break;
|
|
case "center":
|
|
await InvokeScriptSafeAsync("editor.execCommand('justifycenter')");
|
|
break;
|
|
case "right":
|
|
await InvokeScriptSafeAsync("editor.execCommand('justifyright')");
|
|
break;
|
|
case "justify":
|
|
await InvokeScriptSafeAsync("editor.execCommand('justifyfull')");
|
|
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)
|
|
{
|
|
if (Chromium == null) return string.Empty;
|
|
|
|
try
|
|
{
|
|
|
|
return await Chromium.ExecuteScriptAsync(function);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
|
|
return string.Empty;
|
|
}
|
|
|
|
private async void AddImageClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
await InvokeScriptSafeAsync("imageInput.click();");
|
|
}
|
|
|
|
private async Task FocusEditorAsync()
|
|
{
|
|
await InvokeScriptSafeAsync("editor.selection.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 { }
|
|
|
|
return string.Empty;
|
|
}
|
|
|
|
private async void WebViewToggleButtonClicked(object sender, RoutedEventArgs e)
|
|
{
|
|
var enable = WebviewToolBarButton.IsChecked == true ? "true" : "false";
|
|
await InvokeScriptSafeAsync($"toggleToolbar('{enable}');");
|
|
}
|
|
|
|
private async Task UpdateEditorThemeAsync()
|
|
{
|
|
await _domLoadedTask.Task;
|
|
|
|
if (IsComposerDarkMode)
|
|
{
|
|
Chromium.CoreWebView2.Profile.PreferredColorScheme = CoreWebView2PreferredColorScheme.Dark;
|
|
await InvokeScriptSafeAsync("SetDarkEditor();");
|
|
}
|
|
else
|
|
{
|
|
Chromium.CoreWebView2.Profile.PreferredColorScheme = CoreWebView2PreferredColorScheme.Light;
|
|
await InvokeScriptSafeAsync("SetLightEditor();");
|
|
}
|
|
}
|
|
|
|
private async Task RenderInternalAsync(string htmlBody)
|
|
{
|
|
await _domLoadedTask.Task;
|
|
|
|
await UpdateEditorThemeAsync();
|
|
await InitializeEditorAsync();
|
|
|
|
if (string.IsNullOrEmpty(htmlBody))
|
|
{
|
|
await ExecuteScriptFunctionAsync("RenderHTML", " ");
|
|
}
|
|
else
|
|
{
|
|
await ExecuteScriptFunctionAsync("RenderHTML", htmlBody);
|
|
|
|
await FocusEditorAsync();
|
|
}
|
|
}
|
|
|
|
private async Task<string> InitializeEditorAsync()
|
|
{
|
|
var fonts = _fontService.GetFonts();
|
|
var composerFont = _preferencesService.ComposerFont;
|
|
int composerFontSize = _preferencesService.ComposerFontSize;
|
|
var readerFont = _preferencesService.ReaderFont;
|
|
int readerFontSize = _preferencesService.ReaderFontSize;
|
|
return await ExecuteScriptFunctionAsync("initializeJodit", fonts, composerFont, composerFontSize, readerFont, readerFontSize);
|
|
}
|
|
|
|
private async void ChromiumInitialized(Microsoft.UI.Xaml.Controls.WebView2 sender, Microsoft.UI.Xaml.Controls.CoreWebView2InitializedEventArgs args)
|
|
{
|
|
var editorBundlePath = (await _nativeAppService.GetEditorBundlePathAsync()).Replace("editor.html", string.Empty);
|
|
|
|
Chromium.CoreWebView2.SetVirtualHostNameToFolderMapping("app.editor", editorBundlePath, CoreWebView2HostResourceAccessKind.Allow);
|
|
Chromium.Source = new Uri("https://app.editor/editor.html");
|
|
|
|
Chromium.CoreWebView2.DOMContentLoaded -= DOMLoaded;
|
|
Chromium.CoreWebView2.DOMContentLoaded += DOMLoaded;
|
|
|
|
Chromium.CoreWebView2.WebMessageReceived -= ScriptMessageReceived;
|
|
Chromium.CoreWebView2.WebMessageReceived += ScriptMessageReceived;
|
|
}
|
|
|
|
private static async void OnIsComposerDarkModeChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
|
|
{
|
|
if (obj is SignatureEditorDialog dialog)
|
|
{
|
|
await dialog.UpdateEditorThemeAsync();
|
|
}
|
|
}
|
|
|
|
private void ScriptMessageReceived(CoreWebView2 sender, CoreWebView2WebMessageReceivedEventArgs args)
|
|
{
|
|
var change = JsonConvert.DeserializeObject<WebViewMessage>(args.WebMessageAsJson);
|
|
|
|
if (change.Type == "bold")
|
|
{
|
|
BoldButton.IsChecked = change.Value == "true";
|
|
}
|
|
else if (change.Type == "italic")
|
|
{
|
|
ItalicButton.IsChecked = change.Value == "true";
|
|
}
|
|
else if (change.Type == "underline")
|
|
{
|
|
UnderlineButton.IsChecked = change.Value == "true";
|
|
}
|
|
else if (change.Type == "strikethrough")
|
|
{
|
|
StrokeButton.IsChecked = change.Value == "true";
|
|
}
|
|
else if (change.Type == "ol")
|
|
{
|
|
OrderedListButton.IsChecked = change.Value == "true";
|
|
}
|
|
else if (change.Type == "ul")
|
|
{
|
|
BulletListButton.IsChecked = change.Value == "true";
|
|
}
|
|
else if (change.Type == "indent")
|
|
{
|
|
IncreaseIndentButton.IsEnabled = change.Value == "disabled" ? false : true;
|
|
}
|
|
else if (change.Type == "outdent")
|
|
{
|
|
DecreaseIndentButton.IsEnabled = change.Value == "disabled" ? false : true;
|
|
}
|
|
else if (change.Type == "alignment")
|
|
{
|
|
var parsedValue = change.Value switch
|
|
{
|
|
"jodit-icon_left" => 0,
|
|
"jodit-icon_center" => 1,
|
|
"jodit-icon_right" => 2,
|
|
"jodit-icon_justify" => 3,
|
|
_ => 0
|
|
};
|
|
AlignmentListView.SelectionChanged -= AlignmentChanged;
|
|
AlignmentListView.SelectedIndex = parsedValue;
|
|
AlignmentListView.SelectionChanged += AlignmentChanged;
|
|
}
|
|
}
|
|
|
|
private void DOMLoaded(CoreWebView2 sender, CoreWebView2DOMContentLoadedEventArgs args) => _domLoadedTask.TrySetResult(true);
|
|
|
|
private void SignatureNameTextBoxTextChanged(object sender, TextChangedEventArgs e) => IsPrimaryButtonEnabled = !string.IsNullOrWhiteSpace(SignatureNameTextBox.Text);
|
|
|
|
private void InvertComposerThemeClicked(object sender, RoutedEventArgs e) => IsComposerDarkMode = !IsComposerDarkMode;
|
|
}
|
|
}
|