diff --git a/src/SyncClipboard.Core/AppCore.cs b/src/SyncClipboard.Core/AppCore.cs index 6529eea9..27dc0b61 100644 --- a/src/SyncClipboard.Core/AppCore.cs +++ b/src/SyncClipboard.Core/AppCore.cs @@ -190,7 +190,8 @@ public static void ConfigurateUserService(IServiceCollection services) services.AddSingleton(); services.AddSingleton(); services.AddSingleton(sp => sp.GetRequiredService()); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(sp => sp.GetRequiredService()); } private async void PrepareRemoteWorkingFolder() diff --git a/src/SyncClipboard.Core/Clipboard/ClipboardFactoryBase.cs b/src/SyncClipboard.Core/Clipboard/ClipboardFactoryBase.cs index b6fc6b6c..afe594dc 100644 --- a/src/SyncClipboard.Core/Clipboard/ClipboardFactoryBase.cs +++ b/src/SyncClipboard.Core/Clipboard/ClipboardFactoryBase.cs @@ -17,8 +17,12 @@ public abstract class ClipboardFactoryBase : IClipboardFactory, IProfileDtoHelpe protected abstract IWebDav WebDav { get; set; } public abstract Task GetMetaInfomation(CancellationToken ctk); + public Task CreateProfileFromMeta(ClipboardMetaInfomation metaInfomation, CancellationToken ctk) + { + return CreateProfileFromMeta(metaInfomation, true, ctk); + } - public async Task CreateProfileFromMeta(ClipboardMetaInfomation metaInfomation, CancellationToken ctk) + public async Task CreateProfileFromMeta(ClipboardMetaInfomation metaInfomation, bool contentControl, CancellationToken ctk) { if (metaInfomation.Files != null && metaInfomation.Files.Length >= 1) { @@ -27,24 +31,24 @@ public async Task CreateProfileFromMeta(ClipboardMetaInfomation metaInf { if (ImageHelper.FileIsImage(filename)) { - return await ImageProfile.Create(filename, ctk); + return await ImageProfile.Create(filename, contentControl, ctk); } - return await FileProfile.Create(filename, ctk); + return await FileProfile.Create(filename, contentControl, ctk); } else { - return await GroupProfile.Create(metaInfomation.Files, ctk); + return await GroupProfile.Create(metaInfomation.Files, contentControl, ctk); } } if (metaInfomation.Text != null) { - return new TextProfile(metaInfomation.Text); + return new TextProfile(metaInfomation.Text, contentControl); } if (metaInfomation.Image != null) { - return await ImageProfile.Create(metaInfomation.Image, ctk); + return await ImageProfile.Create(metaInfomation.Image, contentControl, ctk); } return new UnknownProfile(); diff --git a/src/SyncClipboard.Core/Clipboard/IClipboardFactory.cs b/src/SyncClipboard.Core/Clipboard/IClipboardFactory.cs index f46b9018..6d855ff7 100644 --- a/src/SyncClipboard.Core/Clipboard/IClipboardFactory.cs +++ b/src/SyncClipboard.Core/Clipboard/IClipboardFactory.cs @@ -6,6 +6,7 @@ public interface IClipboardFactory { Task GetMetaInfomation(CancellationToken ctk); Task CreateProfileFromMeta(ClipboardMetaInfomation metaInfomation, CancellationToken ctk); + Task CreateProfileFromMeta(ClipboardMetaInfomation metaInfomation, bool contentControl, CancellationToken ctk); Task CreateProfileFromRemote(CancellationToken cancelToken); Task CreateProfileFromLocal(CancellationToken ctk); } diff --git a/src/SyncClipboard.Core/Clipboard/Profile/FileProfile.cs b/src/SyncClipboard.Core/Clipboard/Profile/FileProfile.cs index e89d5d20..5d8cf5c7 100644 --- a/src/SyncClipboard.Core/Clipboard/Profile/FileProfile.cs +++ b/src/SyncClipboard.Core/Clipboard/Profile/FileProfile.cs @@ -6,6 +6,7 @@ using SyncClipboard.Core.Models; using SyncClipboard.Core.Models.UserConfigs; using SyncClipboard.Core.Utilities; +using SyncClipboard.Core.Utilities.Image; using System.Security.Cryptography; using System.Text; @@ -27,7 +28,8 @@ protected override IClipboardSetter ClipboardSetter private static readonly string RemoteFileFolder = Env.RemoteFileFolder; - protected FileProfile(string fullPath, string hash) : this(fullPath, Path.GetFileName(fullPath), hash) + protected FileProfile(string fullPath, string hash, bool contentControl = true) + : this(fullPath, Path.GetFileName(fullPath), hash, contentControl) { } @@ -35,17 +37,28 @@ public FileProfile(ClipboardProfileDTO profileDTO) : this(null, profileDTO.File, { } - private FileProfile(string? fullPath, string fileName, string hash) + private FileProfile(string? fullPath, string fileName, string hash, bool contentControl = true) { Hash = hash; FullPath = fullPath; FileName = fileName; + ContentControl = contentControl; } - public static async Task Create(string fullPath, CancellationToken token) + public static async Task Create(string fullPath, bool contentControl, CancellationToken token) { - var hash = await GetMD5HashFromFile(fullPath, token); - return new FileProfile(fullPath, hash); + var hash = await GetMD5HashFromFile(fullPath, contentControl, token); + if (ImageHelper.FileIsImage(fullPath)) + { + return await ImageProfile.Create(fullPath, contentControl, token); + } + + return new FileProfile(fullPath, hash, contentControl); + } + + public static Task Create(string fullPath, CancellationToken token) + { + return Create(fullPath, true, token); } protected string GetTempLocalFilePath() @@ -92,16 +105,16 @@ public override async Task BeforeSetLocal(CancellationToken cancelToken, string localPath = GetTempLocalFilePath(); await WebDav.GetFile(remotePath, localPath, progress, cancelToken); - await CheckHash(localPath, cancelToken); + await CheckHash(localPath, false, cancelToken); Logger.Write("[PULL] download OK " + localPath); FullPath = localPath; _statusTip = FileName; } - protected virtual async Task CheckHash(string localPath, CancellationToken cancelToken) + protected virtual async Task CheckHash(string localPath, bool checkSize, CancellationToken cancelToken) { - var downloadedMd5 = await GetMD5HashFromFile(localPath, cancelToken); + var downloadedMd5 = await GetMD5HashFromFile(localPath, checkSize, cancelToken); var existedMd5 = Hash; if (string.IsNullOrEmpty(existedMd5)) { @@ -148,10 +161,10 @@ protected override bool Same(Profile rhs) } } - protected async static Task GetMD5HashFromFile(string fileName, CancellationToken? cancelToken) + protected async static Task GetMD5HashFromFile(string fileName, bool checkSize, CancellationToken? cancelToken) { var fileInfo = new FileInfo(fileName); - if (fileInfo.Length > Config.GetConfig().MaxFileByte) + if (checkSize && fileInfo.Length > Config.GetConfig().MaxFileByte) { return MD5_FOR_OVERSIZED_FILE; } @@ -200,7 +213,7 @@ protected bool Oversized() public override bool IsAvailableFromRemote() => !Oversized(); - public override bool IsAvailableFromLocal() => IsFileAvailableAfterFilter(FullPath!) + public override bool IsAvailableAfterFilter() => IsFileAvailableAfterFilter(FullPath!) && !Oversized() && Config.GetConfig().EnableUploadSingleFile; protected static bool IsFileAvailableAfterFilter(string fileName) diff --git a/src/SyncClipboard.Core/Clipboard/Profile/GroupProfile.cs b/src/SyncClipboard.Core/Clipboard/Profile/GroupProfile.cs index c2cecd03..ce8d73d3 100644 --- a/src/SyncClipboard.Core/Clipboard/Profile/GroupProfile.cs +++ b/src/SyncClipboard.Core/Clipboard/Profile/GroupProfile.cs @@ -19,24 +19,34 @@ public class GroupProfile : FileProfile protected override IClipboardSetter ClipboardSetter => ServiceProvider.GetRequiredService>(); - private GroupProfile(IEnumerable files, string hash) + private GroupProfile(IEnumerable files, string hash, bool contentControl) : base(Path.Combine(LocalTemplateFolder, $"{Path.GetRandomFileName()}.zip"), hash) { _files = files.ToArray(); + ContentControl = contentControl; } public GroupProfile(ClipboardProfileDTO profileDTO) : base(profileDTO) { } - public static async Task Create(string[] files, CancellationToken token) + public static async Task Create(string[] files, bool contentControl, CancellationToken token) { - var filterdFiles = files.Where(file => IsFileAvailableAfterFilter(file)); - if (filterdFiles.Count() == 1 && File.Exists(filterdFiles.First())) - return await Create(filterdFiles.First(), token); + if (contentControl) + { + var filterdFiles = files.Where(file => IsFileAvailableAfterFilter(file)); + if (filterdFiles.Count() == 1 && File.Exists(filterdFiles.First())) + return await Create(filterdFiles.First(), contentControl, token); + + var hash = await Task.Run(() => CaclHash(filterdFiles, contentControl, token)).WaitAsync(token); + return new GroupProfile(filterdFiles, hash, contentControl); + } + else + { + var hash = await Task.Run(() => CaclHash(files, contentControl, token)).WaitAsync(token); + return new GroupProfile(files, hash, contentControl); + } - var hash = await Task.Run(() => CaclHash(filterdFiles, token)).WaitAsync(token); - return new GroupProfile(files, hash); } private static int FileCompare(FileInfo file1, FileInfo file2) @@ -56,7 +66,7 @@ private static int FileNameCompare(string file1, string file2) ); } - private static string CaclHash(IEnumerable filesEnum, CancellationToken token) + private static string CaclHash(IEnumerable filesEnum, bool contentControl, CancellationToken token) { var files = filesEnum.ToArray(); var maxSize = Config.GetConfig().MaxFileByte; @@ -75,19 +85,19 @@ private static string CaclHash(IEnumerable filesEnum, CancellationToken foreach (var subFile in subFiles) { sumSize += subFile.Length; - if (sumSize > maxSize) + if (contentControl && sumSize > maxSize) return MD5_FOR_OVERSIZED_FILE; hash = (hash * -1521134295) + (subFile.Name + subFile.Length.ToString()).ListHashCode(); } } - else if (File.Exists(file) && IsFileAvailableAfterFilter(file)) + else if (File.Exists(file) && (!contentControl || IsFileAvailableAfterFilter(file))) { var fileInfo = new FileInfo(file); sumSize += fileInfo.Length; hash = (hash * -1521134295) + (fileInfo.Name + fileInfo.Length.ToString()).ListHashCode(); } - if (sumSize > maxSize) + if (contentControl && sumSize > maxSize) { return MD5_FOR_OVERSIZED_FILE; } @@ -125,11 +135,12 @@ public Task PrepareTransferFile(CancellationToken token) zip.AddItem(path, ""); } }); - foreach (var item in zip.Entries) + + if (ContentControl) { - if (!item.IsDirectory) + foreach (var item in zip.Entries) { - if (!IsFileAvailableAfterFilter(item.FileName)) + if (!item.IsDirectory && !IsFileAvailableAfterFilter(item.FileName)) { zip.RemoveEntry(item.FileName); } @@ -170,7 +181,7 @@ protected override ClipboardMetaInfomation CreateMetaInformation() return new ClipboardMetaInfomation() { Files = _files }; } - protected override Task CheckHash(string _, CancellationToken _1) => Task.CompletedTask; + protected override Task CheckHash(string _, bool _1, CancellationToken _2) => Task.CompletedTask; protected override void SetNotification(INotification notification) { @@ -198,7 +209,7 @@ public override string ShowcaseText() return string.Join("\n", _files.Select(file => Path.GetFileName(file))); } - public override bool IsAvailableFromLocal() + public override bool IsAvailableAfterFilter() { bool hasItem = null != _files?.FirstOrDefault(name => Directory.Exists(name) || IsFileAvailableAfterFilter(name)); return hasItem && !Oversized() && Config.GetConfig().EnableUploadMultiFile; diff --git a/src/SyncClipboard.Core/Clipboard/Profile/ImageProfile.cs b/src/SyncClipboard.Core/Clipboard/Profile/ImageProfile.cs index e8924ce6..d74d3e9c 100644 --- a/src/SyncClipboard.Core/Clipboard/Profile/ImageProfile.cs +++ b/src/SyncClipboard.Core/Clipboard/Profile/ImageProfile.cs @@ -13,7 +13,8 @@ protected override IClipboardSetter ClipboardSetter private static string ImageTemplateFolder => Path.Combine(LocalTemplateFolder, "temp images"); - private ImageProfile(string fullPath, string hash) : base(fullPath, hash) + private ImageProfile(string fullPath, string hash, bool contentControl = true) + : base(fullPath, hash, contentControl) { } @@ -21,14 +22,14 @@ public ImageProfile(ClipboardProfileDTO profileDTO) : base(profileDTO) { } - public static async Task Create(IClipboardImage image, CancellationToken token) + public static async Task Create(IClipboardImage image, bool contentControl, CancellationToken token) { for (int i = 0; ; i++) { try { var fullPath = await Task.Run(() => SaveImageToFile(image)).WaitAsync(token); - return await Create(fullPath, token); + return await Create(fullPath, contentControl, token); } catch when (!token.IsCancellationRequested) { @@ -40,10 +41,15 @@ public static async Task Create(IClipboardImage image, Cancellatio } } - public static new async Task Create(string fullPath, CancellationToken token) + public static new async Task Create(string fullPath, bool contentControl, CancellationToken token) { - var hash = await GetMD5HashFromFile(fullPath, token); - return new ImageProfile(fullPath, hash); + var hash = await GetMD5HashFromFile(fullPath, contentControl, token); + return new ImageProfile(fullPath, hash, contentControl); + } + + public static new Task Create(string fullPath, CancellationToken token) + { + return Create(fullPath, true, token); } private static string SaveImageToFile(IClipboardImage image) diff --git a/src/SyncClipboard.Core/Clipboard/Profile/Profile.cs b/src/SyncClipboard.Core/Clipboard/Profile/Profile.cs index 14be3848..160ee4f5 100644 --- a/src/SyncClipboard.Core/Clipboard/Profile/Profile.cs +++ b/src/SyncClipboard.Core/Clipboard/Profile/Profile.cs @@ -57,8 +57,10 @@ public virtual Task BeforeSetLocal(CancellationToken cancelToken, return Task.CompletedTask; } + public bool ContentControl { get; set; } = true; public virtual bool IsAvailableFromRemote() => true; - public virtual bool IsAvailableFromLocal() => true; + public bool IsAvailableFromLocal() => !ContentControl || IsAvailableAfterFilter(); + public virtual bool IsAvailableAfterFilter() => true; public virtual Task EnsureAvailable(CancellationToken token) => Task.CompletedTask; diff --git a/src/SyncClipboard.Core/Clipboard/Profile/TextProfile.cs b/src/SyncClipboard.Core/Clipboard/Profile/TextProfile.cs index 500a328e..b34524ff 100644 --- a/src/SyncClipboard.Core/Clipboard/Profile/TextProfile.cs +++ b/src/SyncClipboard.Core/Clipboard/Profile/TextProfile.cs @@ -16,9 +16,10 @@ public class TextProfile : Profile protected override IClipboardSetter ClipboardSetter => ServiceProvider.GetRequiredService>(); - public TextProfile(string text) + public TextProfile(string text, bool contentControl = true) { Text = text; + ContentControl = contentControl; } public override string ToolTip() @@ -88,5 +89,5 @@ private static bool HasUrl(string str, out string? url) return false; } - public override bool IsAvailableFromLocal() => Config.GetConfig().EnableUploadText; + public override bool IsAvailableAfterFilter() => Config.GetConfig().EnableUploadText; } diff --git a/src/SyncClipboard.Core/I18n/Strings.Designer.cs b/src/SyncClipboard.Core/I18n/Strings.Designer.cs index 485a69a1..ff04b1dc 100644 --- a/src/SyncClipboard.Core/I18n/Strings.Designer.cs +++ b/src/SyncClipboard.Core/I18n/Strings.Designer.cs @@ -258,6 +258,15 @@ public static string CopyAndUpload { } } + /// + /// 查找类似 Copy And Upload without Content Control 的本地化字符串。 + /// + public static string CopyAndUploadWithoutFilter { + get { + return ResourceManager.GetString("CopyAndUploadWithoutFilter", resourceCulture); + } + } + /// /// 查找类似 Copy app data folder path to clipboard 的本地化字符串。 /// @@ -1338,6 +1347,15 @@ public static string UploadService { } } + /// + /// 查找类似 Upload without Content Control 的本地化字符串。 + /// + public static string UploadWithoutFilter { + get { + return ResourceManager.GetString("UploadWithoutFilter", resourceCulture); + } + } + /// /// 查找类似 Connect to built-in server directly without configuration 的本地化字符串。 /// diff --git a/src/SyncClipboard.Core/I18n/Strings.resx b/src/SyncClipboard.Core/I18n/Strings.resx index 3f50c289..36f46dfc 100644 --- a/src/SyncClipboard.Core/I18n/Strings.resx +++ b/src/SyncClipboard.Core/I18n/Strings.resx @@ -564,4 +564,10 @@ Sync Content Control + + Upload without Content Control + + + Copy And Upload without Content Control + \ No newline at end of file diff --git a/src/SyncClipboard.Core/I18n/Strings.zh-CN.resx b/src/SyncClipboard.Core/I18n/Strings.zh-CN.resx index 79ead402..70882899 100644 --- a/src/SyncClipboard.Core/I18n/Strings.zh-CN.resx +++ b/src/SyncClipboard.Core/I18n/Strings.zh-CN.resx @@ -564,4 +564,10 @@ 同步內容控制 + + 上传本地到远程(忽略内容控制) + + + 复制并上传本地到远程(忽略内容控制) + \ No newline at end of file diff --git a/src/SyncClipboard.Core/UserServices/SyncService/DownloadService.cs b/src/SyncClipboard.Core/UserServices/SyncService/DownloadService.cs index 428b8ee4..426dc9f9 100644 --- a/src/SyncClipboard.Core/UserServices/SyncService/DownloadService.cs +++ b/src/SyncClipboard.Core/UserServices/SyncService/DownloadService.cs @@ -26,6 +26,8 @@ public class DownloadService : Service private Profile? _remoteProfileCache; private Profile? _localProfileCache; + private bool _downServiceChangingLocal = false; + private readonly INotification _notificationManager; private readonly ILogger _logger; private readonly ConfigManager _configManager; @@ -66,12 +68,14 @@ public class DownloadService : Service () => SwitchMixedClientMode(!_serverConfig.ClientMixedMode) ), _uploadService.QuickUploadCommand, + _uploadService.QuickUploadWithoutFilterCommand, new UniqueCommand( I18n.Strings.DownloadOnce, Guid.Parse("95396FFF-E5FE-45D3-9D70-4A43FA34FF31"), QuickDownload ), _uploadService.CopyAndQuickUploadCommand, + _uploadService.CopyAndQuickUploadWithoutFilterCommand, new UniqueCommand( I18n.Strings.DownloadAndPaste, QuickDownloadAndPasteGuid, @@ -161,6 +165,13 @@ private void StopAndReload() ReLoad(); } + private void StopAndReloadByNewClipboard() + { + if (_downServiceChangingLocal) + return; + StopAndReload(); + } + private void ReLoad() { if (ClientSwitchOn) @@ -193,8 +204,8 @@ private void SwitchOnPullLoop() if (!_isPullLoopRunning) { _isPullLoopRunning = true; - _clipboardMoniter.ClipboardChanged -= StopAndReload; - _clipboardMoniter.ClipboardChanged += StopAndReload; + _clipboardMoniter.ClipboardChanged -= StopAndReloadByNewClipboard; + _clipboardMoniter.ClipboardChanged += StopAndReloadByNewClipboard; _clipboardListener.Changed -= ClipboardProfileChanged; _clipboardListener.Changed += ClipboardProfileChanged; StartPullLoop(); @@ -209,7 +220,7 @@ private void SwitchOffPullLoop() if (_isPullLoopRunning) { _isPullLoopRunning = false; - _clipboardMoniter.ClipboardChanged -= StopAndReload; + _clipboardMoniter.ClipboardChanged -= StopAndReloadByNewClipboard; _clipboardListener.Changed -= ClipboardProfileChanged; _localProfileCache = null; StopPullLoop(); @@ -217,6 +228,11 @@ private void SwitchOffPullLoop() } } + public void SetRemoteCache(Profile profile) + { + _remoteProfileCache = profile; + } + private async void StartPullLoop() { _trayIcon.SetStatusString(SERVICE_NAME, "Running."); @@ -388,11 +404,13 @@ private async Task DownloadAndSetRemoteProfileToLocal(Profile remoteProfile, Can await remoteProfile.BeforeSetLocal(cancelToken, _toastReporter); _logger.Write("end download: " + remoteProfile.Text); } + _downServiceChangingLocal = true; _messenger.Send(EmptyMessage.Instance, SyncService.PULL_START_ENENT_NAME); if (!await IsLocalProfileObsolete(cancelToken)) { await remoteProfile.SetLocalClipboard(true, cancelToken, false); + _localProfileCache = remoteProfile; _logger.Write("Success set Local clipboard with remote profile: " + remoteProfile.Text); await Task.Delay(TimeSpan.FromMilliseconds(50), cancelToken); // 设置本地剪贴板可能有延迟,延迟发送事件 } @@ -400,6 +418,7 @@ private async Task DownloadAndSetRemoteProfileToLocal(Profile remoteProfile, Can finally { _trayIcon.StopAnimation(); + _downServiceChangingLocal = false; _messenger.Send(remoteProfile, SyncService.PULL_STOP_ENENT_NAME); } } diff --git a/src/SyncClipboard.Core/UserServices/SyncService/UploadService.cs b/src/SyncClipboard.Core/UserServices/SyncService/UploadService.cs index 80b66133..710e77e4 100644 --- a/src/SyncClipboard.Core/UserServices/SyncService/UploadService.cs +++ b/src/SyncClipboard.Core/UserServices/SyncService/UploadService.cs @@ -18,16 +18,29 @@ public class UploadService : ClipboardHander public event ProgramEvent.ProgramEventHandler? PushStarted; public event ProgramEvent.ProgramEventHandler? PushStopped; + private static readonly Guid QuickUploadGuid = Guid.Parse("D0EDB9A4-3409-4A76-BC2B-4C0CD80DD850"); private static readonly Guid CopyAndQuickUploadGuid = Guid.Parse("D13672E9-D14C-4D48-847E-10B030F4B608"); + private static readonly Guid QuickUploadWithoutFilterGuid = Guid.Parse("6C5314DF-B504-25EA-074D-396E5C69BAF1"); + private static readonly Guid CopyAndQuickUploadWithoutFilterGuid = Guid.Parse("40E0B462-FCED-C4CD-7126-1F5204443DC1"); public UniqueCommand QuickUploadCommand => new UniqueCommand( I18n.Strings.UploadOnce, - Guid.Parse("D0EDB9A4-3409-4A76-BC2B-4C0CD80DD850"), - QuickUpload + QuickUploadGuid, + QuickUploadWithContentControl ); public UniqueCommand CopyAndQuickUploadCommand => new UniqueCommand( I18n.Strings.CopyAndUpload, CopyAndQuickUploadGuid, - CopyAndQuickUpload + CopyAndQuickUploadWithContentControl + ); + public UniqueCommand QuickUploadWithoutFilterCommand => new UniqueCommand( + I18n.Strings.UploadWithoutFilter, + QuickUploadWithoutFilterGuid, + QuickUploadIgnoreContentControl + ); + public UniqueCommand CopyAndQuickUploadWithoutFilterCommand => new UniqueCommand( + I18n.Strings.CopyAndUploadWithoutFilter, + CopyAndQuickUploadWithoutFilterGuid, + CopyAndQuickUploadIgnoreContentControl ); private readonly static string SERVICE_NAME_SIMPLE = I18n.Strings.UploadService; @@ -54,6 +67,7 @@ protected override bool SwitchOn private bool _downServiceChangingLocal = false; private Profile? _profileCache; + private DownloadService DownloadService { get; set; } = null!; private readonly INotification _notificationManager; private readonly ILogger _logger; @@ -105,6 +119,7 @@ public override void Load() protected override void StartService() { + DownloadService = _serviceProvider.GetRequiredService(); base.StartService(); } @@ -191,12 +206,8 @@ private async Task IsObsoleteMeta(ClipboardMetaInfomation meta, Cancellati protected override async Task HandleClipboard(ClipboardMetaInfomation meta, Profile profile, CancellationToken token) { _logger.Write(LOG_TAG, "New Push started, meta: " + meta); - PushStarted?.Invoke(); - using var guard = new ScopeGuard(() => - { - _logger.Write(LOG_TAG, "Push End"); - PushStopped?.Invoke(); - }); + + using var endLogGuard = new ScopeGuard(() => _logger.Write(LOG_TAG, "Push End")); await SyncService.remoteProfilemutex.WaitAsync(token); try @@ -216,6 +227,8 @@ protected override async Task HandleClipboard(ClipboardMetaInfomation meta, Prof SetWorkingStartStatus(); using var workingStatusGuard = new ScopeGuard(SetWorkingEndStatus); await UploadClipboard(profile, token); + DownloadService.SetRemoteCache(profile); + _profileCache = profile; } catch (OperationCanceledException) { @@ -235,6 +248,9 @@ private async Task UploadClipboard(Profile currentProfile, CancellationToken can return; } + PushStarted?.Invoke(); + using var eventGuard = new ScopeGuard(() => PushStopped?.Invoke()); + await UploadLoop(currentProfile, cancelToken); } @@ -293,13 +309,13 @@ private async Task CleanServerTempFile(CancellationToken cancelToken) } } - private async void QuickUpload() + private async void QuickUpload(bool contentControl) { var token = StopPreviousAndGetNewToken(); try { var meta = await _clipboardFactory.GetMetaInfomation(token); - var profile = await _clipboardFactory.CreateProfileFromMeta(meta, token); + var profile = await _clipboardFactory.CreateProfileFromMeta(meta, contentControl, token); await HandleClipboard(meta, profile, token); if (NotifyOnManualUpload) _notificationManager.SendTemporary( @@ -309,10 +325,17 @@ private async void QuickUpload() } ); } - catch { } + catch (Exception ex) + { + if (NotifyOnManualUpload) + _notificationManager.SendTemporary(new NotificationPara("Failed to upload manually", ex.Message)); + } } - private async void CopyAndQuickUpload() + private void QuickUploadWithContentControl() => QuickUpload(true); + private void QuickUploadIgnoreContentControl() => QuickUpload(false); + + private async void CopyAndQuickUpload(bool contentControl) { await Task.Run(() => { @@ -330,6 +353,9 @@ await Task.Run(() => _keyEventSimulator.SimulateKeyRelease(modifier); }); await Task.Delay(200); - QuickUpload(); + QuickUpload(contentControl); } + + private void CopyAndQuickUploadWithContentControl() => CopyAndQuickUpload(true); + private void CopyAndQuickUploadIgnoreContentControl() => CopyAndQuickUpload(false); } \ No newline at end of file