mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-18 04:54:38 +03:00
feat: first time setup
This commit is contained in:
@@ -238,6 +238,10 @@ set(PROJECT_SOURCES
|
|||||||
ui/dialog_hotkey.h
|
ui/dialog_hotkey.h
|
||||||
ui/dialog_hotkey.ui
|
ui/dialog_hotkey.ui
|
||||||
|
|
||||||
|
ui/dialog_first_setup.cpp
|
||||||
|
ui/dialog_first_setup.h
|
||||||
|
ui/dialog_first_setup.ui
|
||||||
|
|
||||||
ui/widget/ProxyItem.cpp
|
ui/widget/ProxyItem.cpp
|
||||||
ui/widget/ProxyItem.h
|
ui/widget/ProxyItem.h
|
||||||
ui/widget/ProxyItem.ui
|
ui/widget/ProxyItem.ui
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#include "ui/mainwindow_interface.h"
|
|
||||||
|
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
@@ -13,6 +11,9 @@
|
|||||||
#include "3rdparty/RunGuard.hpp"
|
#include "3rdparty/RunGuard.hpp"
|
||||||
#include "main/NekoRay.hpp"
|
#include "main/NekoRay.hpp"
|
||||||
|
|
||||||
|
#include "ui/mainwindow_interface.h"
|
||||||
|
#include "ui/dialog_first_setup.h"
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#include "sys/windows/MiniDump.h"
|
#include "sys/windows/MiniDump.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -24,9 +25,32 @@ void signal_handler(int signum) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTranslator* trans = nullptr;
|
||||||
|
QTranslator* trans_qt = nullptr;
|
||||||
|
|
||||||
|
void loadTranslate(const QString& locale) {
|
||||||
|
if (trans != nullptr) {
|
||||||
|
trans->deleteLater();
|
||||||
|
}
|
||||||
|
if (trans_qt != nullptr) {
|
||||||
|
trans_qt->deleteLater();
|
||||||
|
}
|
||||||
|
//
|
||||||
|
trans = new QTranslator;
|
||||||
|
trans_qt = new QTranslator;
|
||||||
|
QLocale::setDefault(QLocale(locale));
|
||||||
|
//
|
||||||
|
if (trans->load(":/translations/" + locale + ".qm")) {
|
||||||
|
QCoreApplication::installTranslator(trans);
|
||||||
|
}
|
||||||
|
if (trans_qt->load(QApplication::applicationDirPath() + "/qtbase_" + locale + ".qm")) {
|
||||||
|
QCoreApplication::installTranslator(trans_qt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#define LOCAL_SERVER_PREFIX "nekoraylocalserver-"
|
#define LOCAL_SERVER_PREFIX "nekoraylocalserver-"
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
// Core dump
|
// Core dump
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
Windows_SetCrashHandler();
|
Windows_SetCrashHandler();
|
||||||
@@ -121,7 +145,25 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load coreType
|
// Load coreType
|
||||||
NekoRay::coreType = ReadFileText("groups/coreType").toInt(); // default to 0
|
auto coreLoaded = ReadFileText("groups/coreType");
|
||||||
|
if (coreLoaded.isEmpty()) {
|
||||||
|
loadTranslate(QLocale().name());
|
||||||
|
auto dialogFirstSetup = new DialogFirstSetup;
|
||||||
|
auto coreSelected = dialogFirstSetup->exec();
|
||||||
|
dialogFirstSetup->deleteLater();
|
||||||
|
if (coreSelected < 0) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
NekoRay::coreType = coreSelected;
|
||||||
|
QFile file;
|
||||||
|
file.setFileName("groups/coreType");
|
||||||
|
file.open(QIODevice::ReadWrite | QIODevice::Truncate);
|
||||||
|
file.write(Int2String(coreSelected).toUtf8());
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
NekoRay::coreType = coreLoaded.toInt();
|
||||||
|
}
|
||||||
|
|
||||||
// Dir
|
// Dir
|
||||||
QDir dir;
|
QDir dir;
|
||||||
@@ -182,16 +224,7 @@ int main(int argc, char *argv[]) {
|
|||||||
locale = QLocale().name();
|
locale = QLocale().name();
|
||||||
}
|
}
|
||||||
QGuiApplication::tr("QT_LAYOUT_DIRECTION");
|
QGuiApplication::tr("QT_LAYOUT_DIRECTION");
|
||||||
QLocale::setDefault(QLocale(locale));
|
loadTranslate(locale);
|
||||||
//
|
|
||||||
QTranslator trans;
|
|
||||||
if (trans.load(":/translations/" + locale + ".qm")) {
|
|
||||||
QCoreApplication::installTranslator(&trans);
|
|
||||||
}
|
|
||||||
QTranslator trans_qt;
|
|
||||||
if (trans_qt.load(QApplication::applicationDirPath() + "/qtbase_" + locale + ".qm")) {
|
|
||||||
QCoreApplication::installTranslator(&trans_qt);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Signals
|
// Signals
|
||||||
signal(SIGTERM, signal_handler);
|
signal(SIGTERM, signal_handler);
|
||||||
|
|||||||
@@ -412,6 +412,27 @@
|
|||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>DialogFirstSetup</name>
|
||||||
|
<message>
|
||||||
|
<source>First time setup</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>It looks like you are using this software for the first time, please select a core.
|
||||||
|
|
||||||
|
These settings can be changed later.</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Exit</source>
|
||||||
|
<translation type="obsolete">خروج</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Quit</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>DialogHotkey</name>
|
<name>DialogHotkey</name>
|
||||||
<message>
|
<message>
|
||||||
|
|||||||
@@ -402,6 +402,25 @@
|
|||||||
<translation>自定义 (%1 完整配置)</translation>
|
<translation>自定义 (%1 完整配置)</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
|
<context>
|
||||||
|
<name>DialogFirstSetup</name>
|
||||||
|
<message>
|
||||||
|
<source>First time setup</source>
|
||||||
|
<translation>首次设置</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>It looks like you are using this software for the first time, please select a core.
|
||||||
|
|
||||||
|
These settings can be changed later.</source>
|
||||||
|
<translation>看来您是第一次使用该软件,请选择内核。
|
||||||
|
|
||||||
|
这些设置可以稍后更改。</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Quit</source>
|
||||||
|
<translation>退出</translation>
|
||||||
|
</message>
|
||||||
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>DialogHotkey</name>
|
<name>DialogHotkey</name>
|
||||||
<message>
|
<message>
|
||||||
|
|||||||
23
ui/dialog_first_setup.cpp
Normal file
23
ui/dialog_first_setup.cpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#include "dialog_first_setup.h"
|
||||||
|
#include "ui_dialog_first_setup.h"
|
||||||
|
|
||||||
|
#include "main/NekoRay.hpp"
|
||||||
|
|
||||||
|
DialogFirstSetup::DialogFirstSetup(QWidget *parent) : QDialog(parent), ui(new Ui::DialogFirstSetup) {
|
||||||
|
ui->setupUi(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
DialogFirstSetup::~DialogFirstSetup() {
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DialogFirstSetup::onButtonClicked() {
|
||||||
|
auto s = sender();
|
||||||
|
if (s == ui->v2ray) {
|
||||||
|
done(NekoRay::CoreType::V2RAY);
|
||||||
|
} else if (s == ui->singbox) {
|
||||||
|
done(NekoRay::CoreType::SING_BOX);
|
||||||
|
} else {
|
||||||
|
done(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
23
ui/dialog_first_setup.h
Normal file
23
ui/dialog_first_setup.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
namespace Ui {
|
||||||
|
class DialogFirstSetup;
|
||||||
|
}
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
class DialogFirstSetup : public QDialog {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DialogFirstSetup(QWidget *parent = nullptr);
|
||||||
|
~DialogFirstSetup() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::DialogFirstSetup *ui;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onButtonClicked();
|
||||||
|
};
|
||||||
106
ui/dialog_first_setup.ui
Normal file
106
ui/dialog_first_setup.ui
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>DialogFirstSetup</class>
|
||||||
|
<widget class="QDialog" name="DialogFirstSetup">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>First time setup</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>It looks like you are using this software for the first time, please select a core.
|
||||||
|
|
||||||
|
These settings can be changed later.</string>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="v2ray">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">V2Ray</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="singbox">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">sing-box</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="quit">
|
||||||
|
<property name="text">
|
||||||
|
<string>Quit</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>v2ray</sender>
|
||||||
|
<signal>clicked()</signal>
|
||||||
|
<receiver>DialogFirstSetup</receiver>
|
||||||
|
<slot>onButtonClicked()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>199</x>
|
||||||
|
<y>196</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>199</x>
|
||||||
|
<y>149</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>singbox</sender>
|
||||||
|
<signal>clicked()</signal>
|
||||||
|
<receiver>DialogFirstSetup</receiver>
|
||||||
|
<slot>onButtonClicked()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>199</x>
|
||||||
|
<y>236</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>199</x>
|
||||||
|
<y>149</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>quit</sender>
|
||||||
|
<signal>clicked()</signal>
|
||||||
|
<receiver>DialogFirstSetup</receiver>
|
||||||
|
<slot>onButtonClicked()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>199</x>
|
||||||
|
<y>276</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>199</x>
|
||||||
|
<y>149</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
<slots>
|
||||||
|
<slot>onButtonClicked()</slot>
|
||||||
|
</slots>
|
||||||
|
</ui>
|
||||||
Reference in New Issue
Block a user