mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:17:36 +00:00
LibCore+Userland: Don't auto-start new Core::Timers
This was unintuitive, and only useful in a few cases. In the majority, users had to immediately call `stop()`, and several who did want the timer started would call `start()` on it immediately anyway. Case in point: There are only two places I had to add a manual `start()`.
This commit is contained in:
parent
a8cf0c9371
commit
6edc0cf5ab
10 changed files with 12 additions and 8 deletions
|
@ -16,7 +16,6 @@ PlaybackManager::PlaybackManager(NonnullRefPtr<Audio::ConnectionToServer> connec
|
||||||
return;
|
return;
|
||||||
next_buffer();
|
next_buffer();
|
||||||
});
|
});
|
||||||
m_timer->stop();
|
|
||||||
m_device_sample_rate = connection->get_sample_rate();
|
m_device_sample_rate = connection->get_sample_rate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,6 +132,7 @@ NetworkStatisticsWidget::NetworkStatisticsWidget()
|
||||||
1000, [this] {
|
1000, [this] {
|
||||||
update_models();
|
update_models();
|
||||||
});
|
});
|
||||||
|
m_update_timer->start();
|
||||||
|
|
||||||
update_models();
|
update_models();
|
||||||
};
|
};
|
||||||
|
|
|
@ -110,6 +110,7 @@ ProcessMemoryMapWidget::ProcessMemoryMapWidget()
|
||||||
|
|
||||||
m_table_view->set_key_column_and_sort_order(0, GUI::SortOrder::Ascending);
|
m_table_view->set_key_column_and_sort_order(0, GUI::SortOrder::Ascending);
|
||||||
m_timer = add<Core::Timer>(1000, [this] { refresh(); });
|
m_timer = add<Core::Timer>(1000, [this] { refresh(); });
|
||||||
|
m_timer->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessMemoryMapWidget::set_pid(pid_t pid)
|
void ProcessMemoryMapWidget::set_pid(pid_t pid)
|
||||||
|
|
|
@ -82,8 +82,10 @@ ThreadStackWidget::ThreadStackWidget()
|
||||||
void ThreadStackWidget::show_event(GUI::ShowEvent&)
|
void ThreadStackWidget::show_event(GUI::ShowEvent&)
|
||||||
{
|
{
|
||||||
refresh();
|
refresh();
|
||||||
if (!m_timer)
|
if (!m_timer) {
|
||||||
m_timer = add<Core::Timer>(1000, [this] { refresh(); });
|
m_timer = add<Core::Timer>(1000, [this] { refresh(); });
|
||||||
|
m_timer->start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadStackWidget::hide_event(GUI::HideEvent&)
|
void ThreadStackWidget::hide_event(GUI::HideEvent&)
|
||||||
|
|
|
@ -328,6 +328,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
};
|
};
|
||||||
update_stats();
|
update_stats();
|
||||||
auto& refresh_timer = window->add<Core::Timer>(frequency * 1000, move(update_stats));
|
auto& refresh_timer = window->add<Core::Timer>(frequency * 1000, move(update_stats));
|
||||||
|
refresh_timer.start();
|
||||||
|
|
||||||
auto selected_id = [&](ProcessModel::Column column) -> pid_t {
|
auto selected_id = [&](ProcessModel::Column column) -> pid_t {
|
||||||
if (process_table_view.selection().is_empty())
|
if (process_table_view.selection().is_empty())
|
||||||
|
|
|
@ -329,6 +329,7 @@ static bool prompt_to_stop_profiling(pid_t pid, DeprecatedString const& process_
|
||||||
auto update_timer = Core::Timer::construct(100, [&] {
|
auto update_timer = Core::Timer::construct(100, [&] {
|
||||||
timer_label.set_text(DeprecatedString::formatted("{:.1} seconds", static_cast<float>(clock.elapsed()) / 1000.0f));
|
timer_label.set_text(DeprecatedString::formatted("{:.1} seconds", static_cast<float>(clock.elapsed()) / 1000.0f));
|
||||||
});
|
});
|
||||||
|
update_timer->start();
|
||||||
|
|
||||||
auto& stop_button = widget->add<GUI::Button>("Stop");
|
auto& stop_button = widget->add<GUI::Button>("Stop");
|
||||||
stop_button.set_fixed_size(140, 22);
|
stop_button.set_fixed_size(140, 22);
|
||||||
|
|
|
@ -17,8 +17,8 @@ Timer::Timer(Object* parent)
|
||||||
Timer::Timer(int interval_ms, Function<void()>&& timeout_handler, Object* parent)
|
Timer::Timer(int interval_ms, Function<void()>&& timeout_handler, Object* parent)
|
||||||
: Object(parent)
|
: Object(parent)
|
||||||
, on_timeout(move(timeout_handler))
|
, on_timeout(move(timeout_handler))
|
||||||
|
, m_interval_ms(interval_ms)
|
||||||
{
|
{
|
||||||
start(interval_ms);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timer::start()
|
void Timer::start()
|
||||||
|
|
|
@ -18,15 +18,12 @@ class Timer final : public Object {
|
||||||
public:
|
public:
|
||||||
static ErrorOr<NonnullRefPtr<Timer>> create_repeating(int interval_ms, Function<void()>&& timeout_handler, Object* parent = nullptr)
|
static ErrorOr<NonnullRefPtr<Timer>> create_repeating(int interval_ms, Function<void()>&& timeout_handler, Object* parent = nullptr)
|
||||||
{
|
{
|
||||||
auto timer = TRY(adopt_nonnull_ref_or_enomem(new Timer(interval_ms, move(timeout_handler), parent)));
|
return adopt_nonnull_ref_or_enomem(new Timer(interval_ms, move(timeout_handler), parent));
|
||||||
timer->stop();
|
|
||||||
return timer;
|
|
||||||
}
|
}
|
||||||
static ErrorOr<NonnullRefPtr<Timer>> create_single_shot(int interval_ms, Function<void()>&& timeout_handler, Object* parent = nullptr)
|
static ErrorOr<NonnullRefPtr<Timer>> create_single_shot(int interval_ms, Function<void()>&& timeout_handler, Object* parent = nullptr)
|
||||||
{
|
{
|
||||||
auto timer = TRY(adopt_nonnull_ref_or_enomem(new Timer(interval_ms, move(timeout_handler), parent)));
|
auto timer = TRY(adopt_nonnull_ref_or_enomem(new Timer(interval_ms, move(timeout_handler), parent)));
|
||||||
timer->set_single_shot(true);
|
timer->set_single_shot(true);
|
||||||
timer->stop();
|
|
||||||
return timer;
|
return timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ ClockWidget::ClockWidget()
|
||||||
set_tooltip(Core::DateTime::now().to_deprecated_string("%Y-%m-%d"sv));
|
set_tooltip(Core::DateTime::now().to_deprecated_string("%Y-%m-%d"sv));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
m_timer->start();
|
||||||
|
|
||||||
m_calendar_window = add<GUI::Window>(window());
|
m_calendar_window = add<GUI::Window>(window());
|
||||||
m_calendar_window->set_window_type(GUI::WindowType::Popup);
|
m_calendar_window->set_window_type(GUI::WindowType::Popup);
|
||||||
|
|
|
@ -48,7 +48,6 @@ Compositor::Compositor()
|
||||||
1000 / 60, [this] {
|
1000 / 60, [this] {
|
||||||
notify_display_links();
|
notify_display_links();
|
||||||
});
|
});
|
||||||
m_display_link_notify_timer->stop();
|
|
||||||
|
|
||||||
m_compose_timer = Core::Timer::create_single_shot(
|
m_compose_timer = Core::Timer::create_single_shot(
|
||||||
1000 / 60,
|
1000 / 60,
|
||||||
|
@ -57,6 +56,7 @@ Compositor::Compositor()
|
||||||
},
|
},
|
||||||
this)
|
this)
|
||||||
.release_value_but_fixme_should_propagate_errors();
|
.release_value_but_fixme_should_propagate_errors();
|
||||||
|
m_compose_timer->start();
|
||||||
|
|
||||||
m_immediate_compose_timer = Core::Timer::create_single_shot(
|
m_immediate_compose_timer = Core::Timer::create_single_shot(
|
||||||
0,
|
0,
|
||||||
|
@ -65,6 +65,7 @@ Compositor::Compositor()
|
||||||
},
|
},
|
||||||
this)
|
this)
|
||||||
.release_value_but_fixme_should_propagate_errors();
|
.release_value_but_fixme_should_propagate_errors();
|
||||||
|
m_compose_timer->start();
|
||||||
|
|
||||||
init_bitmaps();
|
init_bitmaps();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue