主界面去掉协议注册/取消按钮:协议由安装包注册、卸载自动取消
- MainWindow.xaml:移除「注册启动协议 / 取消启动协议」按钮,仅保留状态文字 (「已注册 yuncang://(网页可叫醒本软件)」/ 未注册时提示重新运行安装包)。 - MainWindow.xaml.cs:删除 Protocol_Click(含确认框与 Unregister 调用), UpdateProtocolState 只更新文案(仍会提示"已注册但指向旧路径,重启会自动校正")。 - ProtocolHelper:注释更新——注册由 MSI 安装包完成、卸载时自动删除, 启动时由 App.EnsureProtocolRegistered 校正;Unregister 仅供卸载工具/排障。 理由:UI 上留「取消」按钮容易误点,点了网页就再也叫不醒软件,恢复还得重装。 验证:打包 1.0.4 安装后,界面按钮只剩「停止服务 / 复制唤醒地址 / 查询…」, 状态文字正常;版本 1.0.4 与后端 version.json 一致,启动不提示更新。
This commit is contained in:
parent
21e8c6a5ec
commit
1a61cffaa4
@ -48,10 +48,9 @@
|
||||
</DockPanel>
|
||||
</Border>
|
||||
|
||||
<!-- ③ 操作按钮 + 协议状态 -->
|
||||
<!-- ③ 操作按钮 + 协议状态(协议由安装包注册、卸载时自动取消,不提供手动切换) -->
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" Margin="0,0,0,6">
|
||||
<Button x:Name="StartStopButton" Content="停止服务" Padding="14,6" Click="StartStop_Click" />
|
||||
<Button x:Name="ProtocolButton" Content="注册启动协议" Padding="14,6" Margin="10,0,0,0" Click="Protocol_Click" />
|
||||
<Button Content="复制唤醒地址" Padding="14,6" Margin="10,0,0,0" Click="CopyLaunchUrl_Click" />
|
||||
<TextBlock x:Name="ProtocolText" Margin="14,0,0,0" VerticalAlignment="Center"
|
||||
Foreground="{StaticResource MutedBrush}" TextTrimming="CharacterEllipsis" />
|
||||
|
||||
@ -113,35 +113,11 @@ public partial class MainWindow : Window
|
||||
|
||||
// ---------------- 启动协议 ----------------
|
||||
|
||||
private void Protocol_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ProtocolHelper.IsRegistered())
|
||||
{
|
||||
var answer = MessageBox.Show(this,
|
||||
"已注册启动协议。要取消注册吗?(取消后网页就无法叫醒本软件)",
|
||||
"启动协议", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (answer != MessageBoxResult.Yes) return;
|
||||
|
||||
ProtocolHelper.Unregister();
|
||||
AppLog.Write("已取消注册启动协议");
|
||||
}
|
||||
else
|
||||
{
|
||||
ProtocolHelper.Register();
|
||||
AppLog.Write($"已注册启动协议:{ProtocolHelper.Scheme}:// → {ProtocolHelper.RegisteredCommand()}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AppLog.Write($"操作启动协议失败:{ex.Message}");
|
||||
MessageBox.Show(this, ex.Message, "启动协议", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
}
|
||||
|
||||
UpdateProtocolState();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 协议状态只做展示:**注册由安装包完成、卸载时由 MSI 自动删除**;
|
||||
/// 运行时启动时会自动校正到当前 exe(App.EnsureProtocolRegistered)。
|
||||
/// UI 上不提供手动注册/取消 —— 手动取消会让网页再也叫不醒软件,属于误操作。
|
||||
/// </summary>
|
||||
private void UpdateProtocolState()
|
||||
{
|
||||
var registered = ProtocolHelper.IsRegistered();
|
||||
@ -152,9 +128,8 @@ public partial class MainWindow : Window
|
||||
var pointsToMe = command is not null && exe is not null
|
||||
&& command.IndexOf(exe, StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
|
||||
ProtocolButton.Content = registered ? "取消启动协议" : "注册启动协议";
|
||||
ProtocolText.Text = !registered
|
||||
? $"未注册 {ProtocolHelper.Scheme}://(网页无法叫醒本软件)"
|
||||
? $"未注册 {ProtocolHelper.Scheme}://(网页无法叫醒本软件,重新运行安装包可修复)"
|
||||
: pointsToMe
|
||||
? $"已注册 {ProtocolHelper.Scheme}://(网页可叫醒本软件)"
|
||||
: $"已注册,但指向旧路径(重启本软件会自动校正)";
|
||||
|
||||
@ -298,7 +298,8 @@ HKEY_CURRENT_USER\Software\Classes\yuncang
|
||||
- **每次启动都会自动把注册项校正到「当前这个 exe」**(幂等)。这一点很关键:
|
||||
换目录安装、从 `bin\Debug` 换成发布版、重新装一遍之后,注册表里残留的旧路径会让网页
|
||||
唤起一个不存在 / 缺运行时的 exe(典型现象就是弹「You must install .NET」或干脆没反应)。
|
||||
界面上仍可手动「取消启动协议」;
|
||||
- **界面只显示协议状态,不提供手动注册/取消**:注册由安装包完成、卸载时 MSI 自动删除;
|
||||
留一个「取消」按钮只会让用户误点后网页再也叫不醒软件(要恢复还得重装)。
|
||||
- 手工注册/排查:
|
||||
|
||||
```powershell
|
||||
|
||||
@ -15,7 +15,9 @@ namespace YuncangTrace.LocalService.Services;
|
||||
/// 注意:
|
||||
/// - 网页**不能**直接执行 exe,也不能拿到返回值(所以还要配合 127.0.0.1 上的 HTTP 服务);
|
||||
/// - 协议注册在 HKCU,**不需要管理员权限**;
|
||||
/// - 卸载时应该调用 <see cref="Unregister"/> 把注册表清掉。
|
||||
/// - **注册由安装包(MSI)完成**,卸载时 MSI 会自动删除;运行时启动也会校正到当前 exe
|
||||
/// (<see cref="LocalHttpServer"/> 之外的处理见 App.EnsureProtocolRegistered)。
|
||||
/// 这里的 <see cref="Unregister"/> 仅供卸载工具/排障使用,UI 上不再提供手动取消。
|
||||
/// </summary>
|
||||
public static class ProtocolHelper
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user