From eadbe41064d5e4f34dce72315db2ebeb3d8b7b12 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Mon, 14 Dec 2020 13:57:24 +0100 Subject: [PATCH] Add core.on_quit function for plugins To be used for plugins like workspace from exi/lite-plugins --- data/core/init.lua | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 4a85a088..c4f92a05 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -329,22 +329,29 @@ function core.temp_filename(ext) .. string.format("%06x", temp_file_counter) .. (ext or "") end +-- override to perform an operation before quit +function core.on_quit() +end -function core.quit(force) +local function quit_with_function(quit_fn, force) if force then delete_temp_files() - os.exit() - end - if core.confirm_close_all() then - core.quit(true) + core.on_quit() + quit_fn() + else + if core.confirm_close_all() then + quit_with_function(quit_fn, true) + end end end +function core.quit(force) + quit_with_function(os.exit, force) +end + function core.restart() - if core.confirm_close_all() then - core.restart_request = true - end + quit_with_function(function() core.restart_request = true end) end