Skip to content

Commit 5b6e85c

Browse files
committed
可能修复了添加程序后无法操作开关的错误
1 parent 0ad8ec3 commit 5b6e85c

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

PreLaunchTaskr.GUI.WinUI3/App.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public App()
6969
/// <param name="args">Details about the launch request and process.</param>
7070
protected override void OnLaunched(LaunchActivatedEventArgs args)
7171
{
72+
#if !DEBUG
7273
// 只能开一个窗口
7374
if (mainWindow is not null)
7475
{
@@ -81,6 +82,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
8182
Exit();
8283
return;
8384
}
85+
#endif
8486

8587
Configurator = Configurator.Init(GlobalProperties.SettingsLocation, GlobalProperties.LauncherNet8Location);
8688
Launcher = Launcher.Init(BaseDirectory);

PreLaunchTaskr.GUI.WinUI3/MainWindow.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public Brush? InactiveBackground
8888
private Brush? CurrentBackground
8989
{
9090
get => ContentFrame.Background;
91-
set => ContentFrame.Background = value;
91+
set => ContentFrame.Background = value; // 设置当前 Frame 的背景色,只有在 MainWindow 加载完毕后,ContentFrame 才不为 null
9292
}
9393

9494
public readonly nint hWnd;
@@ -103,7 +103,7 @@ private void Frame_Loaded(object sender, RoutedEventArgs e)
103103
double scale = frame.XamlRoot.RasterizationScale;
104104
AppWindow.Resize(new Windows.Graphics.SizeInt32((int) (3 * NavigationViewOpenPaneLength * scale), (int) (720 * scale)));
105105

106-
Activate();
106+
Activate(); // 因为把激活窗口延后到了 Frame 加载完毕,所以没在设置 CurrentBackground 时引发空引用异常。
107107
}
108108

109109
private void Window_Closed(object o, WindowEventArgs e)

PreLaunchTaskr.GUI.WinUI3/ViewModels/ItemModels/ProgramListItem.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ public bool SaveChanges()
6262
string commandArgs = Enabled ? $"-s enable-program --id {Id}" : $"-s disable-program --id {Id}";
6363
try
6464
{
65-
return ProcessStarter.StartSilentAsAdminAndWait(System.IO.Path.GetFullPath(GlobalProperties.ConfiguratorNet8Location), commandArgs) is not null;
65+
return ProcessStarter.StartSilentAsAdminAndWait(
66+
System.IO.Path.Combine(App.BaseDirectory, GlobalProperties.ConfiguratorNet8Location),
67+
commandArgs) is not null;
6668
}
6769
catch
6870
{

PreLaunchTaskr.GUI.WinUI3/Views/AboutPage.xaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@
8686
<SymbolIconSource Symbol="Go" />
8787
</my:IconHyperlinkButton.IconSource>
8888
</my:IconHyperlinkButton>
89+
90+
<my:IconHyperlinkButton
91+
Padding="8"
92+
NavigateUri="https://github.com/microsoft/CsWinRT"
93+
Text="CsWinRT">
94+
<my:IconHyperlinkButton.IconSource>
95+
<SymbolIconSource Symbol="Go" />
96+
</my:IconHyperlinkButton.IconSource>
97+
</my:IconHyperlinkButton>
98+
99+
<my:IconHyperlinkButton
100+
Padding="8"
101+
NavigateUri="https://github.com/microsoft/CsWin32"
102+
Text="CsWin32">
103+
<my:IconHyperlinkButton.IconSource>
104+
<SymbolIconSource Symbol="Go" />
105+
</my:IconHyperlinkButton.IconSource>
106+
</my:IconHyperlinkButton>
89107
</StackPanel>
90108
</Expander>
91109
</StackPanel>

PreLaunchTaskr.GUI.WinUI3/Views/MainPage.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public MainPage(MainViewModel? viewModel)
3636
{
3737
InitializeComponent();
3838

39-
//Navigation.IsPaneOpen = false;
4039
Navigation.ExpandedModeThresholdWidth = Math.E * Navigation.OpenPaneLength;
4140
this.viewModel = viewModel;
4241
}
@@ -66,7 +65,7 @@ private async void SelectProgramFromFile()
6665
string? path = await Win32FilePicker.PickFileAsync([
6766
new Win32FilePickerFilter("应用程序", "*.exe"),
6867
new Win32FilePickerFilter("快捷方式", "*.exe")],
69-
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
68+
"shell:Desktop",
7069
dereferenceLink: true,
7170
App.Current.MainWindow.hWnd);
7271

0 commit comments

Comments
 (0)