mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 22:46:30 +00:00
rework to Azaion.Suite
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using Azaion.Annotator.Extensions;
|
||||
using Azaion.Common.DTO.Config;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Azaion.Suite;
|
||||
|
||||
public partial class MainSuite : Window
|
||||
{
|
||||
private readonly AppConfig _appConfig;
|
||||
private readonly IConfigUpdater _configUpdater;
|
||||
|
||||
public MainSuite(IOptions<AppConfig> appConfig, IConfigUpdater configUpdater)
|
||||
{
|
||||
_configUpdater = configUpdater;
|
||||
_appConfig = appConfig.Value;
|
||||
InitializeComponent();
|
||||
Loaded += OnLoaded;
|
||||
Closed += OnFormClosed;
|
||||
|
||||
SizeChanged += async (_, _) => await SaveUserSettings();
|
||||
LocationChanged += async (_, _) => await SaveUserSettings();
|
||||
StateChanged += async (_, _) => await SaveUserSettings();
|
||||
}
|
||||
|
||||
private void OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!Directory.Exists(_appConfig.DirectoriesConfig.LabelsDirectory))
|
||||
Directory.CreateDirectory(_appConfig.DirectoriesConfig.LabelsDirectory);
|
||||
if (!Directory.Exists(_appConfig.DirectoriesConfig.ImagesDirectory))
|
||||
Directory.CreateDirectory(_appConfig.DirectoriesConfig.ImagesDirectory);
|
||||
if (!Directory.Exists(_appConfig.DirectoriesConfig.ResultsDirectory))
|
||||
Directory.CreateDirectory(_appConfig.DirectoriesConfig.ResultsDirectory);
|
||||
|
||||
|
||||
Left = _appConfig.WindowConfig.WindowLocation.X;
|
||||
Top = _appConfig.WindowConfig.WindowLocation.Y;
|
||||
Width = _appConfig.WindowConfig.WindowSize.Width;
|
||||
Height = _appConfig.WindowConfig.WindowSize.Height;
|
||||
|
||||
if (_appConfig.WindowConfig.FullScreen)
|
||||
WindowState = WindowState.Maximized;
|
||||
}
|
||||
|
||||
private async Task SaveUserSettings()
|
||||
{
|
||||
await ThrottleExt.Throttle(() =>
|
||||
{
|
||||
_configUpdater.Save(_appConfig);
|
||||
return Task.CompletedTask;
|
||||
}, TimeSpan.FromSeconds(5));
|
||||
}
|
||||
|
||||
private void OnFormClosed(object? sender, EventArgs e)
|
||||
{
|
||||
_configUpdater.Save(_appConfig);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user