Skip to content

Commit 4044bf9

Browse files
committed
feat: 添加开发者控制台窗口和命令执行功能
1 parent a912649 commit 4044bf9

4 files changed

Lines changed: 330 additions & 7 deletions

File tree

App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE
207207
}
208208
}
209209

210-
private static void ShowCrashWindow(string summary, string report)
210+
public static void ShowCrashWindow(string summary, string report)
211211
{
212212
try
213213
{

Pages/MorePage.xaml.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using ObsMCLauncher.Services;
1010
using ObsMCLauncher.Utils;
1111
using ObsMCLauncher.ViewModels;
12+
using ObsMCLauncher.Windows;
1213

1314
namespace ObsMCLauncher.Pages
1415
{
@@ -378,12 +379,23 @@ private async System.Threading.Tasks.Task ShowDebugConsoleConfirmationAsync()
378379

379380
if (result)
380381
{
381-
NotificationManager.Instance.ShowNotification(
382-
"开发者模式",
383-
"调试控制台功能在此版本中已简化,后续可迁移到独立窗口。",
384-
NotificationType.Info,
385-
3
386-
);
382+
try
383+
{
384+
var win = new DevConsoleWindow
385+
{
386+
Owner = Window.GetWindow(this)
387+
};
388+
win.Show();
389+
}
390+
catch (Exception ex)
391+
{
392+
NotificationManager.Instance.ShowNotification(
393+
"开发者模式",
394+
$"打开调试控制台失败: {ex.Message}",
395+
NotificationType.Error,
396+
4
397+
);
398+
}
387399
}
388400
}
389401
catch { }

Windows/DevConsoleWindow.xaml

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<Window x:Class="ObsMCLauncher.Windows.DevConsoleWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
5+
Title="开发者控制台"
6+
Height="560"
7+
Width="880"
8+
MinHeight="420"
9+
MinWidth="640"
10+
Background="{DynamicResource BackgroundBrush}"
11+
WindowStartupLocation="CenterOwner"
12+
WindowStyle="None"
13+
AllowsTransparency="False"
14+
ResizeMode="CanResize"
15+
TextElement.Foreground="{DynamicResource TextBrush}"
16+
TextElement.FontWeight="Regular"
17+
TextElement.FontSize="13"
18+
FontFamily="{materialDesign:MaterialDesignFont}">
19+
20+
<WindowChrome.WindowChrome>
21+
<WindowChrome CaptionHeight="40"
22+
ResizeBorderThickness="5"
23+
GlassFrameThickness="0"
24+
CornerRadius="0"/>
25+
</WindowChrome.WindowChrome>
26+
27+
<Grid>
28+
<Grid.RowDefinitions>
29+
<RowDefinition Height="40"/>
30+
<RowDefinition Height="*"/>
31+
<RowDefinition Height="Auto"/>
32+
</Grid.RowDefinitions>
33+
34+
<!-- 标题栏 -->
35+
<Border Grid.Row="0"
36+
Background="{DynamicResource SurfaceBrush}"
37+
BorderBrush="{DynamicResource BorderBrush}"
38+
BorderThickness="0,0,0,1">
39+
<Grid>
40+
<Grid.ColumnDefinitions>
41+
<ColumnDefinition Width="*"/>
42+
<ColumnDefinition Width="Auto"/>
43+
</Grid.ColumnDefinitions>
44+
45+
<StackPanel Grid.Column="0"
46+
Orientation="Horizontal"
47+
Margin="15,0,0,0"
48+
VerticalAlignment="Center">
49+
<materialDesign:PackIcon Kind="Console"
50+
Width="20"
51+
Height="20"
52+
VerticalAlignment="Center"
53+
Foreground="{StaticResource PrimaryBrush}"/>
54+
<TextBlock Text="开发者控制台"
55+
FontSize="13"
56+
FontWeight="SemiBold"
57+
Margin="10,0,0,0"
58+
VerticalAlignment="Center"/>
59+
</StackPanel>
60+
61+
<StackPanel Grid.Column="1"
62+
Orientation="Horizontal"
63+
HorizontalAlignment="Right"
64+
WindowChrome.IsHitTestVisibleInChrome="True">
65+
<Button x:Name="CloseButton"
66+
Click="CloseButton_Click"
67+
Width="46"
68+
Height="40"
69+
Style="{StaticResource MaterialDesignFlatButton}"
70+
Foreground="{DynamicResource TextBrush}"
71+
ToolTip="关闭">
72+
<Button.Resources>
73+
<Style TargetType="Button" BasedOn="{StaticResource MaterialDesignFlatButton}">
74+
<Style.Triggers>
75+
<Trigger Property="IsMouseOver" Value="True">
76+
<Setter Property="Background" Value="#DC3545"/>
77+
</Trigger>
78+
</Style.Triggers>
79+
</Style>
80+
</Button.Resources>
81+
<materialDesign:PackIcon Kind="WindowClose"
82+
Width="16"
83+
Height="16"/>
84+
</Button>
85+
</StackPanel>
86+
</Grid>
87+
</Border>
88+
89+
<!-- 输出区 -->
90+
<Border Grid.Row="1"
91+
Background="#151515"
92+
BorderBrush="{DynamicResource BorderBrush}"
93+
BorderThickness="0"
94+
Padding="0">
95+
<ScrollViewer x:Name="OutputScroll"
96+
VerticalScrollBarVisibility="Auto"
97+
HorizontalScrollBarVisibility="Auto">
98+
<TextBox x:Name="OutputTextBox"
99+
IsReadOnly="True"
100+
Background="Transparent"
101+
BorderThickness="0"
102+
Foreground="#FFFFFF"
103+
FontFamily="Consolas, Courier New"
104+
FontSize="12"
105+
TextWrapping="NoWrap"
106+
AcceptsReturn="True"
107+
Padding="12"/>
108+
</ScrollViewer>
109+
</Border>
110+
111+
<!-- 输入区 -->
112+
<Border Grid.Row="2"
113+
Background="{DynamicResource SurfaceBrush}"
114+
BorderBrush="{DynamicResource BorderBrush}"
115+
BorderThickness="0,1,0,0"
116+
Padding="12,10">
117+
<Grid>
118+
<Grid.ColumnDefinitions>
119+
<ColumnDefinition Width="*"/>
120+
<ColumnDefinition Width="Auto"/>
121+
</Grid.ColumnDefinitions>
122+
123+
<TextBox x:Name="CommandTextBox"
124+
Grid.Column="0"
125+
Height="34"
126+
VerticalContentAlignment="Center"
127+
FontFamily="Consolas, Courier New"
128+
materialDesign:HintAssist.Hint="输入命令(help 查看可用命令)"
129+
KeyDown="CommandTextBox_KeyDown"/>
130+
131+
<Button Grid.Column="1"
132+
Height="34"
133+
Margin="10,0,0,0"
134+
Padding="14,0"
135+
Style="{StaticResource MaterialDesignRaisedButton}"
136+
Background="{StaticResource PrimaryBrush}"
137+
Click="RunButton_Click">
138+
<TextBlock Text="执行"/>
139+
</Button>
140+
</Grid>
141+
</Border>
142+
</Grid>
143+
</Window>
144+

Windows/DevConsoleWindow.xaml.cs

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
using System;
2+
using System.Linq;
3+
using System.Windows;
4+
using System.Windows.Input;
5+
using ObsMCLauncher.Services;
6+
using ObsMCLauncher.Utils;
7+
8+
namespace ObsMCLauncher.Windows
9+
{
10+
public partial class DevConsoleWindow : Window
11+
{
12+
public DevConsoleWindow()
13+
{
14+
InitializeComponent();
15+
16+
AppendLine("ObsMCLauncher " + VersionInfo.Version + " " + VersionInfo.VersionStatusText + " 开发者控制台");
17+
AppendLine("输入 help 查看可用命令");
18+
AppendLine(string.Empty);
19+
}
20+
21+
private void CloseButton_Click(object sender, RoutedEventArgs e)
22+
{
23+
Close();
24+
}
25+
26+
private void RunButton_Click(object sender, RoutedEventArgs e)
27+
{
28+
RunCurrentCommand();
29+
}
30+
31+
private void CommandTextBox_KeyDown(object sender, KeyEventArgs e)
32+
{
33+
if (e.Key == Key.Enter)
34+
{
35+
e.Handled = true;
36+
RunCurrentCommand();
37+
}
38+
}
39+
40+
private void RunCurrentCommand()
41+
{
42+
var cmd = (CommandTextBox.Text ?? string.Empty).Trim();
43+
if (string.IsNullOrWhiteSpace(cmd))
44+
return;
45+
46+
CommandTextBox.Text = string.Empty;
47+
48+
AppendLine($"> {cmd}");
49+
50+
try
51+
{
52+
ExecuteCommand(cmd);
53+
}
54+
catch (Exception ex)
55+
{
56+
AppendLine($"[error] {ex.Message}");
57+
}
58+
}
59+
60+
private void ExecuteCommand(string commandLine)
61+
{
62+
var parts = commandLine.Split(' ', StringSplitOptions.RemoveEmptyEntries);
63+
if (parts.Length == 0)
64+
return;
65+
66+
var cmd = parts[0].ToLowerInvariant();
67+
var args = parts.Skip(1).ToArray();
68+
69+
switch (cmd)
70+
{
71+
case "help":
72+
case "?":
73+
AppendLine("可用命令:");
74+
AppendLine(" help 显示帮助");
75+
AppendLine(" clear 清空输出");
76+
AppendLine(" crash 直接打开崩溃窗口(不抛未处理异常)");
77+
AppendLine(" throw <msg> 抛出一个未处理异常(msg 可选)");
78+
AppendLine(" update [tag] 强制打开更新窗口(不依赖联网检查);tag 可选,默认 v9.9.9-test");
79+
break;
80+
81+
case "clear":
82+
OutputTextBox.Clear();
83+
break;
84+
85+
case "crash":
86+
try
87+
{
88+
var summary = "手动打开崩溃窗口(crash 指令)";
89+
var report = string.Join(Environment.NewLine, new[]
90+
{
91+
"========== ObsMCLauncher 崩溃报告 ==========",
92+
$"时间: {DateTime.Now:yyyy-MM-dd HH:mm:ss}",
93+
"标题: 手动打开崩溃窗口(crash 指令)",
94+
$"版本: {VersionInfo.DisplayVersion}",
95+
$"系统: {System.Runtime.InteropServices.RuntimeInformation.OSDescription}",
96+
$"架构: {System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture}",
97+
$"运行目录: {AppDomain.CurrentDomain.BaseDirectory}",
98+
"",
99+
"---------- 异常信息 ----------",
100+
"(crash 指令不会抛出未处理异常;此窗口用于预览/验证导出与复制功能)"
101+
});
102+
103+
App.ShowCrashWindow(summary, report);
104+
AppendLine("[info] 已打开崩溃窗口");
105+
}
106+
catch (Exception ex)
107+
{
108+
AppendLine($"[error] 打开崩溃窗口失败: {ex.Message}");
109+
}
110+
break;
111+
112+
case "throw":
113+
{
114+
var msg = args.Length > 0 ? string.Join(' ', args) : "手动抛出异常";
115+
Dispatcher.BeginInvoke(new Action(() =>
116+
{
117+
throw new Exception(msg);
118+
}));
119+
AppendLine("[info] 已触发 throw(异常将由全局捕获处理)");
120+
break;
121+
}
122+
123+
case "update":
124+
{
125+
var tag = args.Length > 0 ? args[0] : "v9.9.9-test";
126+
_ = OpenUpdateAsync(tag);
127+
break;
128+
}
129+
130+
default:
131+
AppendLine($"[warn] 未知命令: {cmd}(输入 help 查看帮助)");
132+
break;
133+
}
134+
}
135+
136+
private async System.Threading.Tasks.Task OpenUpdateAsync(string tagName)
137+
{
138+
try
139+
{
140+
AppendLine($"[info] 强制打开更新窗口: {tagName}");
141+
142+
var release = new GitHubRelease
143+
{
144+
TagName = tagName,
145+
Name = $"测试更新 {tagName}",
146+
Body = "**这是一个本地注入的测试更新**\n\n用于验证更新弹窗与下载流程。\n",
147+
HtmlUrl = "https://example.com/",
148+
PublishedAt = DateTime.Now,
149+
Prerelease = true,
150+
Assets = Array.Empty<GitHubAsset>()
151+
};
152+
153+
await UpdateService.ShowUpdateDialogAsync(release);
154+
}
155+
catch (Exception ex)
156+
{
157+
AppendLine($"[error] 打开更新窗口失败: {ex.Message}");
158+
}
159+
}
160+
161+
private void AppendLine(string line)
162+
{
163+
OutputTextBox.AppendText(line + Environment.NewLine);
164+
OutputTextBox.ScrollToEnd();
165+
}
166+
}
167+
}

0 commit comments

Comments
 (0)