fixed #6904: Added "Shorten URL with ShareX" support to browser extension

This commit is contained in:
Jaex 2023-10-24 13:23:07 +03:00
parent 71e9c58b9e
commit e15141e35a
3 changed files with 36 additions and 8 deletions

View file

@ -410,4 +410,14 @@ public enum TaskViewMode // Localized
ListView,
ThumbnailView
}
public enum NativeMessagingContentType
{
None,
Image,
Video,
Audio,
Text,
Link
}
}

View file

@ -27,6 +27,7 @@ namespace ShareX
{
public class NativeMessagingInput
{
public NativeMessagingContentType ContentType { get; set; }
public string URL { get; set; }
public string Text { get; set; }
}

View file

@ -1912,24 +1912,41 @@ public static void HandleNativeMessagingInput(string filePath)
try
{
nativeMessagingInput = JsonHelpers.DeserializeFromFile<NativeMessagingInput>(filePath);
File.Delete(filePath);
}
catch (Exception e)
{
DebugHelper.WriteException(e);
}
finally
{
File.Delete(filePath);
}
if (nativeMessagingInput != null)
{
if (!string.IsNullOrEmpty(nativeMessagingInput.URL) && URLHelpers.IsValidURL(nativeMessagingInput.URL))
switch (nativeMessagingInput.ContentType)
{
case NativeMessagingContentType.Image:
case NativeMessagingContentType.Video:
case NativeMessagingContentType.Audio:
if (!string.IsNullOrEmpty(nativeMessagingInput.URL))
{
UploadManager.DownloadAndUploadFile(nativeMessagingInput.URL);
}
else if (!string.IsNullOrEmpty(nativeMessagingInput.Text))
break;
case NativeMessagingContentType.Text:
if (!string.IsNullOrEmpty(nativeMessagingInput.Text))
{
UploadManager.UploadText(nativeMessagingInput.Text);
}
break;
case NativeMessagingContentType.Link:
if (!string.IsNullOrEmpty(nativeMessagingInput.URL))
{
UploadManager.ShortenURL(nativeMessagingInput.URL);
}
break;
}
}
}
}