Skip to content

Commit

Permalink
Allow file modifications to quiet down before reloading settings (#1330)
Browse files Browse the repository at this point in the history
This commit introduces a 50ms debounce so that we stop flapping around while text editors are making directory changes.

Fixes #1329.
  • Loading branch information
DHowett authored Jun 19, 2019
1 parent 8717189 commit 440bee0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/cascadia/TerminalApp/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,26 @@ namespace winrt::TerminalApp::implementation

if (settingsBasename == modifiedBasename)
{
this->_ReloadSettings();
this->_DispatchReloadSettings();
}
});
}

// Method Description:
// - Dispatches a settings reload with debounce.
// Text editors implement Save in a bunch of different ways, so
// this stops us from reloading too many times or too quickly.
fire_and_forget App::_DispatchReloadSettings()
{
static constexpr auto FileActivityQuiesceTime{ std::chrono::milliseconds(50) };
if (!_settingsReloadQueued.exchange(true))
{
co_await winrt::resume_after(FileActivityQuiesceTime);
_ReloadSettings();
_settingsReloadQueued.store(false);
}
}

// Method Description:
// - Reloads the settings from the profile.json.
void App::_ReloadSettings()
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ namespace winrt::TerminalApp::implementation

wil::unique_folder_change_reader_nothrow _reader;

std::atomic<bool> _settingsReloadQueued{ false };

void _Create();
void _CreateNewTabFlyout();

Expand All @@ -85,6 +87,7 @@ namespace winrt::TerminalApp::implementation
void _HookupKeyBindings(TerminalApp::AppKeyBindings bindings) noexcept;

void _RegisterSettingsChange();
fire_and_forget _DispatchReloadSettings();
void _ReloadSettings();

void _SettingsButtonOnClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
Expand Down

0 comments on commit 440bee0

Please sign in to comment.