-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
79 lines (67 loc) · 2.56 KB
/
Copy pathmain.cpp
File metadata and controls
79 lines (67 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "common/AppSingleInstance.h"
#include "common/FileAssociation.h"
#include "engine/Theme.h"
#include "ui/KeyPresserNextWindow.h"
#include "appversion.h"
#include <QApplication>
#include <QCoreApplication>
#include <QGuiApplication>
#include <QLibraryInfo>
#include <QLocale>
#include <QTranslator>
namespace {
bool LoadTranslator(QApplication* app, const QString& resource_path,
const QString& file_prefix) {
auto* tr = new QTranslator(app);
const QString qt_trans = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
if (tr->load(resource_path) ||
tr->load(QLocale(QLocale::Chinese, QLocale::China), file_prefix,
QStringLiteral("_"), qt_trans)) {
app->installTranslator(tr);
return true;
}
delete tr;
return false;
}
} // namespace
int main(int argc, char* argv[]) {
// Match old KeyPresser DPI strategy for coordinate consistency with engine bind.
QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
// Required by QWindowKit frameless title bar.
QGuiApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
QApplication app(argc, argv);
QApplication::setOrganizationName(QStringLiteral("FinnSoft"));
QApplication::setApplicationName(QStringLiteral("KeyPresserNextCommunity"));
QApplication::setApplicationDisplayName(AppProductName());
QLocale::setDefault(QLocale(QLocale::Chinese, QLocale::China));
// 按钮文案在 qtbase(QPlatformTheme);qt_zh_CN alone 不够
LoadTranslator(&app, QStringLiteral(":/i18n/qtbase_zh_CN.qm"),
QStringLiteral("qtbase"));
LoadTranslator(&app, QStringLiteral(":/i18n/qt_zh_CN.qm"), QStringLiteral("qt"));
Theme::ApplyDarkTheme(&app);
EnsureKpnFileAssociation();
EnsureCustomUrlProtocol();
// 网页 keypressernext:// 唤起:若已有实例则置前并退出
if (!KeyPresserNextProtocolUrlFromArgs(app.arguments()).isEmpty()) {
if (ActivateRunningKeyPresserNext()) {
return 0;
}
}
const QString open_path = PendingKpnPathFromArgs(app.arguments());
bool force_open_duplicate = false;
if (!open_path.isEmpty() && IsKpnOpenInAnotherInstance(open_path)) {
switch (PromptKpnAlreadyOpen(nullptr, open_path)) {
case KpnOpenConflictResult::SwitchToExisting:
ActivateExistingKpnInstance(open_path);
return 0;
case KpnOpenConflictResult::Cancel:
return 0;
case KpnOpenConflictResult::OpenAnotherCopy:
force_open_duplicate = true;
break;
}
}
KeyPresserNextWindow window(open_path, force_open_duplicate);
window.show();
return app.exec();
}