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
|
|
|
|
|
|
|
#include "window/mainwindow.h"
|
2020-03-13 12:59:02 +08:00
|
|
|
#include "window/accessible.h"
|
2016-07-08 17:12:40 +08:00
|
|
|
#include "util/themeappicon.h"
|
2020-06-05 16:16:59 +08:00
|
|
|
#include "controller/dockitemmanager.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>
|
|
|
|
|
2016-07-20 15:17:41 +08:00
|
|
|
#include <DApplication>
|
|
|
|
#include <DLog>
|
2018-04-18 14:50:23 +08:00
|
|
|
#include <DDBusSender>
|
2019-09-17 13:15:53 +08:00
|
|
|
#include <DGuiApplicationHelper>
|
2016-06-15 11:09:34 +08:00
|
|
|
|
|
|
|
#include <unistd.h>
|
2016-10-14 15:47:43 +08:00
|
|
|
#include "dbus/dbusdockadaptors.h"
|
2020-07-16 12:36:46 +08:00
|
|
|
#include <string>
|
2019-11-13 09:09:27 +08:00
|
|
|
|
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
|
|
|
|
2020-07-24 18:22:09 +08:00
|
|
|
const int MAX_STACK_FRAMES = 128;
|
|
|
|
const QString strPath = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation)[0] + "/dde-collapse.log";
|
|
|
|
const QString cfgPath = QStandardPaths::standardLocations(QStandardPaths::ConfigLocation)[0] + "/dde-cfg.ini";
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2016-06-23 17:18:45 +08:00
|
|
|
// let startdde know that we've already started.
|
|
|
|
void RegisterDdeSession()
|
|
|
|
{
|
|
|
|
QString envName("DDE_SESSION_PROCESS_COOKIE_ID");
|
|
|
|
|
|
|
|
QByteArray cookie = qgetenv(envName.toUtf8().data());
|
|
|
|
qunsetenv(envName.toUtf8().data());
|
|
|
|
|
2019-08-19 13:40:06 +08:00
|
|
|
if (!cookie.isEmpty()) {
|
2018-04-18 14:50:23 +08:00
|
|
|
QDBusPendingReply<bool> r = DDBusSender()
|
2020-07-27 15:46:17 +08:00
|
|
|
.interface("com.deepin.SessionManager")
|
|
|
|
.path("/com/deepin/SessionManager")
|
|
|
|
.service("com.deepin.SessionManager")
|
|
|
|
.method("Register")
|
|
|
|
.arg(QString(cookie))
|
|
|
|
.call();
|
2018-04-18 14:50:23 +08:00
|
|
|
|
|
|
|
qDebug() << Q_FUNC_INFO << r.value();
|
2016-06-23 17:18:45 +08:00
|
|
|
}
|
|
|
|
}
|
2020-07-16 12:36:46 +08:00
|
|
|
|
2020-07-24 18:22:09 +08:00
|
|
|
bool IsSaveMode()
|
|
|
|
{
|
|
|
|
QSettings settings(cfgPath, QSettings::IniFormat);
|
|
|
|
settings.beginGroup("dde-dock");
|
|
|
|
int collapseNum = settings.value("collapse").toInt();
|
|
|
|
|
|
|
|
// 自动进入安全模式
|
|
|
|
if (collapseNum >= 3) {
|
|
|
|
settings.setValue("collapse", 0);
|
|
|
|
settings.endGroup();
|
|
|
|
settings.sync();
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-16 12:36:46 +08:00
|
|
|
|
2020-07-24 18:22:09 +08:00
|
|
|
return false;
|
|
|
|
}
|
2020-07-27 15:46:17 +08:00
|
|
|
|
2020-07-16 12:36:46 +08:00
|
|
|
void sig_crash(int sig)
|
|
|
|
{
|
2020-07-27 15:46:17 +08:00
|
|
|
QFile *file = new QFile(strPath);
|
2020-07-24 18:22:09 +08:00
|
|
|
|
|
|
|
// 创建默认配置文件,记录段时间内的崩溃次数
|
|
|
|
if (!QFile::exists(cfgPath)) {
|
|
|
|
QFile file(cfgPath);
|
|
|
|
if (!file.open(QIODevice::WriteOnly))
|
|
|
|
exit(0);
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSettings settings(cfgPath, QSettings::IniFormat);
|
|
|
|
settings.beginGroup("dde-dock");
|
|
|
|
|
|
|
|
QDateTime lastDate = QDateTime::fromString(settings.value("lastDate").toString(), "yyyy-MM-dd hh:mm:ss:zzz");
|
|
|
|
int collapseNum = settings.value("collapse").toInt();
|
|
|
|
|
2020-07-27 15:46:17 +08:00
|
|
|
// 3分钟以内发生崩溃则累加,记录到文件中
|
2020-07-24 18:22:09 +08:00
|
|
|
if (qAbs(lastDate.secsTo(QDateTime::currentDateTime())) < 60 * 3) {
|
|
|
|
settings.setValue("collapse", collapseNum + 1);
|
|
|
|
}
|
|
|
|
settings.setValue("lastDate", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss:zzz"));
|
|
|
|
settings.endGroup();
|
|
|
|
settings.sync();
|
|
|
|
|
2020-07-27 15:46:17 +08:00
|
|
|
if (!file->open(QIODevice::Text | QIODevice::Append)) {
|
|
|
|
qDebug() << file->errorString();
|
|
|
|
exit(0);
|
2020-07-16 12:36:46 +08:00
|
|
|
}
|
|
|
|
|
2020-07-27 15:46:17 +08:00
|
|
|
if (file->size() >= 10 * 1024 * 1024) {
|
|
|
|
// 清空原有内容
|
|
|
|
file->close();
|
|
|
|
if (file->open(QIODevice::Text | QIODevice::Truncate)) {
|
|
|
|
qDebug() << file->errorString();
|
|
|
|
exit(0);
|
|
|
|
}
|
2020-07-16 12:36:46 +08:00
|
|
|
}
|
2020-07-27 15:46:17 +08:00
|
|
|
|
|
|
|
// 捕获异常,打印崩溃日志到配置文件中
|
2020-07-16 12:36:46 +08:00
|
|
|
try {
|
2020-07-27 15:46:17 +08:00
|
|
|
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());
|
|
|
|
|
|
|
|
#ifdef Q_OS_LINUX
|
2020-07-16 12:36:46 +08:00
|
|
|
void *array[MAX_STACK_FRAMES];
|
|
|
|
size_t size = 0;
|
|
|
|
char **strings = nullptr;
|
2020-07-27 15:46:17 +08:00
|
|
|
size_t i;
|
2020-07-16 12:36:46 +08:00
|
|
|
signal(sig, SIG_DFL);
|
2020-07-27 15:46:17 +08:00
|
|
|
size = static_cast<size_t>(backtrace(array, MAX_STACK_FRAMES));
|
|
|
|
strings = backtrace_symbols(array, int(size));
|
2020-07-16 12:36:46 +08:00
|
|
|
for (i = 0; i < size; ++i) {
|
2020-07-27 15:46:17 +08:00
|
|
|
QString line = QString::number(i) + " " + QString::fromStdString(strings[i]) + "\n";
|
|
|
|
file->write(line.toUtf8());
|
2020-07-16 12:36:46 +08:00
|
|
|
|
|
|
|
std::string symbol(strings[i]);
|
2020-07-27 15:46:17 +08:00
|
|
|
QString strSymbol = QString::fromStdString(symbol);
|
|
|
|
int pos1 = strSymbol.indexOf("[");
|
|
|
|
int pos2 = strSymbol.lastIndexOf("]");
|
|
|
|
QString address = strSymbol.mid(pos1 + 1,pos2 - pos1 - 1);
|
|
|
|
|
|
|
|
// 按照内存地址找到对应代码的行号
|
|
|
|
QString cmd = "addr2line -C -f -e " + qApp->applicationName() + " " + address;
|
|
|
|
QProcess *p = new QProcess;
|
|
|
|
p->setReadChannel(QProcess::StandardOutput);
|
|
|
|
p->start(cmd);
|
|
|
|
p->waitForFinished();
|
|
|
|
p->waitForReadyRead();
|
|
|
|
file->write(p->readAllStandardOutput());
|
|
|
|
delete p;
|
|
|
|
p = nullptr;
|
2020-07-16 12:36:46 +08:00
|
|
|
}
|
|
|
|
free(strings);
|
|
|
|
#endif // __linux
|
|
|
|
} catch (...) {
|
|
|
|
//
|
|
|
|
}
|
2020-07-27 15:46:17 +08:00
|
|
|
file->close();
|
2020-07-16 12:36:46 +08:00
|
|
|
exit(0);
|
|
|
|
}
|
2016-06-23 17:18:45 +08:00
|
|
|
|
2016-06-02 09:46:43 +08:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2019-09-17 13:15:53 +08:00
|
|
|
DGuiApplicationHelper::setUseInactiveColorGroup(false);
|
2016-12-30 16:30:09 +08:00
|
|
|
DApplication::loadDXcbPlugin();
|
2016-06-15 11:09:34 +08:00
|
|
|
DApplication app(argc, argv);
|
2020-07-27 15:46:17 +08:00
|
|
|
|
2020-07-16 12:36:46 +08:00
|
|
|
//崩溃信号
|
|
|
|
signal(SIGTERM, sig_crash);
|
|
|
|
signal(SIGSEGV, sig_crash);
|
2020-07-27 15:46:17 +08:00
|
|
|
signal(SIGILL, sig_crash);
|
|
|
|
signal(SIGINT, sig_crash);
|
2020-07-16 12:36:46 +08:00
|
|
|
signal(SIGABRT, sig_crash);
|
2020-07-27 15:46:17 +08:00
|
|
|
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
|
|
|
|
2020-03-13 12:59:02 +08:00
|
|
|
QAccessible::installFactory(accessibleFactory);
|
|
|
|
|
2018-07-12 19:28:48 +08:00
|
|
|
// load dde-network-utils translator
|
|
|
|
QTranslator translator;
|
|
|
|
translator.load("/usr/share/dde-network-utils/translations/dde-network-utils_" + QLocale::system().name());
|
|
|
|
app.installTranslator(&translator);
|
|
|
|
|
2016-07-20 15:17:41 +08:00
|
|
|
DLogManager::registerConsoleAppender();
|
|
|
|
DLogManager::registerFileAppender();
|
|
|
|
|
2018-06-13 14:21:48 +08:00
|
|
|
QCommandLineOption disablePlugOption(QStringList() << "x" << "disable-plugins", "do not load plugins.");
|
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.setApplicationDescription("DDE Dock");
|
|
|
|
parser.addHelpOption();
|
|
|
|
parser.addVersionOption();
|
|
|
|
parser.addOption(disablePlugOption);
|
|
|
|
parser.process(app);
|
|
|
|
|
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-08-01 11:26:39 +08:00
|
|
|
qDebug() << "\n\ndde-dock startup";
|
2018-04-18 14:50:23 +08:00
|
|
|
RegisterDdeSession();
|
2016-08-01 11:26:39 +08:00
|
|
|
|
2016-06-24 15:47:35 +08:00
|
|
|
#ifndef QT_DEBUG
|
|
|
|
QDir::setCurrent(QApplication::applicationDirPath());
|
|
|
|
#endif
|
|
|
|
|
2016-06-23 16:50:16 +08:00
|
|
|
MainWindow mw;
|
2016-10-14 15:47:43 +08:00
|
|
|
DBusDockAdaptors adaptor(&mw);
|
|
|
|
QDBusConnection::sessionBus().registerService("com.deepin.dde.Dock");
|
|
|
|
QDBusConnection::sessionBus().registerObject("/com/deepin/dde/Dock", "com.deepin.dde.Dock", &mw);
|
|
|
|
|
2020-07-28 13:46:30 +08:00
|
|
|
mw.launch();
|
2016-06-02 09:46:43 +08:00
|
|
|
|
2020-07-24 18:22:09 +08:00
|
|
|
if (!IsSaveMode() && !parser.isSet(disablePlugOption)) {
|
2019-08-19 13:40:06 +08:00
|
|
|
DockItemManager::instance()->startLoadPlugins();
|
2018-06-13 14:21:48 +08:00
|
|
|
}
|
|
|
|
|
2016-06-02 09:46:43 +08:00
|
|
|
return app.exec();
|
|
|
|
}
|