mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-07 08:34:06 +02:00
142 lines
5.0 KiB
C#
142 lines
5.0 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using System.Windows.Forms;
|
|
using CefSharp;
|
|
using TweetDuck.Browser.Handling;
|
|
using TweetDuck.Browser.Notification;
|
|
using TweetDuck.Controls;
|
|
using TweetDuck.Dialogs;
|
|
using TweetDuck.Management;
|
|
using TweetDuck.Utils;
|
|
using TweetLib.Core.Features.Notifications;
|
|
|
|
namespace TweetDuck.Browser.Bridge{
|
|
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
|
class TweetDeckBridge{
|
|
public static void ResetStaticProperties(){
|
|
FormNotificationBase.FontSize = null;
|
|
FormNotificationBase.HeadLayout = null;
|
|
}
|
|
|
|
private readonly FormBrowser form;
|
|
private readonly FormNotificationMain notification;
|
|
|
|
protected TweetDeckBridge(FormBrowser form, FormNotificationMain notification){
|
|
this.form = form;
|
|
this.notification = notification;
|
|
}
|
|
|
|
// Browser only
|
|
|
|
public sealed class Browser : TweetDeckBridge{
|
|
public Browser(FormBrowser form, FormNotificationMain notification) : base(form, notification){}
|
|
|
|
public void OpenContextMenu(){
|
|
form.InvokeAsyncSafe(form.OpenContextMenu);
|
|
}
|
|
|
|
public void OpenProfileImport(){
|
|
form.InvokeAsyncSafe(form.OpenProfileImport);
|
|
}
|
|
|
|
public void OnIntroductionClosed(bool showGuide, bool allowDataCollection){
|
|
form.InvokeAsyncSafe(() => form.OnIntroductionClosed(showGuide, allowDataCollection));
|
|
}
|
|
|
|
public void LoadNotificationLayout(string fontSize, string headLayout){
|
|
form.InvokeAsyncSafe(() => {
|
|
FormNotificationBase.FontSize = fontSize;
|
|
FormNotificationBase.HeadLayout = headLayout;
|
|
});
|
|
}
|
|
|
|
public void SetRightClickedLink(string type, string url){
|
|
ContextMenuBase.CurrentInfo.SetLink(type, url);
|
|
}
|
|
|
|
public void SetRightClickedChirp(string tweetUrl, string quoteUrl, string chirpAuthors, string chirpImages){
|
|
ContextMenuBase.CurrentInfo.SetChirp(tweetUrl, quoteUrl, chirpAuthors, chirpImages);
|
|
}
|
|
|
|
public void DisplayTooltip(string text){
|
|
form.InvokeAsyncSafe(() => form.DisplayTooltip(text));
|
|
}
|
|
}
|
|
|
|
// Notification only
|
|
|
|
public sealed class Notification : TweetDeckBridge{
|
|
public Notification(FormBrowser form, FormNotificationMain notification) : base(form, notification){}
|
|
|
|
public void DisplayTooltip(string text){
|
|
notification.InvokeAsyncSafe(() => notification.DisplayTooltip(text));
|
|
}
|
|
|
|
public void LoadNextNotification(){
|
|
notification.InvokeAsyncSafe(notification.FinishCurrentNotification);
|
|
}
|
|
|
|
public void ShowTweetDetail(){
|
|
notification.InvokeAsyncSafe(notification.ShowTweetDetail);
|
|
}
|
|
}
|
|
|
|
// Global
|
|
|
|
public void OnTweetPopup(string columnId, string chirpId, string columnName, string tweetHtml, int tweetCharacters, string tweetUrl, string quoteUrl){
|
|
notification.InvokeAsyncSafe(() => {
|
|
form.OnTweetNotification();
|
|
notification.ShowNotification(new DesktopNotification(columnId, chirpId, columnName, tweetHtml, tweetCharacters, tweetUrl, quoteUrl));
|
|
});
|
|
}
|
|
|
|
public void OnTweetSound(){
|
|
form.InvokeAsyncSafe(() => {
|
|
form.OnTweetNotification();
|
|
form.OnTweetSound();
|
|
});
|
|
}
|
|
|
|
public void ScreenshotTweet(string html, int width){
|
|
form.InvokeAsyncSafe(() => form.OnTweetScreenshotReady(html, width));
|
|
}
|
|
|
|
public void PlayVideo(string videoUrl, string tweetUrl, string username, IJavascriptCallback callShowOverlay){
|
|
form.InvokeAsyncSafe(() => form.PlayVideo(videoUrl, tweetUrl, username, callShowOverlay));
|
|
}
|
|
|
|
public void StopVideo(){
|
|
form.InvokeAsyncSafe(form.StopVideo);
|
|
}
|
|
|
|
public void FixClipboard(){
|
|
form.InvokeAsyncSafe(ClipboardManager.StripHtmlStyles);
|
|
}
|
|
|
|
public void OpenBrowser(string url){
|
|
form.InvokeAsyncSafe(() => BrowserUtils.OpenExternalBrowser(url));
|
|
}
|
|
|
|
public int GetIdleSeconds(){
|
|
return NativeMethods.GetIdleSeconds();
|
|
}
|
|
|
|
public void Alert(string type, string contents){
|
|
MessageBoxIcon icon = type switch{
|
|
"error" => MessageBoxIcon.Error,
|
|
"warning" => MessageBoxIcon.Warning,
|
|
"info" => MessageBoxIcon.Information,
|
|
_ => MessageBoxIcon.None
|
|
};
|
|
|
|
FormMessage.Show("TweetDuck Browser Message", contents, icon, FormMessage.OK);
|
|
}
|
|
|
|
public void CrashDebug(string message){
|
|
#if DEBUG
|
|
System.Diagnostics.Debug.WriteLine(message);
|
|
System.Diagnostics.Debugger.Break();
|
|
#endif
|
|
}
|
|
}
|
|
}
|