From 6fbd8b0dd369c704b21c8757c1f66e55dcf1cb91 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 1 Nov 2024 20:10:48 +0100 Subject: Add option to automatically turn on replay at system startup --- src/Config.cpp | 1 + src/Overlay.cpp | 23 +++++++++++++---------- src/gui/SettingsPage.cpp | 22 +++++++++++++++++----- src/main.cpp | 4 +--- 4 files changed, 32 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/Config.cpp b/src/Config.cpp index 4f68fa1..95949e8 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -119,6 +119,7 @@ namespace gsr { {"replay.record_options.overclock", &config.replay_config.record_options.overclock}, {"replay.record_options.record_cursor", &config.replay_config.record_options.record_cursor}, {"replay.record_options.restore_portal_session", &config.replay_config.record_options.restore_portal_session}, + {"replay.start_replay_automatically", &config.replay_config.start_replay_automatically}, {"replay.show_replay_started_notifications", &config.replay_config.show_replay_started_notifications}, {"replay.show_replay_stopped_notifications", &config.replay_config.show_replay_stopped_notifications}, {"replay.show_replay_saved_notifications", &config.replay_config.show_replay_saved_notifications}, diff --git a/src/Overlay.cpp b/src/Overlay.cpp index 7fce89f..a76a054 100644 --- a/src/Overlay.cpp +++ b/src/Overlay.cpp @@ -211,6 +211,9 @@ namespace gsr { config = std::move(new_config.value()); gsr::init_color_theme(gsr_info); + + if(config.replay_config.start_replay_automatically) + on_press_start_replay(true); } Overlay::~Overlay() { @@ -423,7 +426,7 @@ namespace gsr { } else if(id == "save") { on_press_save_replay(); } else if(id == "start") { - on_press_start_replay(); + on_press_start_replay(false); } }; main_buttons_list->add_widget(std::move(button)); @@ -616,7 +619,7 @@ namespace gsr { } void Overlay::toggle_replay() { - on_press_start_replay(); + on_press_start_replay(false); } void Overlay::save_replay() { @@ -868,16 +871,16 @@ namespace gsr { show_notification("Replay saved", 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY); } - void Overlay::on_press_start_replay() { + void Overlay::on_press_start_replay(bool disable_notification) { switch(recording_status) { case RecordingStatus::NONE: case RecordingStatus::REPLAY: break; case RecordingStatus::RECORD: - show_notification("Unable to start replay when recording.\nStop recording before starting replay.", 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD); + show_notification("Unable to start replay when recording.\nStop recording before starting replay.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD); return; case RecordingStatus::STREAM: - show_notification("Unable to start replay when streaming.\nStop streaming before starting replay.", 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::STREAM); + show_notification("Unable to start replay when streaming.\nStop streaming before starting replay.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::STREAM); return; } @@ -978,7 +981,7 @@ namespace gsr { // TODO: Do not run this is a daemon. Instead get the pid and when launching another notification close the current notification // program and start another one. This can also be used to check when the notification has finished by checking with waitpid NOWAIT // to see when the program has exit. - if(config.replay_config.show_replay_started_notifications) + if(!disable_notification && config.replay_config.show_replay_started_notifications) show_notification("Replay has started", 3.0, get_color_theme().tint_color, get_color_theme().tint_color, NotificationType::REPLAY); } @@ -988,10 +991,10 @@ namespace gsr { case RecordingStatus::RECORD: break; case RecordingStatus::REPLAY: - show_notification("Unable to start recording when replay is turned on.\nTurn off replay before starting recording.", 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY); + show_notification("Unable to start recording when replay is turned on.\nTurn off replay before starting recording.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY); return; case RecordingStatus::STREAM: - show_notification("Unable to start recording when streaming.\nStop streaming before starting recording.", 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::STREAM); + show_notification("Unable to start recording when streaming.\nStop streaming before starting recording.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::STREAM); return; } @@ -1141,10 +1144,10 @@ namespace gsr { case RecordingStatus::STREAM: break; case RecordingStatus::REPLAY: - show_notification("Unable to start streaming when replay is turned on.\nTurn off replay before starting streaming.", 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY); + show_notification("Unable to start streaming when replay is turned on.\nTurn off replay before starting streaming.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::REPLAY); return; case RecordingStatus::RECORD: - show_notification("Unable to start streaming when recording.\nStop recording before starting streaming.", 3.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD); + show_notification("Unable to start streaming when recording.\nStop recording before starting streaming.", 5.0, mgl::Color(255, 255, 255), get_color_theme().tint_color, NotificationType::RECORD); return; } diff --git a/src/gui/SettingsPage.cpp b/src/gui/SettingsPage.cpp index 057497f..2ee1114 100644 --- a/src/gui/SettingsPage.cpp +++ b/src/gui/SettingsPage.cpp @@ -525,12 +525,22 @@ namespace gsr { return replay_time_list; } + std::unique_ptr SettingsPage::create_start_replay_on_startup() { + auto checkbox = std::make_unique(&get_theme().body_font, "Start replay automatically"); + start_replay_automatically_ptr = checkbox.get(); + return checkbox; + } + void SettingsPage::add_replay_widgets() { - auto replay_data_list = std::make_unique(List::Orientation::HORIZONTAL); - replay_data_list->add_widget(create_save_directory("Directory to save replays:")); - replay_data_list->add_widget(create_container_section()); - replay_data_list->add_widget(create_replay_time()); - settings_list_ptr->add_widget(std::make_unique("File info", std::move(replay_data_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f))); + auto file_info_list = std::make_unique(List::Orientation::HORIZONTAL); + file_info_list->add_widget(create_save_directory("Directory to save replays:")); + file_info_list->add_widget(create_container_section()); + file_info_list->add_widget(create_replay_time()); + settings_list_ptr->add_widget(std::make_unique("File info", std::move(file_info_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f))); + + auto general_list = std::make_unique(List::Orientation::HORIZONTAL); + general_list->add_widget(create_start_replay_on_startup()); + settings_list_ptr->add_widget(std::make_unique("General", std::move(general_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f))); auto checkboxes_list = std::make_unique(List::Orientation::VERTICAL); @@ -812,6 +822,7 @@ namespace gsr { void SettingsPage::load_replay() { load_common(config.replay_config.record_options); + start_replay_automatically_ptr->set_checked(config.replay_config.start_replay_automatically); show_replay_started_notification_checkbox_ptr->set_checked(config.replay_config.show_replay_started_notifications); show_replay_stopped_notification_checkbox_ptr->set_checked(config.replay_config.show_replay_stopped_notifications); show_replay_saved_notification_checkbox_ptr->set_checked(config.replay_config.show_replay_saved_notifications); @@ -919,6 +930,7 @@ namespace gsr { void SettingsPage::save_replay() { save_common(config.replay_config.record_options); + config.replay_config.start_replay_automatically = start_replay_automatically_ptr->is_checked(); config.replay_config.show_replay_started_notifications = show_replay_started_notification_checkbox_ptr->is_checked(); config.replay_config.show_replay_stopped_notifications = show_replay_stopped_notification_checkbox_ptr->is_checked(); config.replay_config.show_replay_saved_notifications = show_replay_saved_notification_checkbox_ptr->is_checked(); diff --git a/src/main.cpp b/src/main.cpp index 0cc8076..51610aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -41,9 +41,7 @@ static void disable_prime_run() { unsetenv("__VK_LAYER_NV_optimus"); } -int main(int argc, char **argv) { - (void)argc; - (void)argv; +int main(void) { setlocale(LC_ALL, "C"); // Sigh... stupid C // Cant get window texture when prime-run is used -- cgit v1.2.3