feat: Support automatically check update

chore: Better constant settings
This commit is contained in:
Chenx Dust
2024-08-19 21:53:29 +08:00
parent e7c3f50109
commit 67373d309d
8 changed files with 223 additions and 115 deletions

View File

@@ -21,8 +21,6 @@ MainWindow::MainWindow(QWidget *parent) :
{
zjuConnectController = nullptr;
networkAccessManager = new QNetworkAccessManager(this);
process = new QProcess(this);
processForL2tp = new QProcess(this);
processForL2tpCheck = new QProcess(this);
@@ -53,8 +51,9 @@ MainWindow::MainWindow(QWidget *parent) :
setWindowTitle(QApplication::applicationName() + " v" + QApplication::applicationVersion());
ui->applicationNameLabel->setText(QApplication::applicationDisplayName());
ui->versionLabel->setText(
"Version: " + QApplication::applicationVersion() + "\n" + QSysInfo::prettyProductName() + "\n"
"当前版本v" + QApplication::applicationVersion() + "\n正在检查更新……\n"
);
// 系统托盘
@@ -137,6 +136,12 @@ MainWindow::MainWindow(QWidget *parent) :
addLog("已清除系统代理设置");
});
// 帮助-检查更新
connect(ui->checkUpdateAction, &QAction::triggered, this,
[&]()
{
checkUpdate();
});
// 帮助-关于本软件
connect(ui->aboutAction, &QAction::triggered,
@@ -166,6 +171,67 @@ MainWindow::MainWindow(QWidget *parent) :
}
});
// 自动检查更新
checkUpdateNAM = new QNetworkAccessManager(this);
connect(checkUpdateNAM, &QNetworkAccessManager::finished,
this, [&](QNetworkReply* reply) {
if (reply->error() != QNetworkReply::NoError)
{
addLog("检查更新失败。原因是:" + reply->errorString());
reply->deleteLater();
return;
}
QJsonObject json = QJsonDocument::fromJson(reply->readAll()).object();
reply->deleteLater();
QString nowVersion = QApplication::applicationVersion();
QString latestVersion = json["tag_name"].toString();
addLog("检查更新成功。最新版本:" + latestVersion);
ui->versionLabel->setText(
"当前版本v" + nowVersion + "\n"
"最新版本:" + latestVersion + "\n"
);
// 移除开头的 'v'
if (latestVersion.startsWith('v'))
{
latestVersion = latestVersion.mid(1);
}
qsizetype nowVersionSuffix, latestVersionSuffix;
auto nowVersionQ = QVersionNumber::fromString(nowVersion, &nowVersionSuffix);
auto latestVersionQ = QVersionNumber::fromString(latestVersion, &latestVersionSuffix);
if (latestVersionQ > nowVersionQ ||
(latestVersionQ == nowVersionQ && latestVersion.right(latestVersionSuffix) != nowVersion.right(nowVersionSuffix)))
{
QMessageBox msgBox;
msgBox.setText("版本更新");
msgBox.setInformativeText("存在版本更新:" + latestVersion + "\n"
"是否前往 Github 发布页面查看?");
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
int ret = msgBox.exec();
if (ret == QMessageBox::Ok)
{
QDesktopServices::openUrl(QUrl("https://github.com/" + Utils::REPO_NAME + "/releases/latest"));
}
}
});
if (settings->value("Common/AutoCheckUpdate", true).toBool())
{
checkUpdate();
}
else
{
ui->versionLabel->setText(
"当前版本v" + QApplication::applicationVersion() + "\n自动检查更新已禁用\n"
);
}
setModeToZjuConnect();
}
@@ -179,14 +245,22 @@ void MainWindow::closeEvent(QCloseEvent *event)
void MainWindow::addLog(const QString &log)
{
QString timeString = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
ui->logPlainTextEdit->appendPlainText(timeString + " " + log);
ui->logPlainTextEdit->appendPlainText(timeString + " " + log.trimmed());
}
void MainWindow::clearLog()
{
ui->logPlainTextEdit->clear();
ui->logPlainTextEdit->appendPlainText(
"Version: " + QApplication::applicationVersion() + "\n" + QSysInfo::prettyProductName());
"欢迎使用 " + QApplication::applicationDisplayName() + "\n"
"当前版本v" + QApplication::applicationVersion() + "\n"
"系统版本:" + QSysInfo::prettyProductName());
}
void MainWindow::checkUpdate()
{
QNetworkRequest request(QUrl("https://api.github.com/repos/" + Utils::REPO_NAME + "/releases/latest"));
checkUpdateNAM->get(request);
}
void MainWindow::upgradeSettings()

