Add option to automatically turn on replay at system startup

This commit is contained in:
dec05eba
2024-11-01 20:10:48 +01:00
parent 0815da6f2c
commit 6fbd8b0dd3
7 changed files with 36 additions and 19 deletions

View File

@@ -77,6 +77,7 @@ namespace gsr {
struct ReplayConfig {
RecordOptions record_options;
bool start_replay_automatically = false;
bool show_replay_started_notifications = true;
bool show_replay_stopped_notifications = true;
bool show_replay_saved_notifications = true;

View File

@@ -71,7 +71,7 @@ namespace gsr {
void update_ui_replay_stopped();
void on_press_save_replay();
void on_press_start_replay();
void on_press_start_replay(bool disable_notification);
void on_press_start_record();
void on_press_start_stream();
bool update_compositor_texture(const mgl_monitor *monitor);

View File

@@ -81,6 +81,7 @@ namespace gsr {
std::unique_ptr<List> create_container_section();
std::unique_ptr<Entry> create_replay_time_entry();
std::unique_ptr<List> create_replay_time();
std::unique_ptr<CheckBox> create_start_replay_on_startup();
void add_replay_widgets();
void add_record_widgets();
@@ -142,6 +143,7 @@ namespace gsr {
List *stream_key_list_ptr = nullptr;
List *stream_url_list_ptr = nullptr;
List *container_list_ptr = nullptr;
CheckBox *start_replay_automatically_ptr = nullptr;
CheckBox *show_replay_started_notification_checkbox_ptr = nullptr;
CheckBox *show_replay_stopped_notification_checkbox_ptr = nullptr;
CheckBox *show_replay_saved_notification_checkbox_ptr = nullptr;

View File

@@ -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},

View File

@@ -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;
}

View File

@@ -525,12 +525,22 @@ namespace gsr {
return replay_time_list;
}
std::unique_ptr<CheckBox> SettingsPage::create_start_replay_on_startup() {
auto checkbox = std::make_unique<CheckBox>(&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>(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<Subsection>("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>(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<Subsection>("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>(List::Orientation::HORIZONTAL);
general_list->add_widget(create_start_replay_on_startup());
settings_list_ptr->add_widget(std::make_unique<Subsection>("General", std::move(general_list), mgl::vec2f(settings_scrollable_page_ptr->get_inner_size().x, 0.0f)));
auto checkboxes_list = std::make_unique<List>(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();

View File

@@ -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