2017-09-18 14:33:44 +08:00
|
|
|
|
/*
|
2018-02-07 11:52:47 +08:00
|
|
|
|
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
2017-09-18 14:33:44 +08:00
|
|
|
|
*
|
|
|
|
|
* Author: sbw <sbw@sbw.so>
|
|
|
|
|
*
|
|
|
|
|
* Maintainer: sbw <sbw@sbw.so>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
2016-06-02 09:46:43 +08:00
|
|
|
|
|
2021-04-07 10:41:13 +08:00
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
#include "accessible.h"
|
|
|
|
|
#include "dbusdockadaptors.h"
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
#include "themeappicon.h"
|
|
|
|
|
#include "dockitemmanager.h"
|
|
|
|
|
#include "dockapplication.h"
|
2022-08-25 19:31:31 +00:00
|
|
|
|
#include "traymainwindow.h"
|
|
|
|
|
#include "windowmanager.h"
|
2016-06-02 09:46:43 +08:00
|
|
|
|
|
2020-03-13 12:59:02 +08:00
|
|
|
|
#include <QAccessible>
|
2020-05-14 11:06:20 +08:00
|
|
|
|
#include <QDir>
|
2020-07-16 12:36:46 +08:00
|
|
|
|
#include <QStandardPaths>
|
2020-07-24 18:22:09 +08:00
|
|
|
|
#include <QDateTime>
|
2020-10-20 11:06:26 +08:00
|
|
|
|
#include <QDir>
|
2020-07-24 18:22:09 +08:00
|
|
|
|
|
2016-07-20 15:17:41 +08:00
|
|
|
|
#include <DApplication>
|
|
|
|
|
#include <DLog>
|
2019-09-17 13:15:53 +08:00
|
|
|
|
#include <DGuiApplicationHelper>
|
2016-06-15 11:09:34 +08:00
|
|
|
|
|
|
|
|
|
#include <unistd.h>
|
2020-07-16 12:36:46 +08:00
|
|
|
|
#include <string>
|
2020-03-14 21:26:29 +08:00
|
|
|
|
#include <sys/mman.h>
|
2020-07-16 12:36:46 +08:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <execinfo.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <signal.h>
|
2020-03-14 21:26:29 +08:00
|
|
|
|
|
2016-06-15 11:09:34 +08:00
|
|
|
|
DWIDGET_USE_NAMESPACE
|
2017-08-07 10:17:50 +08:00
|
|
|
|
#ifdef DCORE_NAMESPACE
|
2017-07-26 20:44:35 +08:00
|
|
|
|
DCORE_USE_NAMESPACE
|
2017-08-07 10:17:50 +08:00
|
|
|
|
#else
|
|
|
|
|
DUTIL_USE_NAMESPACE
|
|
|
|
|
#endif
|
2016-06-02 09:46:43 +08:00
|
|
|
|
|
2022-01-12 10:44:40 +08:00
|
|
|
|
const QString g_cfgPath = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation)[0] + "/dde-cfg.ini";
|
|
|
|
|
|
2020-07-24 18:22:09 +08:00
|
|
|
|
using namespace std;
|
|
|
|
|
|
2021-04-13 15:02:45 +08:00
|
|
|
|
/**
|
|
|
|
|
* @brief IsSaveMode
|
|
|
|
|
* @return 判断当前是否应该进入安全模式(安全模式下不加载插件)
|
|
|
|
|
*/
|
2022-01-12 10:44:40 +08:00
|
|
|
|
bool IsSaveMode()
|
2020-07-24 18:22:09 +08:00
|
|
|
|
{
|
2022-01-12 10:44:40 +08:00
|
|
|
|
QSettings settings(g_cfgPath, QSettings::IniFormat);
|
2020-09-24 11:13:58 +08:00
|
|
|
|
settings.beginGroup(qApp->applicationName());
|
2020-07-24 18:22:09 +08:00
|
|
|
|
int collapseNum = settings.value("collapse").toInt();
|
2022-01-12 10:44:40 +08:00
|
|
|
|
/* 崩溃次数达到3次,进入安全模式(不加载插件) */
|
|
|
|
|
if (collapseNum >= 3) {
|
2021-01-21 15:31:25 +08:00
|
|
|
|
settings.remove(""); // 删除记录的数据
|
2020-07-24 18:22:09 +08:00
|
|
|
|
settings.setValue("collapse", 0);
|
|
|
|
|
settings.endGroup();
|
|
|
|
|
settings.sync();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-07-27 15:46:17 +08:00
|
|
|
|
|
2022-01-12 10:44:40 +08:00
|
|
|
|
/**
|
|
|
|
|
* @brief sig_crash
|
|
|
|
|
* @return 当应用收到对应的退出信号时,会调用此函数,用于保存一下应用崩溃时间,崩溃次数,用以判断是否应该进入安全模式,见IsSaveMode()
|
|
|
|
|
*/
|
|
|
|
|
[[noreturn]] void sig_crash(int sig)
|
2020-07-16 12:36:46 +08:00
|
|
|
|
{
|
2022-01-12 10:44:40 +08:00
|
|
|
|
QDir dir(QStandardPaths::standardLocations(QStandardPaths::CacheLocation)[0]);
|
|
|
|
|
dir.cdUp();
|
|
|
|
|
QString filePath = dir.path() + "/dde-collapse.log";
|
|
|
|
|
|
|
|
|
|
QFile *file = new QFile(filePath);
|
|
|
|
|
|
|
|
|
|
// 创建默认配置文件,记录段时间内的崩溃次数
|
|
|
|
|
if (!QFile::exists(g_cfgPath)) {
|
|
|
|
|
QFile cfgFile(g_cfgPath);
|
|
|
|
|
if (!cfgFile.open(QIODevice::WriteOnly))
|
|
|
|
|
exit(0);
|
|
|
|
|
cfgFile.close();
|
|
|
|
|
}
|
2020-07-24 18:22:09 +08:00
|
|
|
|
|
2022-01-12 10:44:40 +08:00
|
|
|
|
QSettings settings(g_cfgPath, QSettings::IniFormat);
|
|
|
|
|
settings.beginGroup("dde-dock");
|
2020-07-24 18:22:09 +08:00
|
|
|
|
|
|
|
|
|
int collapseNum = settings.value("collapse").toInt();
|
2022-01-12 10:29:01 +08:00
|
|
|
|
/* 第一次崩溃或进入安全模式后的第一次崩溃,将时间重置 */
|
2021-01-21 15:31:25 +08:00
|
|
|
|
if (collapseNum == 0) {
|
2022-01-12 10:44:40 +08:00
|
|
|
|
settings.setValue("first_time", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss:zzz"));
|
2021-01-21 15:31:25 +08:00
|
|
|
|
}
|
2022-01-12 10:44:40 +08:00
|
|
|
|
QDateTime lastDate = QDateTime::fromString(settings.value("first_time").toString(), "yyyy-MM-dd hh:mm:ss:zzz");
|
2022-01-12 10:29:01 +08:00
|
|
|
|
/* 将当前崩溃时间与第一次崩溃时间比较,小于9分钟,记录一次崩溃;大于9分钟,覆盖之前的崩溃时间 */
|
|
|
|
|
if (qAbs(lastDate.secsTo(QDateTime::currentDateTime())) < 9 * 60) {
|
2020-07-24 18:22:09 +08:00
|
|
|
|
settings.setValue("collapse", collapseNum + 1);
|
2021-01-21 15:31:25 +08:00
|
|
|
|
switch (collapseNum) {
|
|
|
|
|
case 0:
|
2022-01-12 10:44:40 +08:00
|
|
|
|
settings.setValue("first_time", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss:zzz"));
|
2021-01-21 15:31:25 +08:00
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2022-01-12 10:44:40 +08:00
|
|
|
|
settings.setValue("second_time", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss:zzz"));
|
2021-01-21 15:31:25 +08:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2022-01-12 10:44:40 +08:00
|
|
|
|
settings.setValue("third_time", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss:zzz"));
|
2021-01-21 15:31:25 +08:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
qDebug() << "Error, the collapse is wrong!";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-08-11 18:58:21 +08:00
|
|
|
|
} else {
|
2021-01-21 15:31:25 +08:00
|
|
|
|
if (collapseNum == 2){
|
|
|
|
|
settings.setValue("first_time", settings.value("second_time").toString());
|
2022-01-12 10:44:40 +08:00
|
|
|
|
settings.setValue("second_time", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss:zzz"));
|
2021-01-21 15:31:25 +08:00
|
|
|
|
} else {
|
2022-01-12 10:44:40 +08:00
|
|
|
|
settings.setValue("first_time", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss:zzz"));
|
2021-01-21 15:31:25 +08:00
|
|
|
|
}
|
2020-07-24 18:22:09 +08:00
|
|
|
|
}
|
2021-01-21 15:31:25 +08:00
|
|
|
|
|
2020-07-24 18:22:09 +08:00
|
|
|
|
settings.endGroup();
|
|
|
|
|
settings.sync();
|
2022-01-12 10:44:40 +08:00
|
|
|
|
|
|
|
|
|
if (!file->open(QIODevice::Text | QIODevice::Append)) {
|
|
|
|
|
qDebug() << file->errorString();
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (file->size() >= 10 * 1024 * 1024) {
|
|
|
|
|
// 清空原有内容
|
|
|
|
|
file->close();
|
|
|
|
|
if (file->open(QIODevice::Text | QIODevice::Truncate)) {
|
|
|
|
|
qDebug() << file->errorString();
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 捕获异常,打印崩溃日志到配置文件中
|
|
|
|
|
try {
|
|
|
|
|
QString head = "\n#####" + qApp->applicationName() + "#####\n"
|
|
|
|
|
+ QDateTime::currentDateTime().toString("[yyyy-MM-dd hh:mm:ss:zzz]")
|
|
|
|
|
+ "[crash signal number:" + QString::number(sig) + "]\n";
|
|
|
|
|
file->write(head.toUtf8());
|
|
|
|
|
} catch (...) {
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
file->close();
|
|
|
|
|
delete file;
|
|
|
|
|
file = nullptr;
|
|
|
|
|
exit(0);
|
2020-07-16 12:36:46 +08:00
|
|
|
|
}
|
2016-06-23 17:18:45 +08:00
|
|
|
|
|
2016-06-02 09:46:43 +08:00
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2020-09-28 16:03:06 +08:00
|
|
|
|
if (QString(getenv("XDG_CURRENT_DESKTOP")).compare("deepin", Qt::CaseInsensitive) == 0) {
|
|
|
|
|
qDebug() << "Warning: force enable D_DXCB_FORCE_NO_TITLEBAR now!";
|
|
|
|
|
setenv("D_DXCB_FORCE_NO_TITLEBAR", "1", 1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 15:09:12 +08:00
|
|
|
|
DGuiApplicationHelper::setAttribute(DGuiApplicationHelper::UseInactiveColorGroup, false);
|
2020-09-07 23:51:50 +08:00
|
|
|
|
DockApplication app(argc, argv);
|
2020-07-27 15:46:17 +08:00
|
|
|
|
|
2022-01-12 10:44:40 +08:00
|
|
|
|
//崩溃信号
|
|
|
|
|
signal(SIGSEGV, sig_crash);
|
|
|
|
|
signal(SIGILL, sig_crash);
|
|
|
|
|
signal(SIGINT, sig_crash);
|
|
|
|
|
signal(SIGABRT, sig_crash);
|
|
|
|
|
signal(SIGFPE, sig_crash);
|
2016-12-30 16:30:09 +08:00
|
|
|
|
|
2016-06-15 11:09:34 +08:00
|
|
|
|
app.setOrganizationName("deepin");
|
|
|
|
|
app.setApplicationName("dde-dock");
|
|
|
|
|
app.setApplicationDisplayName("DDE Dock");
|
|
|
|
|
app.setApplicationVersion("2.0");
|
2016-08-08 20:16:50 +08:00
|
|
|
|
app.loadTranslator();
|
2017-08-28 11:38:20 +08:00
|
|
|
|
app.setAttribute(Qt::AA_EnableHighDpiScaling, true);
|
2017-10-19 11:15:10 +08:00
|
|
|
|
app.setAttribute(Qt::AA_UseHighDpiPixmaps, false);
|
2016-06-02 09:46:43 +08:00
|
|
|
|
|
2021-04-13 15:02:45 +08:00
|
|
|
|
// 自动化标记由此开始
|
2020-03-13 12:59:02 +08:00
|
|
|
|
QAccessible::installFactory(accessibleFactory);
|
|
|
|
|
|
2021-05-13 11:39:46 +08:00
|
|
|
|
// 设置日志输出到控制台以及文件
|
2022-11-22 11:56:39 +08:00
|
|
|
|
DLogManager::setLogFormat("%{time}{yyyyMMdd.HH:mm:ss.zzz}[%{type:1}][%{function:-35} %{line:-4}] %{message}\n");
|
2016-07-20 15:17:41 +08:00
|
|
|
|
DLogManager::registerConsoleAppender();
|
|
|
|
|
DLogManager::registerFileAppender();
|
|
|
|
|
|
2021-05-13 11:39:46 +08:00
|
|
|
|
// 启动入参 dde-dock --help可以看到一下内容, -x不加载插件 -r 一般用在startdde启动任务栏
|
2018-06-13 14:21:48 +08:00
|
|
|
|
QCommandLineOption disablePlugOption(QStringList() << "x" << "disable-plugins", "do not load plugins.");
|
2020-10-13 15:35:11 +08:00
|
|
|
|
QCommandLineOption runOption(QStringList() << "r" << "run-by-stardde", "run by startdde.");
|
2018-06-13 14:21:48 +08:00
|
|
|
|
QCommandLineParser parser;
|
|
|
|
|
parser.setApplicationDescription("DDE Dock");
|
|
|
|
|
parser.addHelpOption();
|
|
|
|
|
parser.addVersionOption();
|
|
|
|
|
parser.addOption(disablePlugOption);
|
2020-10-13 15:35:11 +08:00
|
|
|
|
parser.addOption(runOption);
|
2018-06-13 14:21:48 +08:00
|
|
|
|
parser.process(app);
|
|
|
|
|
|
2021-05-13 11:39:46 +08:00
|
|
|
|
// 任务栏单进程限制
|
2020-08-03 14:25:19 +08:00
|
|
|
|
DGuiApplicationHelper::setSingleInstanceInterval(-1);
|
2018-06-13 14:21:48 +08:00
|
|
|
|
if (!app.setSingleInstance(QString("dde-dock_%1").arg(getuid()))) {
|
|
|
|
|
qDebug() << "set single instance failed!";
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-24 15:47:35 +08:00
|
|
|
|
#ifndef QT_DEBUG
|
|
|
|
|
QDir::setCurrent(QApplication::applicationDirPath());
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-06-10 16:18:15 +00:00
|
|
|
|
// 在qApp中记录当前是否为安全模式,如果为安全模式,则无需加载插件,在退出安全模式下,才正常加载插件
|
|
|
|
|
// 此处设置这个属性必须在MainWindow创建之前,因为在mainWindow中会创建加载插件的代理,会在代理中根据这个属性来判断是否需要加载插件
|
|
|
|
|
bool isSafeMode = IsSaveMode();
|
2022-08-25 19:31:31 +00:00
|
|
|
|
bool disablePlugin = parser.isSet(disablePlugOption);
|
|
|
|
|
qApp->setProperty("safeMode", (isSafeMode || disablePlugin));
|
2022-06-10 16:18:15 +00:00
|
|
|
|
|
2022-08-25 19:31:31 +00:00
|
|
|
|
MultiScreenWorker multiScreenWorker;
|
2021-11-05 21:45:53 +08:00
|
|
|
|
|
2022-08-25 19:31:31 +00:00
|
|
|
|
MainWindow mainWindow(&multiScreenWorker);
|
|
|
|
|
TrayMainWindow trayMainWindow(&multiScreenWorker);
|
|
|
|
|
|
|
|
|
|
WindowManager windowManager(&multiScreenWorker);
|
|
|
|
|
|
|
|
|
|
// 保证添加窗口的先后顺序,先添加的窗口显示在左边,后添加的窗口显示在右边
|
|
|
|
|
windowManager.addWindow(&mainWindow);
|
|
|
|
|
windowManager.addWindow(&trayMainWindow);
|
|
|
|
|
|
|
|
|
|
// 注册任务栏的DBus服务
|
|
|
|
|
DBusDockAdaptors adaptor(&windowManager);
|
2021-11-05 21:45:53 +08:00
|
|
|
|
|
2022-11-18 17:08:32 +08:00
|
|
|
|
QDBusConnection::sessionBus().registerService("org.deepin.dde.Dock1");
|
|
|
|
|
QDBusConnection::sessionBus().registerObject("/org/deepin/dde/Dock1", "org.deepin.dde.Dock1", &windowManager);
|
2016-10-14 15:47:43 +08:00
|
|
|
|
|
2021-05-13 11:39:46 +08:00
|
|
|
|
// 当任务栏以-r参数启动时,设置CANSHOW未false,之后调用launch不显示任务栏
|
2020-10-13 15:35:11 +08:00
|
|
|
|
qApp->setProperty("CANSHOW", !parser.isSet(runOption));
|
|
|
|
|
|
2022-08-25 19:31:31 +00:00
|
|
|
|
windowManager.launch();
|
|
|
|
|
mainWindow.setVisible(true);
|
2016-06-02 09:46:43 +08:00
|
|
|
|
|
2021-05-13 11:39:46 +08:00
|
|
|
|
// 判断是否进入安全模式,是否带有入参 -x
|
2022-08-25 19:31:31 +00:00
|
|
|
|
if (!isSafeMode && !disablePlugin) {
|
2021-01-21 15:31:25 +08:00
|
|
|
|
qApp->setProperty("PLUGINSLOADED", true);
|
|
|
|
|
} else {
|
2022-08-25 19:31:31 +00:00
|
|
|
|
windowManager.sendNotifications();
|
2018-06-13 14:21:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-02 09:46:43 +08:00
|
|
|
|
return app.exec();
|
|
|
|
|
}
|