View File

@@ -38,6 +38,8 @@ protected:
void closeEvent(QCloseEvent *e) override;
private:
void checkUpdate();
void upgradeSettings();
void clearLog();
@@ -62,7 +64,7 @@ private:
QAction *trayShowAction;
QAction *trayCloseAction;
ZjuConnectController *zjuConnectController;
QNetworkAccessManager *networkAccessManager;
QNetworkAccessManager *checkUpdateNAM;
QSettings *settings;
QProcess *process;
QProcess *processForL2tp;

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>731</width>
<height>265</height>
<height>266</height>
</rect>
</property>
<property name="windowTitle">
@@ -72,7 +72,7 @@
</spacer>
</item>
<item row="0" column="1" colspan="3">
<widget class="QLabel" name="label1">
<widget class="QLabel" name="applicationNameLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -85,7 +85,7 @@
</font>
</property>
<property name="toolTip">
<string>你好呀</string>
<string>关注 HITSZ OSA 谢谢喵n(*≧▽≦*)n</string>
</property>
<property name="text">
<string>HITsz Connect for Windows</string>
@@ -117,8 +117,8 @@
</sizepolicy>
</property>
<property name="text">
<string>Version: 1.0
Windows Version: Arch Linux
<string>Version1.0
Windows VersionArch Linux
</string>
</property>
<property name="alignment">
@@ -139,7 +139,7 @@ Windows Version: Arch Linux
<item row="2" column="1" colspan="3">
<widget class="QLabel" name="accountLabel">
<property name="text">
<string>提示:左上角“功能”-&gt;“设置”里可以填写账号信息。
<string>提示:左上角“功能”“设置”里可以填写账号信息。
可以使用 TUN 模式解决部分软件无法代理的问题。
建议关闭 Clash 等代理后开启系统代理。
@@ -173,6 +173,7 @@ Windows Version: Arch Linux
<string>帮助</string>
</property>
<addaction name="disableProxyAction"/>
<addaction name="checkUpdateAction"/>
<addaction name="aboutAction"/>
</widget>
<widget class="QMenu" name="fileMenu">
@@ -208,6 +209,16 @@ Windows Version: Arch Linux
<string>清除系统代理</string>
</property>
</action>
<action name="action">
<property name="text">
<string>检查更新</string>
</property>
</action>
<action name="checkUpdateAction">
<property name="text">
<string>检查更新</string>
</property>
</action>
</widget>
<tabstops>
<tabstop>pushButton1</tabstop>

View File

@@ -43,6 +43,15 @@ SettingWindow::SettingWindow(QWidget *parent, QSettings *inputSettings) :
ui->connectAfterStartComboBox->setCurrentText("");
}
if (settings->value("Common/AutoCheckUpdate", true).toBool())
{
ui->autoCheckUpdateComboBox->setCurrentText("");
}
else
{
ui->autoCheckUpdateComboBox->setCurrentText("");
}
ui->serverAddressLineEdit->setText(settings->value("ZJUConnect/ServerAddress", "vpn.hitsz.edu.cn").toString());
ui->serverPortSpinBox->setValue(settings->value("ZJUConnect/ServerPort", 443).toInt());
ui->dnsLineEdit->setText(settings->value("ZJUConnect/DNS", "10.248.98.30").toString());
@@ -82,6 +91,7 @@ SettingWindow::SettingWindow(QWidget *parent, QSettings *inputSettings) :
settings->setValue("Common/Password", QString(ui->passwordLineEdit->text().toUtf8().toBase64()));
settings->setValue("Common/AutoStart", ui->autoStartComboBox->currentText() == "");
settings->setValue("Common/ConnectAfterStart", ui->connectAfterStartComboBox->currentText() == "");
settings->setValue("Common/AutoCheckUpdate", ui->autoCheckUpdateComboBox->currentText() == "");
settings->setValue("ZJUConnect/ServerAddress", ui->serverAddressLineEdit->text());
settings->setValue("ZJUConnect/ServerPort", ui->serverPortSpinBox->value());

View File

@@ -17,6 +17,26 @@
<string notr="true"/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>213</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="applyPushButton">
<property name="text">
<string>确定</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="cancelPushButton">
<property name="text">
@@ -34,26 +54,64 @@
<string>通用</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="2" colspan="2">
<widget class="Line" name="commonTabLine1">
<item row="7" column="0" colspan="4">
<spacer name="commonTabVerticalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="2">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>170</width>
<height>20</height>
<width>444</width>
<height>108</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="commonTabLable2">
<property name="text">
<string>网络账号</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="commonTabLable6">
<property name="text">
<string>自动检查更新</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="commonTabLable3">
<property name="text">
<string>网络密码</string>
</property>
</widget>
</item>
<item row="5" column="3">
<widget class="QComboBox" name="connectAfterStartComboBox">
<item>
<property name="text">
<string>否</string>
</property>
</item>
<item>
<property name="text">
<string>是</string>
</property>
</item>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="passwordLineEdit">
<property name="toolTip">
<string>注意:网络密码和浙大通行证密码可能不同!</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLineEdit" name="usernameLineEdit"/>
</item>
<item row="4" column="3">
<widget class="QComboBox" name="autoStartComboBox">
<property name="maxVisibleItems">
@@ -71,12 +129,32 @@
</item>
</widget>
</item>
<item row="3" column="0" colspan="4">
<widget class="Line" name="commonTabLine2">
<item row="6" column="3">
<widget class="QComboBox" name="autoCheckUpdateComboBox">
<item>
<property name="text">
<string>否</string>
</property>
</item>
<item>
<property name="text">
<string>是</string>
</property>
</item>
</widget>
</item>
<item row="4" column="2" rowspan="3">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<property name="sizeHint" stdset="0">
<size>
<width>170</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="commonTabLable4">
@@ -85,41 +163,7 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="commonTabLable3">
<property name="text">
<string>网络密码</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="4">
<spacer name="commonTabVerticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>444</width>
<height>108</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QLabel" name="commonTabLable1">
<property name="text">
<string>账号</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="commonTabLable2">
<property name="text">
<string>网络账号</string>
</property>
</widget>
</item>
<item row="1" column="2" rowspan="2">
<item row="0" column="2" rowspan="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -132,16 +176,6 @@
</property>
</spacer>
</item>
<item row="2" column="3">
<widget class="QLineEdit" name="passwordLineEdit">
<property name="toolTip">
<string>注意:网络密码和浙大通行证密码可能不同!</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="usernameLineEdit"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="commonTabLable5">
<property name="text">
@@ -149,18 +183,11 @@
</property>
</widget>
</item>
<item row="5" column="3">
<widget class="QComboBox" name="connectAfterStartComboBox">
<item>
<property name="text">
<string>否</string>
</property>
</item>
<item>
<property name="text">
<string>是</string>
</property>
</item>
<item row="2" column="0" colspan="4">
<widget class="Line" name="commonTabLine1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
@@ -385,26 +412,6 @@
</widget>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="applyPushButton">
<property name="text">
<string>确定</string>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>213</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<tabstops>

View File

