Skip to content

Commit e412341

Browse files
authored
Add files via upload
1 parent 25b1c53 commit e412341

File tree

14 files changed

+1399
-0
lines changed

14 files changed

+1399
-0
lines changed

src/1.0.1/MemoryCleaner.pro

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
QT += core gui
2+
# 添加系统托盘支持
3+
QT += network # QSystemTrayIcon需要
4+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
5+
6+
CONFIG += c++17
7+
8+
TARGET = MemoryCleaner
9+
TEMPLATE = app
10+
11+
12+
# You can make your code fail to compile if it uses deprecated APIs.
13+
# In order to do so, uncomment the following line.
14+
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
15+
16+
SOURCES += \
17+
aboutdialog.cpp \
18+
main.cpp \
19+
mainwindow.cpp
20+
21+
HEADERS += \
22+
aboutdialog.h \
23+
mainwindow.h
24+
25+
FORMS += \
26+
aboutdialog.ui \
27+
mainwindow.ui
28+
29+
30+
win32 {
31+
32+
LIBS += -lpsapi -lntdll -ladvapi32 -lkernel32
33+
DEFINES += _WIN32_WINNT=0x0601 # 确保Windows API版本
34+
QMAKE_CXXFLAGS += -std=c++11
35+
}
36+
37+
TRANSLATIONS += \
38+
MemoryCleaner_zh_CN.ts
39+
40+
41+
CONFIG += lrelease
42+
CONFIG += embed_translations
43+
44+
# Default rules for deployment.
45+
qnx: target.path = /tmp/$${TARGET}/bin
46+
else: unix:!android: target.path = /opt/$${TARGET}/bin
47+
!isEmpty(target.path): INSTALLS += target
48+
49+
RESOURCES += \
50+
res.qrc
51+
52+
RC_FILE = logo.rc
53+
RC_ICON = app.ico
54+
55+
DISTFILES += \
56+
logo.rc
57+

src/1.0.1/MemoryCleaner.pro.user

Lines changed: 271 additions & 0 deletions
Large diffs are not rendered by default.

src/1.0.1/MemoryCleaner_zh_CN.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!DOCTYPE TS>
3+
<TS version="2.1" language="zh_CN"></TS>

src/1.0.1/aboutdialog.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// aboutdialog.cpp
2+
#include "aboutdialog.h"
3+
#include "ui_aboutdialog.h"
4+
5+
AboutDialog::AboutDialog(QWidget *parent) :
6+
QDialog(parent),
7+
ui(new Ui::AboutDialog)
8+
{
9+
ui->setupUi(this);
10+
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
11+
}
12+
13+
AboutDialog::~AboutDialog()
14+
{
15+
delete ui;
16+
}

src/1.0.1/aboutdialog.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// aboutdialog.h
2+
#ifndef ABOUTDIALOG_H
3+
#define ABOUTDIALOG_H
4+
5+
#include <QDialog>
6+
7+
namespace Ui {
8+
class AboutDialog;
9+
}
10+
11+
class AboutDialog : public QDialog
12+
{
13+
Q_OBJECT
14+
15+
public:
16+
explicit AboutDialog(QWidget *parent = nullptr);
17+
~AboutDialog();
18+
19+
private:
20+
Ui::AboutDialog *ui;
21+
};
22+
23+
#endif // ABOUTDIALOG_H

src/1.0.1/aboutdialog.ui

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>AboutDialog</class>
4+
<widget class="QDialog" name="AboutDialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>400</width>
10+
<height>300</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>关于 MemoryCleaner</string>
15+
</property>
16+
<layout class="QVBoxLayout" name="verticalLayout">
17+
<item>
18+
<widget class="QLabel" name="labelTitle">
19+
<property name="text">
20+
<string>&lt;h2&gt;MemoryCleaner&lt;/h2&gt;</string>
21+
</property>
22+
<property name="alignment">
23+
<set>Qt::AlignmentFlag::AlignCenter</set>
24+
</property>
25+
</widget>
26+
</item>
27+
<item>
28+
<widget class="QLabel" name="labelVersion">
29+
<property name="text">
30+
<string>版本 1.0</string>
31+
</property>
32+
<property name="alignment">
33+
<set>Qt::AlignmentFlag::AlignCenter</set>
34+
</property>
35+
</widget>
36+
</item>
37+
<item>
38+
<widget class="QLabel" name="labelLicense">
39+
<property name="text">
40+
<string>本程序遵循 GPL 3.0 开源协议</string>
41+
</property>
42+
<property name="alignment">
43+
<set>Qt::AlignmentFlag::AlignCenter</set>
44+
</property>
45+
</widget>
46+
</item>
47+
<item>
48+
<widget class="QLabel" name="labelGitHub">
49+
<property name="text">
50+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/TheUserWW/MemoryCleaner&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#007af4;&quot;&gt;https://github.com/TheUserWW/MemoryCleaner.git&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
51+
</property>
52+
<property name="alignment">
53+
<set>Qt::AlignmentFlag::AlignCenter</set>
54+
</property>
55+
<property name="openExternalLinks">
56+
<bool>true</bool>
57+
</property>
58+
</widget>
59+
</item>
60+
<item>
61+
<widget class="QTextBrowser" name="textBrowserLicense">
62+
<property name="plainText">
63+
<string>This program is free software: you can redistribute it and/or modify
64+
it under the terms of the GNU General Public License as published by
65+
the Free Software Foundation, either version 3 of the License, or
66+
(at your option) any later version.
67+
68+
This program is distributed in the hope that it will be useful,
69+
but WITHOUT ANY WARRANTY; without even the implied warranty of
70+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
71+
GNU General Public License for more details.
72+
73+
You should have received a copy of the GNU General Public License
74+
along with this program. If not, see &lt;https://www.gnu.org/licenses/&gt;.</string>
75+
</property>
76+
</widget>
77+
</item>
78+
<item>
79+
<widget class="QDialogButtonBox" name="buttonBox">
80+
<property name="orientation">
81+
<enum>Qt::Orientation::Horizontal</enum>
82+
</property>
83+
<property name="standardButtons">
84+
<set>QDialogButtonBox::StandardButton::Ok</set>
85+
</property>
86+
</widget>
87+
</item>
88+
</layout>
89+
</widget>
90+
<resources/>
91+
<connections>
92+
<connection>
93+
<sender>buttonBox</sender>
94+
<signal>accepted()</signal>
95+
<receiver>AboutDialog</receiver>
96+
<slot>accept()</slot>
97+
<hints>
98+
<hint type="sourcelabel">
99+
<x>248</x>
100+
<y>254</y>
101+
</hint>
102+
<hint type="destinationlabel">
103+
<x>157</x>
104+
<y>274</y>
105+
</hint>
106+
</hints>
107+
</connection>
108+
</connections>
109+
</ui>

src/1.0.1/app.ico

47.2 KB
Binary file not shown.

src/1.0.1/logo.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
IDI_ICON1 ICON DISCARDABLE "app.ico"

src/1.0.1/main.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include "mainwindow.h"
2+
#include <QApplication>
3+
#include <QTranslator>
4+
#include <QLocale>
5+
#include <QLocalServer>
6+
#include <QLocalSocket>
7+
#include <QMessageBox>
8+
#include <QDebug> // 添加调试输出
9+
10+
int main(int argc, char *argv[]) {
11+
QApplication a(argc, argv);
12+
13+
// 唯一标识符(确保全局唯一)
14+
const QString serverName = "MemoryCleaner_InstanceControl";
15+
16+
// 尝试连接已存在的实例
17+
QLocalSocket socket;
18+
socket.connectToServer(serverName);
19+
if (socket.waitForConnected(500)) { // 500ms超时
20+
qDebug() << "已检测到运行实例,发送激活信号...";
21+
socket.write("SHOW"); // 发送激活指令
22+
socket.waitForBytesWritten(); // 确保写入完成
23+
socket.close();
24+
return 0; // 当前实例退出
25+
}
26+
27+
// 没有其他实例运行,创建服务端
28+
QLocalServer server;
29+
if (!server.listen(serverName)) {
30+
// 如果监听失败,可能是残留的服务器文件未删除(仅在 Unix 系统需要)
31+
if (server.serverError() == QAbstractSocket::AddressInUseError) {
32+
QLocalServer::removeServer(serverName); // 强制清理残留
33+
if (!server.listen(serverName)) {
34+
QMessageBox::critical(nullptr, "错误", "无法启动单实例服务!");
35+
return -1;
36+
}
37+
}
38+
}
39+
40+
// 主窗口初始化
41+
MainWindow w;
42+
w.show();
43+
44+
// 当其他实例请求激活时,显示窗口
45+
QObject::connect(&server, &QLocalServer::newConnection, [&]() {
46+
qDebug() << "收到新连接请求...";
47+
QLocalSocket *clientSocket = server.nextPendingConnection();
48+
if (clientSocket->waitForReadyRead(1000)) { // 等待数据到达
49+
QString message = QString::fromUtf8(clientSocket->readAll());
50+
qDebug() << "收到消息:" << message;
51+
if (message == "SHOW") {
52+
// 必须通过主线程调用 UI 操作
53+
QMetaObject::invokeMethod(&w, [&w]() {
54+
w.showNormal(); // 恢复窗口(如果最小化)
55+
w.activateWindow(); // 激活到前台
56+
w.raise(); // 置顶
57+
qDebug() << "窗口已激活!";
58+
});
59+
}
60+
}
61+
clientSocket->close();
62+
delete clientSocket;
63+
});
64+
65+
return a.exec();
66+
}

0 commit comments

Comments
 (0)