Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
UI now animates correctly
Now the songs you play are scrobbled to the server
  • Loading branch information
Carlos Pérez committed Jul 20, 2022
1 parent c6cbbe1 commit dd7d0f2
Show file tree
Hide file tree
Showing 14 changed files with 295 additions and 226 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ I'm working on getting a pipeline on github actions to get signed bundles for in

### Terminal

[<img src="./ghlogo.svg" width="150px">](https://github.com/thelinkin3000/SonicLair.Net/releases)

The terminal version is an (almost) self contained executable. You can grab the version for your operating system from the releases page. Within the compressed file there is the excutable and (if applicable) the libvlc libraries needed for the audio backend to work. Please keep the directory structure as is.

### Linux caveats
Expand Down
4 changes: 2 additions & 2 deletions SonicLair.Cli/Headless.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Headless()

}

public async void Configure()
public async Task Configure()
{
var _subsonicService = new SubsonicService();
var _musicPlayerService = new MusicPlayerService(_subsonicService);
Expand Down Expand Up @@ -64,7 +64,7 @@ public async void Configure()
}
}
}
catch (Exception ex)
catch (Exception)
{
Console.WriteLine("Error reading the config file. " +
"Please read the docs on github or launch the app in gui mode (no -h) to log in for the first time to your server.");
Expand Down
2 changes: 1 addition & 1 deletion SonicLair.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Console.WriteLine("Headless mode!");
var headless = new Headless();
var token = headless.Token;
headless.Configure();
_ = headless.Configure();
while (!token.IsCancellationRequested)
{
Thread.Sleep(1000);
Expand Down
2 changes: 1 addition & 1 deletion SonicLair.Cli/SonicLairControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public static void AnimateTextView(TextView field, string[] values, int delay, C
{
field.Text = value;
});
Thread.Sleep(delay);
}
Thread.Sleep(delay);
}
});
}
Expand Down
39 changes: 37 additions & 2 deletions SonicLair.Cli/SonicLairListView.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using SonicLairCli;

using SonicLair.Lib.Infrastructure;


using System.Diagnostics;

using Terminal.Gui;
Expand All @@ -13,6 +16,38 @@ public SonicLairListView()
ColorScheme = SonicLairControls.ListViewColorScheme;
}

private Action<SonicLairListView<T>>? _onLeave = null;

public void SetOnLeave(Action<SonicLairListView<T>> action)
{
_onLeave = action;
}

public override bool OnLeave(View view)
{
if (_onLeave != null)
{
_onLeave(this);
}
return base.OnLeave(view);
}

public void ScrollTo(int index)
{
GetCurrentHeight(out int height);
if (Source.Count <= height)
{
return;
}
ScrollUp(Source.Count);
int slack = height / 2;
if(index < slack)
{
return;
}
ScrollDown((index - height + slack).Clamp(0, Source.Count - height));
}

private readonly Dictionary<Key, Action> _hotkeys = new Dictionary<Key, Action>();

public void RegisterHotKey(Key key, Action action)
Expand Down Expand Up @@ -83,9 +118,9 @@ public override bool ProcessKey(KeyEvent kb)
return Process(kb, base.ProcessKey);
}

public override bool ProcessHotKey(KeyEvent kb)
public override bool ProcessHotKey(KeyEvent keyEvent)
{
return Process(kb, base.ProcessHotKey);
return Process(keyEvent, base.ProcessHotKey);
}
}
}
33 changes: 16 additions & 17 deletions SonicLair.Cli/Windows/LoginWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public class LoginWindow : IWindowFrame
{
private readonly Toplevel _top;
private readonly ISubsonicService _service;
private TextField loginText;
private TextField passText;
private TextField urlText;
private CheckBox usePlaintext;
private TextView status;
private TextField? loginText;
private TextField? passText;
private TextField? urlText;
private CheckBox? usePlaintext;
private TextView? status;
private readonly MainWindow _main;

public LoginWindow(Toplevel top, MainWindow main)
Expand All @@ -28,28 +28,28 @@ public LoginWindow(Toplevel top, MainWindow main)
_main = main;
}

private async void LoginClick()
private void LoginClick()
{
if (loginText.Text == null || loginText.Text.IsEmpty ||
passText.Text == null || passText.Text.IsEmpty ||
urlText.Text == null || urlText.Text.IsEmpty)
if (loginText?.Text == null || loginText.Text.IsEmpty ||
passText?.Text == null || passText.Text.IsEmpty ||
urlText?.Text == null || urlText.Text.IsEmpty)
{
MessageBox.ErrorQuery("Error", "At least one field is empty. Please, fill out all fields.", "Ok");
return;
}
else
{
Login(loginText.Text.ToString()!.Trim(),
_ = Login(loginText.Text.ToString()!.Trim(),
passText.Text.ToString()!.Trim(),
urlText.Text.ToString()!.Trim(),
usePlaintext.Checked);
usePlaintext?.Checked ?? false);
}
}

private async void Login(string user, string password, string url, bool plaintext)
private async Task Login(string user, string password, string url, bool plaintext)
{
var cancellationTokenSource = new CancellationTokenSource();
SonicLairControls.AnimateTextView(status,
SonicLairControls.AnimateTextView(status!,
new string[] {
$"Logging into {url} |",
$"Logging into {url} /",
Expand All @@ -68,7 +68,7 @@ private async void Login(string user, string password, string url, bool plaintex
_service.Configure(account);
try
{
var artists = await _service.GetArtists();
_ = await _service.GetArtists();
var directory = Path.Join(Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile), ".soniclair");
Directory.CreateDirectory(directory);
var path = Path.Join(directory, "config.json");
Expand Down Expand Up @@ -97,7 +97,6 @@ private async void Login(string user, string password, string url, bool plaintex
catch (Exception ex)
{
MessageBox.ErrorQuery("Error", ex.Message, "Ok");
return;
}
}

Expand Down Expand Up @@ -235,10 +234,10 @@ public void Load()
return;
}
configFile.Close();
Login(account.Username, account.Password, account.Url, account.UsePlaintext);
_ = Login(account.Username, account.Password, account.Url, account.UsePlaintext);
}
}
catch (Exception ex)
catch (Exception)
{
MessageBox.ErrorQuery("Error!", "Error reading the config file. Log in again and the app will recreate it.", "Ok");
}
Expand Down
Loading

0 comments on commit dd7d0f2

Please sign in to comment.