imporve log widget

This commit is contained in:
arm64v8a
2022-12-12 10:03:07 +09:00
parent e0a1f9f164
commit 8e20e499e1
8 changed files with 103 additions and 52 deletions

View File

@@ -35,7 +35,7 @@ jobs:
if: steps.cache-common.outputs.cache-hit != 'true'
uses: actions/setup-go@v3
with:
go-version: 1.19.2
go-version: 1.19.4
- name: Build golang parts
if: steps.cache-common.outputs.cache-hit != 'true'
shell: bash
@@ -57,7 +57,6 @@ jobs:
matrix:
platform: [ windows-2022, ubuntu-20.04, macos-10.15 ]
arch: [ x64 ]
qt_version: [ 5.15.2 ]
fail-fast: false
runs-on: ${{ matrix.platform }}
@@ -87,12 +86,12 @@ jobs:
if: matrix.platform == 'macos-10.15'
uses: jurplel/install-qt-action@v3
with:
version: ${{ matrix.qt_version }}
version: 5.15.2
py7zrversion: ' '
aqtversion: ' '
setup-python: false
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
shell: bash
if: matrix.platform == 'windows-2022'
@@ -116,14 +115,14 @@ jobs:
uses: actions/cache@v3
with:
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
shell: bash
if: steps.cache-deps.outputs.cache-hit != 'true'
run: |
./libs/build_deps_all.sh
# ========================================================================================================= Generate MakeFile and Build
- name: Windows - ${{ matrix.qt_version }} - Generate MakeFile and Build
- name: Windows - Generate MakeFile and Build
shell: bash
if: matrix.platform == 'windows-2022'
env:
@@ -137,7 +136,7 @@ jobs:
ninja
cd ..
./libs/deploy_windows64.sh
- name: Linux - ${{ matrix.qt_version }} - Generate MakeFile and Build
- name: Linux - Generate MakeFile and Build
shell: bash
if: matrix.platform == 'ubuntu-20.04'
run: |
@@ -147,7 +146,7 @@ jobs:
ninja
cd ..
./libs/deploy_linux64.sh
- name: macOS - ${{ matrix.qt_version }} - Generate MakeFile and Build
- name: macOS - Generate MakeFile and Build
shell: bash
if: matrix.platform == 'macos-10.15'
run: |

View File

@@ -12,7 +12,6 @@ import (
"neko/pkg/speedtest"
"nekobox_core/box_main"
"reflect"
"time"
"unsafe"
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)
}
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 {
err = errors.New("instance already started")
return

View File

@@ -8,7 +8,6 @@ import (
"io"
"libcore"
"libcore/stun"
"log"
"neko/gen"
"neko/pkg/grpc_server"
"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)
}
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 {
err = errors.New("instance already started")
return

View File

@@ -2,8 +2,6 @@ package neko_common
import (
"net/http"
"strings"
"time"
)
var Version_v2ray string = "N/A"
@@ -20,19 +18,3 @@ const (
)
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()
}

View File

@@ -67,6 +67,7 @@ namespace NekoRay {
_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::integer));
_add(new configItem("log_ignore", &log_ignore, itemType::stringList));
}
void DataStore::UpdateStartedId(int id) {

View File

@@ -76,6 +76,7 @@ namespace NekoRay {
QString mw_size = "";
bool check_include_pre = false;
QString system_proxy_format = "";
QStringList log_ignore = {};
// Subscription
QString user_agent = "Nekoray/1.0 (Prefer Clash Format)";

View File

@@ -1205,6 +1205,28 @@ End: %2</source>
<source>Open Config Folder</source>
<translation></translation>
</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 &quot;%1&quot; as a routing rule?</source>
<translation>&quot;%1&quot;</translation>
</message>
<message>
<source>Edit</source>
<translation></translation>
</message>
</context>
<context>
<name>ProxyItem</name>

View File

@@ -558,7 +558,7 @@ void MainWindow::on_menu_exit_triggered() {
QProcess::startDetached("./updater", QStringList{});
} else if (exit_reason == 2) {
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();
QCoreApplication::quit();
@@ -1277,9 +1277,15 @@ inline void FastAppendTextDocument(const QString &message, QTextDocument *doc) {
}
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);
// From https://gist.github.com/jemyzhang/7130092
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) {
QMenu *menu = ui->masterLogBrowser->createStandardContextMenu();
@@ -1305,14 +1313,74 @@ void MainWindow::on_masterLogBrowser_customContextMenuRequested(const QPoint &po
sep->setSeparator(true);
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;
action_clear->setText(tr("Clear"));
action_clear->setData(-1);
connect(action_clear, &QAction::triggered, this, [=] {
qvLogDocument->clear();
ui->masterLogBrowser->clear();
});
menu->addAction(action_clear);
menu->exec(ui->masterLogBrowser->viewport()->mapToGlobal(pos)); // 弹出菜单
}