Skip to content

Commit

Permalink
feat: read lexoffice voucher url from clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
DerStimmler committed Feb 14, 2025
1 parent 7efa313 commit 19c6a00
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 98 deletions.
211 changes: 113 additions & 98 deletions Lexoffice/LexofficeRechnungskontrolle.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions Lexoffice/LexofficeRechnungskontrolle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public partial class LexofficeRechnungskontrolle : UserControl
private readonly IKundeRepository _kundeRepository;
private readonly LexofficeEinstellungen _lexofficeKonfiguration;
private readonly IMitarbeiterRepository _mitarbeiterRepository;
private readonly CancellationTokenSource _cts;

public LexofficeRechnungskontrolle(
LexofficeEinstellungen lexofficeKonfiguration,
Expand All @@ -32,11 +33,55 @@ IKontoRepository kontoRepository
)
{
InitializeComponent();

txtLexofficeClipboardHint.Visible = false;

_lexofficeKonfiguration = lexofficeKonfiguration;
_clockodoEinstellungen = clockodoEinstellungen;
_mitarbeiterRepository = mitarbeiterRepository;
_kundeRepository = kundeRepository;
_kontoRepository = kontoRepository;

_cts = new CancellationTokenSource();

ObserveClipboard();
}

private void ObserveClipboard()
{
Task.Run(async () =>
{
while (!_cts.Token.IsCancellationRequested)
{
var staThread = new Thread(() =>
{
try
{
var clipboardText = Clipboard.GetText();

Invoke(() =>
{
txtLexofficeClipboardHint.Visible = IsLexofficeInvoiceUrl(clipboardText);
});
}
catch (Exception)
{
// ignored
}
});
staThread.SetApartmentState(ApartmentState.STA);
staThread.Start();
staThread.Join();

// Use await to properly delay:
await Task.Delay(1000, _cts.Token);
}
}, _cts.Token);
}

private static bool IsLexofficeInvoiceUrl(string url)
{
return url.StartsWith("https://app.lexoffice.de/voucher/");
}

private async void btnRechnungPrüfen_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -154,4 +199,12 @@ private Result<string> RechnungsIdAuslesen(string text)

return übereinstimmungen.Value;
}

private void txtLexofficeClipboardHint_Click(object sender, EventArgs e)
{
var clipboardText = Clipboard.GetText();

if (IsLexofficeInvoiceUrl(clipboardText))
tbxRechnungUrl.Text = clipboardText;
}
}

0 comments on commit 19c6a00

Please sign in to comment.