SiteViewer/SiteViewer/App.xaml.cs
kykaevv f04a0d517c Initial commit: SiteViewer kiosk app (WPF + WebView2, schedule, LAN admin).
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-01 13:09:05 +03:00

98 lines
3.0 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
using SiteViewer.Services;
namespace SiteViewer
{
public partial class App : Application
{
public static SitesStore Sites { get; } = new SitesStore();
public static UiSettings Ui { get; } = new UiSettings();
public static AdminHost Admin { get; } = new AdminHost(Sites);
public static string WebViewUserDataFolder { get; } = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"SiteViewer",
"WebView2");
protected override void OnStartup(StartupEventArgs e)
{
DispatcherUnhandledException += (_, args) =>
{
args.Handled = true;
try
{
MessageBox.Show(
"Произошла ошибка, приложение продолжит работу.\n\n" + args.Exception.Message,
"SiteViewer",
MessageBoxButton.OK,
MessageBoxImage.Warning);
}
catch
{
// ignore
}
};
AppDomain.CurrentDomain.UnhandledException += (_, args) =>
{
if (args.ExceptionObject is Exception ex)
{
try
{
var folder = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"SiteViewer");
Directory.CreateDirectory(folder);
File.AppendAllText(
Path.Combine(folder, "crash.log"),
"[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "] " + ex + "\n\n");
}
catch
{
// ignore
}
}
};
TaskScheduler.UnobservedTaskException += (_, args) =>
{
args.SetObserved();
};
Directory.CreateDirectory(WebViewUserDataFolder);
base.OnStartup(e);
try
{
Admin.Start();
}
catch (Exception ex)
{
MessageBox.Show(
"Не удалось запустить веб-сервер на порту " + AdminHost.Port + ".\n" + ex.Message,
"SiteViewer",
MessageBoxButton.OK,
MessageBoxImage.Warning);
}
}
protected override void OnExit(ExitEventArgs e)
{
try
{
Admin.Dispose();
}
catch
{
// ignore
}
base.OnExit(e);
}
}
}