Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharkboy-j committed Oct 4, 2022
2 parents 4aff1cb + b8ec7b1 commit f953e79
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 89 deletions.
28 changes: 18 additions & 10 deletions src/Kebler.UI/CSControls/LinkableTextBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ namespace Kebler.UI.CSControls
{
public class LinkableTextBlock : TextBlock
{
[DefaultValue(false)] [Localizability(LocalizationCategory.Text)]
[DefaultValue(false)]
[Localizability(LocalizationCategory.Text)]
public static readonly DependencyProperty SureLinkProperty =
DependencyProperty.Register(nameof(SureLink), typeof(bool),
typeof(LinkableTextBlock),
new FrameworkPropertyMetadata());


[DefaultValue(false)] [Localizability(LocalizationCategory.Text)]
[DefaultValue(false)]
[Localizability(LocalizationCategory.Text)]
public static readonly DependencyProperty CopyOnlyProperty =
DependencyProperty.Register(nameof(CopyOnly), typeof(bool),
typeof(LinkableTextBlock),
Expand All @@ -40,15 +42,19 @@ static LinkableTextBlock()
UpdateSourceTrigger.PropertyChanged));
}

public LinkableTextBlock()
{
}

public bool SureLink
{
get => (bool) GetValue(SureLinkProperty);
get => (bool)GetValue(SureLinkProperty);
set => SetValue(SureLinkProperty, value);
}

public bool CopyOnly
{
get => (bool) GetValue(CopyOnlyProperty);
get => (bool)GetValue(CopyOnlyProperty);
set => SetValue(CopyOnlyProperty, value);
}

Expand All @@ -61,11 +67,11 @@ private static object CoerceText(DependencyObject d, object baseValue)

protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
{
if(Text.IsNotNullOrNotEmpty())
if (Text.IsNotNullOrNotEmpty())
{
if (CopyOnly)
Clipboard.SetText(Text);
else if (isLink)
else if (isLink)
Process.Start(new ProcessStartInfo("cmd", $"/c start {Text}") { CreateNoWindow = true });
}
}
Expand All @@ -75,11 +81,13 @@ private static void TextPropertyChanged(DependencyObject sender, DependencyPrope
{
if (sender is LinkableTextBlock LTB)
{
var bs = (TextBlock) sender;
LTB.ToolTip = LTB.CopyOnly ? "Click to copy" : "Click to open";

if(string.IsNullOrEmpty(LTB.Text))
var bs = (TextBlock)sender;

if (string.IsNullOrEmpty(LTB.Text))
return;

var result = Uri.TryCreate(LTB.Text, UriKind.RelativeOrAbsolute, out var uriResult);

if (LTB.SureLink || result)
Expand All @@ -88,7 +96,7 @@ private static void TextPropertyChanged(DependencyObject sender, DependencyPrope
SetForeground(sender, Brushes.DodgerBlue);
}

if (LTB.Text.Length > 0) bs.SetValue(TextProperty, LTB.Text);
if (LTB.Text.Length > 0) bs.SetValue(TextProperty, LTB.Text);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Kebler/Dialogs/RemoveTorrentDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
Grid.Column="1"
Padding="10,0,10,0"
HorizontalAlignment="Center"
Click="Add"
Click="Remove"
IsDefault="True"
Content="{lex:BLoc BTNS_Yes}"
Visibility="{Binding IsWorking, Converter={StaticResource ReverseBoolToVisibilityConverter}, FallbackValue=Visible}" />
Expand Down
5 changes: 4 additions & 1 deletion src/Kebler/Dialogs/RemoveTorrentDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void Stop(object sender, RoutedEventArgs e)
IsWorking = false;
}

public async void Add(object sender, RoutedEventArgs e)
public async void Remove(object sender, RoutedEventArgs e)
{

try
Expand All @@ -78,6 +78,9 @@ await Task.Factory.StartNew(async () =>
return;
Result = await _transmissionClient.TorrentRemoveAsync(_toRemove, _cancellationToken, with);
Log.Info("RM response: " + Result);

if (Result == Enums.RemoveResult.Ok)
break;
}
}, _cancellationToken);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Kebler/NLog.config
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
archiveFileName="${logDirectory}/app_{#}.log"
archiveNumbering="Date"
archiveEvery="Day"
maxArchiveFiles="5"
archiveAboveSize="20000000"
maxArchiveFiles="3"
footer="${footer}"/>

<target name="ErrorsFile" xsi:type="File"
fileName="${logDirectory}/errors_${shortdate}.log"
layout="${layout}"
encoding="${encoding}"
maxArchiveFiles="5"
maxArchiveFiles="3"
archiveAboveSize="20000000"
footer="${footer}"/>


Expand Down
59 changes: 24 additions & 35 deletions src/Kebler/ViewModels/AddTorrentViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,25 +468,21 @@ public async Task<bool> Add()
{
Log.Info($"Search for similar");

await _wnd.Dispatcher.InvokeAsync(async () =>
if (_torrents.Select(x => x.Item1).Contains(torrent.DisplayName))
{
if (_torrents.Select(x => x.Item1).Contains(torrent.DisplayName))
Log.Info($"Here is similar torrent");

var title = LocalizationProvider.GetLocalizedValue(
nameof(Strings.ASK_REMOVE_SIMILAR)).Replace("%d", torrent.DisplayName);
var res = await MessageBoxViewModel.ShowDialog(title,
null, null, Enums.MessageBoxDilogButtons.YesNo);
Log.Info($"Response for removing similar => {res}");

if (res == true)
{
Log.Info($"Here is similar torrent");

var title = LocalizationProvider.GetLocalizedValue(
nameof(Strings.ASK_REMOVE_SIMILAR)).Replace("%d", torrent.DisplayName);
var res = await MessageBoxViewModel.ShowDialog(title,
null, null, Enums.MessageBoxDilogButtons.YesNo);
Log.Info($"Response for removing similar => {res}");

if (res == true)
{
_remove(_torrents.First(x => x.Item1.Equals(torrent.DisplayName)).Item2);
}
_remove(_torrents.First(x => x.Item1.Equals(torrent.DisplayName)).Item2);
}

});
}

}

Expand All @@ -505,24 +501,21 @@ await _wnd.Dispatcher.InvokeAsync(async () =>
{
var toAdd = _torrent.Trackers.Select(tr => tr.First()).ToArray();

await _wnd.Dispatcher.InvokeAsync(async () =>
{
var quest = LocalizationProvider.GetLocalizedValue(
var quest = LocalizationProvider.GetLocalizedValue(
nameof(Strings.ASK_UpdateTrackers));


bool? shouldUpdate = true;
bool? shouldUpdate = true;

if (ConfigService.Instanse.AskUpdateTrackers)
{
shouldUpdate = await MessageBoxViewModel.ShowDialog($"{quest} for {_torrent.DisplayName}", null, null, Enums.MessageBoxDilogButtons.YesNoCancel);
}
if (ConfigService.Instanse.AskUpdateTrackers)
{
shouldUpdate = await MessageBoxViewModel.ShowDialog($"{quest} for {_torrent.DisplayName}", null, null, Enums.MessageBoxDilogButtons.YesNoCancel);
}

if (shouldUpdate == true)
{
await UpdateTrackers(toAdd, TorrentResult.Value.ID);
}
});
if (shouldUpdate == true)
{
await UpdateTrackers(toAdd, TorrentResult.Value.ID);
}


foreach (var tr in toAdd)
Expand All @@ -545,12 +538,8 @@ await _wnd.Dispatcher.InvokeAsync(async () =>
TorrentResult.CustomException != null)
{

await _wnd.Dispatcher.InvokeAsync(async () =>
{
await MessageBoxViewModel.ShowDialog(TorrentResult.CustomException.Message
, null, string.Empty);

});
await MessageBoxViewModel.ShowDialog(TorrentResult.CustomException.Message
, null, string.Empty);

Log?.Error(TorrentResult.CustomException);

Expand Down
6 changes: 3 additions & 3 deletions src/Kebler/ViewModels/ConnectionManagerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void Add()
// App.InvokeServerListChanged();
}

public void Remove()
public async void Remove()
{
//Log.Ui();

Expand All @@ -92,15 +92,15 @@ public void Remove()
Log.Info($"RemoveResult: {result}");
if (!result)
//TODO: Add string
MessageBoxViewModel.ShowDialog("RemoveErrorContent", manager);
await MessageBoxViewModel.ShowDialog("RemoveErrorContent", manager);

var ind = ServerIndex -= 1;

//if (App.Instance.KeblerControl.SelectedServer.Id == SelectedServer.Id)
//{
// App.Instance.KeblerControl.Disconnect();
//}
_eventAggregator.PublishOnUIThreadAsync(new Messages.ServersUpdated());
await _eventAggregator.PublishOnUIThreadAsync(new Messages.ServersUpdated());

SelectedServer = null;
GetServers();
Expand Down
8 changes: 4 additions & 4 deletions src/Kebler/ViewModels/KeblerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private Task GetLongChecker()

#region Config

private void ApplyConfig()
private async void ApplyConfig()
{
try
{
Expand All @@ -355,7 +355,7 @@ private void ApplyConfig()
Log.Error(ex);
Crashes.TrackError(ex);

MessageBoxViewModel.ShowDialog(LocalizationProvider.GetLocalizedValue(nameof(Strings.ConfigApllyError)), manager);
await MessageBoxViewModel.ShowDialog(LocalizationProvider.GetLocalizedValue(nameof(Strings.ConfigApllyError)), manager);
}
}

Expand Down Expand Up @@ -835,12 +835,12 @@ public async void MoveBot()
}


public void CopyMagnet()
public async void CopyMagnet()
{
if (SelectedTorrent != null)
Clipboard.SetText(SelectedTorrent.MagnetLink);
else
MessageBoxViewModel.ShowDialog("Please select torrent");
await MessageBoxViewModel.ShowDialog("Please select torrent");
}


Expand Down
34 changes: 13 additions & 21 deletions src/Kebler/ViewModels/KeblerViewModel/ConnectionThings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,26 +213,22 @@ private void StartCycle()

if (_transmissionClient != null)
{
await GetStatistic();

if (State == WindowState.Normal)
{
await GetStatistic();
await GetSettings();

await GetSettings();
await GetAllTorrentsData();

await GetAllTorrentsData();
ParseStats();

if (allTorrents != null)
{
ParseTransmissionServerSettings();
if (allTorrents != null)
{
ParseTransmissionServerSettings();

if (allTorrents?.Clone() is TransmissionTorrents data)
await ProcessParsingTransmissionResponse(data);
}
if (allTorrents?.Clone() is TransmissionTorrents data)
await ProcessParsingTransmissionResponse(data);
}

ParseStats();

}
else
{
Expand Down Expand Up @@ -286,10 +282,8 @@ private void StartCycle()
}

Log.Error(ex.Message);
await Application.Current?.Dispatcher?.InvokeAsync(async () =>
{
await MessageBoxViewModel.ShowDialog(msg, manager, string.Empty);
});
await MessageBoxViewModel.ShowDialog(msg, manager, string.Empty);

}
catch (Exception ex)
{
Expand Down Expand Up @@ -373,10 +367,8 @@ await _eventAggregator.PublishOnBackgroundThreadAsync(new Messages.ReconnectAllo
}

Log.Error(ex.Message);
await Application.Current?.Dispatcher?.InvokeAsync(async () =>
{
await MessageBoxViewModel.ShowDialog(msg, manager, string.Empty);
});
await MessageBoxViewModel.ShowDialog(msg, manager, string.Empty);

}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ private void ParseStats()
{
try
{
var dSpeedText = BytesToUserFriendlySpeed.GetSizeString(_stats.DownloadSpeed);
var uSpeedText = BytesToUserFriendlySpeed.GetSizeString(_stats.UploadSpeed);

var dSpeed = string.IsNullOrEmpty(dSpeedText) ? "0 b/s" : dSpeedText;
var uSpeed = string.IsNullOrEmpty(uSpeedText) ? "0 b/s" : uSpeedText;

Expand Down
12 changes: 9 additions & 3 deletions src/Kebler/ViewModels/MessageBoxViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Windows;
using Caliburn.Micro;
using Kebler.Core.Models;
using Kebler.TransmissionTorrentClient.Models;
Expand All @@ -21,9 +22,14 @@ public MessageBoxViewModel(string message, string title = null,
Enums.MessageBoxDilogButtons buttons = Enums.MessageBoxDilogButtons.Ok)
{
var mgr = manager ?? new WindowManager();
var vm = new MessageBoxViewModel(msg, titile, buttons, true);
var resp = await mgr.ShowDialogAsync(vm);
return vm.Result;

var rsp = await Application.Current.Dispatcher.InvokeAsync<Task<bool?>>(async () =>
{
var vm = new MessageBoxViewModel(msg, titile, buttons, true);
return await mgr.ShowDialogAsync(vm);
});

return await rsp;
}
}
}
Loading

0 comments on commit f953e79

Please sign in to comment.