Skip to content

Commit 70149ad

Browse files
committed
NewFeature: add independent software packaging function
1 parent 9facbe9 commit 70149ad

File tree

20 files changed

+913
-55
lines changed

20 files changed

+913
-55
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## [2025.04.29] - v2.1.0.0
2+
### [new feature] Add independent software packaging function
3+
14
## [2025.04.19] - v2.0.0.0
25
### [Optimize] User interface redesign
36

app/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ message("CMAKE_TOOLCHAIN_ROOT = ${CMAKE_TOOLCHAIN_ROOT} ")
3232
message("include(${CMAKE_TOOLCHAIN_ROOT}/cmake-core/global.cmake) ")
3333

3434

35-
project(${PROJECT_NAME} VERSION 2.0.0.0)
35+
project(${PROJECT_NAME} VERSION 2.1.0.0)
3636
# set(CMAKE_DEBUG_POSTFIX d)
3737
set(LIB_TYPE SHARED) # SHARED STATIC
3838
# set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

app/data/plugins/project/proj_pkg/pkg-win/pkg-win-nsis.bat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@ makensis /INPUTCHARSET UTF8 /DPRODUCT_NAME=%PROJ_NAME% /DPRODUCT_VERSION=%VERSIO
3131

3232
move "%SCRIPT_DIR%\%PROJ_NAME%*.exe" "%ROOT_DIR%"
3333

34-
echo. & pause
34+
if "%~1"=="" (
35+
echo. & pause
36+
)

app/data/plugins/project/proj_pkg/pkg-win/pkg-win-nsis.nsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Section "${PRODUCT_NAME}" SEC_MAIN ;Installer
111111
File /r "${BIN_DIR}\bin64"
112112
File /r "${BIN_DIR}\conf"
113113
File /r "${BIN_DIR}\data"
114-
File /r "${BIN_DIR}\tools"
114+
;File /r "${BIN_DIR}\tools"
115115
;RMDir /r "$INSTDIR\lib"
116116
;RMDir /r "$INSTDIR\logs"
117117
;Rename "$INSTDIR\Release" "$INSTDIR\bin64"

app/data/plugins/project/proj_pkg/proj_pkg.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import os
55
import sys
6+
import platform
67

78
PROJECT_BASE_DIR = os.path.dirname( os.path.abspath(__file__) )
89
PYTOOL_DIR = os.path.dirname( os.path.dirname(PROJECT_BASE_DIR) )
@@ -18,10 +19,43 @@
1819
PKG_RPM_PATH = "/pkg-rpm/pkg-rpm.sh"
1920

2021
class ProjPkg(object):
21-
GROUP_LIST:list = []
22+
@staticmethod
23+
def pkg_run(json_config):
24+
dic = pyt_json.PytJson.load_config(json_config)
25+
if not dic:
26+
return None
27+
28+
root_dir = dic["root_dir"]
29+
if not os.path.exists(root_dir):
30+
print("root—dir not exist: " + root_dir)
31+
return None
32+
33+
script_dir = dic["script_dir"]
34+
script_abs_dir = root_dir + "/" + script_dir
35+
if not os.path.exists(script_abs_dir):
36+
print("script_dir not exist: " + script_abs_dir)
37+
return None
38+
39+
os_type = platform.system()
40+
if os_type == "Windows":
41+
print("pkg exe for Windows")
42+
pkg_script = root_dir + PKG_WIN_NSIS
43+
if not os.path.exists(pkg_script):
44+
print("pkg_script not exist: " + pkg_script)
45+
return None
46+
os.system(pkg_script + " pkg > " + root_dir + "/pkg_win.log")
47+
elif os_type == "Linux":
48+
print("pkg rpm for Linux")
49+
pkg_script = root_dir + PKG_RPM
50+
if not os.path.exists(pkg_script):
51+
print("pkg_script not exist: " + pkg_script)
52+
return None
53+
os.system(pkg_script + " pkg > " + root_dir + "/pkg_rpm.log")
54+
elif os_type == "Darwin": # macOS
55+
print("pkg app for Darwin")
2256

2357
@staticmethod
24-
def pkg(json_config):
58+
def pkg_gen(json_config):
2559
dic = pyt_json.PytJson.load_config(json_config)
2660
if not dic:
2761
return None
@@ -34,7 +68,7 @@ def pkg(json_config):
3468

3569
if not os.path.exists(root_dir):
3670
print("root—dir not exist: " + root_dir)
37-
return
71+
return None
3872

3973
ProjPkg.add_pkg_scripts(proj_name, root_dir, script_dir)
4074
ProjPkg.update_pkg_dirs(root_dir, script_dir, pkg_dirs)

app/data/plugins/project/proj_pkg/run_pkg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@
3232

3333
if __name__ == '__main__':
3434
print("json = ", args.config)
35-
proj_pkg.ProjPkg.pkg(args.config)
35+
proj_pkg.ProjPkg.pkg_gen(args.config)
36+
proj_pkg.ProjPkg.pkg_run(args.config)

app/data/plugins/project/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
if args.type == "project":
3131
print("json = ", args.config)
3232
project.Project.create(args.config)
33-
proj_pkg.ProjPkg.pkg(BASE_DIR + "/pkg.json.bak")
33+
proj_pkg.ProjPkg.pkg_gen(BASE_DIR + "/pkg.json.bak")
3434
elif args.type == "module":
3535
module.Module.MOUDLE_DIR = "/src-app/"
3636
module.Module.add(args.root_dir, module.ModuleType(args.module_type), args.module_name, has_main=True, deps=[])

app/pkg-win-nsis.bat

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ start /wait %QT_HOME%\bin\windeployqt.exe -qmldir %QT_HOME%/qml %BIN_DIR%\%PROJ_
2121

2222
call %SCRIPT_DIR%\vs-env.bat
2323

24-
set VERSION="2.0.0.0"
24+
set VERSION="2.1.0.0"
2525
echo packaging %VERSION% for "x64"
2626
makensis /INPUTCHARSET UTF8 /DPRODUCT_NAME=%PROJ_NAME% /DPRODUCT_VERSION=%VERSION% /DOS_ARCH="x64" %SCRIPT_DIR%/pkg-win-nsis.nsi
2727
echo packaging %VERSION% for "x86"
@@ -31,4 +31,6 @@ makensis /INPUTCHARSET UTF8 /DPRODUCT_NAME=%PROJ_NAME% /DPRODUCT_VERSION=%VERSIO
3131

3232
move "%SCRIPT_DIR%\%PROJ_NAME%*.exe" "%ROOT_DIR%"
3333

34-
echo. & pause
34+
if "%~1"=="" (
35+
echo. & pause
36+
)

app/scripts/pkg-rpm/SPECS/app.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Name: _PROJ_NAME_
2-
Version: 2.0.0.0
2+
Version: 2.1.0.0
33
Release: 1%{?dist}
44
Summary: Client Application
55
License: ""

app/src/app/DevAssistant/QDAMainWindow.cpp

Lines changed: 109 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <windows.h>
1313
#endif // WIN
1414

15+
#include <CApp/CAppConf.h>
1516
#include <CUtils/logger.h>
1617
#include <COSEnv/CETrayIcon.h>
1718

@@ -27,7 +28,7 @@
2728
#define LOG_TAG "TAG_DevAssistant"
2829

2930
QDAMainWindow::QDAMainWindow(QWidget *parent)
30-
: QMainWindow(parent), ui(new Ui::QDAMainWindow)
31+
: QMainWindow(parent), ui(new Ui::QDAMainWindow), trayIcon(new QSystemTrayIcon(this))
3132
{
3233
ui->setupUi(this);
3334
setMinimumSize(1280, 720);
@@ -42,6 +43,9 @@ QDAMainWindow::QDAMainWindow(QWidget *parent)
4243
connect(ui->actionProjectOpen, SIGNAL(triggered()), project, SLOT(OnProjectOpen()));
4344
connect(ui->actionProjectReview, SIGNAL(triggered()), project, SLOT(OnProjectView()));
4445

46+
proj_pkg = new QDAProjectPkg();
47+
connect(proj_pkg, SIGNAL(SigShowWidget(QWidget*)), this, SLOT(OnSetCentralWidget(QWidget*)));
48+
4549
// QDAExampleDialog
4650
example = new QDAExampleDialog();
4751
connect(example, SIGNAL(SigShowWidget(QWidget *)), this, SLOT(OnSetCentralWidget(QWidget *)));
@@ -77,6 +81,7 @@ QDAMainWindow::QDAMainWindow(QWidget *parent)
7781
//ui->projGenButton->setIcon(style()->standardIcon(QStyle::SP_FileDialogListView));
7882
connect(ui->envCheckButton, SIGNAL(clicked(bool)), project, SLOT(OnCheckEnv()));
7983
connect(ui->projGenButton, SIGNAL(clicked(bool)), project, SLOT(OnProjectCreate()));
84+
connect(ui->pkgGenButton, SIGNAL(clicked(bool)), proj_pkg, SLOT(OnProjectPkg()));
8085

8186
// Extend Functions
8287
ui->dataEncryptButton->setStyleSheet(QUI::Style::PushButtonCyan());
@@ -86,12 +91,16 @@ QDAMainWindow::QDAMainWindow(QWidget *parent)
8691

8792
QDAAppConfig::GetInstance()->LoadConfig();
8893

89-
CE::TrayIcon::SetIcon(winId(), "IDI_ICON1", "开发助手", 0);
94+
//CE::TrayIcon::SetIcon(winId(), "IDI_ICON1", "开发助手", 0);
95+
setupTrayIcon();
9096
}
9197

9298
QDAMainWindow::~QDAMainWindow()
9399
{
100+
delete trayIcon;
101+
94102
delete project;
103+
delete proj_pkg;
95104
delete example;
96105
delete practical;
97106
delete custom;
@@ -119,43 +128,110 @@ void QDAMainWindow::OnSetCentralWidget(QWidget *widget)
119128

120129
/////////////////////////////////////// TrayIcon Section ///////////////////////////////////////
121130

122-
bool QDAMainWindow::nativeEvent(const QByteArray& eventType, void* message, long* result)
131+
//bool QDAMainWindow::nativeEvent(const QByteArray& eventType, void* message, long* result)
132+
//{
133+
//#if WIN
134+
// MSG* msg = (MSG*)message;
135+
// if (msg->message == WM_TO_TRAY) {
136+
// LOGI("eventType = %s", QString(eventType).toStdString().c_str());
137+
// if (msg->lParam == WM_LBUTTONUP) { // Left Button Double Click
138+
// CE::TrayIcon::ShowWindow(winId(), true);
139+
// showMaximized(); // Required
140+
// }
141+
// //else if (msg->lParam == WM_LBUTTONDBLCLK) { // Left Button Double Click
142+
// // //CE::TrayIcon::DelIcon(winId());
143+
// //}
144+
// }
145+
//#endif // WIN
146+
//
147+
// return QWidget::nativeEvent(eventType, message, result);
148+
//}
149+
//
150+
//void QDAMainWindow::changeEvent(QEvent * event)
151+
//{
152+
// LOGI("event->type() = %d", event->type());
153+
// if (QEvent::WindowStateChange == event->type())
154+
// {
155+
// QWindowStateChangeEvent * stateEvent = dynamic_cast<QWindowStateChangeEvent*>(event);
156+
// if (Q_NULLPTR != stateEvent) {
157+
// Qt::WindowStates x = stateEvent->oldState();
158+
// if (Qt::WindowMinimized == stateEvent->oldState()) {
159+
// CE::TrayIcon::ShowWindow(winId(), true);
160+
// showMaximized(); // Required
161+
// }
162+
// else if (Qt::WindowMaximized == stateEvent->oldState()) {
163+
// CE::TrayIcon::ShowWindow(winId(), false);
164+
// }
165+
// }
166+
// }
167+
// else if (QEvent::Quit == event->type()) {
168+
// CE::TrayIcon::DelIcon(winId());
169+
// }
170+
//}
171+
172+
void QDAMainWindow::setupTrayIcon()
123173
{
124-
#if WIN
125-
MSG* msg = (MSG*)message;
126-
if (msg->message == WM_TO_TRAY) {
127-
LOGI("eventType = %s", QString(eventType).toStdString().c_str());
128-
if (msg->lParam == WM_LBUTTONUP) { // Left Button Double Click
129-
CE::TrayIcon::ShowWindow(winId(), true);
130-
showMaximized(); // Required
174+
QMenu* trayIconMenu = new QMenu(this);
175+
QAction* restoreAction = trayIconMenu->addAction(u8"恢复窗口");
176+
QAction* quitAction = trayIconMenu->addAction(u8"退出程序");
177+
178+
connect(restoreAction, &QAction::triggered, this, &QDAMainWindow::showNormal);
179+
connect(quitAction, &QAction::triggered, qApp, &QApplication::quit);
180+
connect(trayIcon, &QSystemTrayIcon::activated, this, &QDAMainWindow::onTrayIconActivated);
181+
182+
QString rootDir = QString::fromStdString(CKAppConf::GetInstance()->GetRootDir());
183+
LOGI("root_dir = %s", rootDir.toStdString().c_str());
184+
trayIcon->setContextMenu(trayIconMenu);
185+
trayIcon->setIcon(QIcon(rootDir + "/data/Resource/logo.ico"));
186+
187+
trayIcon->show();
188+
if (!trayIcon->isVisible()) {
189+
qApp->quit();
190+
QMessageBox msgBox;
191+
int ret = QUI::Style::ShowMsgBox(msgBox, QMessageBox::Critical, u8"提示", u8"系统托盘不支持图标!");
192+
if (ret == QMessageBox::Ok) {
193+
qApp->quit();
131194
}
132-
//else if (msg->lParam == WM_LBUTTONDBLCLK) { // Left Button Double Click
133-
// //CE::TrayIcon::DelIcon(winId());
134-
//}
135195
}
136-
#endif // WIN
137-
138-
return QWidget::nativeEvent(eventType, message, result);
139196
}
140197

141-
void QDAMainWindow::changeEvent(QEvent * event)
198+
void QDAMainWindow::onTrayIconActivated(QSystemTrayIcon::ActivationReason reason)
142199
{
143-
LOGI("event->type() = %d", event->type());
144-
if (QEvent::WindowStateChange == event->type())
145-
{
146-
QWindowStateChangeEvent * stateEvent = dynamic_cast<QWindowStateChangeEvent*>(event);
147-
if (Q_NULLPTR != stateEvent) {
148-
Qt::WindowStates x = stateEvent->oldState();
149-
if (Qt::WindowMinimized == stateEvent->oldState()) {
150-
CE::TrayIcon::ShowWindow(winId(), true);
151-
showMaximized(); // Required
152-
}
153-
else if (Qt::WindowMaximized == stateEvent->oldState()) {
154-
CE::TrayIcon::ShowWindow(winId(), false);
155-
}
156-
}
200+
if (reason == QSystemTrayIcon::Trigger) {
201+
showNormal();
202+
activateWindow();
203+
raise();
157204
}
158-
else if (QEvent::Quit == event->type()) {
159-
CE::TrayIcon::DelIcon(winId());
205+
}
206+
207+
void QDAMainWindow::changeEvent(QEvent* event) {
208+
QMainWindow::changeEvent(event);
209+
210+
if (event->type() == QEvent::WindowStateChange) {
211+
QWindowStateChangeEvent* changEvent = static_cast<QWindowStateChangeEvent*>(event);
212+
LOGI("event->type() = %d, changEvent->oldState() = %d, windowState() = %d",
213+
event->type(), changEvent->oldState(), windowState());
214+
215+
if (changEvent->oldState() == Qt::WindowNoState && windowState() == Qt::WindowMaximized) { // Normal -> Maximized
216+
hide();
217+
showMaximized();
218+
}
219+
else if (changEvent->oldState() == Qt::WindowMaximized && windowState() == Qt::WindowNoState) { // Maximized -> Normal
220+
hide();
221+
showNormal();
222+
}
223+
else if (windowState() == Qt::WindowMinimized) {
224+
//showMinimized();
225+
hide();
226+
}
227+
else if (windowState() == Qt::WindowActive) { // e.g. Minimized to Normal
228+
hide();
229+
showNormal();
230+
}
160231
}
161232
}
233+
234+
void QDAMainWindow::closeEvent(QCloseEvent* event) {
235+
hide();
236+
event->ignore();
237+
}

app/src/app/DevAssistant/QDAMainWindow.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
#include <CUtils/def_macro.h>
88

99
#include <QMainWindow>
10+
#include <QSystemTrayIcon>
1011

1112
namespace Ui {
1213
class QDAMainWindow;
1314
}
1415
class QDAProjectDialog;
16+
class QDAProjectPkg;
1517
class QDAExampleDialog;
1618
class QDAPracticalDialog;
1719
class QDACustomDialog;
@@ -26,26 +28,33 @@ class QDAMainWindow : public QMainWindow
2628
QDAMainWindow(QWidget *parent = nullptr);
2729
virtual ~QDAMainWindow();
2830

29-
void LoadWelcome();
30-
3131
public Q_SLOTS:
3232
void OnSetWelcome();
3333
void OnSetCentralWidget(QWidget *widget);
3434

3535
private:
3636
Ui::QDAMainWindow *ui;
3737
QDAProjectDialog *project;
38+
QDAProjectPkg* proj_pkg;
3839
QDAExampleDialog *example;
3940
QDAPracticalDialog *practical;
4041
QDACustomDialog *custom;
4142
QDAPlanDialog *plan;
4243
QDAHelpDialog *help;
4344
QWidget* initWidget;
4445

45-
protected:
4646
////////////////////////// TrayIcon Section //////////////////////////
47-
virtual bool nativeEvent(const QByteArray& eventType, void* message, long* result) override;
48-
virtual void changeEvent(QEvent* event) override;
47+
protected:
48+
//virtual bool nativeEvent(const QByteArray& eventType, void* message, long* result) override;
49+
//virtual void changeEvent(QEvent* event) override;
50+
void setupTrayIcon();
51+
void changeEvent(QEvent* event) override;
52+
void closeEvent(QCloseEvent* event) override;
53+
54+
protected slots:
55+
void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason);
56+
private:
57+
QSystemTrayIcon* trayIcon;
4958
};
5059

5160
#endif // QDA_MAINWINDOW_H

app/src/app/DevAssistant/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int LoadApp(int argc, char* argv[]) {
6060

6161
QDAMainWindow window;
6262
window.setWindowTitle("DevAssistant");
63-
window.showMaximized();
63+
window.showNormal();
6464

6565
return app.exec();
6666
}

0 commit comments

Comments
 (0)