mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-11-03 12:32:53 +08:00
[fix] preserve Linux desktop options when restarting after updates
This commit is contained in:
@@ -17,6 +17,7 @@ namespace {
|
||||
struct Request {
|
||||
fs::path application;
|
||||
Artifact artifact;
|
||||
std::vector<std::string> restart_arguments;
|
||||
};
|
||||
Request ReadRequest(const fs::path& job) {
|
||||
const auto request = nlohmann::json::parse(ReadText(job / "request.json"));
|
||||
@@ -24,7 +25,8 @@ Request ReadRequest(const fs::path& job) {
|
||||
if (!SupportedInstallation(application)) throw std::runtime_error("Invalid installation destination");
|
||||
const auto artifact = VerifyEnvelope(request.at("envelope").get<std::string>(), PublicKey(),
|
||||
PlatformKey(application), BuildVersion());
|
||||
return {application, artifact};
|
||||
return {application, artifact,
|
||||
request.value("restart_arguments", std::vector<std::string>{})};
|
||||
}
|
||||
|
||||
void WaitForCommit(const fs::path& job) {
|
||||
@@ -81,6 +83,7 @@ int Install(const fs::path& job) {
|
||||
|
||||
int Coordinate(const fs::path& job) {
|
||||
fs::path application;
|
||||
std::vector<std::string> restart_arguments;
|
||||
bool committed = false;
|
||||
bool success = false;
|
||||
bool exited = false;
|
||||
@@ -89,6 +92,7 @@ int Coordinate(const fs::path& job) {
|
||||
try {
|
||||
const auto request = ReadRequest(job);
|
||||
application = request.application;
|
||||
restart_arguments = request.restart_arguments;
|
||||
auto pinned = PinHelper(ExecutablePath());
|
||||
{
|
||||
maintenance = std::make_unique<MaintenanceLock>(application);
|
||||
@@ -139,7 +143,7 @@ int Coordinate(const fs::path& job) {
|
||||
maintenance.reset();
|
||||
if (committed && exited) {
|
||||
try {
|
||||
Restart(application);
|
||||
Restart(application, restart_arguments);
|
||||
if (success) {
|
||||
const auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(90);
|
||||
while (!fs::exists(job / "started") && std::chrono::steady_clock::now() < deadline)
|
||||
|
||||
@@ -72,7 +72,8 @@ void Controller::Start(const std::string& envelope) {
|
||||
const auto job = PrivateDirectory();
|
||||
try {
|
||||
WriteText(job / "request.json", nlohmann::json{
|
||||
{"application", PathUtf8(application)}, {"envelope", envelope}}.dump());
|
||||
{"application", PathUtf8(application)}, {"envelope", envelope},
|
||||
{"restart_arguments", RestartArguments()}}.dump());
|
||||
DownloadPackage(artifact, job / artifact.filename, progress_, cancel_);
|
||||
if (cancel_) throw std::runtime_error("Update cancelled");
|
||||
// Relocate the coordinator so package installation can replace the
|
||||
|
||||
@@ -23,7 +23,8 @@ int Run(const fs::path& executable, const std::vector<std::string>& arguments,
|
||||
int RunElevated(const fs::path& executable, const fs::path& job);
|
||||
void WaitForApplicationExit(const fs::path& application);
|
||||
void InstallPackage(const fs::path& package, const fs::path& application);
|
||||
void Restart(const fs::path& application);
|
||||
std::vector<std::string> RestartArguments();
|
||||
void Restart(const fs::path& application, const std::vector<std::string>& arguments);
|
||||
void RestoreServices();
|
||||
// Pin relocated helper files against changes during elevation (Windows).
|
||||
std::shared_ptr<void> PinHelper(const fs::path& helper);
|
||||
|
||||
Reference in New Issue
Block a user