Skip to content

Commit

Permalink
fix share; new release
Browse files Browse the repository at this point in the history
  • Loading branch information
OpportunityLiu committed Oct 24, 2020
1 parent 6487104 commit 983042d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 44 deletions.
2 changes: 1 addition & 1 deletion ExClient/Galleries/Commenting/Comment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private Comment(CommentCollection owner, int id, HtmlNode commentNode)

var postedAndAuthorNode = commentNode.Descendants("div").First(node => node.HasClass("c3"));
Author = postedAndAuthorNode.Element("a").GetInnerText();
Posted = DateTimeOffset.ParseExact(postedAndAuthorNode.FirstChild.InnerText, "'Posted on' dd MMMM yyyy, HH:mm ' by:  '", culture, System.Globalization.DateTimeStyles.AssumeUniversal | System.Globalization.DateTimeStyles.AllowWhiteSpaces);
Posted = DateTimeOffset.ParseExact(postedAndAuthorNode.FirstChild.InnerText, "'Posted on' dd MMMM yyyy, HH:mm 'by:  '", culture, System.Globalization.DateTimeStyles.AssumeUniversal | System.Globalization.DateTimeStyles.AllowWhiteSpaces);

if (!IsUploaderComment)
{
Expand Down
87 changes: 46 additions & 41 deletions ExViewer/Helpers/ShareHandler.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using ExViewer.Views;

using Opportunity.MvvmUniverse;

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;

using Windows.ApplicationModel;
using Windows.ApplicationModel.Core;
using Windows.ApplicationModel.DataTransfer;
Expand All @@ -21,6 +24,20 @@ namespace ExViewer.Helpers
{
public static class ShareHandler
{
static ShareHandler()
{
if (!IsShareSupported)
{
return;
}
var manager = DataTransferManager.GetForCurrentView();
manager.DataRequested += _DataRequested;
if (CustomHandlers.Instance != null)
{
manager.ShareProvidersRequested += CustomHandlers.Instance.ShareProvidersRequested;
}
}

public static bool IsShareSupported => DataTransferManager.IsSupported();

public static void Share(TypedEventHandler<DataTransferManager, DataRequestedEventArgs> handler)
Expand All @@ -29,8 +46,7 @@ public static void Share(TypedEventHandler<DataTransferManager, DataRequestedEve
{
return;
}

new ShareHandlerStorage(handler);
_CurrentHandler = handler;
if (ExApiInfo.RS3)
{
DataTransferManager.ShowShareUI(new ShareUIOptions { Theme = Settings.SettingCollection.Current.Theme == Windows.UI.Xaml.ApplicationTheme.Dark ? ShareUITheme.Dark : ShareUITheme.Light });
Expand Down Expand Up @@ -128,54 +144,27 @@ public IEnumerator<IStorageItem> GetEnumerator()
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}

private class ShareHandlerStorage
{
public ShareHandlerStorage(TypedEventHandler<DataTransferManager, DataRequestedEventArgs> handler)
{
this.handler = handler;
var t = DataTransferManager.GetForCurrentView();
t.DataRequested += T_DataRequested;
if (CustomHandlers.Instance != null)
{
t.ShareProvidersRequested += T_ShareProvidersRequested;
}
}

private void T_ShareProvidersRequested(DataTransferManager sender, ShareProvidersRequestedEventArgs args)
{
sender.ShareProvidersRequested -= T_ShareProvidersRequested;

args.Providers.Add(CustomHandlers.Instance.CopyProvider);
private static TypedEventHandler<DataTransferManager, DataRequestedEventArgs> _CurrentHandler;

if (args.Data.Contains(StandardDataFormats.WebLink))
{
args.Providers.Add(CustomHandlers.Instance.OpenLinkProvider);
}

if (args.Data.Contains(StandardDataFormats.StorageItems))
{
args.Providers.Add(CustomHandlers.Instance.SetWallpaperProvider);
}
}

private readonly TypedEventHandler<DataTransferManager, DataRequestedEventArgs> handler;

private void T_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
private static void _DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
var d = args.Request.Data;
d.Properties.Title = Package.Current.DisplayName;
d.Properties.ApplicationName = Package.Current.DisplayName;
d.Properties.PackageFamilyName = Package.Current.Id.FamilyName;
if(_CurrentHandler != null)
{
sender.DataRequested -= T_DataRequested;
var d = args.Request.Data;
d.Properties.Title = Package.Current.DisplayName;
d.Properties.ApplicationName = Package.Current.DisplayName;
d.Properties.PackageFamilyName = Package.Current.Id.FamilyName;
handler?.Invoke(sender, args);
_CurrentHandler?.Invoke(sender, args);
_CurrentHandler = null;
}
}

private class CustomHandlers
{
public static CustomHandlers Instance { get; } = create();
public static CustomHandlers Instance { get; } = _Create();

private static CustomHandlers create()
private static CustomHandlers _Create()
{
if (!ExApiInfo.ShareProviderSupported)
{
Expand All @@ -184,6 +173,22 @@ private static CustomHandlers create()

return new CustomHandlers();
}

public void ShareProvidersRequested(DataTransferManager sender, ShareProvidersRequestedEventArgs args)
{
args.Providers.Add(CopyProvider);

if (args.Data.Contains(StandardDataFormats.WebLink))
{
args.Providers.Add(OpenLinkProvider);
}

if (args.Data.Contains(StandardDataFormats.StorageItems))
{
args.Providers.Add(SetWallpaperProvider);
}
}

public ShareProvider OpenLinkProvider { get; }
= new ShareProvider(Strings.Resources.Sharing.OpenInBrowser
, RandomAccessStreamReference.CreateFromUri(new Uri(@"ms-appx:///Assets/ShareTarget/MicrosoftEdge.png"))
Expand Down
2 changes: 1 addition & 1 deletion ExViewer/Package.appxmanifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" IgnorableNamespaces="uap mp uap3">
<Identity Name="2289Opportunity.E-Viewer" Publisher="CN=Opportunity" Version="2020.10.3.0" />
<Identity Name="2289Opportunity.E-Viewer" Publisher="CN=Opportunity" Version="2020.10.25.0" />
<mp:PhoneIdentity PhoneProductId="b0e97c45-19f9-4a1b-9836-fa1508c91c7e" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>ms-resource:///Resources/AppDisplayName</DisplayName>
Expand Down
2 changes: 1 addition & 1 deletion ExViewer/Views/UpdateDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal UpdateDialog(VersionChecker.GitHubRelease release)
private long currentDownloaded = 0;
private long totalDownloaded = 0;

private static string[] downloadExt = new[] { ".cer", ".appx", ".appxbundle" };
private static string[] downloadExt = new[] { ".cer", "msix", ".appx", ".appxbundle" };

private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
Expand Down

0 comments on commit 983042d

Please sign in to comment.