45 lines
1.2 KiB
C++
Raw Normal View History

2026-08-04 14:23:07 +08:00
#include "mainwindow.h"
#include "SingleInstanceManager.h"
#include "AuthView.h"
#include "Version.h"
#include <QApplication>
#include <QIcon>
#include <QObject>
#include <string>
#include "StyledMessageBox.h"
2026-08-04 14:23:07 +08:00
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// 设置应用程序图标
a.setWindowIcon(QIcon(":/common/resource/logo.png"));
// 使用 SingleInstanceManager 检查单例
SingleInstanceManager instanceManager(
QStringLiteral("%1_SingleInstance_Key").arg(STATORWORKPIECEPOSITION_APP_KEY));
if (instanceManager.isAnotherInstanceRunning()) {
// 已有实例在运行,显示提示信息并退出
StyledMessageBox::information(nullptr,
2026-08-04 14:23:07 +08:00
QObject::tr("应用程序已运行"),
QObject::tr("%1应用程序已经在运行中请勿重复启动")
.arg(QString::fromUtf8(STATORWORKPIECEPOSITION_APP_NAME)));
2026-08-04 14:23:07 +08:00
return 0;
}
// 检查授权,无授权则显示授权对话框
if (!AuthView::CheckAndShow(nullptr)) {
// 用户取消授权或授权失败,退出程序
return 0;
}
// 没有其他实例运行,正常启动应用程序
MainWindow w;
w.show();
return a.exec();
}