deeplinks implementation: proper routing

This commit is contained in:
cryptozoidberg 2021-12-30 17:30:46 +01:00
parent bdfc14e90d
commit ca8ce3c184
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
6 changed files with 96 additions and 8 deletions

View file

@ -224,4 +224,5 @@ namespace command_line
extern const arg_descriptor<bool> arg_force_predownload;
extern const arg_descriptor<bool> arg_validate_predownload;
extern const arg_descriptor<std::string> arg_predownload_link;
extern const arg_descriptor<std::string> arg_deeplink;
}

View file

@ -12,6 +12,7 @@
using namespace epee;
#include <boost/program_options.hpp>
#include <boost/interprocess/ipc/message_queue.hpp>
#include "p2p/p2p_protocol_defs.h"
#include "common/command_line.h"
#include "currency_core/currency_core.h"
@ -62,6 +63,7 @@ namespace
const command_line::arg_descriptor<std::string> arg_pack_file = {"pack-file", "perform gzip-packing and calculate hash for a given file", "", true };
const command_line::arg_descriptor<std::string> arg_unpack_file = {"unpack-file", "Perform gzip-unpacking and calculate hash for a given file", "", true };
const command_line::arg_descriptor<std::string> arg_target_file = {"target-file", "Specify target file for pack-file and unpack-file commands", "", true };
const command_line::arg_descriptor<std::string> arg_send_ipc = {"send-ipc", "Send IPC request to UI", "", true };
}
typedef COMMAND_REQUEST_STAT_INFO_T<t_currency_protocol_handler<core>::stat_info> COMMAND_REQUEST_STAT_INFO;
@ -1165,6 +1167,33 @@ bool process_archive(archive_processor_t& arch_processor, bool is_packing, std::
return true;
}
bool handle_send_ipc(const std::string& parms)
{
try{
boost::interprocess::message_queue mq
(boost::interprocess::open_only //only open
, GUI_IPC_MESSAGE_CHANNEL_NAME //name
);
mq.send(parms.data(), parms.size(), 0);
return true;
}
catch (const std::exception& ex)
{
boost::interprocess::message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME);
LOG_ERROR("Failed to receive IPC que: " << ex.what());
}
catch (...)
{
boost::interprocess::message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME);
LOG_ERROR("Failed to receive IPC que: unknown exception");
}
return false;
}
bool handle_pack_file(po::variables_map& vm)
{
bool do_pack = false;
@ -1263,6 +1292,8 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_params, arg_pack_file);
command_line::add_arg(desc_params, arg_unpack_file);
command_line::add_arg(desc_params, arg_target_file);
command_line::add_arg(desc_params, arg_send_ipc);
po::options_description desc_all;
desc_all.add(desc_general).add(desc_params);
@ -1339,6 +1370,10 @@ int main(int argc, char* argv[])
{
return handle_pack_file(vm) ? EXIT_SUCCESS : EXIT_FAILURE;
}
else if (command_line::has_arg(vm, arg_send_ipc))
{
handle_send_ipc(command_line::get_arg(vm, arg_send_ipc)) ? EXIT_SUCCESS : EXIT_FAILURE;
}
else
{
std::cerr << "Not enough arguments." << ENDL;

View file

@ -121,6 +121,10 @@ MainWindow::~MainWindow()
delete m_channel;
m_channel = nullptr;
}
if (m_ipc_worker.joinable())
{
m_ipc_worker.join();
}
}
void MainWindow::on_load_finished(bool ok)
@ -745,14 +749,14 @@ void qt_log_message_handler(QtMsgType type, const QMessageLogContext &context, c
bool MainWindow::init_ipc_server()
{
#define GUI_IPC_BUFFER_SIZE 4000
#define GUI_IPC_BUFFER_SIZE 10000
try {
//Create a message queue.
std::shared_ptr<boost::interprocess::message_queue*> pmq = new boost::interprocess::message_queue(create_only //only create
std::shared_ptr<boost::interprocess::message_queue> pmq(new boost::interprocess::message_queue(boost::interprocess::create_only //only create
, GUI_IPC_MESSAGE_CHANNEL_NAME //name
, 100 //max message number
, GUI_IPC_BUFFER_SIZE //max message size
);
, GUI_IPC_BUFFER_SIZE //max message size
));
m_ipc_worker = std::thread([this, pmq]()
{
@ -765,13 +769,14 @@ bool MainWindow::init_ipc_server()
while (m_gui_deinitialize_done_1 == false)
{
std::string buff(GUI_IPC_BUFFER_SIZE, ' ');
bool data_received = pmq->timed_receive(buff.data(), GUI_IPC_BUFFER_SIZE, recvd_size, priority, boost::posix_time::ptime(microsec_clock::universal_time()) + boost::posix_time::milliseconds(300));
bool data_received = pmq->timed_receive((void*)buff.data(), GUI_IPC_BUFFER_SIZE, recvd_size, priority, boost::posix_time::ptime(boost::posix_time::microsec_clock::universal_time()) + boost::posix_time::milliseconds(1000));
if (data_received && recvd_size != 0)
{
//todo process token
handle_ipc_event(buff);//todo process token
}
}
message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME);
}
boost::interprocess::message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME);
LOG_PRINT_L0("IPC Handling thread finished");
}
catch (const std::exception& ex)
{
@ -803,6 +808,32 @@ bool MainWindow::init_ipc_server()
}
bool MainWindow::handle_ipc_event(const std::string& arguments)
{
std::string zzz = "Received IPC: " + arguments;
message_box(zzz.c_str());
handle_deeplink_click(arguments.c_str());
return true;
}
bool MainWindow::handle_deeplink_params_in_commandline()
{
std::string deep_link_params = command_line::get_arg(m_backend.get_arguments(), command_line::arg_deeplink);
try {
boost::interprocess::message_queue mq(boost::interprocess::open_only, GUI_IPC_MESSAGE_CHANNEL_NAME);
mq.send(deep_link_params.data(), deep_link_params.size(), 0);
return false;
}
catch (...)
{
//ui not launched yet
return true;
}
}
bool MainWindow::init_backend(int argc, char* argv[])
{
TRY_ENTRY();
@ -813,6 +844,12 @@ bool MainWindow::init_backend(int argc, char* argv[])
return false;
}
if (command_line::has_arg(m_backend.get_arguments(), command_line::arg_deeplink))
{
if (!handle_deeplink_params_in_commandline())
return false;
}
if (!init_window())
{
this->show_msg_box("Failed to main screen launch, check logs for the more detais.");
@ -833,6 +870,12 @@ bool MainWindow::init_backend(int argc, char* argv[])
QLoggingCategory::setFilterRules("*=true"); // enable all logs
}
if (!init_ipc_server())
{
this->show_msg_box("Failed to initialize IP server, check debug logs for more details.");
return false;
}
return true;
CATCH_ENTRY2(false);
}

