Add browser download confirmation and parameterized client startup
This commit is contained in:
1 parent
028fec64be
commit
3cf197a98c
25 files changed
+568
-46
No files matched your search
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "../shared/protocol.h"
|
||||
#include <functional>
|
||||
namespace browser_bridge {
|
||||
// Launch only for an explicit add. Queries and connection checks must never start the app.
|
||||
inline std::string ForwardToClient(const Message& request,const std::string& json,
|
||||
const std::function<std::string(const std::string&)>& exchange,
|
||||
const std::function<std::string()>& launch,
|
||||
const std::function<std::string(const std::string&)>& wait_ready) {
|
||||
auto response=exchange(json);
|
||||
Message reply; std::string error;
|
||||
if (Get(request,"action")!="add" || !Parse(response,reply,error)) return response;
|
||||
const auto status=Get(reply,"status");
|
||||
if (status!="client_not_running" && status!="client_not_ready") return response;
|
||||
if (status=="client_not_running") {
|
||||
auto failure=launch(); if (!failure.empty()) return failure;
|
||||
}
|
||||
auto probe=wait_ready(Serialize({{"action","ping"},{"request_id",Get(request,"request_id")}}));
|
||||
if (Parse(probe,reply,error) && Get(reply,"status")=="ready") return exchange(json);
|
||||
return probe;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user