feat: make Windows Agent configuration GUI-only
Build web service image / build (push) Successful in 40s
Build web service image / build (push) Successful in 40s
This commit is contained in:
@@ -15,22 +15,16 @@ internal static class Program
|
||||
[STAThread]
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
if (args.Contains("--prevent-auto-lock", StringComparer.OrdinalIgnoreCase))
|
||||
if (args.Length != 0)
|
||||
{
|
||||
PowerPolicy.Apply();
|
||||
if (args.Contains("--exit", StringComparer.OrdinalIgnoreCase)) return;
|
||||
MessageBox.Show("请直接双击 WxAgent.Tray.exe 运行;启动参数和命令行配置不受支持。", "WxAgent", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
ApplicationConfiguration.Initialize();
|
||||
var configPath = GetOption(args, "--config") ?? Path.Combine(AppContext.BaseDirectory, "service.json");
|
||||
using var context = new TrayApplicationContext(Path.GetFullPath(configPath));
|
||||
Application.Run(context);
|
||||
}
|
||||
|
||||
private static string? GetOption(string[] args, string name)
|
||||
{
|
||||
for (var index = 0; index < args.Length - 1; index++)
|
||||
if (args[index] == name) return args[index + 1];
|
||||
return null;
|
||||
ApplicationConfiguration.Initialize();
|
||||
var configPath = Path.Combine(AppContext.BaseDirectory, "service.json");
|
||||
using var context = new TrayApplicationContext(configPath);
|
||||
Application.Run(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +98,7 @@ internal sealed class TrayApplicationContext : ApplicationContext
|
||||
Visible = true,
|
||||
ContextMenuStrip = menu
|
||||
};
|
||||
trayIcon.DoubleClick += (_, _) => OpenConsole();
|
||||
trayIcon.DoubleClick += (_, _) => OpenConfig();
|
||||
try
|
||||
{
|
||||
var firstRun = EnsureConfiguration();
|
||||
@@ -178,7 +172,8 @@ internal sealed class TrayApplicationContext : ApplicationContext
|
||||
Remote = source.Remote,
|
||||
Reporting = source.Reporting,
|
||||
RemoteConfigurationFile = source.RemoteConfigurationFile,
|
||||
EnableValidationOperations = source.EnableValidationOperations
|
||||
EnableValidationOperations = source.EnableValidationOperations,
|
||||
PreventAutoLock = source.PreventAutoLock
|
||||
};
|
||||
|
||||
private ServiceOptions ReadOptions() =>
|
||||
@@ -191,6 +186,7 @@ internal sealed class TrayApplicationContext : ApplicationContext
|
||||
var loaded = ReadOptions();
|
||||
loaded.Validate();
|
||||
options = loaded;
|
||||
if (loaded.PreventAutoLock) PowerPolicy.Apply();
|
||||
service = ServiceHost.Build(loaded, new WindowsAgentBackend(new AccountBindingStore(loaded), loaded), logPath: GetLogPath());
|
||||
try
|
||||
{
|
||||
@@ -363,7 +359,7 @@ internal static class ServiceSettingsEditor
|
||||
{
|
||||
Text = "WxAgent 服务设置",
|
||||
Width = 620,
|
||||
Height = 355,
|
||||
Height = 405,
|
||||
StartPosition = FormStartPosition.CenterScreen,
|
||||
MinimizeBox = false,
|
||||
MaximizeBox = false,
|
||||
@@ -377,18 +373,30 @@ internal static class ServiceSettingsEditor
|
||||
var tokenBox = new TextBox { Left = 145, Top = 87, Width = 345, Text = token, MaxLength = 0 };
|
||||
var copy = new Button { Left = 500, Top = 85, Width = 88, Text = "复制" };
|
||||
var regenerate = new Button { Left = 145, Top = 123, Width = 105, Text = "重新生成" };
|
||||
var validation = new CheckBox
|
||||
{
|
||||
Left = 145, Top = 158, Width = 430,
|
||||
Text = "启用本机验证写操作(仅授权测试机)",
|
||||
Checked = current.EnableValidationOperations
|
||||
};
|
||||
var preventAutoLock = new CheckBox
|
||||
{
|
||||
Left = 145, Top = 187, Width = 430,
|
||||
Text = "防止自动息屏、睡眠和锁屏",
|
||||
Checked = current.PreventAutoLock
|
||||
};
|
||||
var note = new Label
|
||||
{
|
||||
Left = 18, Top = 170, Width = 570, Height = 72,
|
||||
Text = "仅保留一个访问凭据,可直接输入自定义内容(不能为空或包含空白字符,不限制长度)。\n保存后新凭据立即生效,重新生成会使旧凭据失效。本机回环访问不需要凭据。"
|
||||
Left = 18, Top = 220, Width = 570, Height = 48,
|
||||
Text = "仅保留一个访问凭据,可直接输入自定义内容(不能为空或包含空白字符)。\n验证写操作只应在明确授权的测试机启用;本机回环访问不需要凭据。"
|
||||
};
|
||||
var data = new Label
|
||||
{
|
||||
Left = 18, Top = 246, Width = 570, Height = 24,
|
||||
Left = 18, Top = 278, Width = 570, Height = 24,
|
||||
Text = $"数据目录:{current.DataDirectory}", AutoEllipsis = true
|
||||
};
|
||||
var save = new Button { Left = 370, Top = 285, Width = 105, Text = "保存" };
|
||||
var cancel = new Button { Left = 485, Top = 285, Width = 105, Text = "取消" };
|
||||
var save = new Button { Left = 370, Top = 330, Width = 105, Text = "保存" };
|
||||
var cancel = new Button { Left = 485, Top = 330, Width = 105, Text = "取消" };
|
||||
copy.Click += (_, _) => { Clipboard.SetText(tokenBox.Text); copy.Text = "已复制"; };
|
||||
regenerate.Click += (_, _) =>
|
||||
{
|
||||
@@ -415,7 +423,9 @@ internal static class ServiceSettingsEditor
|
||||
DataDirectory = current.DataDirectory,
|
||||
Remote = current.Remote,
|
||||
Reporting = current.Reporting,
|
||||
RemoteConfigurationFile = current.RemoteConfigurationFile
|
||||
RemoteConfigurationFile = current.RemoteConfigurationFile,
|
||||
EnableValidationOperations = validation.Checked,
|
||||
PreventAutoLock = preventAutoLock.Checked
|
||||
};
|
||||
try { edited.Validate(); }
|
||||
catch (Exception exception)
|
||||
@@ -427,7 +437,7 @@ internal static class ServiceSettingsEditor
|
||||
form.Close();
|
||||
};
|
||||
cancel.Click += (_, _) => form.Close();
|
||||
form.Controls.AddRange([listenLabel, hostBox, portBox, external, tokenLabel, tokenBox, copy, regenerate, note, data, save, cancel]);
|
||||
form.Controls.AddRange([listenLabel, hostBox, portBox, external, tokenLabel, tokenBox, copy, regenerate, validation, preventAutoLock, note, data, save, cancel]);
|
||||
form.AcceptButton = save;
|
||||
form.CancelButton = cancel;
|
||||
form.ShowDialog();
|
||||
|
||||
Reference in New Issue
Block a user