Release v0.1.0

This commit is contained in:
nikit3s
2026-09-26 21:51:08 +03:00
parent 1975c1ceff
commit 7ac8c78d8b
12 changed files with 317 additions and 52 deletions
+33 -6
View File
@@ -5,6 +5,8 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using SbLauncher;
@@ -15,16 +17,19 @@ public static class UiStress
{
var app = new Application();
app.ShutdownMode = ShutdownMode.OnExplicitShutdown;
var root = AppDomain.CurrentDomain.BaseDirectory;
var window = (Window)XamlReader.Parse(File.ReadAllText(Path.Combine(root, "Ui.xaml")));
var sourceRoot = AppDomain.CurrentDomain.BaseDirectory;
var dataRoot = Environment.GetEnvironmentVariable("SB_STRESS_ROOT");
if (string.IsNullOrEmpty(dataRoot)) dataRoot = sourceRoot;
var window = (Window)XamlReader.Parse(File.ReadAllText(Path.Combine(sourceRoot, "Ui.xaml")));
var vm = new MainVm();
window.DataContext = vm;
vm.ThemeApplier = delegate(string theme) { Theme.Apply(window, theme); };
vm.Load(new Paths(root));
vm.Load(new Paths(dataRoot));
vm.SetTheme(Theme.Dark);
var stopwatch = Stopwatch.StartNew();
long previous = 0, longest = 0;
int ticks = 0;
bool cleared = false;
var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(50) };
timer.Tick += delegate
{
@@ -38,7 +43,17 @@ public static class UiStress
// проверить запуск и остановку Storyboard при нагрузке.
if (ticks % 10 == 0)
vm.ConnectionPhase = new[] { "connecting", "connected", "disconnecting", "idle" }[(ticks / 10) % 4];
if (now >= 4000) { timer.Stop(); app.Shutdown(); }
if (ticks == 32 && !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SB_STRESS_SCREENSHOT")))
{
vm.SetTheme(Theme.Light);
Capture(window, Environment.GetEnvironmentVariable("SB_STRESS_SCREENSHOT"));
}
if (ticks == 20)
{
vm.ClearLogCommand.Execute(null);
cleared = vm.LogText.Length == 0;
}
if (now >= 5000) { timer.Stop(); app.Shutdown(); }
};
window.Show();
timer.Start();
@@ -48,7 +63,19 @@ public static class UiStress
});
app.Run();
vm.DisposeTimers();
Console.WriteLine("UI ticks: " + ticks + ", max interval: " + longest + " ms, log length: " + vm.LogText.Length);
return ticks >= 40 && longest < 500 && vm.LogText.Length <= 50000 ? 0 : 1;
Console.WriteLine("UI ticks: " + ticks + ", max interval: " + longest +
" ms, log length: " + vm.LogText.Length + ", clear: " + cleared);
return ticks >= 30 && longest < 500 && vm.LogText.Length <= 50000 && cleared ? 0 : 1;
}
static void Capture(Window window, string path)
{
window.UpdateLayout();
var bmp = new RenderTargetBitmap((int)window.Width, (int)window.Height,
96, 96, PixelFormats.Pbgra32);
bmp.Render((Visual)window.Content);
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
using (var stream = new FileStream(path, FileMode.Create)) encoder.Save(stream);
}
}