@@ -69,26 +69,26 @@ void Utils::showAboutMessageBox(QWidget *parent)
QMessageBox messageBox(parent);
messageBox.setWindowTitle("关于本软件");
messageBox.setTextFormat(Qt::RichText);
QString aboutText = QApplication::applicationName() + " v" + QApplication::applicationVersion() +
QString aboutText = QApplication::applicationDisplayName() + " v" + QApplication::applicationVersion() +
"<br>针对哈工大深圳的修改版 ZJU-Connect-for-Windows" +
"<br>作者: <a href='https://github.com/chenx-dust'>Chenx Dust</a>" +
"<br>项目主页: <a href='https://github.com/hitszosa/HITsz-Connect-for-Windows'>https://github.com/hitszosa/HITsz-Connect-for-Windows</a>" +
"<br>作者<a href='https://github.com/chenx-dust'>Chenx Dust</a>" +
"<br>项目主页<a href='https://github.com/" + REPO_NAME + "'>https://github.com/" + REPO_NAME + "</a>" +
"<br><br>ZJU-Connect-for-Windows" +
"<br>基于 Qt 编写的 ZJUConnect 图形界面" +
"<br>作者: <a href='https://myth.cx'>Myth</a>" +
"<br>项目主页: <a href='https://github.com/Mythologyli/ZJU-Connect-for-Windows'>https://github.com/Mythologyli/ZJU-Connect-for-Windows</a>" +
"<br>作者<a href='https://myth.cx'>Myth</a>" +
"<br>项目主页<a href='https://github.com/Mythologyli/ZJU-Connect-for-Windows'>https://github.com/Mythologyli/ZJU-Connect-for-Windows</a>" +
"<br><br>zju-connect" +
"<br>ZJU RVPN 客户端的 Go 语言实现,基于 EasierConnect" +
"<br>作者: <a href='https://myth.cx'>Myth</a>" +
"<br>项目主页: <a href='https://github.com/Mythologyli/zju-connect'>https://github.com/Mythologyli/zju-connect</a>" +
"<br>作者<a href='https://myth.cx'>Myth</a>" +
"<br>项目主页<a href='https://github.com/Mythologyli/zju-connect'>https://github.com/Mythologyli/zju-connect</a>" +
"<br><br>EasierConnect" +
"<br>EasyConnect 客户端的开源实现" +
"<br>作者: <a href='https://github.com/lyc8503'>lyc8503</a>" +
"<br>项目主页: <a href='https://github.com/lyc8503/EasierConnect'>https://github.com/lyc8503/EasierConnect</a>"
"<br>作者<a href='https://github.com/lyc8503'>lyc8503</a>" +
"<br>项目主页<a href='https://github.com/lyc8503/EasierConnect'>https://github.com/lyc8503/EasierConnect</a>"
"<br><br>zju-web-login" +
"<br>ZJU 网页认证登录脚本" +
"<br>作者: <a href='https://azuk.top'>Azuk 443</a>" +
"<br>项目主页: <a href='https://github.com/Mythologyli/zju-web-login'>https://github.com/Mythologyli/zju-web-login</a>";
"<br>作者<a href='https://azuk.top'>Azuk 443</a>" +
"<br>项目主页<a href='https://github.com/Mythologyli/zju-web-login'>https://github.com/Mythologyli/zju-web-login</a>";
messageBox.setText(aboutText);
messageBox.setIconPixmap(QPixmap(":/resource/icon.png").scaled(
100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation

View File

@@ -3,6 +3,8 @@
namespace Utils
{
const QString REPO_NAME("hitszosa/HITsz-Connect-for-Windows");
QString ConsoleOutputToQString(const QByteArray &byteArray);
void setWidgetFixedWhenHidden(QWidget *widget);

View File

@@ -109,6 +109,8 @@ void MainWindow::setModeToZjuConnect()
{
if (!isZjuConnectLinked)
{
addLog("VPN 启动!");
if (settings->value("ZJUConnect/ServerAddress", "vpn.hitsz.edu.cn").toString().isEmpty())
{
QMessageBox::critical(this, "错误", "服务器地址不能为空");