forked from lthn/blockchain
--qt-dev-tools option added for web UI debugging
This commit is contained in:
parent
2a8a715df6
commit
2467d99afb
5 changed files with 137 additions and 93 deletions
|
|
@ -94,45 +94,92 @@ std::wstring convert_to_lower_via_qt(const std::wstring& w)
|
|||
return QString().fromStdWString(w).toLower().toStdWString();
|
||||
}
|
||||
|
||||
|
||||
MainWindow::MainWindow():
|
||||
//m_quit_requested(false),
|
||||
m_gui_deinitialize_done_1(false),
|
||||
m_backend_stopped_2(false),
|
||||
m_system_shutdown(false)
|
||||
MainWindow::MainWindow()
|
||||
: m_gui_deinitialize_done_1(false)
|
||||
, m_backend_stopped_2(false)
|
||||
, m_system_shutdown(false)
|
||||
, m_view(nullptr)
|
||||
, m_channel(nullptr)
|
||||
{
|
||||
#ifndef _MSC_VER
|
||||
//workaround for macos broken tolower from std, very dirty hack
|
||||
bc_services::set_external_to_low_converter(convert_to_lower_via_qt);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
m_backend.subscribe_to_core_events(nullptr);
|
||||
if (m_view)
|
||||
{
|
||||
m_view->page()->setWebChannel(nullptr);
|
||||
m_view = nullptr;
|
||||
}
|
||||
if (m_channel)
|
||||
{
|
||||
m_channel->deregisterObject(this);
|
||||
delete m_channel;
|
||||
m_channel = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_load_finished(bool ok)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
LOG_PRINT("MainWindow::on_load_finished(ok = " << (ok ? "true" : "false") << ")", LOG_LEVEL_0);
|
||||
CATCH_ENTRY2(void());
|
||||
}
|
||||
|
||||
bool MainWindow::init_window()
|
||||
{
|
||||
m_view = new QWebEngineView(this);
|
||||
m_channel = new QWebChannel(m_view->page());
|
||||
m_view->page()->setWebChannel(m_channel);
|
||||
|
||||
QWidget* central_widget_to_be_set = m_view;
|
||||
|
||||
std::string qt_dev_tools_option = m_backend.get_qt_dev_tools_option();
|
||||
if (!qt_dev_tools_option.empty())
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
|
||||
m_view->page()->setDevToolsPage(m_view->page());
|
||||
#endif
|
||||
*/
|
||||
std::vector<std::string> qt_dev_tools_option_parts;
|
||||
boost::split(qt_dev_tools_option_parts, qt_dev_tools_option, [](char c) { return c == ','; });
|
||||
|
||||
Qt::Orientation orientation = Qt::Vertical;
|
||||
if (qt_dev_tools_option_parts.size() >= 1 && qt_dev_tools_option_parts[0] == "horizontal")
|
||||
orientation = Qt::Horizontal;
|
||||
|
||||
//temporary
|
||||
m_view = new QWebEngineView(this);
|
||||
m_channel = new QWebChannel(m_view->page());
|
||||
m_view->page()->setWebChannel(m_channel);
|
||||
|
||||
|
||||
QSplitter* pspliter = new QSplitter(Qt::Horizontal);
|
||||
pspliter->addWidget(m_view);
|
||||
QWebEngineView* pinspector = new QWebEngineView();
|
||||
pspliter->addWidget(pinspector);
|
||||
pinspector->page()->setInspectedPage(m_view->page());
|
||||
|
||||
double zoom_factor = 1.3;
|
||||
if (qt_dev_tools_option_parts.size() >= 2)
|
||||
epee::string_tools::get_xtype_from_string(zoom_factor, qt_dev_tools_option_parts[1]);
|
||||
|
||||
QSplitter* spliter = new QSplitter(orientation);
|
||||
spliter->addWidget(m_view);
|
||||
QWebEngineView* inspector = new QWebEngineView();
|
||||
spliter->addWidget(inspector);
|
||||
m_view->page()->setDevToolsPage(inspector->page());
|
||||
inspector->setZoomFactor(zoom_factor);
|
||||
|
||||
spliter->setCollapsible(0, false);
|
||||
spliter->setCollapsible(1, false);
|
||||
|
||||
QList<int> Sizes;
|
||||
Sizes.append(0.5 * m_view->sizeHint().height());
|
||||
Sizes.append(0.5 * m_view->sizeHint().height());
|
||||
spliter->setSizes(Sizes);
|
||||
|
||||
central_widget_to_be_set = spliter;
|
||||
#else
|
||||
LOG_ERROR("Qt Dev Tool is not available for this Qt version, try building with Qt 5.11.0 or higher");
|
||||
#endif
|
||||
}
|
||||
|
||||
// register QObjects to be exposed to JavaScript
|
||||
m_channel->registerObject(QStringLiteral("mediator_object"), this);
|
||||
|
||||
connect(m_view, SIGNAL(loadFinished(bool)), SLOT(on_load_finished(bool)));
|
||||
|
||||
setCentralWidget(pspliter);
|
||||
//setCentralWidget(m_view);
|
||||
connect(m_view, SIGNAL(loadFinished(bool)), SLOT(on_load_finished(bool)));
|
||||
|
||||
setCentralWidget(central_widget_to_be_set);
|
||||
//this->setMouseTracking(true);
|
||||
|
||||
m_view->page()->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, true);
|
||||
|
|
@ -156,30 +203,9 @@ MainWindow::MainWindow():
|
|||
m_localization[localization_id_tray_menu_show] = "localization_id_tray_menu_show";
|
||||
m_localization[localization_id_tray_menu_minimize] = "localization_id_tray_menu_minimize";
|
||||
|
||||
#ifndef _MSC_VER
|
||||
//workaround for macos broken tolower from std, very dirty hack
|
||||
bc_services::set_external_to_low_converter(convert_to_lower_via_qt);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
m_backend.subscribe_to_core_events(nullptr);
|
||||
m_view->page()->setWebChannel(nullptr);
|
||||
m_channel->deregisterObject(this);
|
||||
delete m_channel;
|
||||
}
|
||||
|
||||
void MainWindow::on_load_finished(bool ok)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
LOG_PRINT("MainWindow::on_load_finished(ok = " << (ok ? "true" : "false") << ")", LOG_LEVEL_0);
|
||||
CATCH_ENTRY2(void());
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-------------
|
||||
QString MainWindow::get_default_user_dir(const QString& param)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
|
|
@ -195,6 +221,7 @@ bool MainWindow::toggle_mining()
|
|||
return true;
|
||||
CATCH_ENTRY2(false);
|
||||
}
|
||||
|
||||
QString MainWindow::get_exchange_last_top(const QString& params)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
|
|
@ -211,10 +238,6 @@ QString MainWindow::get_tx_pool_info()
|
|||
return MAKE_RESPONSE(ar);
|
||||
CATCH_ENTRY_FAIL_API_RESPONCE();
|
||||
}
|
||||
// bool MainWindow::store_config()
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
QString MainWindow::get_default_fee()
|
||||
{
|
||||
|
|
@ -682,7 +705,13 @@ void qt_log_message_handler(QtMsgType type, const QMessageLogContext &context, c
|
|||
bool MainWindow::init_backend(int argc, char* argv[])
|
||||
{
|
||||
TRY_ENTRY();
|
||||
if (!m_backend.init(argc, argv, this))
|
||||
if (!m_backend.init_command_line(argc, argv))
|
||||
return false;
|
||||
|
||||
if (!init_window())
|
||||
return false;
|
||||
|
||||
if (!m_backend.init(this))
|
||||
return false;
|
||||
|
||||
if (m_backend.is_qt_logs_enabled())
|
||||
|
|
|
|||
|
|
@ -212,6 +212,7 @@ private:
|
|||
void restore_pos(bool consider_showed = false);
|
||||
bool store_app_config();
|
||||
bool load_app_config();
|
||||
bool init_window();
|
||||
|
||||
std::string get_wallet_log_prefix(size_t wallet_id) const { return m_backend.get_wallet_log_prefix(wallet_id); }
|
||||
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ namespace plain_wallet
|
|||
args[1] = const_cast<char*>(argss_1.c_str());
|
||||
args[2] = const_cast<char*>(argss_2.c_str());
|
||||
args[3] = nullptr;
|
||||
if (!ptr->gwm.init(3, args, nullptr))
|
||||
if (!(ptr->gwm.init_command_line(3, args) && ptr->gwm.init(nullptr)))
|
||||
{
|
||||
LOG_ERROR("Failed to init wallets_manager");
|
||||
return GENERAL_INTERNAL_ERRROR_INIT;
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ const command_line::arg_descriptor<uint32_t> arg_qt_remote_debugging_port = { "r
|
|||
const command_line::arg_descriptor<std::string> arg_remote_node = { "remote-node", "Switch GUI to work with remote node instead of local daemon", "", true };
|
||||
const command_line::arg_descriptor<bool> arg_enable_qt_logs = { "enable-qt-logs", "Forward Qt log messages into main log", false, true };
|
||||
const command_line::arg_descriptor<bool> arg_disable_logs_init("disable-logs-init", "Disable log initialization in GUI");
|
||||
//const command_line::arg_descriptor<bool> arg_disable_logs_init = { "disable-logs-init", "Disable log initialization in GUI" };
|
||||
const command_line::arg_descriptor<std::string> arg_qt_dev_tools = { "qt-dev-tools", "Enable main web page inspection with Chromium DevTools, <vertical|horizontal>[,scale], e.g. \"horizontal,1.3\"", "", false };
|
||||
|
||||
|
||||
void wallet_lock_time_watching_policy::watch_lock_time(uint64_t lock_time)
|
||||
|
|
@ -106,32 +106,8 @@ void terminate_handler_func()
|
|||
std::abort(); // default terminate handler's behavior
|
||||
}
|
||||
|
||||
bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler)
|
||||
bool wallets_manager::init_command_line(int argc, char* argv[])
|
||||
{
|
||||
m_stop_singal_sent = false;
|
||||
if (pview_handler)
|
||||
m_pview = pview_handler;
|
||||
|
||||
view::daemon_status_info dsi = AUTO_VAL_INIT(dsi);
|
||||
dsi.pos_difficulty = dsi.pow_difficulty = "---";
|
||||
m_pview->update_daemon_status(dsi);
|
||||
|
||||
tools::signal_handler::install_fatal([](int sig_number, void* address) {
|
||||
LOG_ERROR("\n\nFATAL ERROR\nsig: " << sig_number << ", address: " << address);
|
||||
std::fflush(nullptr); // all open output streams are flushed
|
||||
});
|
||||
|
||||
// setup custom callstack retrieving function
|
||||
epee::misc_utils::get_callstack(tools::get_callstack);
|
||||
//#ifndef MOBILE_WALLET_BUILD
|
||||
// setup custom terminate functions
|
||||
std::set_terminate(&terminate_handler_func);
|
||||
//#endif
|
||||
//#if !defined(NDEBUG)
|
||||
// log_space::log_singletone::add_logger(LOGGER_DEBUGGER, nullptr, nullptr);
|
||||
//#endif
|
||||
LOG_PRINT_L0("Initing...");
|
||||
|
||||
TRY_ENTRY();
|
||||
po::options_description desc_cmd_only("Command line options");
|
||||
po::options_description desc_cmd_sett("Command line options and settings options");
|
||||
|
|
@ -155,11 +131,12 @@ bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler)
|
|||
command_line::add_arg(desc_cmd_sett, arg_remote_node);
|
||||
command_line::add_arg(desc_cmd_sett, arg_enable_qt_logs);
|
||||
command_line::add_arg(desc_cmd_sett, arg_disable_logs_init);
|
||||
command_line::add_arg(desc_cmd_sett, arg_qt_dev_tools);
|
||||
command_line::add_arg(desc_cmd_sett, command_line::arg_no_predownload);
|
||||
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);
|
||||
|
||||
|
||||
|
||||
#ifndef MOBILE_WALLET_BUILD
|
||||
currency::core::init_options(desc_cmd_sett);
|
||||
|
|
@ -206,6 +183,50 @@ bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler)
|
|||
return true;
|
||||
});
|
||||
|
||||
if (!coomand_line_parsed)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Command line has wrong arguments: " << std::endl;
|
||||
for (int i = 0; i != argc; i++)
|
||||
ss << "[" << i << "] " << argv[i] << std::endl;
|
||||
std::cerr << ss.str() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
bool wallets_manager::init(view::i_view* pview_handler)
|
||||
{
|
||||
m_stop_singal_sent = false;
|
||||
if (pview_handler)
|
||||
m_pview = pview_handler;
|
||||
|
||||
view::daemon_status_info dsi = AUTO_VAL_INIT(dsi);
|
||||
dsi.pos_difficulty = dsi.pow_difficulty = "---";
|
||||
m_pview->update_daemon_status(dsi);
|
||||
|
||||
tools::signal_handler::install_fatal([](int sig_number, void* address) {
|
||||
LOG_ERROR("\n\nFATAL ERROR\nsig: " << sig_number << ", address: " << address);
|
||||
std::fflush(nullptr); // all open output streams are flushed
|
||||
});
|
||||
|
||||
// setup custom callstack retrieving function
|
||||
epee::misc_utils::get_callstack(tools::get_callstack);
|
||||
//#ifndef MOBILE_WALLET_BUILD
|
||||
// setup custom terminate functions
|
||||
std::set_terminate(&terminate_handler_func);
|
||||
//#endif
|
||||
//#if !defined(NDEBUG)
|
||||
// log_space::log_singletone::add_logger(LOGGER_DEBUGGER, nullptr, nullptr);
|
||||
//#endif
|
||||
LOG_PRINT_L0("Initing...");
|
||||
|
||||
TRY_ENTRY();
|
||||
//set up logging options
|
||||
if (command_line::has_arg(m_vm, arg_alloc_win_console))
|
||||
{
|
||||
|
|
@ -260,21 +281,11 @@ bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler)
|
|||
{
|
||||
log_space::log_singletone::add_logger(LOGGER_FILE, log_file_name.c_str(), log_dir.c_str());
|
||||
LOG_PRINT_L0(CURRENCY_NAME << " v" << PROJECT_VERSION_LONG);
|
||||
LOG_PRINT("Module folder: " << argv[0], LOG_LEVEL_0);
|
||||
//LOG_PRINT("Module folder: " << argv[0], LOG_LEVEL_0);
|
||||
}
|
||||
|
||||
m_qt_logs_enbaled = command_line::get_arg(m_vm, arg_enable_qt_logs);
|
||||
|
||||
m_pview->init(path_to_html);
|
||||
|
||||
if (!coomand_line_parsed)
|
||||
{
|
||||
std::stringstream ss;
|
||||
for (int i = 0; i != argc; i++)
|
||||
ss << "[" << i << "] " << argv[i] << std::endl;
|
||||
|
||||
LOG_PRINT_L0("Command line has wrong arguments: " << std::endl << ss.str());
|
||||
}
|
||||
return true;
|
||||
CATCH_ENTRY_L0("init", false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,7 +88,8 @@ public:
|
|||
|
||||
wallets_manager();
|
||||
~wallets_manager();
|
||||
bool init(int argc, char* argv[], view::i_view* pview_handler);
|
||||
bool init_command_line(int argc, char* argv[]);
|
||||
bool init(view::i_view* pview_handler);
|
||||
bool start();
|
||||
bool stop();
|
||||
bool quick_stop_no_save(); //stop without storing wallets
|
||||
|
|
@ -155,6 +156,7 @@ public:
|
|||
void get_gui_options(view::gui_options& opt);
|
||||
std::string get_wallet_log_prefix(size_t wallet_id) const;
|
||||
bool is_qt_logs_enabled() const { return m_qt_logs_enbaled; }
|
||||
std::string get_qt_dev_tools_option() const { return m_qt_dev_tools; }
|
||||
void set_use_deffered_global_outputs(bool use) { m_use_deffered_global_outputs = use; }
|
||||
private:
|
||||
void main_worker(const po::variables_map& vm);
|
||||
|
|
@ -209,6 +211,7 @@ private:
|
|||
|
||||
bool m_remote_node_mode;
|
||||
bool m_qt_logs_enbaled;
|
||||
std::string m_qt_dev_tools;
|
||||
std::atomic<bool> m_is_pos_allowed;
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue