Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 4753a26

Browse files
author
15dd
committed
ver1.2
1 parent be44de9 commit 4753a26

File tree

4 files changed

+32
-25
lines changed

4 files changed

+32
-25
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,5 @@
2929
- 第二种方法:使用浏览器扩展`yaaw for chrome``aria2 for edge`直接自动下载
3030

3131
## 截图
32-
<center class="half">
33-
<img src="/resource/readme/1.png" height="200"/>&nbsp<img src="/resource/readme/2.png" height="200"/>
34-
</center>
32+
![1](/resource/readme/1.png)
33+
![2](/resource/readme/2.png)

about.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
</font>
9797
</property>
9898
<property name="text">
99-
<string>Version 1.1</string>
99+
<string>Version 1.2</string>
100100
</property>
101101
</widget>
102102
</item>

aria2Launcher.cpp

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ aria2Launcher::aria2Launcher(QWidget *parent)
66
{
77
ui->setupUi(this);
88

9+
//检测是否已开启aria2 launcher
10+
static QSharedMemory* shareMem = new QSharedMemory("SingleApp"); //创建“SingleApp”的共享内存块
11+
if (!shareMem->create(1))//创建大小1b的内存
12+
{
13+
QApplication::beep();
14+
QMessageBox::warning(this, "警告", "Aria2 Launcher已在运行");
15+
exit(-1); //创建失败,说明已经有一个程序运行,退出当前程序
16+
}//https://blog.csdn.net/qianlixiaomage/article/details/125851086
17+
918
checkFile();//检测所需文件是否存在
1019
checkAria2Status();//检测是否已经有aria2c运行,可选择新建进程或kill已存在的进程再新建进程
1120
uiInitialize();//ui初始化
1221
showWindow();//根据设置决定是否开启webui
1322
showHide();//根据设置决定是显示窗口还是启动到托盘
14-
15-
//this->resize((this->width())+1,(this->height())+1);//界面刷新
1623

1724
connect(ui->aboutqt, &QAction::triggered, [this]() {QMessageBox::aboutQt(this, tr("About Qt")); });//弹出qt版本
1825
connect(ui->aboutthis, &QAction::triggered, [this]() {aboutWin->exec(); });//弹出关于窗口
@@ -72,20 +79,24 @@ void aria2Launcher::checkFile() { //检测所需文件是否存在
7279
QFileInfo file3("aria2.session");
7380
QFileInfo file4("yaaw");
7481
if (!file1.isFile()) {
75-
QMessageBox::critical(this, "缺少文件", "aria2c.exe不存在,无法启动");
76-
exit(0);
82+
QApplication::beep();
83+
QMessageBox::warning(this, "缺少文件", "aria2c.exe不存在,无法启动");
84+
exit(-1);
7785
}
7886
else if (!file2.isFile()) {
79-
QMessageBox::critical(this, "缺少文件", "aria2.conf不存在,无法启动");
80-
exit(0);
87+
QApplication::beep();
88+
QMessageBox::warning(this, "缺少文件", "aria2.conf不存在,无法启动");
89+
exit(-1);
8190
}
8291
else if (!file3.isFile()) {
83-
QMessageBox::critical(this, "缺少文件", "aria2.session不存在,无法启动");
84-
exit(0);
92+
QApplication::beep();
93+
QMessageBox::warning(this, "缺少文件", "aria2.session不存在,无法启动");
94+
exit(-1);
8595
}
8696
else if (!file4.isDir()) {
87-
QMessageBox::critical(this, "缺少文件夹", "/yaaw/不存在,无法启动");
88-
exit(0);
97+
QApplication::beep();
98+
QMessageBox::warning(this, "缺少文件夹", "/yaaw/不存在,无法启动");
99+
exit(-1);
89100
}
90101
}
91102

@@ -94,6 +105,7 @@ void aria2Launcher::checkAria2Status() { //检测是否已经有aria2c运行,可
94105
bool flag = true;
95106
int findPid = (int)FindProcessIDByName("aria2c.exe"); //检测aria2c是否已经存在
96107
while (findPid != 0 && flag == true) { //如果aria2c.exe已存在
108+
QApplication::beep();
97109
int id = QMessageBox::information(this, "提示", QString("第%1次检测\naria2c.exe(PID:%2)已在运行(造成这种情况的原因可能是以下几点)\n1:有正在使用aria2c的应用\n2:您未正确关闭此软件或其他使用aria2c的软件\n\n继续:创建一个新的aria2c进程,不影响已存在的进程\n结束进程:结束已存在的aria2c进程(请确保您没有使用此进程下载文件中)\n\n如果您不知道如何选择,请点击<继续>").arg(n).arg(findPid), QString("继续"), QString("结束进程(PID:%1)").arg(findPid), 0);
98110
switch (id) {
99111
case 0: { //继续,选择此选项时退出循环,不再检测,直接创建新进程
@@ -150,7 +162,7 @@ void aria2Launcher::uiInitialize() { //ui初始化
150162

151163
//菜单初始化
152164
connect(SOH, &QAction::triggered, this, &aria2Launcher::showOrHide);
153-
connect(Close, &QAction::triggered, this, &aria2Launcher::quitApp);
165+
connect(Close, &QAction::triggered, [this]() {qApp->quit(); });
154166
connect(trayIcon, &QSystemTrayIcon::activated, this, &aria2Launcher::on_activatedSysTrayIcon);
155167

156168
QActionGroup* group = new QActionGroup(this);
@@ -159,31 +171,27 @@ void aria2Launcher::uiInitialize() { //ui初始化
159171
}
160172

161173
void aria2Launcher::closeEvent(QCloseEvent* event) { //关闭事件
162-
if (!quitApp()) {
163-
event->ignore();
164-
}
165-
}
166-
167-
bool aria2Launcher::quitApp() { //退出询问
174+
QApplication::beep();
168175
int id = QMessageBox::information(this, "二次确认", "是否退出程序?\n退出请确保没有文件正在下载中", QString("退出"), QString("最小化到系统托盘"), QString("取消"), 2);
169176
switch (id) {
170177
case 0: {
171-
qApp->quit();
178+
event->accept();
172179
break;
173180
}
174181
case 1: {
175182
this->hide();
176183
showWindowsMessage();//提示程序已进入托盘
177-
return false;
184+
event->ignore();
178185
break;
179186
}
180187
case 2: {
181-
return false;
188+
event->ignore();
182189
break;
183190
}
184191
}
185192
}
186193

194+
187195
void aria2Launcher::showWindowsMessage() {//提示程序已进入托盘
188196
if (settingWin->ui->radioButton_3->isChecked()) {
189197
trayIcon->showMessage("Aria2 Launcher已最小化到托盘", "如果您希望不再看到这个提示,请前往设置关闭");

aria2Launcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <QCloseEvent>
1616
#include <QFileInfo>
1717
#include <QWebEngineView>
18+
#include <QSharedMemory>
1819

1920
class aria2Launcher : public QMainWindow
2021
{
@@ -33,7 +34,6 @@ class aria2Launcher : public QMainWindow
3334
void uiInitialize();//ui初始化
3435
void checkFile();//检测所需文件是否存在
3536
void closeEvent(QCloseEvent* event);//关闭事件
36-
bool quitApp();//退出询问
3737
DWORD FindProcessIDByName(const std::string& processName); //寻找aria2c.exe的pid
3838
private:
3939
qint64 pid; //pid

0 commit comments

Comments
 (0)