1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-08 20:34:05 +02:00

Add option for custom video player executable & arguments

This commit is contained in:
chylex 2020-02-15 21:17:44 +01:00
parent 0ee22a30ad
commit 0863001c80
6 changed files with 178 additions and 40 deletions

View File

@ -34,8 +34,10 @@ sealed class UserConfig : BaseConfig{
public bool IgnoreTrackingUrlWarning { get; set; } = false;
public string SearchEngineUrl { get; set; } = null;
private int _zoomLevel = 100;
public int VideoPlayerVolume { get; set; } = 50;
public string VideoPlayerPath { get; set; } = null;
public string VideoPlayerPathArgs { get; set; } = null;
public int VideoPlayerVolume { get; set; } = 50;
public bool EnableSpellCheck { get; set; } = false;
private string _spellCheckLanguage = "en-US";

View File

@ -1,5 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Windows.Forms;
using CefSharp;
using TweetDuck.Core.Controls;
using TweetDuck.Core.Handling;
using TweetDuck.Core.Notification;
@ -100,8 +101,12 @@ public void ScreenshotTweet(string html, int width){
form.InvokeAsyncSafe(() => form.OnTweetScreenshotReady(html, width));
}
public void PlayVideo(string videoUrl, string tweetUrl, string username){
form.InvokeAsyncSafe(() => form.PlayVideo(videoUrl, tweetUrl, username));
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(){

View File

@ -1,8 +1,10 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using TweetDuck.Configuration;
using TweetDuck.Core.Bridge;
using TweetDuck.Core.Controls;
@ -508,24 +510,43 @@ public void OnTweetSound(){
AnalyticsFile.SoundNotifications.Trigger();
}
public void PlayVideo(string videoUrl, string tweetUrl, string username){
if (string.IsNullOrEmpty(videoUrl)){
videoPlayer?.Close();
return;
}
public void PlayVideo(string videoUrl, string tweetUrl, string username, IJavascriptCallback callShowOverlay){
string playerPath = Config.VideoPlayerPath;
if (videoPlayer == null){
videoPlayer = new VideoPlayer(this);
if (playerPath == null || !File.Exists(playerPath)){
if (videoPlayer == null){
videoPlayer = new VideoPlayer(this);
videoPlayer.ProcessExited += (sender, args) => {
browser.HideVideoOverlay(true);
};
}
videoPlayer.ProcessExited += (sender, args) => {
browser.HideVideoOverlay(true);
};
}
videoPlayer.Launch(videoUrl, tweetUrl, username);
callShowOverlay.ExecuteAsync();
callShowOverlay.Dispose();
videoPlayer.Launch(videoUrl, tweetUrl, username);
}
else{
callShowOverlay.Dispose();
string quotedUrl = '"' + videoUrl + '"';
string playerArgs = Config.VideoPlayerPathArgs == null ? quotedUrl : Config.VideoPlayerPathArgs + ' ' + quotedUrl;
try{
using(Process.Start(playerPath, playerArgs)){}
}catch(Exception e){
Program.Reporter.HandleException("Error Opening Video Player", "Could not open the video player.", true, e);
}
}
AnalyticsFile.VideoPlays.Trigger();
}
public void StopVideo(){
videoPlayer?.Close();
}
public bool ProcessBrowserKey(Keys key){
if (videoPlayer != null && videoPlayer.Running){
videoPlayer.SendKeyEvent(key);

View File

@ -56,6 +56,10 @@ private void InitializeComponent() {
this.checkHardwareAcceleration = new System.Windows.Forms.CheckBox();
this.panelCustomBrowser = new System.Windows.Forms.Panel();
this.btnCustomBrowserChange = new System.Windows.Forms.Button();
this.labelVideoPlayerPath = new System.Windows.Forms.Label();
this.panelCustomVideoPlayer = new System.Windows.Forms.Panel();
this.comboBoxCustomVideoPlayer = new System.Windows.Forms.ComboBox();
this.btnCustomVideoPlayerChange = new System.Windows.Forms.Button();
this.labelLocales = new System.Windows.Forms.Label();
this.checkSpellCheck = new System.Windows.Forms.CheckBox();
this.labelSpellCheckLanguage = new System.Windows.Forms.Label();
@ -68,6 +72,7 @@ private void InitializeComponent() {
this.flowPanelLeft.SuspendLayout();
this.flowPanelRight.SuspendLayout();
this.panelCustomBrowser.SuspendLayout();
this.panelCustomVideoPlayer.SuspendLayout();
this.SuspendLayout();
//
// checkExpandLinks
@ -368,18 +373,18 @@ private void InitializeComponent() {
this.comboBoxCustomBrowser.Location = new System.Drawing.Point(5, 1);
this.comboBoxCustomBrowser.Margin = new System.Windows.Forms.Padding(5, 1, 3, 0);
this.comboBoxCustomBrowser.Name = "comboBoxCustomBrowser";
this.comboBoxCustomBrowser.Size = new System.Drawing.Size(176, 23);
this.comboBoxCustomBrowser.Size = new System.Drawing.Size(173, 23);
this.comboBoxCustomBrowser.TabIndex = 0;
//
// labelSearchEngine
//
this.labelSearchEngine.AutoSize = true;
this.labelSearchEngine.Font = new System.Drawing.Font("Segoe UI Semibold", 9F, System.Drawing.FontStyle.Bold);
this.labelSearchEngine.Location = new System.Drawing.Point(3, 164);
this.labelSearchEngine.Location = new System.Drawing.Point(3, 221);
this.labelSearchEngine.Margin = new System.Windows.Forms.Padding(3, 12, 3, 0);
this.labelSearchEngine.Name = "labelSearchEngine";
this.labelSearchEngine.Size = new System.Drawing.Size(82, 15);
this.labelSearchEngine.TabIndex = 6;
this.labelSearchEngine.TabIndex = 8;
this.labelSearchEngine.Text = "Search Engine";
//
// comboBoxSearchEngine
@ -387,11 +392,11 @@ private void InitializeComponent() {
this.comboBoxSearchEngine.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSearchEngine.Font = new System.Drawing.Font("Segoe UI", 9F);
this.comboBoxSearchEngine.FormattingEnabled = true;
this.comboBoxSearchEngine.Location = new System.Drawing.Point(5, 183);
this.comboBoxSearchEngine.Location = new System.Drawing.Point(5, 240);
this.comboBoxSearchEngine.Margin = new System.Windows.Forms.Padding(5, 4, 3, 3);
this.comboBoxSearchEngine.Name = "comboBoxSearchEngine";
this.comboBoxSearchEngine.Size = new System.Drawing.Size(176, 23);
this.comboBoxSearchEngine.TabIndex = 7;
this.comboBoxSearchEngine.Size = new System.Drawing.Size(173, 23);
this.comboBoxSearchEngine.TabIndex = 9;
//
// flowPanelRight
//
@ -403,6 +408,8 @@ private void InitializeComponent() {
this.flowPanelRight.Controls.Add(this.checkHardwareAcceleration);
this.flowPanelRight.Controls.Add(this.labelBrowserPath);
this.flowPanelRight.Controls.Add(this.panelCustomBrowser);
this.flowPanelRight.Controls.Add(this.labelVideoPlayerPath);
this.flowPanelRight.Controls.Add(this.panelCustomVideoPlayer);
this.flowPanelRight.Controls.Add(this.labelSearchEngine);
this.flowPanelRight.Controls.Add(this.comboBoxSearchEngine);
this.flowPanelRight.Controls.Add(this.labelLocales);
@ -444,7 +451,7 @@ private void InitializeComponent() {
//
this.btnCustomBrowserChange.AutoSize = true;
this.btnCustomBrowserChange.Font = new System.Drawing.Font("Segoe UI", 9F);
this.btnCustomBrowserChange.Location = new System.Drawing.Point(189, 0);
this.btnCustomBrowserChange.Location = new System.Drawing.Point(186, 0);
this.btnCustomBrowserChange.Margin = new System.Windows.Forms.Padding(5, 0, 3, 0);
this.btnCustomBrowserChange.Name = "btnCustomBrowserChange";
this.btnCustomBrowserChange.Padding = new System.Windows.Forms.Padding(2, 0, 2, 0);
@ -454,26 +461,72 @@ private void InitializeComponent() {
this.btnCustomBrowserChange.UseVisualStyleBackColor = true;
this.btnCustomBrowserChange.Visible = false;
//
// labelVideoPlayerPath
//
this.labelVideoPlayerPath.AutoSize = true;
this.labelVideoPlayerPath.Font = new System.Drawing.Font("Segoe UI Semibold", 9F, System.Drawing.FontStyle.Bold);
this.labelVideoPlayerPath.Location = new System.Drawing.Point(3, 164);
this.labelVideoPlayerPath.Margin = new System.Windows.Forms.Padding(3, 12, 3, 0);
this.labelVideoPlayerPath.Name = "labelVideoPlayerPath";
this.labelVideoPlayerPath.Size = new System.Drawing.Size(106, 15);
this.labelVideoPlayerPath.TabIndex = 6;
this.labelVideoPlayerPath.Text = "Play Videos With...";
//
// panelCustomVideoPlayer
//
this.panelCustomVideoPlayer.Controls.Add(this.comboBoxCustomVideoPlayer);
this.panelCustomVideoPlayer.Controls.Add(this.btnCustomVideoPlayerChange);
this.panelCustomVideoPlayer.Location = new System.Drawing.Point(0, 182);
this.panelCustomVideoPlayer.Margin = new System.Windows.Forms.Padding(0, 3, 0, 3);
this.panelCustomVideoPlayer.Name = "panelCustomVideoPlayer";
this.panelCustomVideoPlayer.Size = new System.Drawing.Size(300, 24);
this.panelCustomVideoPlayer.TabIndex = 7;
//
// comboBoxCustomVideoPlayer
//
this.comboBoxCustomVideoPlayer.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxCustomVideoPlayer.Font = new System.Drawing.Font("Segoe UI", 9F);
this.comboBoxCustomVideoPlayer.FormattingEnabled = true;
this.comboBoxCustomVideoPlayer.Location = new System.Drawing.Point(5, 1);
this.comboBoxCustomVideoPlayer.Margin = new System.Windows.Forms.Padding(5, 1, 3, 0);
this.comboBoxCustomVideoPlayer.Name = "comboBoxCustomVideoPlayer";
this.comboBoxCustomVideoPlayer.Size = new System.Drawing.Size(173, 23);
this.comboBoxCustomVideoPlayer.TabIndex = 0;
//
// btnCustomVideoPlayerChange
//
this.btnCustomVideoPlayerChange.AutoSize = true;
this.btnCustomVideoPlayerChange.Font = new System.Drawing.Font("Segoe UI", 9F);
this.btnCustomVideoPlayerChange.Location = new System.Drawing.Point(186, 0);
this.btnCustomVideoPlayerChange.Margin = new System.Windows.Forms.Padding(5, 0, 3, 0);
this.btnCustomVideoPlayerChange.Name = "btnCustomVideoPlayerChange";
this.btnCustomVideoPlayerChange.Padding = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.btnCustomVideoPlayerChange.Size = new System.Drawing.Size(71, 25);
this.btnCustomVideoPlayerChange.TabIndex = 1;
this.btnCustomVideoPlayerChange.Text = "Change...";
this.btnCustomVideoPlayerChange.UseVisualStyleBackColor = true;
this.btnCustomVideoPlayerChange.Visible = false;
//
// labelLocales
//
this.labelLocales.AutoSize = true;
this.labelLocales.Font = new System.Drawing.Font("Segoe UI Semibold", 10.5F, System.Drawing.FontStyle.Bold);
this.labelLocales.Location = new System.Drawing.Point(0, 236);
this.labelLocales.Location = new System.Drawing.Point(0, 293);
this.labelLocales.Margin = new System.Windows.Forms.Padding(0, 27, 0, 1);
this.labelLocales.Name = "labelLocales";
this.labelLocales.Size = new System.Drawing.Size(67, 19);
this.labelLocales.TabIndex = 8;
this.labelLocales.TabIndex = 10;
this.labelLocales.Text = "LOCALES";
//
// checkSpellCheck
//
this.checkSpellCheck.AutoSize = true;
this.checkSpellCheck.Font = new System.Drawing.Font("Segoe UI", 9F);
this.checkSpellCheck.Location = new System.Drawing.Point(6, 262);
this.checkSpellCheck.Location = new System.Drawing.Point(6, 319);
this.checkSpellCheck.Margin = new System.Windows.Forms.Padding(6, 6, 3, 2);
this.checkSpellCheck.Name = "checkSpellCheck";
this.checkSpellCheck.Size = new System.Drawing.Size(125, 19);
this.checkSpellCheck.TabIndex = 9;
this.checkSpellCheck.TabIndex = 11;
this.checkSpellCheck.Text = "Enable Spell Check";
this.checkSpellCheck.UseVisualStyleBackColor = true;
//
@ -481,11 +534,11 @@ private void InitializeComponent() {
//
this.labelSpellCheckLanguage.AutoSize = true;
this.labelSpellCheckLanguage.Font = new System.Drawing.Font("Segoe UI Semibold", 9F, System.Drawing.FontStyle.Bold);
this.labelSpellCheckLanguage.Location = new System.Drawing.Point(3, 295);
this.labelSpellCheckLanguage.Location = new System.Drawing.Point(3, 352);
this.labelSpellCheckLanguage.Margin = new System.Windows.Forms.Padding(3, 12, 3, 0);
this.labelSpellCheckLanguage.Name = "labelSpellCheckLanguage";
this.labelSpellCheckLanguage.Size = new System.Drawing.Size(123, 15);
this.labelSpellCheckLanguage.TabIndex = 10;
this.labelSpellCheckLanguage.TabIndex = 12;
this.labelSpellCheckLanguage.Text = "Spell Check Language";
//
// comboBoxSpellCheckLanguage
@ -493,21 +546,21 @@ private void InitializeComponent() {
this.comboBoxSpellCheckLanguage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSpellCheckLanguage.Font = new System.Drawing.Font("Segoe UI", 9F);
this.comboBoxSpellCheckLanguage.FormattingEnabled = true;
this.comboBoxSpellCheckLanguage.Location = new System.Drawing.Point(5, 314);
this.comboBoxSpellCheckLanguage.Location = new System.Drawing.Point(5, 371);
this.comboBoxSpellCheckLanguage.Margin = new System.Windows.Forms.Padding(5, 4, 3, 3);
this.comboBoxSpellCheckLanguage.Name = "comboBoxSpellCheckLanguage";
this.comboBoxSpellCheckLanguage.Size = new System.Drawing.Size(290, 23);
this.comboBoxSpellCheckLanguage.TabIndex = 11;
this.comboBoxSpellCheckLanguage.TabIndex = 13;
//
// labelTranslationTarget
//
this.labelTranslationTarget.AutoSize = true;
this.labelTranslationTarget.Font = new System.Drawing.Font("Segoe UI Semibold", 9F, System.Drawing.FontStyle.Bold);
this.labelTranslationTarget.Location = new System.Drawing.Point(3, 352);
this.labelTranslationTarget.Location = new System.Drawing.Point(3, 409);
this.labelTranslationTarget.Margin = new System.Windows.Forms.Padding(3, 12, 3, 0);
this.labelTranslationTarget.Name = "labelTranslationTarget";
this.labelTranslationTarget.Size = new System.Drawing.Size(142, 15);
this.labelTranslationTarget.TabIndex = 12;
this.labelTranslationTarget.TabIndex = 14;
this.labelTranslationTarget.Text = "Bing Translator Language";
//
// comboBoxTranslationTarget
@ -515,11 +568,11 @@ private void InitializeComponent() {
this.comboBoxTranslationTarget.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxTranslationTarget.Font = new System.Drawing.Font("Segoe UI", 9F);
this.comboBoxTranslationTarget.FormattingEnabled = true;
this.comboBoxTranslationTarget.Location = new System.Drawing.Point(5, 371);
this.comboBoxTranslationTarget.Location = new System.Drawing.Point(5, 428);
this.comboBoxTranslationTarget.Margin = new System.Windows.Forms.Padding(5, 4, 3, 3);
this.comboBoxTranslationTarget.Name = "comboBoxTranslationTarget";
this.comboBoxTranslationTarget.Size = new System.Drawing.Size(290, 23);
this.comboBoxTranslationTarget.TabIndex = 13;
this.comboBoxTranslationTarget.TabIndex = 15;
//
// panelSeparator
//
@ -549,6 +602,8 @@ private void InitializeComponent() {
this.flowPanelRight.PerformLayout();
this.panelCustomBrowser.ResumeLayout(false);
this.panelCustomBrowser.PerformLayout();
this.panelCustomVideoPlayer.ResumeLayout(false);
this.panelCustomVideoPlayer.PerformLayout();
this.ResumeLayout(false);
}
@ -594,5 +649,9 @@ private void InitializeComponent() {
private System.Windows.Forms.CheckBox checkFocusDmInput;
private System.Windows.Forms.Panel panelCustomBrowser;
private System.Windows.Forms.Button btnCustomBrowserChange;
private System.Windows.Forms.Label labelVideoPlayerPath;
private System.Windows.Forms.Panel panelCustomVideoPlayer;
private System.Windows.Forms.ComboBox comboBoxCustomVideoPlayer;
private System.Windows.Forms.Button btnCustomVideoPlayerChange;
}
}

View File

@ -19,6 +19,9 @@ sealed partial class TabSettingsGeneral : BaseTabSettings{
private readonly int browserListIndexDefault;
private readonly int browserListIndexCustom;
private readonly int videoPlayerListIndexDefault;
private readonly int videoPlayerListIndexCustom;
private readonly int searchEngineIndexDefault;
private readonly int searchEngineIndexCustom;
@ -95,6 +98,10 @@ public TabSettingsGeneral(Action reloadColumns, UpdateHandler updates){
browserListIndexCustom = comboBoxCustomBrowser.Items.Add("(custom program...)");
UpdateBrowserPathSelection();
videoPlayerListIndexDefault = comboBoxCustomVideoPlayer.Items.Add("(default TweetDuck player)");
videoPlayerListIndexCustom = comboBoxCustomVideoPlayer.Items.Add("(custom program...)");
UpdateVideoPlayerPathSelection();
comboBoxSearchEngine.Items.Add(new SearchEngine("DuckDuckGo", "https://duckduckgo.com/?q="));
comboBoxSearchEngine.Items.Add(new SearchEngine("Google", "https://www.google.com/search?q="));
comboBoxSearchEngine.Items.Add(new SearchEngine("Bing", "https://www.bing.com/search?q="));
@ -148,6 +155,8 @@ public override void OnReady(){
checkHardwareAcceleration.CheckedChanged += checkHardwareAcceleration_CheckedChanged;
comboBoxCustomBrowser.SelectedIndexChanged += comboBoxCustomBrowser_SelectedIndexChanged;
btnCustomBrowserChange.Click += btnCustomBrowserChange_Click;
comboBoxCustomVideoPlayer.SelectedIndexChanged += comboBoxCustomVideoPlayer_SelectedIndexChanged;
btnCustomVideoPlayerChange.Click += btnCustomVideoPlayerChange_Click;
comboBoxSearchEngine.SelectedIndexChanged += comboBoxSearchEngine_SelectedIndexChanged;
checkSpellCheck.CheckedChanged += checkSpellCheck_CheckedChanged;
@ -303,6 +312,48 @@ private void btnCustomBrowserChange_Click(object sender, EventArgs e){
comboBoxCustomBrowser.SelectedIndexChanged += comboBoxCustomBrowser_SelectedIndexChanged;
}
private void UpdateVideoPlayerChangeButton(){
btnCustomVideoPlayerChange.Visible = comboBoxCustomVideoPlayer.SelectedIndex == videoPlayerListIndexCustom;
}
private void UpdateVideoPlayerPathSelection(){
if (string.IsNullOrEmpty(Config.VideoPlayerPath) || !File.Exists(Config.VideoPlayerPath)){
comboBoxCustomVideoPlayer.SelectedIndex = videoPlayerListIndexDefault;
}
else{
comboBoxCustomVideoPlayer.SelectedIndex = videoPlayerListIndexCustom;
}
UpdateVideoPlayerChangeButton();
}
private void comboBoxCustomVideoPlayer_SelectedIndexChanged(object sender, EventArgs e){
if (comboBoxCustomVideoPlayer.SelectedIndex == videoPlayerListIndexCustom){
btnCustomVideoPlayerChange_Click(sender, e);
}
else{
Config.VideoPlayerPath = null;
Config.VideoPlayerPathArgs = null;
UpdateVideoPlayerChangeButton();
}
}
private void btnCustomVideoPlayerChange_Click(object sender, EventArgs e){
using(DialogSettingsExternalProgram dialog = new DialogSettingsExternalProgram("External Video Player", "Play Videos With..."){
Path = Config.VideoPlayerPath,
Args = Config.VideoPlayerPathArgs
}){
if (dialog.ShowDialog() == DialogResult.OK){
Config.VideoPlayerPath = dialog.Path;
Config.VideoPlayerPathArgs = dialog.Args;
}
}
comboBoxCustomVideoPlayer.SelectedIndexChanged -= comboBoxCustomVideoPlayer_SelectedIndexChanged;
UpdateVideoPlayerPathSelection();
comboBoxCustomVideoPlayer.SelectedIndexChanged += comboBoxCustomVideoPlayer_SelectedIndexChanged;
}
private void comboBoxSearchEngine_SelectedIndexChanged(object sender, EventArgs e){
if (comboBoxSearchEngine.SelectedIndex == searchEngineIndexCustom){
using(DialogSettingsSearchEngine dialog = new DialogSettingsSearchEngine()){

View File

@ -1215,11 +1215,11 @@
window.TDGF_playVideo = function(videoUrl, tweetUrl, username){
return if !videoUrl;
$('<div id="td-video-player-overlay" class="ovl" style="display:block"></div>').on("click contextmenu", function(){
$TD.playVideo(null, null, null);
}).appendTo(app);
$TD.playVideo(videoUrl, tweetUrl || videoUrl, username || null);
$TD.playVideo(videoUrl, tweetUrl || videoUrl, username || null, function(){
$('<div id="td-video-player-overlay" class="ovl" style="display:block"></div>').on("click contextmenu", function(){
$TD.stopVideo();
}).appendTo(app);
});
};
const getGifLink = function(ele){