bgsave: switch to using a 'save' command to the kit.

Also pass 'autosave' status in a more conventional way.

Ideally we would split 'save' away from a ChildSession / ClientSession
and have this on DocumentBroker / Document - for the future.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I39a6caf8b17fa2fc2d940ae0d11bdc2d4da20b6c
private/skyler/prettier-plus-eslint
Michael Meeks 2024-04-12 18:38:06 +01:00
parent 76230b6b4b
commit 0b3b27cb72
2 changed files with 38 additions and 30 deletions

View File

@ -438,6 +438,7 @@ bool ChildSession::_handleInput(const char *buffer, int length)
tokens.equals(0, "windowmouse") ||
tokens.equals(0, "windowgesture") ||
tokens.equals(0, "uno") ||
tokens.equals(0, "save") ||
tokens.equals(0, "selecttext") ||
tokens.equals(0, "windowselecttext") ||
tokens.equals(0, "selectgraphic") ||
@ -538,26 +539,32 @@ bool ChildSession::_handleInput(const char *buffer, int length)
newTokens.push_back(firstLine.substr(4)); // Copy the remaining part.
return unoCommand(newTokens);
}
else if (tokens[1].find(".uno:Save") != std::string::npos)
{
static bool doBgSave = !!getenv("COOL_BGSAVE");
bool saving = false;
if (doBgSave)
saving = !saveDocumentBackground(tokens);
if (!saving)
{ // fallback to foreground save
// Disable processing of other messages while saving document
InputProcessingManager processInput(getProtocol(), false);
return unoCommand(tokens);
}
return true;
}
return unoCommand(tokens);
}
else if (tokens.equals(0, "save"))
{
static bool doBgSave = !!getenv("COOL_BGSAVE");
SigUtil::addActivity(getId(), (doBgSave ? "bg " : "") + firstLine);
bool autosave = tokens[1] == "autosave=true";
StringVector unoSave = StringVector::tokenize("uno .uno:Save " + tokens.cat(std::string(" "), 2));
bool saving = false;
if (doBgSave && autosave)
saving = !saveDocumentBackground(unoSave);
if (!saving)
{ // fallback to foreground save
// Disable processing of other messages while saving document
InputProcessingManager processInput(getProtocol(), false);
return unoCommand(unoSave);
}
else
return true;
}
else if (tokens.equals(0, "selecttext"))
{
return selectText(tokens, LokEventTargetEnum::Document);
@ -1914,6 +1921,9 @@ bool ChildSession::unoCommand(const StringVector& tokens)
tokens.equals(1, ".uno:OpenHyperlink") ||
tokens.startsWith(1, "vnd.sun.star.script:"));
// check that internal UNO commands don't make it to the core
assert (!tokens.equals(1, ".uno:AutoSave"));
getLOKitDocument()->setView(_viewId);
if (tokens.size() == 2)

View File

@ -2671,11 +2671,7 @@ bool DocumentBroker::sendUnoSave(const std::shared_ptr<ClientSession>& session,
// We do not want save to terminate editing mode if we are in edit mode now.
//TODO: Perhaps we want to terminate if forced by the user,
// otherwise autosave doesn't terminate?
oss << "\"DontTerminateEdit\":"
"{"
"\"type\":\"boolean\","
"\"value\":true"
"}";
oss << "\"DontTerminateEdit\" : { \"type\":\"boolean\", \"value\":true\" }";
}
if (dontSaveIfUnmodified)
@ -2683,11 +2679,7 @@ bool DocumentBroker::sendUnoSave(const std::shared_ptr<ClientSession>& session,
if (dontTerminateEdit)
oss << ',';
oss << "\"DontSaveIfUnmodified\":"
"{"
"\"type\":\"boolean\","
"\"value\":true"
"}";
oss << "\"DontSaveIfUnmodified\" : { \"type\":\"boolean\", \"value\":true\" }";
}
// arguments end
@ -2698,12 +2690,15 @@ bool DocumentBroker::sendUnoSave(const std::shared_ptr<ClientSession>& session,
_nextStorageAttrs.setUserModified(isModified() || haveModifyActivityAfterSaveRequest());
// Note: It's odd to capture these here, but this function is used from ClientSession too.
_nextStorageAttrs.setIsAutosave(isAutosave || (_unitWsd && _unitWsd->isAutosave()));
bool autosave = isAutosave || (_unitWsd && _unitWsd->isAutosave());
_nextStorageAttrs.setIsAutosave(autosave);
_nextStorageAttrs.setExtendedData(extendedData);
const std::string saveArgs = oss.str();
LOG_TRC(".uno:Save arguments: " << saveArgs);
const auto command = "uno .uno:Save " + saveArgs;
LOG_TRC("save arguments: " << saveArgs);
// re-written to .uno:Save in the Kit.
const auto command = std::string("save autosave=") + (autosave ? "true" : "")+ " " + saveArgs;
if (forwardToChild(session, command))
{
_saveManager.markLastSaveRequestTime();
@ -3760,6 +3755,9 @@ bool DocumentBroker::forwardToChild(const std::shared_ptr<ClientSession>& sessio
const std::string viewId = session->getId();
// Should not get through; we have our own save command.
assert(!message.starts_with("uno .uno:Save"));
LOG_TRC("Forwarding payload to child [" << viewId << "]: " << getAbbreviatedMessage(message));
#if 0 // extreme paste debugging - message can be giant and binary