Skip to content

Commit bf49036

Browse files
authored
Add files via upload
Signed-off-by: wwcrdrvf6u <122241403+wwcrdrvf6u@users.noreply.github.com>
1 parent 4a67473 commit bf49036

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+14108
-5415
lines changed

AdjustVideoWindow.xaml

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,58 @@
1-
<Window x:Class="ShowWrite.AdjustVideoWindow"
1+
<Window x:Class="ShowWrite.AdjustVideoWindow"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
Title="画面调节" Height="409" Width="364"
4+
xmlns:local="clr-namespace:ShowWrite"
5+
xmlns:services="clr-namespace:ShowWrite.Services"
6+
Title="{Binding Source={x:Static services:LanguageManager.Instance}, Path=Translations[AdjustVideo]}" Height="409" Width="364"
57
WindowStartupLocation="CenterOwner">
68
<StackPanel Margin="15,0,15,0" VerticalAlignment="Center" Height="332">
7-
<TextBlock Text="亮度" Foreground="Black" Margin="0,5"/>
9+
<TextBlock Text="{Binding Source={x:Static services:LanguageManager.Instance}, Path=Translations[Brightness]}" Foreground="Black" Margin="0,5"/>
810
<Slider x:Name="BrightnessSlider" Minimum="-100" Maximum="100" TickFrequency="1" ValueChanged="BrightnessSlider_ValueChanged"/>
911

10-
<TextBlock Text="对比度" Foreground="Black" Margin="0,10,0,5"/>
12+
<TextBlock Text="{Binding Source={x:Static services:LanguageManager.Instance}, Path=Translations[Contrast]}" Foreground="Black" Margin="0,10,0,5"/>
1113
<Slider x:Name="ContrastSlider" Minimum="0.1" Maximum="3" TickFrequency="0.1" ValueChanged="ContrastSlider_ValueChanged"/>
12-
<TextBlock Text="旋转方向:" FontWeight="Bold" Margin="0,0,0,10"/>
14+
<TextBlock Text="{Binding Source={x:Static services:LanguageManager.Instance}, Path=Translations[RotationDirection]}" FontWeight="Bold" Margin="0,0,0,10"/>
1315
<ComboBox x:Name="RotationBox" Width="150">
14-
<ComboBoxItem Content="" Tag="0"/>
15-
<ComboBoxItem Content="90°" Tag="90"/>
16-
<ComboBoxItem Content="180°" Tag="180"/>
17-
<ComboBoxItem Content="270°" Tag="270"/>
16+
<ComboBoxItem Tag="0">
17+
<ComboBoxItem.Content>
18+
<TextBlock>
19+
<Run Text="0"/>
20+
<Run Text="{Binding Source={x:Static services:LanguageManager.Instance}, Path=Translations[Degrees]}"/>
21+
</TextBlock>
22+
</ComboBoxItem.Content>
23+
</ComboBoxItem>
24+
<ComboBoxItem Tag="90">
25+
<ComboBoxItem.Content>
26+
<TextBlock>
27+
<Run Text="90"/>
28+
<Run Text="{Binding Source={x:Static services:LanguageManager.Instance}, Path=Translations[Degrees]}"/>
29+
</TextBlock>
30+
</ComboBoxItem.Content>
31+
</ComboBoxItem>
32+
<ComboBoxItem Tag="180">
33+
<ComboBoxItem.Content>
34+
<TextBlock>
35+
<Run Text="180"/>
36+
<Run Text="{Binding Source={x:Static services:LanguageManager.Instance}, Path=Translations[Degrees]}"/>
37+
</TextBlock>
38+
</ComboBoxItem.Content>
39+
</ComboBoxItem>
40+
<ComboBoxItem Tag="270">
41+
<ComboBoxItem.Content>
42+
<TextBlock>
43+
<Run Text="270"/>
44+
<Run Text="{Binding Source={x:Static services:LanguageManager.Instance}, Path=Translations[Degrees]}"/>
45+
</TextBlock>
46+
</ComboBoxItem.Content>
47+
</ComboBoxItem>
1848
</ComboBox>
1949

