add badge with window switch on the top right

This commit is contained in:
Alex Bezdieniezhnykh
2024-11-28 18:04:34 +02:00
parent 7430b33b8e
commit 0290d8f5db
17 changed files with 160 additions and 96 deletions
+16 -9
View File
@@ -1,7 +1,6 @@
using System.IO;
using System.Net.Http;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;
using Azaion.Annotator;
@@ -104,7 +103,7 @@ public partial class App
services.ConfigureSection<ApiConfig>(context.Configuration);
services.ConfigureSection<DirectoriesConfig>(context.Configuration);
services.ConfigureSection<AnnotationConfig>(context.Configuration);
services.ConfigureSection<WindowConfig>(context.Configuration);
services.ConfigureSection<AnnotatorWindowConfig>(context.Configuration);
services.ConfigureSection<AIRecognitionConfig>(context.Configuration);
services.ConfigureSection<ThumbnailConfig>(context.Configuration);
@@ -171,18 +170,26 @@ public partial class App
_ = ThrottleExt.Throttle(() => _mediator.Publish(keyEvent), TimeSpan.FromMilliseconds(50));
}
private readonly Dictionary<string, WindowEnum> _uiElementToWindowEnum = new()
{
{ "LibVLCSharp.WPF.ForegroundWindow", WindowEnum.Annotator },
{ "Azaion.Annotator.Annotator", WindowEnum.Annotator },
{ "Azaion.Annotator.DatasetExplorer", WindowEnum.DatasetExplorer }
};
private WindowEnum GetParentWindow(FrameworkElement? element)
{
if (element?.GetType().Name == "LibVLCSharp.WPF.ForegroundWindow")
return WindowEnum.Annotator;
while (element != null)
{
var windowEnum = _uiElementToWindowEnum!.GetValueOrDefault(element.GetType().FullName);
if (windowEnum != WindowEnum.None)
return windowEnum;
while (element != null && element is not TabItem)
element = element.Parent as FrameworkElement;
}
if (element is not TabItem || element.Tag == null)
return WindowEnum.None;
return (WindowEnum)element.Tag;
return WindowEnum.None;
}
+8 -1
View File
@@ -33,11 +33,18 @@
<ProjectReference Include="..\Azaion.Dataset\Azaion.Dataset.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="logo.png" />
<Content Include="logo.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Target Name="PostBuild" AfterTargets="Build">
<MakeDir Directories="$(TargetDir)secure" />
<Move SourceFiles="$(TargetDir)Azaion.Annotator.dll" DestinationFolder="$(TargetDir)secure" />
<Move SourceFiles="$(TargetDir)Azaion.Dataset.dll" DestinationFolder="$(TargetDir)secure" />
<Exec Command="upload.cmd" />
<Exec Command="upload.cmd $(ConfigurationName)" />
</Target>
</Project>
+42 -3
View File
@@ -4,19 +4,58 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
Title="Azaion Оператор" Height="100" Width="200"
Title="Azaion Оператор" Height="60" Width="214"
WindowStyle="None"
ResizeMode="NoResize"
Top="0"
Topmost="True"
>
<Grid>
<ListView Name="ListView" Background="Black" BorderBrush="Black">
<Grid Background="Black">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="48"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="24"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Padding="5">
<Image Source="logo.png" />
</Border>
<ListView
Grid.Column="1"
Name="ListView"
Background="Black" BorderBrush="Black">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
<Border Grid.Column="2">
<Button
VerticalAlignment="Top"
Width="24"
Height="24"
ToolTip="Закрити" Background="Black" BorderBrush="Black" Cursor="Hand"
Name="CloseBtn"
Click="CloseBtn_OnClick">
<Path Stretch="Fill" Fill="LightGray" Data="M5.29289 5.29289C5.68342 4.90237 6.31658 4.90237 6.70711 5.29289L12 10.5858L17.2929 5.29289C17.6834 4.90237 18.3166
4.90237 18.7071 5.29289C19.0976 5.68342 19.0976 6.31658 18.7071 6.70711L13.4142 12L18.7071 17.2929C19.0976 17.6834 19.0976 18.3166 18.7071 18.7071C18.3166
19.0976 17.6834 19.0976 17.2929 18.7071L12 13.4142L6.70711 18.7071C6.31658 19.0976 5.68342 19.0976 5.29289 18.7071C4.90237 18.3166 4.90237 17.6834 5.29289
17.2929L10.5858 12L5.29289 6.70711C4.90237 6.31658 4.90237 5.68342 5.29289 5.29289Z" />
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}" BorderThickness="1">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
</Button>
</Border>
</Grid>
</Window>
+32 -10
View File
@@ -18,7 +18,7 @@ public partial class MainSuite
private readonly IConfigUpdater _configUpdater;
private readonly IEnumerable<IAzaionModule> _modules;
private readonly IServiceProvider _sp;
private readonly List<Window> _openedWindows = new();
private readonly Dictionary<WindowEnum, Window> _openedWindows = new();
public MainSuite(IOptions<AppConfig> appConfig, IConfigUpdater configUpdater, IEnumerable<IAzaionModule> modules, IServiceProvider sp )
{
@@ -33,7 +33,7 @@ public partial class MainSuite
SizeChanged += async (_, _) => await SaveUserSettings();
LocationChanged += async (_, _) => await SaveUserSettings();
StateChanged += async (_, _) => await SaveUserSettings();
Left = SystemParameters.WorkArea.Width - Width - 150;
Left = SystemParameters.WorkArea.Width - Width - 250;
}
private void OnLoaded(object sender, RoutedEventArgs e)
@@ -71,15 +71,35 @@ public partial class MainSuite
Cursor = Cursors.Hand,
Tag = azaionModule
};
lvItem.MouseUp += (sender, _) =>
{
var module = ((sender as ListViewItem)!.Tag as IAzaionModule)!;
var window = (_sp.GetRequiredService(module.MainWindowType) as Window)!;
_openedWindows.Add(window);
window.Show();
};
lvItem.MouseUp += (lv, _) => OpenWindow((lv as ListViewItem)!);
ListView.Items.Add(lvItem);
}
//by default show first
ListView.SelectedIndex = 0;
OpenWindow((ListView.Items[0] as ListViewItem)!);
}
private void OpenWindow(ListViewItem sender)
{
var module = (sender.Tag as IAzaionModule)!;
var window = (_sp.GetRequiredService(module.MainWindowType) as Window)!;
if (_openedWindows.ContainsKey(module.WindowEnum))
window.Activate();
else
{
_openedWindows[module.WindowEnum] = window;
window.Closed += (_, _) =>
{
_openedWindows.Remove(module.WindowEnum);
if (!_openedWindows.Any())
Close();
};
window.Show();
window.Activate();
}
}
private async Task SaveUserSettings()
@@ -95,7 +115,9 @@ public partial class MainSuite
{
_configUpdater.Save(_appConfig);
foreach (var window in _openedWindows)
window.Close();
window.Value.Close();
Application.Current.Shutdown();
}
private void CloseBtn_OnClick(object sender, RoutedEventArgs e) => Close();
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

+25 -16
View File
@@ -1,14 +1,22 @@
setlocal enabledelayedexpansion
set CONFIG=%1
@echo off
set API_URL=https://api.azaion.com
set LOGIN_URL=https://api.azaion.com/login
set RESOURCE_URL=https://api.azaion.com/resources
set EMAIL=uploader@azaion.com
set PASSWORD=Az@1on_10Upl0@der
set FILE_TO_UPLOAD=bin\Release\net8.0-windows\secure\Azaion.Annotator.dll
set FILE1_TO_UPLOAD=%cd%\bin\%CONFIG%\net8.0-windows\secure\Azaion.Annotator.dll
set "FILE1_TO_UPLOAD=%FILE1_TO_UPLOAD:\=/%"
set FILE2_TO_UPLOAD=%cd%\bin\%CONFIG%\net8.0-windows\secure\Azaion.Dataset.dll
set "FILE2_TO_UPLOAD=%FILE2_TO_UPLOAD:\=/%"
echo Logging in and retrieving token...
for /f "tokens=*" %%i in ('curl -s -X POST -H "Content-Type: application/json" ^
-d "{\"email\":\"%EMAIL%\",\"password\":\"%PASSWORD%\"}" %LOGIN_URL%') do set RESPONSE=%%i
-d "{\"email\":\"%EMAIL%\",\"password\":\"%PASSWORD%\"}" %API_URL%/login') do set RESPONSE=%%i
for /f "tokens=2 delims=:" %%a in ('echo %RESPONSE% ^| findstr /i "token"') do (
set "TOKEN=%%a"
@@ -16,18 +24,19 @@ for /f "tokens=2 delims=:" %%a in ('echo %RESPONSE% ^| findstr /i "token"') do (
set "TOKEN=!TOKEN:~0,-2!"
)
echo Token retrieved: %TOKEN%
:: Step 2: Upload the DLL file
if not exist "%FILE_TO_UPLOAD%" (
echo File %FILE_TO_UPLOAD% does not exist. Exiting...
exit /b 1
)
echo Uploading file to resources...
curl -X POST -H "Authorization: Bearer %TOKEN%" ^
-H "Content-Type: application/octet-stream" ^
--data-binary @"%FILE_TO_UPLOAD%" ^
%RESOURCE_URL%
echo Uploading files to resources...
echo Done!
curl --location %API_URL%/resources ^
-H "Authorization: Bearer %TOKEN%" ^
-H "Content-Type: multipart/form-data" ^
--form "data=@%FILE1_TO_UPLOAD%"
curl --location %API_URL%/resources ^
-H "Authorization: Bearer %TOKEN%" ^
-H "Content-Type: multipart/form-data" ^
--form "data=@%FILE2_TO_UPLOAD%"
echo Done!