feat(app): 初始化自动关机工具首个版本
实现基于 WPF 的 AutoShutdown 主界面,支持关机、重启、睡眠、休眠、唤醒、锁屏和注销等电源任务。 支持指定时间和倒计时计划、执行前提醒、系统关机撤销、Windows 唤醒任务、托盘运行、自定义图标以及 OmniNotify 通知适配。 修复关闭到托盘时的运行提醒,并支持单击托盘图标打开或收起主界面。 补充 README、发布配置和 win-x64 Release 输出要求。 Release: win-x64
This commit is contained in:
103
Program.cs
Normal file
103
Program.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace AutoShutdown;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
[STAThread]
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
var app = new System.Windows.Application();
|
||||
|
||||
#if DEBUG
|
||||
if (args.Any(arg => arg.Equals("--capture-notification-settings-ui", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
CaptureNotificationSettingsUiAndExit(app, args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Any(arg => arg.Equals("--capture-ui", StringComparison.OrdinalIgnoreCase) || arg.StartsWith("--capture-ui=", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
CaptureUiAndExit(app, args);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
app.Run(new MainWindow());
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
private static void CaptureUiAndExit(System.Windows.Application app, string[] args)
|
||||
{
|
||||
var size = ResolveCaptureSize(args);
|
||||
var window = new MainWindow(enableTray: false)
|
||||
{
|
||||
WindowStartupLocation = WindowStartupLocation.Manual,
|
||||
Left = -20000,
|
||||
Top = -20000,
|
||||
Width = size.Width,
|
||||
Height = size.Height,
|
||||
ShowInTaskbar = false
|
||||
};
|
||||
|
||||
window.ContentRendered += (_, _) =>
|
||||
{
|
||||
window.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
var requestedPath = args
|
||||
.FirstOrDefault(arg => arg.StartsWith("--capture-ui=", StringComparison.OrdinalIgnoreCase))
|
||||
?.Split('=', 2)[1];
|
||||
|
||||
var path = Services.ScreenshotService.Capture(window, requestedPath);
|
||||
Console.WriteLine(path);
|
||||
window.Close();
|
||||
}, System.Windows.Threading.DispatcherPriority.ApplicationIdle);
|
||||
};
|
||||
|
||||
app.Run(window);
|
||||
}
|
||||
|
||||
private static void CaptureNotificationSettingsUiAndExit(System.Windows.Application app, string[] args)
|
||||
{
|
||||
var window = new NotificationSettingsWindow(
|
||||
Models.NotificationSettings.Default(),
|
||||
new Services.NotificationService(Models.NotificationSettings.Default()))
|
||||
{
|
||||
WindowStartupLocation = WindowStartupLocation.Manual,
|
||||
Left = -20000,
|
||||
Top = -20000,
|
||||
ShowInTaskbar = false
|
||||
};
|
||||
|
||||
window.ContentRendered += (_, _) =>
|
||||
{
|
||||
window.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
var requestedPath = args
|
||||
.FirstOrDefault(arg => arg.StartsWith("--capture-ui=", StringComparison.OrdinalIgnoreCase))
|
||||
?.Split('=', 2)[1];
|
||||
|
||||
var path = Services.ScreenshotService.Capture(window, requestedPath);
|
||||
Console.WriteLine(path);
|
||||
window.Close();
|
||||
}, System.Windows.Threading.DispatcherPriority.ApplicationIdle);
|
||||
};
|
||||
|
||||
app.Run(window);
|
||||
}
|
||||
|
||||
private static System.Windows.Size ResolveCaptureSize(string[] args)
|
||||
{
|
||||
var sizeArg = args.FirstOrDefault(arg => arg.StartsWith("--capture-size=", StringComparison.OrdinalIgnoreCase));
|
||||
if (sizeArg is null)
|
||||
{
|
||||
return new System.Windows.Size(1100, 760);
|
||||
}
|
||||
|
||||
var raw = sizeArg.Split('=', 2)[1].ToLowerInvariant().Split('x', 2);
|
||||
return raw.Length == 2 && double.TryParse(raw[0], out var width) && double.TryParse(raw[1], out var height)
|
||||
? new System.Windows.Size(width, height)
|
||||
: new System.Windows.Size(1100, 760);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user