View file

@ -60,6 +60,7 @@ public:
bool init_backend(int argc, char* argv[]);
bool show_inital();
void show_notification(const std::string& title, const std::string& message);
bool handle_ipc_event(const std::string& arguments);
struct app_config
{
@ -194,6 +195,7 @@ signals:
void on_core_event(const QString method_name); //general function
void set_options(const QString str); //general function
void get_wallet_name();
void handle_deeplink_click(const QString str);
private:
//-------------------- i_core_event_handler --------------------
@ -236,6 +238,8 @@ private:
bool store_app_config();
bool load_app_config();
bool init_window();
bool init_ipc_server();
std::string get_wallet_log_prefix(size_t wallet_id) const { return m_backend.get_wallet_log_prefix(wallet_id); }
@ -258,6 +262,7 @@ private:
app_config m_config;
epee::locked_object<std::map<uint64_t, uint64_t>> m_wallet_states;
std::thread m_ipc_worker;
struct events_que_struct
{
std::list<currency::core_event> m_que;

View file

@ -183,6 +183,7 @@ bool wallets_manager::init_command_line(int argc, char* argv[], std::string& fai
command_line::add_arg(desc_cmd_sett, command_line::arg_force_predownload);
command_line::add_arg(desc_cmd_sett, command_line::arg_validate_predownload);
command_line::add_arg(desc_cmd_sett, command_line::arg_predownload_link);
command_line::add_arg(desc_cmd_sett, command_line::arg_deeplink);
#ifndef MOBILE_WALLET_BUILD
@ -247,6 +248,7 @@ bool wallets_manager::init_command_line(int argc, char* argv[], std::string& fai
m_qt_logs_enbaled = command_line::get_arg(m_vm, arg_enable_qt_logs);
m_qt_dev_tools = command_line::get_arg(m_vm, arg_qt_dev_tools);
return true;
CATCH_ENTRY2(false);
}

View file

@ -97,6 +97,8 @@ public:
bool quick_clear_wallets_no_save();
bool send_stop_signal();
bool get_opened_wallets(std::list<view::open_wallet_response>& result);
const po::variables_map& get_arguments();
std::string open_wallet(const std::wstring& path, const std::string& password, uint64_t txs_to_return, view::open_wallet_response& owr, bool exclude_mining_txs = false);
std::string generate_wallet(const std::wstring& path, const std::string& password, view::open_wallet_response& owr);
std::string restore_wallet(const std::wstring& path, const std::string& password, const std::string& seed_phrase, const std::string& seed_password, view::open_wallet_response& owr);