Add debug logs for window position and autoupdate.

This commit is contained in:
John Preston 2017-07-03 15:23:41 +03:00
parent ebb10fb8ed
commit f316e3bd17
7 changed files with 71 additions and 39 deletions

View file

@ -427,9 +427,10 @@ void UpdateChecker::unpackUpdate() {
LOG(("Update Error: cant open file '%1' for writing").arg(tempDirPath + '/' + relativeName)); LOG(("Update Error: cant open file '%1' for writing").arg(tempDirPath + '/' + relativeName));
return fatalFail(); return fatalFail();
} }
if (f.write(fileInnerData) != fileSize) { auto writtenBytes = f.write(fileInnerData);
if (writtenBytes != fileSize) {
f.close(); f.close();
LOG(("Update Error: cant write file '%1'").arg(tempDirPath + '/' + relativeName)); LOG(("Update Error: cant write file '%1', desiredSize: %2, write result: %3").arg(tempDirPath + '/' + relativeName).arg(fileSize).arg(writtenBytes));
return fatalFail(); return fatalFail();
} }
f.close(); f.close();

View file

@ -546,6 +546,7 @@ void MainWindow::psFirstShow() {
show(); show();
//_private.enableShadow(winId()); //_private.enableShadow(winId());
if (cWindowPos().maximized) { if (cWindowPos().maximized) {
DEBUG_LOG(("Window Pos: First show, setting maximized."));
setWindowState(Qt::WindowMaximized); setWindowState(Qt::WindowMaximized);
} }

View file

@ -383,6 +383,7 @@ void MainWindow::psFirstShow() {
show(); show();
_private->enableShadow(winId()); _private->enableShadow(winId());
if (cWindowPos().maximized) { if (cWindowPos().maximized) {
DEBUG_LOG(("Window Pos: First show, setting maximized."));
setWindowState(Qt::WindowMaximized); setWindowState(Qt::WindowMaximized);
} }

View file

@ -808,10 +808,12 @@ void MainWindow::psFirstShow() {
show(); show();
if (cWindowPos().maximized) { if (cWindowPos().maximized) {
DEBUG_LOG(("Window Pos: First show, setting maximized."));
setWindowState(Qt::WindowMaximized); setWindowState(Qt::WindowMaximized);
} }
if ((cLaunchMode() == LaunchModeAutoStart && cStartMinimized() && !App::passcoded()) || cStartInTray()) { if ((cLaunchMode() == LaunchModeAutoStart && cStartMinimized() && !App::passcoded()) || cStartInTray()) {
DEBUG_LOG(("Window Pos: First show, setting minimized after."));
setWindowState(Qt::WindowMinimized); setWindowState(Qt::WindowMinimized);
if (Global::WorkMode().value() == dbiwmTrayOnly || Global::WorkMode().value() == dbiwmWindowAndTray) { if (Global::WorkMode().value() == dbiwmTrayOnly || Global::WorkMode().value() == dbiwmWindowAndTray) {
hide(); hide();

View file

@ -91,10 +91,14 @@ DeclareSetting(bool, CtrlEnter);
DeclareSetting(bool, AutoUpdate); DeclareSetting(bool, AutoUpdate);
struct TWindowPos { struct TWindowPos {
TWindowPos() : moncrc(0), maximized(0), x(0), y(0), w(0), h(0) { TWindowPos() = default;
}
int32 moncrc, maximized; int32 moncrc = 0;
int32 x, y, w, h; int maximized = 0;
int x = 0;
int y = 0;
int w = 0;
int h = 0;
}; };
DeclareSetting(TWindowPos, WindowPos); DeclareSetting(TWindowPos, WindowPos);
DeclareSetting(bool, SupportTray); DeclareSetting(bool, SupportTray);

View file

@ -1270,11 +1270,13 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
} break; } break;
case dbiWindowPosition: { case dbiWindowPosition: {
TWindowPos pos; auto position = TWindowPos();
stream >> pos.x >> pos.y >> pos.w >> pos.h >> pos.moncrc >> pos.maximized; stream >> position.x >> position.y >> position.w >> position.h;
stream >> position.moncrc >> position.maximized;
if (!_checkStreamStatus(stream)) return false; if (!_checkStreamStatus(stream)) return false;
cSetWindowPos(pos); DEBUG_LOG(("Window Pos: Read from storage %1, %2, %3, %4 (maximized %5)").arg(position.x).arg(position.y).arg(position.w).arg(position.h).arg(Logs::b(position.maximized)));
cSetWindowPos(position);
} break; } break;
case dbiLoggedPhoneNumber: { case dbiLoggedPhoneNumber: {
@ -2380,8 +2382,11 @@ void writeSettings() {
data.stream << quint32(dbiLangPackKey) << quint64(_langPackKey); data.stream << quint32(dbiLangPackKey) << quint64(_langPackKey);
} }
TWindowPos pos(cWindowPos()); auto position = cWindowPos();
data.stream << quint32(dbiWindowPosition) << qint32(pos.x) << qint32(pos.y) << qint32(pos.w) << qint32(pos.h) << qint32(pos.moncrc) << qint32(pos.maximized); data.stream << quint32(dbiWindowPosition) << qint32(position.x) << qint32(position.y) << qint32(position.w) << qint32(position.h);
data.stream << qint32(position.moncrc) << qint32(position.maximized);
DEBUG_LOG(("Window Pos: Writing to storage %1, %2, %3, %4 (maximized %5)").arg(position.x).arg(position.y).arg(position.w).arg(position.h).arg(Logs::b(position.maximized)));
settings.writeEncrypted(data, SettingsKey); settings.writeEncrypted(data, SettingsKey);
} }

View file

@ -250,32 +250,38 @@ void MainWindow::initSize() {
setMinimumWidth(st::windowMinWidth); setMinimumWidth(st::windowMinWidth);
setMinimumHeight((_title ? _title->height() : 0) + st::windowMinHeight); setMinimumHeight((_title ? _title->height() : 0) + st::windowMinHeight);
auto pos = cWindowPos(); auto position = cWindowPos();
DEBUG_LOG(("Window Pos: Initializing first %1, %2, %3, %4 (maximized %5)").arg(position.x).arg(position.y).arg(position.w).arg(position.h).arg(Logs::b(position.maximized)));
auto avail = QDesktopWidget().availableGeometry(); auto avail = QDesktopWidget().availableGeometry();
bool maximized = false; bool maximized = false;
auto geom = QRect(avail.x() + (avail.width() - st::windowDefaultWidth) / 2, avail.y() + (avail.height() - st::windowDefaultHeight) / 2, st::windowDefaultWidth, st::windowDefaultHeight); auto geom = QRect(avail.x() + (avail.width() - st::windowDefaultWidth) / 2, avail.y() + (avail.height() - st::windowDefaultHeight) / 2, st::windowDefaultWidth, st::windowDefaultHeight);
if (pos.w && pos.h) { if (position.w && position.h) {
for (auto screen : QGuiApplication::screens()) { for (auto screen : QGuiApplication::screens()) {
if (pos.moncrc == screenNameChecksum(screen->name())) { if (position.moncrc == screenNameChecksum(screen->name())) {
auto screenGeometry = screen->geometry(); auto screenGeometry = screen->geometry();
DEBUG_LOG(("Window Pos: Screen found, screen geometry: %1, %2, %3, %4").arg(screenGeometry.x()).arg(screenGeometry.y()).arg(screenGeometry.width()).arg(screenGeometry.height()));
auto w = screenGeometry.width(), h = screenGeometry.height(); auto w = screenGeometry.width(), h = screenGeometry.height();
if (w >= st::windowMinWidth && h >= st::windowMinHeight) { if (w >= st::windowMinWidth && h >= st::windowMinHeight) {
if (pos.w > w) pos.w = w; if (position.w > w) position.w = w;
if (pos.h > h) pos.h = h; if (position.h > h) position.h = h;
pos.x += screenGeometry.x(); position.x += screenGeometry.x();
pos.y += screenGeometry.y(); position.y += screenGeometry.y();
if (pos.x + st::windowMinWidth <= screenGeometry.x() + screenGeometry.width() && if (position.x + st::windowMinWidth <= screenGeometry.x() + screenGeometry.width() &&
pos.y + st::windowMinHeight <= screenGeometry.y() + screenGeometry.height()) { position.y + st::windowMinHeight <= screenGeometry.y() + screenGeometry.height()) {
geom = QRect(pos.x, pos.y, pos.w, pos.h); DEBUG_LOG(("Window Pos: Resulting geometry is %1, %2, %3, %4").arg(position.x).arg(position.y).arg(position.w).arg(position.h));
geom = QRect(position.x, position.y, position.w, position.h);
} }
} }
break; break;
} }
} }
if (pos.y < 0) pos.y = 0; if (position.y < 0) position.y = 0;
maximized = pos.maximized; maximized = position.maximized;
} }
DEBUG_LOG(("Window Pos: Setting first %1, %2, %3, %4").arg(geom.x()).arg(geom.y()).arg(geom.width()).arg(geom.height()));
setGeometry(geom); setGeometry(geom);
} }
@ -335,39 +341,51 @@ void MainWindow::savePosition(Qt::WindowState state) {
if (state == Qt::WindowActive) state = windowHandle()->windowState(); if (state == Qt::WindowActive) state = windowHandle()->windowState();
if (state == Qt::WindowMinimized || !positionInited()) return; if (state == Qt::WindowMinimized || !positionInited()) return;
auto pos = cWindowPos(), curPos = pos; auto savedPosition = cWindowPos();
auto realPosition = savedPosition;
if (state == Qt::WindowMaximized) { if (state == Qt::WindowMaximized) {
curPos.maximized = 1; realPosition.maximized = 1;
} else { } else {
auto r = geometry(); auto r = geometry();
curPos.x = r.x(); realPosition.x = r.x();
curPos.y = r.y(); realPosition.y = r.y();
curPos.w = r.width() - (_rightColumn ? _rightColumn->width() : 0); realPosition.w = r.width() - (_rightColumn ? _rightColumn->width() : 0);
curPos.h = r.height(); realPosition.h = r.height();
curPos.maximized = 0; realPosition.maximized = 0;
realPosition.moncrc = 0;
} }
DEBUG_LOG(("Window Pos: Saving position: %1, %2, %3, %4 (maximized %5)").arg(realPosition.x).arg(realPosition.y).arg(realPosition.w).arg(realPosition.h).arg(Logs::b(realPosition.maximized)));
int px = curPos.x + curPos.w / 2, py = curPos.y + curPos.h / 2; auto centerX = realPosition.x + realPosition.w / 2;
auto centerY = realPosition.y + realPosition.h / 2;
int minDelta = 0; int minDelta = 0;
QScreen *chosen = 0; QScreen *chosen = nullptr;
auto screens = QGuiApplication::screens(); auto screens = QGuiApplication::screens();
for (auto screen : QGuiApplication::screens()) { for (auto screen : QGuiApplication::screens()) {
auto delta = (screen->geometry().center() - QPoint(px, py)).manhattanLength(); auto delta = (screen->geometry().center() - QPoint(centerX, centerY)).manhattanLength();
if (!chosen || delta < minDelta) { if (!chosen || delta < minDelta) {
minDelta = delta; minDelta = delta;
chosen = screen; chosen = screen;
} }
} }
if (chosen) { if (chosen) {
curPos.x -= chosen->geometry().x(); auto screenGeometry = chosen->geometry();
curPos.y -= chosen->geometry().y(); DEBUG_LOG(("Window Pos: Screen found, geometry: %1, %2, %3, %4").arg(screenGeometry.x()).arg(screenGeometry.y()).arg(screenGeometry.width()).arg(screenGeometry.height()));
curPos.moncrc = screenNameChecksum(chosen->name()); realPosition.x -= screenGeometry.x();
realPosition.y -= screenGeometry.y();
realPosition.moncrc = screenNameChecksum(chosen->name());
} }
if (curPos.w >= st::windowMinWidth && curPos.h >= st::windowMinHeight) { if (realPosition.w >= st::windowMinWidth && realPosition.h >= st::windowMinHeight) {
if (curPos.x != pos.x || curPos.y != pos.y || curPos.w != pos.w || curPos.h != pos.h || curPos.moncrc != pos.moncrc || curPos.maximized != pos.maximized) { if (realPosition.x != savedPosition.x
cSetWindowPos(curPos); || realPosition.y != savedPosition.y
|| realPosition.w != savedPosition.w
|| realPosition.h != savedPosition.h
|| realPosition.moncrc != savedPosition.moncrc
|| realPosition.maximized != savedPosition.maximized) {
DEBUG_LOG(("Window Pos: Writing: %1, %2, %3, %4 (maximized %5)").arg(realPosition.x).arg(realPosition.y).arg(realPosition.w).arg(realPosition.h).arg(Logs::b(realPosition.maximized)));
cSetWindowPos(realPosition);
Local::writeSettings(); Local::writeSettings();
} }
} }