mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-04-29 20:34:04 +02:00
Random refactoring
This commit is contained in:
parent
8c9168a4bf
commit
4e26fd9d56
Configuration
Core
Controls
Notification
Other
Utils
@ -163,15 +163,12 @@ public bool CloseLockingProcess(int closeTimeout, int killTimeout){
|
|||||||
lockingProcess = null;
|
lockingProcess = null;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}catch(Exception ex){
|
}catch(Exception ex) when (ex is InvalidOperationException || ex is Win32Exception){
|
||||||
if (ex is InvalidOperationException || ex is Win32Exception){
|
if (lockingProcess != null){
|
||||||
if (lockingProcess != null){
|
bool hasExited = CheckLockingProcessExited();
|
||||||
bool hasExited = CheckLockingProcessExited();
|
lockingProcess.Dispose();
|
||||||
lockingProcess.Dispose();
|
return hasExited;
|
||||||
return hasExited;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else throw;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Drawing;
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace TweetDuck.Core.Controls{
|
namespace TweetDuck.Core.Controls{
|
||||||
@ -13,7 +14,7 @@ public FlatProgressBar(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void SetValueInstant(int value){
|
public void SetValueInstant(int value){
|
||||||
ControlExtensions.SetValueInstant(this, value);
|
ControlExtensions.SetValueInstant(this, Math.Max(Minimum, Math.Min(Maximum, value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnPaint(PaintEventArgs e){
|
protected override void OnPaint(PaintEventArgs e){
|
||||||
|
@ -69,7 +69,9 @@ protected virtual Point PrimaryLocation{
|
|||||||
protected virtual bool CanDragWindow => true;
|
protected virtual bool CanDragWindow => true;
|
||||||
|
|
||||||
public new Point Location{
|
public new Point Location{
|
||||||
get => base.Location;
|
get{
|
||||||
|
return base.Location;
|
||||||
|
}
|
||||||
|
|
||||||
set{
|
set{
|
||||||
Visible = (base.Location = value) != ControlExtensions.InvisibleLocation;
|
Visible = (base.Location = value) != ControlExtensions.InvisibleLocation;
|
||||||
|
@ -175,12 +175,14 @@ private void timerDisplayDelay_Tick(object sender, EventArgs e){
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void timerHideProgress_Tick(object sender, EventArgs e){
|
private void timerHideProgress_Tick(object sender, EventArgs e){
|
||||||
if (Bounds.Contains(Cursor.Position) || FreezeTimer || ContextMenuOpen)return;
|
if (Bounds.Contains(Cursor.Position) || FreezeTimer || ContextMenuOpen){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
timeLeft -= timerProgress.Interval;
|
timeLeft -= timerProgress.Interval;
|
||||||
|
|
||||||
int value = BrowserUtils.Scale(1025, (totalTime-timeLeft)/(double)totalTime);
|
int value = BrowserUtils.Scale(progressBarTimer.Maximum+25, (totalTime-timeLeft)/(double)totalTime);
|
||||||
progressBarTimer.SetValueInstant(Math.Min(1000, Math.Max(0, Program.UserConfig.NotificationTimerCountDown ? 1000-value : value)));
|
progressBarTimer.SetValueInstant(Program.UserConfig.NotificationTimerCountDown ? progressBarTimer.Maximum-value : value);
|
||||||
|
|
||||||
if (timeLeft <= 0){
|
if (timeLeft <= 0){
|
||||||
FinishCurrentNotification();
|
FinishCurrentNotification();
|
||||||
@ -196,7 +198,7 @@ public virtual void ShowNotification(TweetNotification notification){
|
|||||||
public override void HideNotification(){
|
public override void HideNotification(){
|
||||||
base.HideNotification();
|
base.HideNotification();
|
||||||
|
|
||||||
progressBarTimer.Value = Program.UserConfig.NotificationTimerCountDown ? 1000 : 0;
|
progressBarTimer.Value = Program.UserConfig.NotificationTimerCountDown ? progressBarTimer.Maximum : progressBarTimer.Minimum;
|
||||||
timerProgress.Stop();
|
timerProgress.Stop();
|
||||||
totalTime = 0;
|
totalTime = 0;
|
||||||
|
|
||||||
@ -239,7 +241,7 @@ protected override string GetTweetHTML(TweetNotification tweet){
|
|||||||
protected override void LoadTweet(TweetNotification tweet){
|
protected override void LoadTweet(TweetNotification tweet){
|
||||||
timerProgress.Stop();
|
timerProgress.Stop();
|
||||||
totalTime = timeLeft = tweet.GetDisplayDuration(Program.UserConfig.NotificationDurationValue);
|
totalTime = timeLeft = tweet.GetDisplayDuration(Program.UserConfig.NotificationDurationValue);
|
||||||
progressBarTimer.Value = Program.UserConfig.NotificationTimerCountDown ? 1000 : 0;
|
progressBarTimer.Value = Program.UserConfig.NotificationTimerCountDown ? progressBarTimer.Maximum : progressBarTimer.Minimum;
|
||||||
|
|
||||||
base.LoadTweet(tweet);
|
base.LoadTweet(tweet);
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
namespace TweetDuck.Core.Other.Management{
|
namespace TweetDuck.Core.Other.Management{
|
||||||
sealed class VideoPlayer : IDisposable{
|
sealed class VideoPlayer : IDisposable{
|
||||||
private readonly string PlayerExe = Path.Combine(Program.ProgramPath, "TweetDuck.Video.exe");
|
|
||||||
|
|
||||||
public bool Running{
|
public bool Running{
|
||||||
get{
|
get{
|
||||||
if (currentProcess == null){
|
if (currentProcess == null){
|
||||||
@ -50,7 +48,7 @@ public void Launch(string url, string username){
|
|||||||
currentPipe.DataIn += currentPipe_DataIn;
|
currentPipe.DataIn += currentPipe_DataIn;
|
||||||
|
|
||||||
if ((currentProcess = Process.Start(new ProcessStartInfo{
|
if ((currentProcess = Process.Start(new ProcessStartInfo{
|
||||||
FileName = PlayerExe,
|
FileName = Path.Combine(Program.ProgramPath, "TweetDuck.Video.exe"),
|
||||||
Arguments = $"{owner.Handle} {Program.UserConfig.VideoPlayerVolume} \"{url}\" \"{currentPipe.GenerateToken()}\"",
|
Arguments = $"{owner.Handle} {Program.UserConfig.VideoPlayerVolume} \"{url}\" \"{currentPipe.GenerateToken()}\"",
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
RedirectStandardOutput = true
|
RedirectStandardOutput = true
|
||||||
|
@ -29,14 +29,10 @@ public TabSettingsAdvanced(Action<string> reinjectBrowserCSS){
|
|||||||
numMemoryThreshold.Enabled = checkBrowserGCReload.Checked;
|
numMemoryThreshold.Enabled = checkBrowserGCReload.Checked;
|
||||||
numMemoryThreshold.SetValueSafe(SysConfig.BrowserMemoryThreshold);
|
numMemoryThreshold.SetValueSafe(SysConfig.BrowserMemoryThreshold);
|
||||||
|
|
||||||
BrowserCache.CalculateCacheSize(bytes => this.InvokeSafe(() => {
|
BrowserCache.CalculateCacheSize(task => {
|
||||||
if (bytes == -1L){
|
string text = task.IsCompleted ? (int)Math.Ceiling(task.Result/(1024.0*1024.0))+" MB" : "(unknown size)";
|
||||||
btnClearCache.Text = "Clear Cache (unknown size)";
|
this.InvokeSafe(() => btnClearCache.Text = $"Clear Cache ({text})");
|
||||||
}
|
});
|
||||||
else{
|
|
||||||
btnClearCache.Text = "Clear Cache ("+(int)Math.Ceiling(bytes/(1024.0*1024.0))+" MB)";
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnReady(){
|
public override void OnReady(){
|
||||||
|
@ -9,14 +9,9 @@ static class BrowserCache{
|
|||||||
private static bool ClearOnExit { get; set; }
|
private static bool ClearOnExit { get; set; }
|
||||||
|
|
||||||
public static readonly string CacheFolder = Path.Combine(Program.StoragePath, "Cache");
|
public static readonly string CacheFolder = Path.Combine(Program.StoragePath, "Cache");
|
||||||
|
private static IEnumerable<string> CacheFiles => Directory.EnumerateFiles(CacheFolder);
|
||||||
|
|
||||||
private static IEnumerable<string> CacheFiles{
|
public static void CalculateCacheSize(Action<Task<long>> callbackBytes){
|
||||||
get{
|
|
||||||
return Directory.EnumerateFiles(CacheFolder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void CalculateCacheSize(Action<long> callbackBytes){
|
|
||||||
Task<long> task = new Task<long>(() => {
|
Task<long> task = new Task<long>(() => {
|
||||||
return CacheFiles.Select(file => {
|
return CacheFiles.Select(file => {
|
||||||
try{
|
try{
|
||||||
@ -27,7 +22,7 @@ public static void CalculateCacheSize(Action<long> callbackBytes){
|
|||||||
}).Sum();
|
}).Sum();
|
||||||
});
|
});
|
||||||
|
|
||||||
task.ContinueWith(originalTask => callbackBytes(originalTask.Exception == null ? originalTask.Result : -1L), TaskContinuationOptions.ExecuteSynchronously);
|
task.ContinueWith(callbackBytes);
|
||||||
task.Start();
|
task.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user