20-
<CheckBox x:Name="MirrorHCheck" Content="水平镜像" Margin="0,15,0,5"/>
21-
<CheckBox x:Name="MirrorVCheck" Content="垂直镜像" Margin="0,0,0,15"/>
50+
<CheckBox x:Name="MirrorHCheck" Content="{Binding Source={x:Static services:LanguageManager.Instance}, Path=Translations[HorizontalMirror]}" Margin="0,15,0,5"/>
51+
<CheckBox x:Name="MirrorVCheck" Content="{Binding Source={x:Static services:LanguageManager.Instance}, Path=Translations[VerticalMirror]}" Margin="0,0,0,15"/>
2252

2353
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Height="60">
24-
<Button Content="确定" Width="80" Margin="10" Click="Ok_Click"/>
25-
<Button Content="取消" Width="80" Margin="10" IsCancel="True"/>
54+
<Button Content="{Binding Source={x:Static services:LanguageManager.Instance}, Path=Translations[OK]}" Width="80" Margin="10" Click="Ok_Click"/>
55+
<Button Content="{Binding Source={x:Static services:LanguageManager.Instance}, Path=Translations[Cancel]}" Width="80" Margin="10" IsCancel="True"/>
2656
</StackPanel>
2757
</StackPanel>
2858
</Window>

AdjustVideoWindow.xaml.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Windows;
1+
using ShowWrite.Services;
2+
using System.Windows;
23
using System.Windows.Controls;
34

45
namespace ShowWrite
@@ -11,10 +12,15 @@ public partial class AdjustVideoWindow : Window
1112
public bool MirrorH { get; private set; }
1213
public bool MirrorV { get; private set; }
1314

