From 53f1b3a7db38be38304930db4be35e88c1722915 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 23 Jul 2018 18:07:55 +0200 Subject: [PATCH] MacOS: no longer shows several info messages when file is changed on disk but not reloaded --- src/source_base.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/source_base.cc b/src/source_base.cc index 812e874..7260426 100644 --- a/src/source_base.cc +++ b/src/source_base.cc @@ -191,18 +191,20 @@ void Source::BaseView::monitor_file() { #ifdef __APPLE__ // TODO: Gio file monitor is bugged on MacOS class Recursive { public: - static void f(BaseView *view, std::time_t previous_last_write_time = static_cast(-1)) { + static void f(BaseView *view, std::time_t previous_last_write_time = static_cast(-1), bool check_called = false) { view->delayed_monitor_changed_connection.disconnect(); - view->delayed_monitor_changed_connection = Glib::signal_timeout().connect([view, previous_last_write_time]() { + view->delayed_monitor_changed_connection = Glib::signal_timeout().connect([view, previous_last_write_time, check_called]() { boost::system::error_code ec; auto last_write_time = boost::filesystem::last_write_time(view->file_path, ec); if(!ec && last_write_time != view->last_write_time) { - if(last_write_time == previous_last_write_time) // If no change has happened in the last second (std::time_t is in seconds) - view->check_last_write_time(last_write_time); - else { - Recursive::f(view, last_write_time); + if(last_write_time == previous_last_write_time) { // If no change has happened in the last second (std::time_t is in seconds). + if(!check_called) // To avoid several info messages when file is changed but not reloaded. + view->check_last_write_time(last_write_time); + Recursive::f(view, last_write_time, true); return false; } + Recursive::f(view, last_write_time); + return false; } Recursive::f(view); return false;