Skip to content

Commit 4c5cbac

Browse files
committed
Fix crash returning from profile edit page with unsaved profile rename
1 parent 7564cfe commit 4c5cbac

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

YtFlowApp/EditProfilePage.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ namespace winrt::YtFlowApp::implementation
161161
}
162162
auto const navArgs{args};
163163
auto const lifetime{get_strong()};
164+
co_await SaveProfileName();
165+
164166
if (std::exchange(m_forceQuit, false))
165167
{
166168
co_return;
@@ -174,7 +176,7 @@ namespace winrt::YtFlowApp::implementation
174176
unsavedPluginNames = unsavedPluginNames + L"\r\n" + model->Plugin().Name();
175177
}
176178
}
177-
if (unsavedPluginNames == L"")
179+
if (unsavedPluginNames.empty())
178180
{
179181
co_return;
180182
}
@@ -259,12 +261,17 @@ namespace winrt::YtFlowApp::implementation
259261
}
260262
}
261263

262-
fire_and_forget EditProfilePage::SaveProfileName()
264+
IAsyncAction EditProfilePage::SaveProfileName()
263265
{
264266
try
265267
{
266-
const auto profile{m_profile};
267-
const auto newProfileName{ProfileNameBox().Text()};
268+
auto const lifetime{get_strong()};
269+
auto const profile{m_profile};
270+
auto const newProfileName{ProfileNameBox().Text()};
271+
if (!profile)
272+
{
273+
co_return;
274+
}
268275
if (profile->Name() == newProfileName)
269276
{
270277
co_return;
@@ -275,6 +282,9 @@ namespace winrt::YtFlowApp::implementation
275282
auto conn{FfiDbInstance.Connect()};
276283
conn.UpdateProfile(profile->Id(), winrt::to_string(newProfileName).data(),
277284
winrt::to_string(profile->Locale()).data());
285+
286+
co_await resume_foreground(lifetime->Dispatcher());
287+
profile->Name(newProfileName);
278288
}
279289
catch (...)
280290
{

YtFlowApp/EditProfilePage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace winrt::YtFlowApp::implementation
5252
private:
5353
static inline Windows::Storage::ApplicationData appData{Windows::Storage::ApplicationData::Current()};
5454

55-
fire_and_forget SaveProfileName();
55+
Windows::Foundation::IAsyncAction SaveProfileName();
5656
void RefreshTreeView();
5757
void LoadTreeNodesByName();
5858
void LoadTreeNodesByDependency();

YtFlowApp/HomeProfileControl.xaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,20 @@
2424
<RowDefinition Height="*" />
2525
</Grid.RowDefinitions>
2626
<FontIcon Grid.Column="0" Grid.RowSpan="2" FontFamily="Segoe MDL2 Assets" Glyph="&#xE7B8;" />
27-
<TextBlock Grid.Column="1" Grid.Row="0" VerticalAlignment="Bottom" FontSize="18" Text="{x:Bind Profile.Name}" />
28-
<TextBlock Grid.Column="1" Grid.Row="1" VerticalAlignment="Top" Text="Local Profile" Foreground="{ThemeResource SystemControlPageTextBaseMediumBrush}" />
27+
<TextBlock
28+
Grid.Column="1"
29+
Grid.Row="0"
30+
VerticalAlignment="Bottom"
31+
FontSize="18"
32+
Text="{x:Bind Profile.Name}"
33+
/>
34+
<TextBlock
35+
Grid.Column="1"
36+
Grid.Row="1"
37+
VerticalAlignment="Top"
38+
Text="Local Profile"
39+
Foreground="{ThemeResource SystemControlPageTextBaseMediumBrush}"
40+
/>
2941
<Button
3042
Grid.Column="2"
3143
Grid.Row="0"

0 commit comments

Comments
 (0)