15+
private readonly LanguageManager _languageManager;
16+
1417
public AdjustVideoWindow(double brightness, double contrast, int rotation, bool mirrorH, bool mirrorV)
1518
{
1619
InitializeComponent();
1720

21+
_languageManager = LanguageManager.Instance;
22+
_languageManager.LanguageChanged += UpdateLanguage;
23+
1824
// 初始化滑块值
1925
BrightnessSlider.Value = brightness;
2026
ContrastSlider.Value = contrast;
@@ -26,6 +32,12 @@ public AdjustVideoWindow(double brightness, double contrast, int rotation, bool
2632
MirrorVCheck.IsChecked = mirrorV;
2733
}
2834

35+
private void UpdateLanguage()
36+
{
37+
// 更新窗口标题
38+
Title = _languageManager.GetTranslation("AdjustVideo");
39+
}
40+
2941
// 添加缺失的事件处理方法 - 这是关键修复
3042
private void BrightnessSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
3143
{

App.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<Application x:Class="ShowWrite.App"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
4-
StartupUri="MainWindow.xaml">
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
4+
>
55
<Application.Resources>
66
<ResourceDictionary>
77
<ResourceDictionary.MergedDictionaries>
8-
<ui:ThemesDictionary Theme="light" />
9-
<ui:ControlsDictionary />
8+
<ui:ThemeResources/>
9+
<ui:XamlControlsResources/>
1010
</ResourceDictionary.MergedDictionaries>
1111
</ResourceDictionary>
1212
</Application.Resources>

App.xaml.cs

Lines changed: 81 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Threading.Tasks;
1+
using ShowWrite.Services;
32
using System.Windows;
43

54
namespace ShowWrite
@@ -9,23 +8,33 @@ public partial class App : System.Windows.Application
98
private SplashWindow _splashWindow;
109
private MainWindow _mainWindow;
1110

12-
protected override async void OnStartup(StartupEventArgs e)
11+
protected override void OnStartup(StartupEventArgs e)
1312
{
1413
base.OnStartup(e);
1514

16-
// 1. 先显示启动图
17-
ShowSplashWindow();
18-
1915
try
2016
{
21-
// 2. 异步初始化主窗口
22-
await InitializeMainWindowAsync();
17+
Logger.Info("App", "应用程序启动开始");
18+
19+
// 0. 加载语言设置
20+
LoadLanguageSettings();
21+
22+
// 1. 显示启动图
23+
ShowSplashWindow();
24+
25+
// 2. 等待一小段时间让启动图完全显示
26+
System.Threading.Thread.Sleep(500);
27+
28+
// 3. 在主线程创建主窗口
29+
CreateMainWindow();
2330

24-
// 3. 关闭启动图
31+
// 4. 关闭启动图
2532
CloseSplashWindow();
2633

27-
// 4. 显示主窗口
28-
_mainWindow.Show();
34+
// 5. 显示主窗口
35+
_mainWindow?.Show();
36+
37+
Logger.Info("App", "应用程序启动完成");
2938
}
3039
catch (Exception ex)
3140
{
@@ -35,18 +44,51 @@ protected override async void OnStartup(StartupEventArgs e)
3544
}
3645
}
3746

47+
/// <summary>
48+
/// 加载语言设置
49+
/// </summary>
50+
private void LoadLanguageSettings()
51+
{
52+
try
53+
{
54+
Logger.Debug("App", "加载语言设置");
55+
56+
var configPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json");
57+
if (System.IO.File.Exists(configPath))
58+
{
59+
var json = System.IO.File.ReadAllText(configPath, System.Text.Encoding.UTF8);
60+
var config = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.AppConfig>(json);
61+
if (config != null)
62+
{
63+
LanguageManager.Instance.CurrentLanguage = (LanguageType)config.Language;
64+
Logger.Info("App", $"语言设置已加载: {LanguageManager.Instance.CurrentLanguage}");
65+
}
66+
}
67+
}
68+
catch (Exception ex)
69+
{
70+
Logger.Error("App", $"加载语言设置失败: {ex.Message}", ex);
71+
}
72+
}
73+
3874
/// <summary>
3975
/// 显示启动图窗口
4076
/// </summary>
4177
private void ShowSplashWindow()
4278
{
4379
try
4480
{
81+
Logger.Debug("App", "显示启动图窗口");
4582
_splashWindow = new SplashWindow();
4683
_splashWindow.Show();
4784
_splashWindow.Activate();
4885
_splashWindow.Topmost = true;
4986
_splashWindow.UpdateLayout();
87+
88+
// 确保启动图窗口处理消息
89+
Dispatcher.Invoke(() => { }, System.Windows.Threading.DispatcherPriority.Background);
90+
91+
Logger.Debug("App", "启动图窗口已显示");
5092
}
5193
catch (Exception ex)
5294
{
@@ -55,29 +97,22 @@ private void ShowSplashWindow()
5597
}
5698

5799
/// <summary>
58-
/// 异步初始化主窗口
100+
/// 创建主窗口
59101
/// </summary>
60-
private async Task InitializeMainWindowAsync()
102+
private void CreateMainWindow()
61103
{
62104
try
63105
{
64-
Logger.Debug("App", "开始异步初始化主窗口");
106+
Logger.Debug("App", "创建主窗口开始");
65107

66-
// 在后台线程创建和初始化主窗口
67-
await Task.Run(() =>
68-
{
69-
Dispatcher.Invoke(() =>
70-
{
71-
_mainWindow = new MainWindow();
72-
// 注意:这里我们修改了 MainWindow 构造函数,使其不显示启动图
73-
});
74-
});
108+
// 同步创建主窗口,不使用 async
109+
_mainWindow = new MainWindow();
75110

76-
Logger.Debug("App", "主窗口初始化完成");
111+
Logger.Debug("App", "主窗口创建完成");
77112
}
78113
catch (Exception ex)
79114
{
80-
Logger.Error("App", $"初始化主窗口失败: {ex.Message}", ex);
115+
Logger.Error("App", $"创建主窗口失败: {ex.Message}", ex);
81116
throw;
82117
}
83118
}
@@ -91,8 +126,18 @@ private void CloseSplashWindow()
91126
{
92127
if (_splashWindow != null)
93128
{
94-
_splashWindow.CloseSplash();
129+
Logger.Debug("App", "关闭启动图窗口");
130+
131+
// 先隐藏再关闭
132+
_splashWindow.Hide();
133+
_splashWindow.Close();
95134
_splashWindow = null;
135+
136+
// 强制垃圾回收
137+
GC.Collect();
138+
GC.WaitForPendingFinalizers();
139+
140+
Logger.Debug("App", "启动图窗口已关闭");
96141
}
97142
}
98143
catch (Exception ex)
@@ -108,12 +153,21 @@ protected override void OnExit(ExitEventArgs e)
108153
{
109154
try
110155
{
156+
Logger.Info("App", "应用程序退出");
157+
111158
// 确保启动图被关闭
112-
if (_splashWindow != null && _splashWindow.IsLoaded)
159+
if (_splashWindow != null)
113160
{
114161
_splashWindow.Close();
115162
_splashWindow = null;
116163
}
164+
165+
// 确保主窗口被关闭
166+
if (_mainWindow != null)
167+
{
168+
_mainWindow.Close();
169+
_mainWindow = null;
170+
}
117171
}
118172
catch { }
119173

0 commit comments

Comments
 (0)