feat: improve custom config

This commit is contained in:
arm64v8a
2022-10-21 19:44:02 +09:00
parent 48938f1db3
commit d49c2d4e90
11 changed files with 105 additions and 49 deletions

View File

@@ -3,6 +3,7 @@
#include "qv2ray/v2/ui/widgets/editors/w_JsonEditor.hpp"
#include "fmt/CustomBean.hpp"
#include "fmt/Preset.hpp"
#include "ui/edit/gen_hysteria.h"
EditCustom::EditCustom(QWidget *parent) :
@@ -15,12 +16,6 @@ EditCustom::EditCustom(QWidget *parent) :
" host: your-domain.com\n"
" sni: your-domain.com\n"
);
if (IS_NEKO_BOX) {
ui->core->hide();
ui->core_l->hide();
ui->command->hide();
ui->command_l->hide();
}
}
EditCustom::~EditCustom() {
@@ -34,13 +29,27 @@ void EditCustom::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
// load known core
auto core_map = QString2QJsonObject(NekoRay::dataStore->extraCore->core_map);
for (const auto &key: core_map.keys()) {
if (key == "naive" || key == "hysteria") continue;
ui->core->addItem(key);
}
if (preset_core == "hysteria") {
preset_command = Preset::Hysteria::command;
preset_config = Preset::Hysteria::config;
ui->config_simple->setPlaceholderText("");
} else if (preset_core == "internal") {
preset_command = preset_config = "";
ui->config_simple->setPlaceholderText("{\n"
" \"type\": \"socks\",\n"
" // ...\n"
"}");
}
// load core ui
P_LOAD_COMBO(core)
ui->command->setText(bean->command.join(" "));
P_LOAD_STRING(config_simple)
// custom external
if (!bean->core.isEmpty()) {
ui->core->setDisabled(true);
} else if (!preset_core.isEmpty()) {
@@ -51,6 +60,14 @@ void EditCustom::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
ui->config_simple->setText(preset_config);
}
// custom internal
if (preset_core == "internal") {
ui->core->hide();
ui->core_l->hide();
ui->command->hide();
ui->command_l->hide();
}
// Generators
if (bean->core == "hysteria") {
ui->generator->setVisible(true);
@@ -71,6 +88,11 @@ bool EditCustom::onEnd() {
bean->command = ui->command->text().split(" ");
P_SAVE_STRING_QTEXTEDIT(config_simple)
if (bean->core.isEmpty()) {
MessageBoxWarning(software_name, tr("Please pick a core."));
return false;
}
return true;
}