BugFix: give time to Save on exit and stop recordings on Quit

This commit is contained in:
Bruno Herbelin
2022-01-16 19:16:51 +01:00
parent e52785a8b4
commit e96444671e
7 changed files with 74 additions and 35 deletions

View File

@@ -79,12 +79,9 @@ void FrameGrabbing::verify(FrameGrabber **rec)
*rec = nullptr; *rec = nullptr;
} }
FrameGrabber *FrameGrabbing::front() bool FrameGrabbing::busy() const
{ {
if (grabbers_.empty()) return !grabbers_.empty();
return nullptr;
return grabbers_.front();
} }
struct fgId: public std::unary_function<FrameGrabber*, bool> struct fgId: public std::unary_function<FrameGrabber*, bool>

View File

@@ -119,7 +119,7 @@ public:
void add(FrameGrabber *rec); void add(FrameGrabber *rec);
void chain(FrameGrabber *rec, FrameGrabber *new_rec); void chain(FrameGrabber *rec, FrameGrabber *new_rec);
void verify(FrameGrabber **rec); void verify(FrameGrabber **rec);
FrameGrabber *front(); bool busy() const;
FrameGrabber *get(uint64_t id); FrameGrabber *get(uint64_t id);
void stopAll(); void stopAll();
void clearAll(); void clearAll();

View File

@@ -66,13 +66,13 @@ const std::chrono::milliseconds timeout_ = std::chrono::milliseconds(4);
// static multithreaded session saving // static multithreaded session saving
static void saveSession(const std::string& filename, Session *session, bool with_version) static void saveSession(const std::string& filename, Session *session, bool with_version)
{ {
// lock access while saving
session->lock();
// capture a snapshot of current version if requested // capture a snapshot of current version if requested
if (with_version) if (with_version)
Action::manager().snapshot( SystemToolkit::date_time_string()); Action::manager().snapshot( SystemToolkit::date_time_string());
// lock access while saving
session->lock();
// save file to disk // save file to disk
if ( SessionVisitor::saveSession(filename, session) ) { if ( SessionVisitor::saveSession(filename, session) ) {
// all ok // all ok

View File

@@ -602,6 +602,14 @@ void Session::unlock()
access_.unlock(); access_.unlock();
} }
bool Session::locked()
{
bool l = access_.try_lock();
if (l)
access_.unlock();
return !l;
}
void Session::validate (SourceList &sources) void Session::validate (SourceList &sources)
{ {
// verify that all sources given are valid in the sesion // verify that all sources given are valid in the sesion

View File

@@ -151,6 +151,7 @@ public:
// lock and unlock access (e.g. while saving) // lock and unlock access (e.g. while saving)
void lock (); void lock ();
void unlock (); void unlock ();
bool locked ();
protected: protected:
bool active_; bool active_;

View File

@@ -141,6 +141,7 @@ UserInterface::UserInterface()
currentTextEdit.clear(); currentTextEdit.clear();
screenshot_step = 0; screenshot_step = 0;
pending_save_on_exit = false; pending_save_on_exit = false;
close_and_exit = false;
sessionopendialog = nullptr; sessionopendialog = nullptr;
sessionimportdialog = nullptr; sessionimportdialog = nullptr;
@@ -152,6 +153,9 @@ bool UserInterface::Init()
if (Rendering::manager().mainWindow().window()== nullptr) if (Rendering::manager().mainWindow().window()== nullptr)
return false; return false;
pending_save_on_exit = false;
close_and_exit = false;
// Setup Dear ImGui context // Setup Dear ImGui context
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();
@@ -683,18 +687,27 @@ bool UserInterface::TryClose()
// force close if trying to close again although it is already pending for save // force close if trying to close again although it is already pending for save
if (pending_save_on_exit) { if (pending_save_on_exit) {
Rendering::manager().close(); close_and_exit = true;
return true; return true;
} }
// general case: determine if a pending save of session is required // determine if a pending save of session is required
pending_save_on_exit = ( Settings::application.recentSessions.save_on_exit pending_save_on_exit = ( Settings::application.recentSessions.save_on_exit
&& !Mixer::manager().session()->empty() && !Mixer::manager().session()->empty()
&& Mixer::manager().session()->filename().empty() ); && Mixer::manager().session()->filename().empty() );
// if no pending save of session is needed, close // if no pending save of session is needed, close
if (!pending_save_on_exit) if (!pending_save_on_exit)
Rendering::manager().close(); {
// stop all recordings
FrameGrabbing::manager().stopAll();
// save on exit
if (Settings::application.recentSessions.save_on_exit)
Mixer::manager().save(false);
close_and_exit = true;
}
// say we can close if no pending save of session is needed // say we can close if no pending save of session is needed
return !pending_save_on_exit; return !pending_save_on_exit;
@@ -745,7 +758,8 @@ void UserInterface::NewFrame()
// overlay to ensure file dialog is modal // overlay to ensure file dialog is modal
if (DialogToolkit::FileDialog::busy()){ if (DialogToolkit::FileDialog::busy()){
ImGui::OpenPopup("Busy"); if (!ImGui::IsPopupOpen("Busy"))
ImGui::OpenPopup("Busy");
if (ImGui::BeginPopupModal("Busy", NULL, ImGuiWindowFlags_AlwaysAutoResize)) if (ImGui::BeginPopupModal("Busy", NULL, ImGuiWindowFlags_AlwaysAutoResize))
{ {
ImGui::Text("Close file dialog box to resume."); ImGui::Text("Close file dialog box to resume.");
@@ -754,27 +768,49 @@ void UserInterface::NewFrame()
} }
// popup to inform to save before close // popup to inform to save before close
if (pending_save_on_exit && !ImGui::IsPopupOpen(MENU_SAVE_ON_EXIT)) if (pending_save_on_exit) {
ImGui::OpenPopup(MENU_SAVE_ON_EXIT); if (!ImGui::IsPopupOpen(MENU_SAVE_ON_EXIT))
if (ImGui::BeginPopupModal(MENU_SAVE_ON_EXIT, NULL, ImGuiWindowFlags_AlwaysAutoResize)) ImGui::OpenPopup(MENU_SAVE_ON_EXIT);
{ if (ImGui::BeginPopupModal(MENU_SAVE_ON_EXIT, NULL, ImGuiWindowFlags_AlwaysAutoResize))
ImGui::Spacing(); {
ImGuiToolkit::PushFont(ImGuiToolkit::FONT_ITALIC); ImGui::Spacing();
ImGui::Text("Looks like you started some work"); ImGuiToolkit::PushFont(ImGuiToolkit::FONT_ITALIC);
ImGui::Text("but didn't save the session."); ImGui::Text("Looks like you started some work");
ImGui::PopFont(); ImGui::Text("but didn't save the session.");
ImGui::Spacing(); ImGui::PopFont();
if (ImGui::Button(MENU_SAVEAS_FILE, ImVec2(ImGui::GetWindowContentRegionWidth(), 0))) { ImGui::Spacing();
pending_save_on_exit = false; if (ImGui::Button(MENU_SAVEAS_FILE, ImVec2(ImGui::GetWindowContentRegionWidth(), 0))) {
saveOrSaveAs(); pending_save_on_exit = false;
ImGui::CloseCurrentPopup(); saveOrSaveAs();
ImGui::CloseCurrentPopup();
}
if (ImGui::Button(MENU_QUIT, ImVec2(ImGui::GetWindowContentRegionWidth(), 0))) {
pending_save_on_exit = false;
close_and_exit = true;
ImGui::CloseCurrentPopup();
}
ImGui::Spacing();
ImGui::EndPopup();
} }
if (ImGui::Button(MENU_QUIT, ImVec2(ImGui::GetWindowContentRegionWidth(), 0))) { }
ImGui::CloseCurrentPopup();
// Asked to close_and_exit
if (close_and_exit){
if (!ImGui::IsPopupOpen("Closing"))
ImGui::OpenPopup("Closing");
if (ImGui::BeginPopupModal("Closing", NULL, ImGuiWindowFlags_AlwaysAutoResize))
{
ImGui::Text("Please wait...");
if (FrameGrabbing::manager().busy())
ImGui::Text(" - Stop recordings.");
if (Settings::application.recentSessions.save_on_exit)
ImGui::Text(" - Save session.");
ImGui::EndPopup();
}
// exit only after everything is closed
if (!FrameGrabbing::manager().busy() && !Mixer::manager().session()->locked()) {
Rendering::manager().close(); Rendering::manager().close();
} }
ImGui::Spacing();
ImGui::EndPopup();
} }
// navigator bar first // navigator bar first
@@ -856,10 +892,6 @@ void UserInterface::Terminate()
// restore windows position for saving // restore windows position for saving
WorkspaceWindow::restoreWorkspace(true); WorkspaceWindow::restoreWorkspace(true);
// save on exit
if (Settings::application.recentSessions.save_on_exit)
Mixer::manager().save(false);
// Cleanup // Cleanup
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown(); ImGui_ImplGlfw_Shutdown();

View File

@@ -405,6 +405,7 @@ protected:
int target_view_navigator; int target_view_navigator;
unsigned int screenshot_step; unsigned int screenshot_step;
bool pending_save_on_exit; bool pending_save_on_exit;
bool close_and_exit;
// Dialogs // Dialogs
DialogToolkit::OpenSessionDialog *sessionopendialog; DialogToolkit::OpenSessionDialog *sessionopendialog;