Skip to content

Commit

Permalink
quickjs enable std option
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Dec 5, 2022
1 parent 5a1bcf0 commit a94234e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 16 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/qjs
Submodule qjs updated 2 files
+22 −12 nekoray_qjs.c
+1 −0 nekoray_qjs.h
9 changes: 1 addition & 8 deletions main/NekoRay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace NekoRay {
_add(new configItem("sp_format", &system_proxy_format, itemType::string));
_add(new configItem("sub_clear", &sub_clear, 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) {
Expand Down Expand Up @@ -233,49 +233,42 @@ namespace NekoRay {
switch (item->type) {
case itemType::string:
if (value.type() != QJsonValue::String) {
MessageBoxWarning("错误", "Not a string\n" + key);
continue;
}
*(QString *) item->ptr = value.toString();
break;
case itemType::integer:
if (value.type() != QJsonValue::Double) {
MessageBoxWarning("错误", "Not a int\n" + key);
continue;
}
*(int *) item->ptr = value.toInt();
break;
case itemType::integer64:
if (value.type() != QJsonValue::Double) {
MessageBoxWarning("错误", "Not a int64\n" + key);
continue;
}
*(long long *) item->ptr = value.toDouble();
break;
case itemType::boolean:
if (value.type() != QJsonValue::Bool) {
MessageBoxWarning("错误", "Not a bool\n" + key);
continue;
}
*(bool *) item->ptr = value.toBool();
break;
case itemType::stringList:
if (value.type() != QJsonValue::Array) {
MessageBoxWarning("错误", "Not a Array\n" + key);
continue;
}
*(QList<QString> *) item->ptr = QJsonArray2QListString(value.toArray());
break;
case itemType::integerList:
if (value.type() != QJsonValue::Array) {
MessageBoxWarning("错误", "Not a Array\n" + key);
continue;
}
*(QList<int> *) item->ptr = QJsonArray2QListInt(value.toArray());
break;
case itemType::jsonStore:
if (value.type() != QJsonValue::Object) {
MessageBoxWarning("错误", "Not a json object\n" + key);
continue;
}
if (load_control_no_jsonStore)
Expand Down
2 changes: 1 addition & 1 deletion main/NekoRay_DataStore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace NekoRay {
// Security
bool insecure_hint = true;
bool skip_cert = false;
bool enable_js_hook = false;
int enable_js_hook = 0;

// Remember
int remember_spmode = NekoRay::SystemProxyMode::DISABLE;
Expand Down
3 changes: 2 additions & 1 deletion main/QJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ namespace NekoRay::qjs {
this->neko_ctx = malloc(sizeof(nekoray_qjs_context));
nekoray_qjs_new_arg arg;
arg.neko_ctx = NEKO_CTX;
arg.enable_std = NekoRay::dataStore->enable_js_hook == 2 ? 1 : 0;
arg.func_log = func_log;
nekoray_qjs_new(arg);
#endif
Expand Down Expand Up @@ -138,7 +139,7 @@ namespace NekoRay::qjs {

QByteArray ReadHookJS() {
#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()));
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions ui/dialog_basic_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)

D_LOAD_BOOL(insecure_hint)
D_LOAD_BOOL(skip_cert)
D_LOAD_BOOL(enable_js_hook)
ui->enable_js_hook->setCurrentIndex(NekoRay::dataStore->enable_js_hook);
}

DialogBasicSettings::~DialogBasicSettings() {
Expand Down Expand Up @@ -279,7 +279,7 @@ void DialogBasicSettings::accept() {

D_SAVE_BOOL(insecure_hint)
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");
QDialog::accept();
Expand Down
37 changes: 34 additions & 3 deletions ui/dialog_basic_settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,41 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="enable_js_hook">
<property name="text">
<string>Enable hook.js</string>
<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">
<string>Enable hook.js</string>
</property>
</widget>
</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>
Expand Down

0 comments on commit a94234e

Please sign in to comment.