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