1- using System . Collections . Generic ;
2- using System . IO ;
3- using System . Text . Json ;
4- using CAT2 . Models ;
1+ using CAT2 . Models ;
52using Wpf . Ui . Appearance ;
6- using static ChmlFrp . SDK . UserActions ;
73
84namespace CAT2 . ViewModels ;
95
@@ -17,72 +13,11 @@ public partial class MainWindowViewModel : ObservableObject
1713
1814 [ ObservableProperty ] private bool _isDarkTheme ;
1915
20- public MainWindowViewModel ( )
16+ [ RelayCommand ]
17+ private void ChangeTheme ( )
2118 {
22- AppDomain . CurrentDomain . UnhandledException += ( _ , args ) =>
23- {
24- if ( args . ExceptionObject is not Exception ex ) return ;
25-
26- WritingLog ( ex . Message . Contains ( "拒绝访问" )
27- ? "请以管理员身份运行本程序"
28- : $ "请将此日志反馈给开发者\n 联系方式:\n 1.QQ:2976779544\n 2.Email:[email protected] \n 3.GitHub:Qianyiaz/CAT2\n 版本号:{ Constants . Version } 次版本号:{ FileVersion } \n 异常信息:\n { ex } ") ; 29-
30- Process . Start ( new ProcessStartInfo
31- {
32- FileName = LogFilePath ,
33- UseShellExecute = true
34- } ) ;
35- } ;
36-
37- ApplicationThemeManager . Changed += ( theme , _ ) =>
38- {
39- IsDarkTheme = theme == ApplicationTheme . Dark ;
40- } ;
41- ApplicationThemeManager . ApplySystemTheme ( ) ;
42-
43- MainClass . SizeChanged += ( _ , e ) =>
44- {
45- MainClass . RootNavigation . SetCurrentValue ( NavigationView . IsPaneOpenProperty , e . NewSize . Width > 875 ) ;
46- } ;
47-
48- MainClass . Loaded += async ( _ , _ ) =>
49- {
50- Init ( "CAT2" ) ;
51- SystemThemeWatcher . Watch ( MainClass ) ;
52-
53- await Task . WhenAll (
54- Task . Run ( ( ) =>
55- {
56- SnackBarService . SetSnackbarPresenter ( MainClass . RootSnackbarDialog ) ;
57- ContentDialogService . SetDialogHost ( MainClass . RootContentDialogPresenter ) ;
58- } ) ,
59- LoginAsyncFromToken ( ) ,
60- Task . Run ( async ( ) =>
61- {
62- if ( File . Exists ( SettingsFilePath ) ) return ;
63- await File . WriteAllTextAsync ( SettingsFilePath , JsonSerializer . Serialize ( new
64- {
65- StartedItems = new Dictionary < string , bool > ( )
66- } ) ) ;
67- WritingLog ( "settings.json文件不存在,已创建" ) ;
68- } ) ) ;
69-
70- MainClass . RootNavigation . Navigate ( "登录" ) ;
71- if ( IsLoggedIn )
72- {
73- MainClass . LoginItem . Visibility = Visibility . Collapsed ;
74- MainClass . TunnelItem . Visibility = Visibility . Visible ;
75- MainClass . NodeItem . Visibility = Visibility . Visible ;
76- MainClass . UserItem . Visibility = Visibility . Visible ;
77- MainClass . RootNavigation . Navigate ( "管理隧道" ) ;
78- }
79-
80- MainClass . Topmost = false ;
81- WritingLog ( "主窗口加载完成" ) ;
82- } ;
19+ ApplicationThemeManager . Apply ( ApplicationThemeManager . GetAppTheme ( ) == ApplicationTheme . Dark
20+ ? ApplicationTheme . Light
21+ : ApplicationTheme . Dark ) ;
8322 }
84-
85- [ RelayCommand ]
86- private void ChangeTheme ( ) =>
87- ApplicationThemeManager . Apply ( ApplicationThemeManager . GetAppTheme ( ) == ApplicationTheme . Dark ? ApplicationTheme . Light : ApplicationTheme . Dark ) ;
8823}
0 commit comments