quickjs enable std option

This commit is contained in:
arm64v8a
2022-12-05 17:34:32 +09:00
parent 5a1bcf011e
commit a94234e699
6 changed files with 41 additions and 16 deletions

2
3rdparty/qjs vendored

View File

@@ -66,7 +66,7 @@ namespace NekoRay {
_add(new configItem("sp_format", &system_proxy_format, itemType::string)); _add(new configItem("sp_format", &system_proxy_format, itemType::string));
_add(new configItem("sub_clear", &sub_clear, itemType::boolean)); _add(new configItem("sub_clear", &sub_clear, itemType::boolean));
_add(new configItem("sub_insecure", &sub_insecure, itemType::boolean)); _add(new configItem("sub_insecure", &sub_insecure, itemType::boolean));
_add(new configItem("enable_js_hook", &enable_js_hook, itemType::boolean)); _add(new configItem("enable_js_hook", &enable_js_hook, itemType::integer));
} }
void DataStore::UpdateStartedId(int id) { void DataStore::UpdateStartedId(int id) {
@@ -233,49 +233,42 @@ namespace NekoRay {
switch (item->type) { switch (item->type) {
case itemType::string: case itemType::string:
if (value.type() != QJsonValue::String) { if (value.type() != QJsonValue::String) {
MessageBoxWarning("错误", "Not a string\n" + key);
continue; continue;
} }
*(QString *) item->ptr = value.toString(); *(QString *) item->ptr = value.toString();
break; break;
case itemType::integer: case itemType::integer:
if (value.type() != QJsonValue::Double) { if (value.type() != QJsonValue::Double) {
MessageBoxWarning("错误", "Not a int\n" + key);
continue; continue;
} }
*(int *) item->ptr = value.toInt(); *(int *) item->ptr = value.toInt();
break; break;
case itemType::integer64: case itemType::integer64:
if (value.type() != QJsonValue::Double) { if (value.type() != QJsonValue::Double) {
MessageBoxWarning("错误", "Not a int64\n" + key);
continue; continue;
} }
*(long long *) item->ptr = value.toDouble(); *(long long *) item->ptr = value.toDouble();
break; break;
case itemType::boolean: case itemType::boolean:
if (value.type() != QJsonValue::Bool) { if (value.type() != QJsonValue::Bool) {
MessageBoxWarning("错误", "Not a bool\n" + key);
continue; continue;
} }
*(bool *) item->ptr = value.toBool(); *(bool *) item->ptr = value.toBool();
break; break;
case itemType::stringList: case itemType::stringList:
if (value.type() != QJsonValue::Array) { if (value.type() != QJsonValue::Array) {
MessageBoxWarning("错误", "Not a Array\n" + key);
continue; continue;
} }
*(QList<QString> *) item->ptr = QJsonArray2QListString(value.toArray()); *(QList<QString> *) item->ptr = QJsonArray2QListString(value.toArray());
break; break;
case itemType::integerList: case itemType::integerList:
if (value.type() != QJsonValue::Array) { if (value.type() != QJsonValue::Array) {
MessageBoxWarning("错误", "Not a Array\n" + key);
continue; continue;
} }
*(QList<int> *) item->ptr = QJsonArray2QListInt(value.toArray()); *(QList<int> *) item->ptr = QJsonArray2QListInt(value.toArray());
break; break;
case itemType::jsonStore: case itemType::jsonStore:
if (value.type() != QJsonValue::Object) { if (value.type() != QJsonValue::Object) {
MessageBoxWarning("错误", "Not a json object\n" + key);
continue; continue;
} }
if (load_control_no_jsonStore) if (load_control_no_jsonStore)

View File

@@ -86,7 +86,7 @@ namespace NekoRay {
// Security // Security
bool insecure_hint = true; bool insecure_hint = true;
bool skip_cert = false; bool skip_cert = false;
bool enable_js_hook = false; int enable_js_hook = 0;
// Remember // Remember
int remember_spmode = NekoRay::SystemProxyMode::DISABLE; int remember_spmode = NekoRay::SystemProxyMode::DISABLE;

View File

@@ -80,6 +80,7 @@ namespace NekoRay::qjs {
this->neko_ctx = malloc(sizeof(nekoray_qjs_context)); this->neko_ctx = malloc(sizeof(nekoray_qjs_context));
nekoray_qjs_new_arg arg; nekoray_qjs_new_arg arg;
arg.neko_ctx = NEKO_CTX; arg.neko_ctx = NEKO_CTX;
arg.enable_std = NekoRay::dataStore->enable_js_hook == 2 ? 1 : 0;
arg.func_log = func_log; arg.func_log = func_log;
nekoray_qjs_new(arg); nekoray_qjs_new(arg);
#endif #endif
@@ -138,7 +139,7 @@ namespace NekoRay::qjs {
QByteArray ReadHookJS() { QByteArray ReadHookJS() {
#ifndef NKR_NO_QUICKJS #ifndef NKR_NO_QUICKJS
if (NekoRay::dataStore->enable_js_hook) { if (NekoRay::dataStore->enable_js_hook > 0) {
return ReadFile(QString("./hook.%1.js").arg(software_name.toLower())); return ReadFile(QString("./hook.%1.js").arg(software_name.toLower()));
} }
#endif #endif

View File

@@ -228,7 +228,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
D_LOAD_BOOL(insecure_hint) D_LOAD_BOOL(insecure_hint)
D_LOAD_BOOL(skip_cert) D_LOAD_BOOL(skip_cert)
D_LOAD_BOOL(enable_js_hook) ui->enable_js_hook->setCurrentIndex(NekoRay::dataStore->enable_js_hook);
} }
DialogBasicSettings::~DialogBasicSettings() { DialogBasicSettings::~DialogBasicSettings() {
@@ -279,7 +279,7 @@ void DialogBasicSettings::accept() {
D_SAVE_BOOL(insecure_hint) D_SAVE_BOOL(insecure_hint)
D_SAVE_BOOL(skip_cert) D_SAVE_BOOL(skip_cert)
D_SAVE_BOOL(enable_js_hook) NekoRay::dataStore->enable_js_hook = ui->enable_js_hook->currentIndex();
MW_dialog_message(Dialog_DialogBasicSettings, "UpdateDataStore"); MW_dialog_message(Dialog_DialogBasicSettings, "UpdateDataStore");
QDialog::accept(); QDialog::accept();

View File

@@ -579,12 +579,43 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="enable_js_hook"> <widget class="QGroupBox" name="horizontalGroupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_14">
<item>
<widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>Enable hook.js</string> <string>Enable hook.js</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QComboBox" name="enable_js_hook">
<item>
<property name="text">
<string notr="true">Disable</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">Enable</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">Enable + load std module</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>