Skip to content

Commit d0e799b

Browse files
committed
Fix double navigation issue
1 parent 5b17fad commit d0e799b

9 files changed

+48
-41
lines changed

Flow.Launcher/SettingPages/Views/SettingsPaneAbout.xaml.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ namespace Flow.Launcher.SettingPages.Views;
88
public partial class SettingsPaneAbout
99
{
1010
private SettingsPaneAboutViewModel _viewModel = null!;
11-
private SettingWindowViewModel _settingViewModel = null;
11+
private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
1212

1313
protected override void OnNavigatedTo(NavigationEventArgs e)
1414
{
15+
// Sometimes the navigation is not triggered by button click,
16+
// so we need to reset the page type
17+
_settingViewModel.PageType = typeof(SettingsPaneAbout);
18+
1519
// If the navigation is not triggered by button click, view model will be null again
1620
if (_viewModel == null)
1721
{
1822
_viewModel = Ioc.Default.GetRequiredService<SettingsPaneAboutViewModel>();
19-
_settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
2023
DataContext = _viewModel;
2124
}
2225
if (!IsInitialized)
2326
{
2427
InitializeComponent();
2528
}
26-
// Sometimes the navigation is not triggered by button click,
27-
// so we need to reset the page type
28-
_settingViewModel.PageType = typeof(SettingsPaneAbout);
2929
base.OnNavigatedTo(e);
3030
}
3131

Flow.Launcher/SettingPages/Views/SettingsPaneGeneral.xaml.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ namespace Flow.Launcher.SettingPages.Views;
88
public partial class SettingsPaneGeneral
99
{
1010
private SettingsPaneGeneralViewModel _viewModel = null!;
11-
private SettingWindowViewModel _settingViewModel = null;
11+
private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
1212

1313
protected override void OnNavigatedTo(NavigationEventArgs e)
1414
{
15+
// Sometimes the navigation is not triggered by button click,
16+
// so we need to reset the page type
17+
_settingViewModel.PageType = typeof(SettingsPaneGeneral);
18+
1519
// If the navigation is not triggered by button click, view model will be null again
1620
if (_viewModel == null)
1721
{
1822
_viewModel = Ioc.Default.GetRequiredService<SettingsPaneGeneralViewModel>();
19-
_settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
2023
DataContext = _viewModel;
2124
}
2225
if (!IsInitialized)
2326
{
2427
InitializeComponent();
2528
}
26-
// Sometimes the navigation is not triggered by button click,
27-
// so we need to reset the page type
28-
_settingViewModel.PageType = typeof(SettingsPaneGeneral);
2929
base.OnNavigatedTo(e);
3030
}
3131
}

Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ namespace Flow.Launcher.SettingPages.Views;
88
public partial class SettingsPaneHotkey
99
{
1010
private SettingsPaneHotkeyViewModel _viewModel = null!;
11-
private SettingWindowViewModel _settingViewModel = null;
11+
private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
1212

1313
protected override void OnNavigatedTo(NavigationEventArgs e)
1414
{
15+
// Sometimes the navigation is not triggered by button click,
16+
// so we need to reset the page type
17+
_settingViewModel.PageType = typeof(SettingsPaneHotkey);
18+
1519
// If the navigation is not triggered by button click, view model will be null again
1620
if (_viewModel == null)
1721
{
1822
_viewModel = Ioc.Default.GetRequiredService<SettingsPaneHotkeyViewModel>();
19-
_settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
2023
DataContext = _viewModel;
2124
}
2225
if (!IsInitialized)
2326
{
2427
InitializeComponent();
2528
}
26-
// Sometimes the navigation is not triggered by button click,
27-
// so we need to reset the page type
28-
_settingViewModel.PageType = typeof(SettingsPaneHotkey);
2929
base.OnNavigatedTo(e);
3030
}
3131
}

Flow.Launcher/SettingPages/Views/SettingsPanePluginStore.xaml.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ namespace Flow.Launcher.SettingPages.Views;
1111
public partial class SettingsPanePluginStore
1212
{
1313
private SettingsPanePluginStoreViewModel _viewModel = null!;
14-
private SettingWindowViewModel _settingViewModel = null;
14+
private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
1515

1616
protected override void OnNavigatedTo(NavigationEventArgs e)
1717
{
18+
// Sometimes the navigation is not triggered by button click,
19+
// so we need to reset the page type
20+
_settingViewModel.PageType = typeof(SettingsPanePluginStore);
21+
1822
// If the navigation is not triggered by button click, view model will be null again
1923
if (_viewModel == null)
2024
{
2125
_viewModel = Ioc.Default.GetRequiredService<SettingsPanePluginStoreViewModel>();
22-
_settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
2326
DataContext = _viewModel;
2427
}
2528
if (!IsInitialized)
2629
{
2730
InitializeComponent();
2831
}
2932
_viewModel.PropertyChanged += ViewModel_PropertyChanged;
30-
// Sometimes the navigation is not triggered by button click,
31-
// so we need to reset the page type
32-
_settingViewModel.PageType = typeof(SettingsPanePluginStore);
3333
base.OnNavigatedTo(e);
3434
}
3535

Flow.Launcher/SettingPages/Views/SettingsPanePlugins.xaml.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,25 @@ namespace Flow.Launcher.SettingPages.Views;
1111
public partial class SettingsPanePlugins
1212
{
1313
private SettingsPanePluginsViewModel _viewModel = null!;
14-
private SettingWindowViewModel _settingViewModel = null;
14+
private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
1515

1616
protected override void OnNavigatedTo(NavigationEventArgs e)
1717
{
18+
// Sometimes the navigation is not triggered by button click,
19+
// so we need to reset the page type
20+
_settingViewModel.PageType = typeof(SettingsPanePlugins);
21+
1822
// If the navigation is not triggered by button click, view model will be null again
1923
if (_viewModel == null)
2024
{
2125
_viewModel = Ioc.Default.GetRequiredService<SettingsPanePluginsViewModel>();
22-
_settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
2326
DataContext = _viewModel;
2427
}
2528
if (!IsInitialized)
2629
{
2730
InitializeComponent();
2831
}
2932
_viewModel.PropertyChanged += ViewModel_PropertyChanged;
30-
// Sometimes the navigation is not triggered by button click,
31-
// so we need to reset the page type
32-
_settingViewModel.PageType = typeof(SettingsPanePlugins);
3333
base.OnNavigatedTo(e);
3434
}
3535

Flow.Launcher/SettingPages/Views/SettingsPaneProxy.xaml.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ namespace Flow.Launcher.SettingPages.Views;
88
public partial class SettingsPaneProxy
99
{
1010
private SettingsPaneProxyViewModel _viewModel = null!;
11-
private SettingWindowViewModel _settingViewModel = null;
11+
private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
1212

1313
protected override void OnNavigatedTo(NavigationEventArgs e)
1414
{
15+
// Sometimes the navigation is not triggered by button click,
16+
// so we need to reset the page type
17+
_settingViewModel.PageType = typeof(SettingsPaneProxy);
18+
1519
// If the navigation is not triggered by button click, view model will be null again
1620
if (_viewModel == null)
1721
{
1822
_viewModel = Ioc.Default.GetRequiredService<SettingsPaneProxyViewModel>();
19-
_settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
2023
DataContext = _viewModel;
2124
}
2225
if (!IsInitialized)
2326
{
2427
InitializeComponent();
2528
}
26-
// Sometimes the navigation is not triggered by button click,
27-
// so we need to reset the page type
28-
_settingViewModel.PageType = typeof(SettingsPaneProxy);
2929
base.OnNavigatedTo(e);
3030
}
3131
}

Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ namespace Flow.Launcher.SettingPages.Views;
88
public partial class SettingsPaneTheme
99
{
1010
private SettingsPaneThemeViewModel _viewModel = null!;
11-
private SettingWindowViewModel _settingViewModel = null;
11+
private readonly SettingWindowViewModel _settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
1212

1313
protected override void OnNavigatedTo(NavigationEventArgs e)
1414
{
15+
// Sometimes the navigation is not triggered by button click,
16+
// so we need to reset the page type
17+
_settingViewModel.PageType = typeof(SettingsPaneTheme);
18+
1519
// If the navigation is not triggered by button click, view model will be null again
1620
if (_viewModel == null)
1721
{
1822
_viewModel = Ioc.Default.GetRequiredService<SettingsPaneThemeViewModel>();
19-
_settingViewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
2023
DataContext = _viewModel;
2124
}
2225
if (!IsInitialized)
2326
{
2427
InitializeComponent();
2528
}
26-
// Sometimes the navigation is not triggered by button click,
27-
// so we need to reset the page type
28-
_settingViewModel.PageType = typeof(SettingsPaneTheme);
2929
base.OnNavigatedTo(e);
3030
}
3131
}

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ private void NavigationView_SelectionChanged(NavigationView sender, NavigationVi
241241
{
242242
if (args.IsSettingsSelected)
243243
{
244+
_viewModel.SetPageType(typeof(SettingsPaneGeneral));
244245
ContentFrame.Navigate(typeof(SettingsPaneGeneral));
245246
}
246247
else
@@ -263,8 +264,11 @@ private void NavigationView_SelectionChanged(NavigationView sender, NavigationVi
263264
nameof(About) => typeof(SettingsPaneAbout),
264265
_ => typeof(SettingsPaneGeneral)
265266
};
266-
_viewModel.SetPageType(pageType);
267-
ContentFrame.Navigate(pageType);
267+
// Only navigate if the page type changes to fix navigation forward/back issue
268+
if (_viewModel.SetPageType(pageType))
269+
{
270+
ContentFrame.Navigate(pageType);
271+
}
268272
}
269273
}
270274

@@ -282,7 +286,8 @@ private void NavView_Loaded(object sender, RoutedEventArgs e)
282286

283287
private void ContentFrame_Loaded(object sender, RoutedEventArgs e)
284288
{
285-
NavView.SelectedItem ??= NavView.MenuItems[0]; /* Set First Page */
289+
_viewModel.SetPageType(null); // Set page type to null so that NavigationView_SelectionChanged can navigate the frame
290+
NavView.SelectedItem = NavView.MenuItems[0]; /* Set First Page */
286291
}
287292

288293
#endregion

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using Flow.Launcher.Infrastructure.UserSettings;
33
using Flow.Launcher.Plugin;
4-
using Flow.Launcher.SettingPages.Views;
54

65
namespace Flow.Launcher.ViewModel;
76

@@ -14,12 +13,15 @@ public SettingWindowViewModel(Settings settings)
1413
_settings = settings;
1514
}
1615

17-
public void SetPageType(Type pageType)
16+
public bool SetPageType(Type pageType)
1817
{
18+
if (_pageType == pageType) return false;
19+
1920
_pageType = pageType;
21+
return true;
2022
}
2123

22-
private Type _pageType = typeof(SettingsPaneGeneral);
24+
private Type _pageType = null;
2325
public Type PageType
2426
{
2527
get => _pageType;

0 commit comments

Comments
 (0)