mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
imporve log widget
This commit is contained in:
15
.github/workflows/build-qv2ray-cmake.yml
vendored
15
.github/workflows/build-qv2ray-cmake.yml
vendored
@@ -35,7 +35,7 @@ jobs:
|
|||||||
if: steps.cache-common.outputs.cache-hit != 'true'
|
if: steps.cache-common.outputs.cache-hit != 'true'
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: 1.19.2
|
go-version: 1.19.4
|
||||||
- name: Build golang parts
|
- name: Build golang parts
|
||||||
if: steps.cache-common.outputs.cache-hit != 'true'
|
if: steps.cache-common.outputs.cache-hit != 'true'
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -57,7 +57,6 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
platform: [ windows-2022, ubuntu-20.04, macos-10.15 ]
|
platform: [ windows-2022, ubuntu-20.04, macos-10.15 ]
|
||||||
arch: [ x64 ]
|
arch: [ x64 ]
|
||||||
qt_version: [ 5.15.2 ]
|
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
|
|
||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
@@ -87,12 +86,12 @@ jobs:
|
|||||||
if: matrix.platform == 'macos-10.15'
|
if: matrix.platform == 'macos-10.15'
|
||||||
uses: jurplel/install-qt-action@v3
|
uses: jurplel/install-qt-action@v3
|
||||||
with:
|
with:
|
||||||
version: ${{ matrix.qt_version }}
|
version: 5.15.2
|
||||||
py7zrversion: ' '
|
py7zrversion: ' '
|
||||||
aqtversion: ' '
|
aqtversion: ' '
|
||||||
setup-python: false
|
setup-python: false
|
||||||
cache: true
|
cache: true
|
||||||
cache-key-prefix: QtCache-${{ matrix.platform }}-${{ matrix.arch }}-${{ matrix.qt_version }}
|
cache-key-prefix: QtCache-${{ matrix.platform }}-${{ matrix.arch }}
|
||||||
- name: Windows - Download Custom Qt 5.15 SDK
|
- name: Windows - Download Custom Qt 5.15 SDK
|
||||||
shell: bash
|
shell: bash
|
||||||
if: matrix.platform == 'windows-2022'
|
if: matrix.platform == 'windows-2022'
|
||||||
@@ -116,14 +115,14 @@ jobs:
|
|||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: libs/deps
|
path: libs/deps
|
||||||
key: DepsCache-${{ matrix.platform }}-${{ matrix.arch }}-${{ matrix.qt_version }}-${{ hashFiles('libs/build_deps_*.sh') }}
|
key: DepsCache-${{ matrix.platform }}-${{ matrix.arch }}-${{ hashFiles('libs/build_deps_*.sh') }}
|
||||||
- name: Build Dependencies
|
- name: Build Dependencies
|
||||||
shell: bash
|
shell: bash
|
||||||
if: steps.cache-deps.outputs.cache-hit != 'true'
|
if: steps.cache-deps.outputs.cache-hit != 'true'
|
||||||
run: |
|
run: |
|
||||||
./libs/build_deps_all.sh
|
./libs/build_deps_all.sh
|
||||||
# ========================================================================================================= Generate MakeFile and Build
|
# ========================================================================================================= Generate MakeFile and Build
|
||||||
- name: Windows - ${{ matrix.qt_version }} - Generate MakeFile and Build
|
- name: Windows - Generate MakeFile and Build
|
||||||
shell: bash
|
shell: bash
|
||||||
if: matrix.platform == 'windows-2022'
|
if: matrix.platform == 'windows-2022'
|
||||||
env:
|
env:
|
||||||
@@ -137,7 +136,7 @@ jobs:
|
|||||||
ninja
|
ninja
|
||||||
cd ..
|
cd ..
|
||||||
./libs/deploy_windows64.sh
|
./libs/deploy_windows64.sh
|
||||||
- name: Linux - ${{ matrix.qt_version }} - Generate MakeFile and Build
|
- name: Linux - Generate MakeFile and Build
|
||||||
shell: bash
|
shell: bash
|
||||||
if: matrix.platform == 'ubuntu-20.04'
|
if: matrix.platform == 'ubuntu-20.04'
|
||||||
run: |
|
run: |
|
||||||
@@ -147,7 +146,7 @@ jobs:
|
|||||||
ninja
|
ninja
|
||||||
cd ..
|
cd ..
|
||||||
./libs/deploy_linux64.sh
|
./libs/deploy_linux64.sh
|
||||||
- name: macOS - ${{ matrix.qt_version }} - Generate MakeFile and Build
|
- name: macOS - Generate MakeFile and Build
|
||||||
shell: bash
|
shell: bash
|
||||||
if: matrix.platform == 'macos-10.15'
|
if: matrix.platform == 'macos-10.15'
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"neko/pkg/speedtest"
|
"neko/pkg/speedtest"
|
||||||
"nekobox_core/box_main"
|
"nekobox_core/box_main"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
box "github.com/sagernet/sing-box"
|
box "github.com/sagernet/sing-box"
|
||||||
@@ -39,16 +38,6 @@ func (s *server) Start(ctx context.Context, in *gen.LoadConfigReq) (out *gen.Err
|
|||||||
log.Println("Start:", in.CoreConfig)
|
log.Println("Start:", in.CoreConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
if neko_common.GetBuildTime() > 0 {
|
|
||||||
if time.Now().Unix() >= neko_common.GetExpireTime() {
|
|
||||||
err = errors.New("Your version is too old! Please update!! 版本太旧,请升级!")
|
|
||||||
return
|
|
||||||
} else if time.Now().Unix() >= (neko_common.GetExpireTime() - 30*24*60*60) {
|
|
||||||
log.Println("Your version is too old! Please update!! 版本太旧,请升级!")
|
|
||||||
log.Println("This version expires on " + time.Unix(neko_common.GetExpireTime(), 0).Format("2006-01-02"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if instance != nil {
|
if instance != nil {
|
||||||
err = errors.New("instance already started")
|
err = errors.New("instance already started")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"libcore"
|
"libcore"
|
||||||
"libcore/stun"
|
"libcore/stun"
|
||||||
"log"
|
|
||||||
"neko/gen"
|
"neko/gen"
|
||||||
"neko/pkg/grpc_server"
|
"neko/pkg/grpc_server"
|
||||||
"neko/pkg/neko_common"
|
"neko/pkg/neko_common"
|
||||||
@@ -39,16 +38,6 @@ func (s *server) Start(ctx context.Context, in *gen.LoadConfigReq) (out *gen.Err
|
|||||||
logrus.Println("Start:", in.CoreConfig, in.TryDomains)
|
logrus.Println("Start:", in.CoreConfig, in.TryDomains)
|
||||||
}
|
}
|
||||||
|
|
||||||
if neko_common.GetBuildTime() > 0 {
|
|
||||||
if time.Now().Unix() >= neko_common.GetExpireTime() {
|
|
||||||
err = errors.New("Your version is too old! Please update!! 版本太旧,请升级!")
|
|
||||||
return
|
|
||||||
} else if time.Now().Unix() >= (neko_common.GetExpireTime() - 30*24*60*60) {
|
|
||||||
log.Println("Your version is too old! Please update!! 版本太旧,请升级!")
|
|
||||||
log.Println("This version expires on " + time.Unix(neko_common.GetExpireTime(), 0).Format("2006-01-02"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if instance != nil {
|
if instance != nil {
|
||||||
err = errors.New("instance already started")
|
err = errors.New("instance already started")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package neko_common
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version_v2ray string = "N/A"
|
var Version_v2ray string = "N/A"
|
||||||
@@ -20,19 +18,3 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var GetProxyHttpClient func() *http.Client
|
var GetProxyHttpClient func() *http.Client
|
||||||
|
|
||||||
func GetBuildTime() int64 {
|
|
||||||
if !strings.HasPrefix(Version_neko, "nekoray-") {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
ver := strings.TrimLeft(Version_neko, "nekoray-")
|
|
||||||
buildDate := ver[strings.Index(ver, "-")+1:]
|
|
||||||
buildTime, _ := time.Parse("2006-01-02", buildDate)
|
|
||||||
return buildTime.Unix()
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetExpireTime() int64 {
|
|
||||||
buildTime := time.Unix(GetBuildTime(), 0)
|
|
||||||
expireTime := buildTime.AddDate(0, 6, 0) // current force update: 6 months
|
|
||||||
return expireTime.Unix()
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ namespace NekoRay {
|
|||||||
_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::integer));
|
_add(new configItem("enable_js_hook", &enable_js_hook, itemType::integer));
|
||||||
|
_add(new configItem("log_ignore", &log_ignore, itemType::stringList));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataStore::UpdateStartedId(int id) {
|
void DataStore::UpdateStartedId(int id) {
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ namespace NekoRay {
|
|||||||
QString mw_size = "";
|
QString mw_size = "";
|
||||||
bool check_include_pre = false;
|
bool check_include_pre = false;
|
||||||
QString system_proxy_format = "";
|
QString system_proxy_format = "";
|
||||||
|
QStringList log_ignore = {};
|
||||||
|
|
||||||
// Subscription
|
// Subscription
|
||||||
QString user_agent = "Nekoray/1.0 (Prefer Clash Format)";
|
QString user_agent = "Nekoray/1.0 (Prefer Clash Format)";
|
||||||
|
|||||||
@@ -1205,6 +1205,28 @@ End: %2</source>
|
|||||||
<source>Open Config Folder</source>
|
<source>Open Config Folder</source>
|
||||||
<translation>打开配置目录</translation>
|
<translation>打开配置目录</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Set ignore keyword</source>
|
||||||
|
<translation>设置忽略关键字</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Set the following keywords to ignore?
|
||||||
|
Split by line.</source>
|
||||||
|
<translation>将以下关键字设置为忽略?
|
||||||
|
一行一个。</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Save as route</source>
|
||||||
|
<translation>保存为路由规则</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Save "%1" as a routing rule?</source>
|
||||||
|
<translation>将"%1"保存为一条路由规则?</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Edit</source>
|
||||||
|
<translation>编辑</translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ProxyItem</name>
|
<name>ProxyItem</name>
|
||||||
|
|||||||
@@ -558,7 +558,7 @@ void MainWindow::on_menu_exit_triggered() {
|
|||||||
QProcess::startDetached("./updater", QStringList{});
|
QProcess::startDetached("./updater", QStringList{});
|
||||||
} else if (exit_reason == 2) {
|
} else if (exit_reason == 2) {
|
||||||
QDir::setCurrent(QApplication::applicationDirPath());
|
QDir::setCurrent(QApplication::applicationDirPath());
|
||||||
QProcess::startDetached(qEnvironmentVariable("NKR_FROM_LAUNCHER") == "1" ? "./launcher" : "./nekoray", QStringList{});
|
QProcess::startDetached(qEnvironmentVariable("NKR_FROM_LAUNCHER") == "1" ? "./launcher" : QApplication::applicationFilePath(), QStringList{});
|
||||||
}
|
}
|
||||||
tray->hide();
|
tray->hide();
|
||||||
QCoreApplication::quit();
|
QCoreApplication::quit();
|
||||||
@@ -1277,9 +1277,15 @@ inline void FastAppendTextDocument(const QString &message, QTextDocument *doc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::show_log_impl(const QString &log) {
|
void MainWindow::show_log_impl(const QString &log) {
|
||||||
if (log.trimmed().isEmpty()) return;
|
auto log2 = log.trimmed();
|
||||||
|
if (log2.isEmpty()) return;
|
||||||
|
|
||||||
FastAppendTextDocument(log, qvLogDocument);
|
auto log_ignore = NekoRay::dataStore->log_ignore;
|
||||||
|
for (const auto &str: log_ignore) {
|
||||||
|
if (log2.contains(str)) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FastAppendTextDocument(log2, qvLogDocument);
|
||||||
// qvLogDocument->setPlainText(qvLogDocument->toPlainText() + log);
|
// qvLogDocument->setPlainText(qvLogDocument->toPlainText() + log);
|
||||||
// From https://gist.github.com/jemyzhang/7130092
|
// From https://gist.github.com/jemyzhang/7130092
|
||||||
auto maxLines = 200;
|
auto maxLines = 200;
|
||||||
@@ -1298,6 +1304,8 @@ void MainWindow::show_log_impl(const QString &log) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ADD_TO_CURRENT_ROUTE(a, b) NekoRay::dataStore->routing->a = (SplitLines(NekoRay::dataStore->routing->a) << b).join("\n");
|
||||||
|
|
||||||
void MainWindow::on_masterLogBrowser_customContextMenuRequested(const QPoint &pos) {
|
void MainWindow::on_masterLogBrowser_customContextMenuRequested(const QPoint &pos) {
|
||||||
QMenu *menu = ui->masterLogBrowser->createStandardContextMenu();
|
QMenu *menu = ui->masterLogBrowser->createStandardContextMenu();
|
||||||
|
|
||||||
@@ -1305,14 +1313,74 @@ void MainWindow::on_masterLogBrowser_customContextMenuRequested(const QPoint &po
|
|||||||
sep->setSeparator(true);
|
sep->setSeparator(true);
|
||||||
menu->addAction(sep);
|
menu->addAction(sep);
|
||||||
|
|
||||||
|
auto action_add_ignore = new QAction;
|
||||||
|
action_add_ignore->setText(tr("Set ignore keyword"));
|
||||||
|
connect(action_add_ignore, &QAction::triggered, this, [=] {
|
||||||
|
auto list = NekoRay::dataStore->log_ignore;
|
||||||
|
auto newStr = ui->masterLogBrowser->textCursor().selectedText().trimmed();
|
||||||
|
if (!newStr.isEmpty()) list << newStr;
|
||||||
|
bool ok;
|
||||||
|
newStr = QInputDialog::getMultiLineText(GetMessageBoxParent(), tr("Set ignore keyword"), tr("Set the following keywords to ignore?\nSplit by line."), list.join("\n"), &ok);
|
||||||
|
if (ok) {
|
||||||
|
NekoRay::dataStore->log_ignore = SplitLines(newStr);
|
||||||
|
NekoRay::dataStore->Save();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menu->addAction(action_add_ignore);
|
||||||
|
|
||||||
|
auto action_add_route = new QAction;
|
||||||
|
action_add_route->setText(tr("Save as route"));
|
||||||
|
connect(action_add_route, &QAction::triggered, this, [=] {
|
||||||
|
auto newStr = ui->masterLogBrowser->textCursor().selectedText().trimmed();
|
||||||
|
if (newStr.isEmpty()) return;
|
||||||
|
//
|
||||||
|
bool ok;
|
||||||
|
newStr = QInputDialog::getText(GetMessageBoxParent(), tr("Save as route"), tr("Edit"), {}, newStr, &ok).trimmed();
|
||||||
|
if (!ok) return;
|
||||||
|
if (newStr.isEmpty()) return;
|
||||||
|
//
|
||||||
|
auto select = IsIpAddress(newStr) ? 0 : 3;
|
||||||
|
QStringList items = {"proxyIP", "bypassIP", "blockIP", "proxyDomain", "bypassDomain", "blockDomain"};
|
||||||
|
auto item = QInputDialog::getItem(GetMessageBoxParent(), tr("Save as route"),
|
||||||
|
tr("Save \"%1\" as a routing rule?").arg(newStr),
|
||||||
|
items, select, false, &ok);
|
||||||
|
if (ok) {
|
||||||
|
auto index = items.indexOf(item);
|
||||||
|
switch (index) {
|
||||||
|
case 0:
|
||||||
|
ADD_TO_CURRENT_ROUTE(proxy_ip, newStr);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
ADD_TO_CURRENT_ROUTE(direct_ip, newStr);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
ADD_TO_CURRENT_ROUTE(block_ip, newStr);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
ADD_TO_CURRENT_ROUTE(proxy_domain, newStr);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
ADD_TO_CURRENT_ROUTE(direct_domain, newStr);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
ADD_TO_CURRENT_ROUTE(block_domain, newStr);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
MW_dialog_message("", "UpdateDataStore,RouteChanged");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menu->addAction(action_add_route);
|
||||||
|
|
||||||
auto action_clear = new QAction;
|
auto action_clear = new QAction;
|
||||||
action_clear->setText(tr("Clear"));
|
action_clear->setText(tr("Clear"));
|
||||||
action_clear->setData(-1);
|
|
||||||
connect(action_clear, &QAction::triggered, this, [=] {
|
connect(action_clear, &QAction::triggered, this, [=] {
|
||||||
qvLogDocument->clear();
|
qvLogDocument->clear();
|
||||||
ui->masterLogBrowser->clear();
|
ui->masterLogBrowser->clear();
|
||||||
});
|
});
|
||||||
menu->addAction(action_clear);
|
menu->addAction(action_clear);
|
||||||
|
|
||||||
menu->exec(ui->masterLogBrowser->viewport()->mapToGlobal(pos)); // 弹出菜单
|
menu->exec(ui->masterLogBrowser->viewport()->mapToGlobal(pos)); // 弹出菜单
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user