commit 52835ebd4f5be843228c4a8f367774d0f359be62 Author: Marto Date: Thu Jan 1 15:58:28 2026 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..556087b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/SilentShutdown/bin/ +/SilentShutdown/obj +.idea \ No newline at end of file diff --git a/SilentShutdown.sln b/SilentShutdown.sln new file mode 100644 index 0000000..4eca152 --- /dev/null +++ b/SilentShutdown.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SilentShutdown", "SilentShutdown\SilentShutdown.csproj", "{DE9DEAC2-DEB9-49C5-9784-0B2018DC4D69}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DE9DEAC2-DEB9-49C5-9784-0B2018DC4D69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DE9DEAC2-DEB9-49C5-9784-0B2018DC4D69}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DE9DEAC2-DEB9-49C5-9784-0B2018DC4D69}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DE9DEAC2-DEB9-49C5-9784-0B2018DC4D69}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/SilentShutdown/App.axaml b/SilentShutdown/App.axaml new file mode 100644 index 0000000..1bfacc6 --- /dev/null +++ b/SilentShutdown/App.axaml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/SilentShutdown/App.axaml.cs b/SilentShutdown/App.axaml.cs new file mode 100644 index 0000000..65fa9f6 --- /dev/null +++ b/SilentShutdown/App.axaml.cs @@ -0,0 +1,47 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Data.Core; +using Avalonia.Data.Core.Plugins; +using System.Linq; +using Avalonia.Markup.Xaml; +using SilentShutdown.ViewModels; +using SilentShutdown.Views; + +namespace SilentShutdown; + +public partial class App : Application +{ + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + // Avoid duplicate validations from both Avalonia and the CommunityToolkit. + // More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins + DisableAvaloniaDataAnnotationValidation(); + desktop.MainWindow = new MainWindow + { + DataContext = new MainWindowViewModel(), + }; + } + + base.OnFrameworkInitializationCompleted(); + } + + private void DisableAvaloniaDataAnnotationValidation() + { + // Get an array of plugins to remove + var dataValidationPluginsToRemove = + BindingPlugins.DataValidators.OfType().ToArray(); + + // remove each entry found + foreach (var plugin in dataValidationPluginsToRemove) + { + BindingPlugins.DataValidators.Remove(plugin); + } + } +} \ No newline at end of file diff --git a/SilentShutdown/Assets/avalonia-logo.ico b/SilentShutdown/Assets/avalonia-logo.ico new file mode 100644 index 0000000..f7da8bb Binary files /dev/null and b/SilentShutdown/Assets/avalonia-logo.ico differ diff --git a/SilentShutdown/Models/DataStorage.cs b/SilentShutdown/Models/DataStorage.cs new file mode 100644 index 0000000..61e89db --- /dev/null +++ b/SilentShutdown/Models/DataStorage.cs @@ -0,0 +1,16 @@ +using System; +using System.IO; + +namespace SilentShutdown.Models; + +public class DataStorage +{ + private string Path { get; set; } + + public DataStorage() + { + Path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SilentShutdown", + "settings.json"); + Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Path)!); + } +} \ No newline at end of file diff --git a/SilentShutdown/Program.cs b/SilentShutdown/Program.cs new file mode 100644 index 0000000..8dbf477 --- /dev/null +++ b/SilentShutdown/Program.cs @@ -0,0 +1,21 @@ +using Avalonia; +using System; + +namespace SilentShutdown; + +sealed class Program +{ + // Initialization code. Don't use any Avalonia, third-party APIs or any + // SynchronizationContext-reliant code before AppMain is called: things aren't initialized + // yet and stuff might break. + [STAThread] + public static void Main(string[] args) => BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace(); +} \ No newline at end of file diff --git a/SilentShutdown/SilentShutdown.csproj b/SilentShutdown/SilentShutdown.csproj new file mode 100644 index 0000000..c743b9f --- /dev/null +++ b/SilentShutdown/SilentShutdown.csproj @@ -0,0 +1,26 @@ + + + WinExe + net9.0 + enable + app.manifest + true + + + + + + + + + + + + + + None + All + + + + diff --git a/SilentShutdown/ViewLocator.cs b/SilentShutdown/ViewLocator.cs new file mode 100644 index 0000000..3c2c1c7 --- /dev/null +++ b/SilentShutdown/ViewLocator.cs @@ -0,0 +1,37 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using SilentShutdown.ViewModels; + +namespace SilentShutdown; + +/// +/// Given a view model, returns the corresponding view if possible. +/// +[RequiresUnreferencedCode( + "Default implementation of ViewLocator involves reflection which may be trimmed away.", + Url = "https://docs.avaloniaui.net/docs/concepts/view-locator")] +public class ViewLocator : IDataTemplate +{ + public Control? Build(object? param) + { + if (param is null) + return null; + + var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); + var type = Type.GetType(name); + + if (type != null) + { + return (Control)Activator.CreateInstance(type)!; + } + + return new TextBlock { Text = "Not Found: " + name }; + } + + public bool Match(object? data) + { + return data is ViewModelBase; + } +} \ No newline at end of file diff --git a/SilentShutdown/ViewModels/MainWindowViewModel.cs b/SilentShutdown/ViewModels/MainWindowViewModel.cs new file mode 100644 index 0000000..72fc345 --- /dev/null +++ b/SilentShutdown/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,6 @@ +namespace SilentShutdown.ViewModels; + +public partial class MainWindowViewModel : ViewModelBase +{ + public string Greeting { get; } = "Welcome to Avalonia!"; +} \ No newline at end of file diff --git a/SilentShutdown/ViewModels/ViewModelBase.cs b/SilentShutdown/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..909acad --- /dev/null +++ b/SilentShutdown/ViewModels/ViewModelBase.cs @@ -0,0 +1,7 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace SilentShutdown.ViewModels; + +public abstract class ViewModelBase : ObservableObject +{ +} \ No newline at end of file diff --git a/SilentShutdown/Views/MainWindow.axaml b/SilentShutdown/Views/MainWindow.axaml new file mode 100644 index 0000000..ecedc1c --- /dev/null +++ b/SilentShutdown/Views/MainWindow.axaml @@ -0,0 +1,20 @@ + + + + + + + + + + diff --git a/SilentShutdown/Views/MainWindow.axaml.cs b/SilentShutdown/Views/MainWindow.axaml.cs new file mode 100644 index 0000000..5d57df3 --- /dev/null +++ b/SilentShutdown/Views/MainWindow.axaml.cs @@ -0,0 +1,11 @@ +using Avalonia.Controls; + +namespace SilentShutdown.Views; + +public partial class MainWindow : Window +{ + public MainWindow() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/SilentShutdown/app.manifest b/SilentShutdown/app.manifest new file mode 100644 index 0000000..e66ac0d --- /dev/null +++ b/SilentShutdown/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + +