-
Notifications
You must be signed in to change notification settings - Fork 744
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add share to X (Twitter) with web intents. (#2485)
* Add share to X (Twitter) with web intent. * Fix wording * Fix wording again * Remove share settings designer config * Update src/LiveSplit.Core/Web/Share/Twitter.cs Co-authored-by: Ero <56401411+just-ero@users.noreply.github.com> * Fix typo --------- Co-authored-by: Kuhaku369 <kuhaku.o.9893@gmail.com> Co-authored-by: wooferzfg <spapushin@gmail.com> Co-authored-by: Ero <56401411+just-ero@users.noreply.github.com>
- Loading branch information
1 parent
bcce0d8
commit 52c7af9
Showing
6 changed files
with
149 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using LiveSplit.Model; | ||
using LiveSplit.Options; | ||
using System; | ||
using System.Diagnostics; | ||
using System.Drawing; | ||
using System.Drawing.Imaging; | ||
using System.IO; | ||
using System.Windows.Forms; | ||
|
||
namespace LiveSplit.Web.Share | ||
{ | ||
public class Twitter : IRunUploadPlatform | ||
{ | ||
public ISettings Settings { get; set; } | ||
|
||
protected static readonly Twitter _Instance = new Twitter(); | ||
public static Twitter Instance => _Instance; | ||
|
||
public static readonly Uri BaseUri = new Uri("https://twitter.com/intent/tweet"); | ||
|
||
protected Twitter() { } | ||
|
||
public string PlatformName => "X (Twitter)"; | ||
|
||
public string Description => | ||
@"X (Twitter) allows you to share your run with the world. | ||
When sharing, a screenshot of LiveSplit is automatically copied to the clipboard. | ||
When you click share, LiveSplit opens a Tweet composition window in your default browser."; | ||
|
||
public bool VerifyLogin() | ||
{ | ||
return true; | ||
} | ||
|
||
public bool SubmitRun(IRun run, Func<Image> screenShotFunction = null, bool attachSplits = false, TimingMethod method = TimingMethod.RealTime, string comment = "", params string[] additionalParams) | ||
{ | ||
if (attachSplits) | ||
comment += " " + SplitsIO.Instance.Share(run, screenShotFunction); | ||
|
||
ImageToClipboard(screenShotFunction()); | ||
var uri = MakeUri(comment); | ||
Process.Start(uri); | ||
|
||
return true; | ||
} | ||
|
||
private void ImageToClipboard(Image image) | ||
{ | ||
if (image is null) | ||
return; | ||
|
||
Image pngImage; | ||
using (var stream = new MemoryStream()) | ||
{ | ||
image.Save(stream, ImageFormat.Png); | ||
pngImage = Image.FromStream(stream); | ||
} | ||
Clipboard.SetDataObject(pngImage); | ||
} | ||
private string MakeUri(string text) | ||
{ | ||
var intentText = ""; | ||
if (!String.IsNullOrEmpty(text)) | ||
{ | ||
intentText = "?text=" + Uri.EscapeDataString(text); | ||
} | ||
|
||
return BaseUri + intentText; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters