Skip to content

Commit

Permalink
Merge pull request #28 from Valyreon/develop
Browse files Browse the repository at this point in the history
Logging and bugfixes
  • Loading branch information
Valyreon authored Apr 17, 2024
2 parents 706b178 + 50f3517 commit 964d3cf
Show file tree
Hide file tree
Showing 29 changed files with 655 additions and 217 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ dotnet_diagnostic.IDE0002.severity = warning
dotnet_diagnostic.IDE0005.severity = warning
dotnet_diagnostic.IDE0058.severity = none
dotnet_diagnostic.IDE1006.severity = none
dotnet_diagnostic.IDE0058.severity = none

dotnet_diagnostic.RCS1194.severity = none

Expand Down
6 changes: 3 additions & 3 deletions InstallerFiles/Scoop/subloader.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"version": "1.6.0",
"version": "1.6.1",
"description": "Subloader enables you to quickly find and download subtitles for your video files using OpenSubtitles API.",
"homepage": "https://github.com/Valyreon/Subloader",
"license": "MIT-Modern-Variant",
"architecture": {
"64bit": {
"url": "https://github.com/Valyreon/Subloader/releases/download/v1.6.0/scoop.zip",
"hash": "f7e0f5ced70a6260fec80eaa8864ae507381f5fdb294a48cf2c867d41cc198fd"
"url": "https://github.com/Valyreon/Subloader/releases/download/v1.6.1/scoop.zip",
"hash": "a1506a42a1b936ff1673f47bd1b1a63da7d7254c801418fceaba03e95f6d0cbb"
}
},
"post_install": "add_to_openwith_menu.ps1",
Expand Down
2 changes: 1 addition & 1 deletion OpenSubtitlesSharp/OpenSubtitlesSharp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<Title>OpenSubtitlesSharp</Title>
Expand Down
1 change: 0 additions & 1 deletion SubloaderAvalonia/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public override void Initialize()

public override async void OnFrameworkInitializationCompleted()
{

if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
CheckMutex(desktop.Args);
Expand Down
12 changes: 12 additions & 0 deletions SubloaderAvalonia/Extensions/DateTimeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace SubloaderAvalonia.Extensions;

public static class DateTimeExtensions
{
public static long ToUnixTimestamp(this DateTime dateTime)
{
dateTime = dateTime.ToUniversalTime();
return (long)(dateTime - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
}
}
44 changes: 29 additions & 15 deletions SubloaderAvalonia/Models/ApplicationSettings.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenSubtitlesSharp;
using SubloaderAvalonia.Extensions;

namespace SubloaderAvalonia.Models;

public class ApplicationSettings
{
public static readonly IReadOnlyList<string> ValidFormats = new List<string> { "srt", "sub", "mpl", "webvtt", "dfxp", "txt" };

private User loggedInUser;
private SearchParameters defaultSearchParameters;
private string preferredFormat = "srt";
private IReadOnlyList<string> wantedLanguages;

public bool AllowMultipleDownloads { get; set; }
public SearchParameters DefaultSearchParameters { get; set; } = new();
public SearchParameters DefaultSearchParameters
{
get => defaultSearchParameters ??= new();
set => defaultSearchParameters = value;
}
public bool DownloadToSubsFolder { get; set; }
public bool KeepWindowOnTop { get; set; } = true;
public User LoggedInUser { get; set; }
public bool OverwriteSameLanguageSub { get; set; }
public string PreferredFormat { get; set; } = "srt";

public IReadOnlyList<string> WantedLanguages { get; set; }

public ApplicationSettings Initialize()
public User LoggedInUser
{
DefaultSearchParameters ??= new();
PreferredFormat ??= "srt";
WantedLanguages ??= new List<string>() { "en" };
get => loggedInUser == null || loggedInUser.TokenExpirationUnixTimestamp <= DateTime.UtcNow.ToUnixTimestamp() ? null : loggedInUser;
set => loggedInUser = value;
}

public bool OverwriteSameLanguageSub { get; set; }

if (LoggedInUser?.ResetTime.HasValue == true && LoggedInUser.ResetTime.Value <= DateTime.UtcNow)
{
LoggedInUser.ResetTime = null;
}
public string PreferredFormat
{
get => ValidFormats.Contains(preferredFormat) ? preferredFormat : "srt";
set => preferredFormat = value;
}

return this;
public IReadOnlyList<string> WantedLanguages
{
get => wantedLanguages == null || !wantedLanguages.Any() ? wantedLanguages = new List<string>() { "en" } : wantedLanguages;
set => wantedLanguages = value;
}
}
17 changes: 13 additions & 4 deletions SubloaderAvalonia/Models/User.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
using System;
using ReactiveUI;

namespace SubloaderAvalonia.Models;

public class User
public class User : ReactiveObject
{
public int AllowedDownloads { get; set; }
public string BaseUrl { get; set; }
public bool IsVIP { get; set; }
public string Level { get; set; }
public int RemainingDownloads { get; set; }
public DateTime? ResetTime { get; set; }
public string Token { get; set; }
public int UserId { get; set; }
public string Username { get; set; }
public long TokenExpirationUnixTimestamp { get; set; }
public string TokenExpirationTimestampString
{
get
{
var dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(TokenExpirationUnixTimestamp);
var dateTime = dateTimeOffset.LocalDateTime;
return dateTime.ToString("u")[..^1];
}
set => _ = value;
}
}
25 changes: 14 additions & 11 deletions SubloaderAvalonia/Resources/Colors.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@
<Converters:PageParamsToVisibilityMultiConverter x:Key="PageParamsToVisibilityMultiConverter" />

<SolidColorBrush x:Key="MainDarkColor" Color="#323232" />
<SolidColorBrush x:Key="MainBorderColor" Color="#bfbfbf" />
<SolidColorBrush x:Key="MainBorderColor" Color="#bbb" />
<SolidColorBrush x:Key="MainBackgroundColor" Color="#e8e8e8" />
<SolidColorBrush x:Key="LighterBorderColor" Color="#ddd" />
<SolidColorBrush x:Key="AccentColor" Color="#6495ED" />

<SolidColorBrush x:Key="HighlightBrush" Color="#6495ED" />
<SolidColorBrush x:Key="ThemeAccentBrush" Color="#6495ED" />
<SolidColorBrush x:Key="ThemeAccentBrush2" Color="#6495ED" />
<SolidColorBrush x:Key="ThemeAccentBrush3" Color="#6495ED" />
<SolidColorBrush x:Key="ThemeAccentBrush4" Color="#6495ED" />


<SolidColorBrush x:Key="MediumLightAccentColor" Color="#9abaf3" />
<SolidColorBrush x:Key="LighterAccentColor" Color="#eff4fd" />
<SolidColorBrush x:Key="MediumAccentColor" Color="#bbd0f7" />

<Color x:Key="SystemAccentColor">#6495ED</Color>
<Color x:Key="SystemAccentColorLight1">#eff4fd</Color>
<Color x:Key="SystemAccentColorDark1">#bbd0f7</Color>
<Color x:Key="HighlightColor">#FF6495ED</Color>
<Color x:Key="HighlightColor2">#FF6495ED</Color>
<Color x:Key="ThemeAccentColor">#CC6495ED</Color>
<Color x:Key="ThemeAccentColor2">#996495ED</Color>
<Color x:Key="ThemeAccentColor3">#666495ED</Color>
<Color x:Key="ThemeAccentColor4">#336495ED</Color>

<SolidColorBrush x:Key="HighlightBrush" Color="{StaticResource HighlightColor}" />
<SolidColorBrush x:Key="HighlightBrush2" Color="{StaticResource HighlightColor2}" />
<SolidColorBrush x:Key="ThemeAccentBrush2" Color="{StaticResource ThemeAccentColor2}" />
<SolidColorBrush x:Key="ThemeAccentBrush3" Color="{StaticResource ThemeAccentColor3}" />
<SolidColorBrush x:Key="ThemeAccentBrush4" Color="{StaticResource ThemeAccentColor4}" />
<SolidColorBrush x:Key="ThemeAccentBrush" Color="{StaticResource ThemeAccentColor}" />

<DrawingImage x:Key="ChevronDown">
<DrawingImage.Drawing>
Expand Down
35 changes: 1 addition & 34 deletions SubloaderAvalonia/Resources/Generic.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,4 @@
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cmp="clr-namespace:SubloaderAvalonia.CustomComponents"
xmlns:vm="clr-namespace:SubloaderAvalonia.ViewModels">
<ControlTheme x:Key="{x:Type Button}" TargetType="Button">
<Setter Property="FontSize" Value="12" />
<Setter Property="Height" Value="30" />
<Setter Property="FontWeight" Value="SemiBold" />
<Setter Property="Foreground" Value="{StaticResource MainDarkColor}" />
<Setter Property="Template">
<ControlTemplate>
<Border
x:Name="border"
Height="{TemplateBinding Height}"
Background="White"
BorderBrush="{StaticResource MainBorderColor}"
BorderThickness="1">
<ContentPresenter
x:Name="PART_ContentPresenter"
Margin="10,5"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="{TemplateBinding Content}" />
<Border.Styles>
<Style Selector="Border:pointerover">
<Setter Property="BorderBrush" Value="{StaticResource AccentColor}" />
<Setter Property="Background" Value="{StaticResource LighterAccentColor}" />
</Style>
<Style Selector="Button:pressed Border#border">
<Setter Property="BorderThickness" Value="2" />
</Style>
</Border.Styles>
</Border>
</ControlTemplate>
</Setter>
</ControlTheme>
</ResourceDictionary>
xmlns:vm="clr-namespace:SubloaderAvalonia.ViewModels" />
12 changes: 1 addition & 11 deletions SubloaderAvalonia/Services/OpenSubtitlesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ public async Task<DownloadInfo> DownloadSubtitleAsync(SubtitleEntry subtitle, st

File.WriteAllBytes(destination, await GetRawFileAsync(downloadInfo.Link));

if (_settings.LoggedInUser != null)
{
_settings.LoggedInUser.ResetTime = downloadInfo.ResetTimeUtc;
_settings.LoggedInUser.RemainingDownloads = downloadInfo.Remaining;

_ = ApplicationDataReader.SaveSettingsAsync(_settings);
}

return downloadInfo;
}

Expand Down Expand Up @@ -92,13 +84,11 @@ public async Task<User> LoginAsync(string username, string password)
return new User
{
Token = info.Token,
BaseUrl = info.BaseUrl,
AllowedDownloads = info.User.AllowedDownloads,
RemainingDownloads = info.User.RemainingDownloads,
IsVIP = info.User.Vip,
Level = info.User.Level,
UserId = info.User.UserId,
Username = username
Username = username,
};
}

Expand Down
39 changes: 31 additions & 8 deletions SubloaderAvalonia/Styles/Styles.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,52 @@
<Setter Property="Background" Value="White" />
<Setter Property="BorderBrush" Value="{DynamicResource MainBorderColor}" />
</Style>
<Style Selector="TextBox:focus Border">
<Style Selector="TextBox:focus /template/ Border">
<Setter Property="BorderBrush" Value="{DynamicResource AccentColor}" />
</Style>
<Style Selector="TextBox:pointerover Border">
<Style Selector="TextBox:pointerover /template/ Border">
<Setter Property="BorderBrush" Value="{DynamicResource MediumAccentColor}" />
</Style>
<Style Selector="TextBox:focus:pointerover Border">
<Style Selector="TextBox:focus:pointerover /template/ Border">
<Setter Property="BorderBrush" Value="{DynamicResource AccentColor}" />
</Style>

<Style Selector="ComboBox">
<Setter Property="Background" Value="White" />
<Setter Property="BorderBrush" Value="{DynamicResource MainBorderColor}" />
</Style>
<Style Selector="ComboBox:focus Border">
<Setter Property="BorderBrush" Value="{DynamicResource AccentColor}" />
</Style>
<Style Selector="ComboBox:pointerover /template/ Border">
<Setter Property="BorderBrush" Value="{DynamicResource AccentColor}" />
</Style>

<Style Selector="Label">
<Setter Property="Margin" Value="0,0,0,5" />
<Setter Property="Padding" Value="0" />
<Setter Property="FontSize" Value="12" />
<Setter Property="Foreground" Value="{DynamicResource MainDarkColor}" />
<Style Selector="CheckBox">
<Setter Property="Background" Value="White" />
<Setter Property="BorderBrush" Value="{DynamicResource MainBorderColor}" />
</Style>
<Style Selector="CheckBox:pointover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="{DynamicResource LighterAccentColor}" />
<Setter Property="BorderBrush" Value="{DynamicResource MainBorderColor}" />
</Style>

<Style Selector="Button">
<Setter Property="Background" Value="White" />
<Setter Property="Height" Value="30" />
<Setter Property="FontWeight" Value="SemiBold" />
<Setter Property="BorderBrush" Value="{DynamicResource MainBorderColor}" />
</Style>
<Style Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="BorderBrush" Value="{DynamicResource AccentColor}" />
</Style>
<Style Selector="Button:pressed /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="BorderThickness" Value="2" />
<Setter Property="Background" Value="{DynamicResource ThemeAccentColor4}" />
</Style>

<Style Selector="TabItem /template/ ContentPresenter#PART_HeaderPresenter">
<Setter Property="FontWeight" Value="SemiBold" />
<Setter Property="Foreground" Value="Red" />
</Style>
</Styles>
6 changes: 3 additions & 3 deletions SubloaderAvalonia/Utilities/ApplicationDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ public static async Task<ApplicationSettings> LoadSettingsAsync()

if (!File.Exists(path))
{
return new ApplicationSettings().Initialize();
return new ApplicationSettings();
}

await semaphore.WaitAsync();
var text = await File.ReadAllTextAsync(path);
semaphore.Release();
try
{
return JsonSerializer.Deserialize<ApplicationSettings>(text).Initialize();
return JsonSerializer.Deserialize<ApplicationSettings>(text);
}
catch (Exception)
{
}

return new ApplicationSettings().Initialize();
return new ApplicationSettings();
}

private static string GetConfigPath()
Expand Down
3 changes: 2 additions & 1 deletion SubloaderAvalonia/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public object CurrentControl
private set
{
previousControl = currentControl;
this.RaiseAndSetIfChanged(ref currentControl, value);
currentControl = value;
this.RaisePropertyChanged(nameof(CurrentControl));
}
}

Expand Down
12 changes: 6 additions & 6 deletions SubloaderAvalonia/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ static SettingsViewModel()
AllLanguages = JsonSerializer.Deserialize<IEnumerable<SubtitleLanguage>>(manager.GetString("LanguagesList")).ToDictionary(x => x.Code);
}

public SettingsViewModel()
{

}

public SettingsViewModel(INavigator navigator, IOpenSubtitlesService openSubtitlesService, ApplicationSettings settings)
{
this.navigator = navigator;
Expand Down Expand Up @@ -97,12 +102,6 @@ public SettingsViewModel(INavigator navigator, IOpenSubtitlesService openSubtitl
Username = _settings.LoggedInUser?.Username;
IsLoggedIn = _settings.LoggedInUser != null;

if (IsLoggedIn && User.ResetTime.HasValue && User.ResetTime.Value > DateTime.UtcNow)
{
var timeSpan = User.ResetTime.Value - DateTime.UtcNow;
ResetTimer = $"{timeSpan.Hours:D2} hours and {timeSpan.Minutes:D2} minutes";
}

PropertyChanged += (e, v) => Save();
WantedLanguageList.CollectionChanged += (e, v) => Save();
}
Expand Down Expand Up @@ -239,6 +238,7 @@ private async void CheckForUpdates()
}

public ReactiveCommand<Unit, Process> OpenProjectHomeCommand => ReactiveCommand.Create(() => Process.Start(new ProcessStartInfo("https://github.com/Valyreon/Subloader") { UseShellExecute = true }));
public ReactiveCommand<Unit, Process> RegisterCommand => ReactiveCommand.Create(() => Process.Start(new ProcessStartInfo("https://www.opensubtitles.com/en/users/sign_up") { UseShellExecute = true }));

public string LoginErrorText
{
Expand Down
Loading

0 comments on commit 964d3cf

Please sign in to comment.