mirror of
https://github.com/achiez/NebulaAuth-Steam-Desktop-Authenticator-by-Achies.git
synced 2026-08-03 10:09:19 +00:00
Move projects to ./src
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using NebulaAuth.Core;
|
||||
using NebulaAuth.Model;
|
||||
using SteamLib.SteamMobile;
|
||||
|
||||
namespace NebulaAuth.ViewModel;
|
||||
|
||||
public partial class MainVM
|
||||
{
|
||||
[ObservableProperty] private string _code = "Code";
|
||||
[ObservableProperty] private double _codeProgress;
|
||||
private Timer _codeTimer;
|
||||
|
||||
|
||||
[MemberNotNull(nameof(_codeTimer))]
|
||||
private void CreateCodeTimer()
|
||||
{
|
||||
CodeProgress = CalculateCodeProgress();
|
||||
_codeTimer = new Timer(UpdateCode, null, 0, 1000);
|
||||
}
|
||||
|
||||
private void UpdateCode(object? state = null)
|
||||
{
|
||||
var currentTime = TimeAligner.GetSteamTime();
|
||||
var untilChange = currentTime % 30;
|
||||
if (untilChange != 0) return;
|
||||
|
||||
if (Application.Current == null) return;
|
||||
Application.Current.Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
CodeProgress = -1;
|
||||
CodeProgress = 30;
|
||||
if (Application.Current.MainWindow?.WindowState == WindowState.Minimized) return;
|
||||
if (SelectedMafile == null) return;
|
||||
Code = SteamGuardCodeGenerator.GenerateCode(SelectedMafile.SharedSecret);
|
||||
}, DispatcherPriority.Normal);
|
||||
}
|
||||
|
||||
|
||||
private long CalculateCodeProgress()
|
||||
{
|
||||
var currentTime = TimeAligner.GetSteamTime();
|
||||
var untilChange = currentTime % 30;
|
||||
return 30 - untilChange;
|
||||
}
|
||||
|
||||
|
||||
[RelayCommand(AllowConcurrentExecutions = false)]
|
||||
private async Task CopyCode()
|
||||
{
|
||||
var selectedMafile = SelectedMafile;
|
||||
if (selectedMafile == null) return;
|
||||
try
|
||||
{
|
||||
Clipboard.SetText(Code);
|
||||
Code = LocManager.GetOrDefault("CodeCopied", "MainWindow", "CodeCopied");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Shell.Logger.Error(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await Task.Delay(200);
|
||||
selectedMafile = SelectedMafile;
|
||||
if (selectedMafile != null)
|
||||
Code = SteamGuardCodeGenerator.GenerateCode(selectedMafile.SharedSecret);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user