Skip to content

Commit

Permalink
Ask user in dialog to restart app after update finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Müller authored and TheOneRing committed Nov 15, 2023
1 parent 994f35b commit de2533d
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 39 deletions.
3 changes: 1 addition & 2 deletions src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,9 @@ Application::Application(Platform *platform, const QString &displayLanguage, boo

#ifdef WITH_AUTO_UPDATER
// Update checks
UpdaterScheduler *updaterScheduler = new UpdaterScheduler(this);
UpdaterScheduler *updaterScheduler = new UpdaterScheduler(_gui->settingsDialog(), this);
connect(updaterScheduler, &UpdaterScheduler::updaterAnnouncement, _gui.data(),
[this](const QString &title, const QString &msg) { _gui->slotShowTrayMessage(title, msg); });
connect(updaterScheduler, &UpdaterScheduler::requestRestart, FolderMan::instance(), &FolderMan::slotScheduleAppRestart);
#endif

// Cleanup at Quit.
Expand Down
21 changes: 0 additions & 21 deletions src/gui/folderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,6 @@ void FolderMan::scheduleAllFolders()
}
}

void FolderMan::slotScheduleAppRestart()
{
_appRestartRequired = true;
qCInfo(lcFolderMan) << "Application restart requested!";
}

void FolderMan::slotSyncOnceFileUnlocks(const QString &path, FileSystem::LockMode mode)
{
_lockWatcher->addFile(path, mode);
Expand Down Expand Up @@ -841,21 +835,6 @@ void FolderMan::setIgnoreHiddenFiles(bool ignore)
}
}

void FolderMan::restartApplication()
{
if (Utility::isLinux()) {
// restart:
qCInfo(lcFolderMan) << "Restarting application NOW, PID" << qApp->applicationPid() << "is ending.";
qApp->quit();
QStringList args = qApp->arguments();
QString prg = args.takeFirst();

QProcess::startDetached(prg, args);
} else {
qCDebug(lcFolderMan) << "On this platform we do not restart.";
}
}

Result<void, QString> FolderMan::unsupportedConfiguration(const QString &path) const
{
auto it = _unsupportedConfigurationError.find(path);
Expand Down
8 changes: 0 additions & 8 deletions src/gui/folderman.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,6 @@ public slots:
*/
void slotIsConnectedChanged();

/**
* restart the client as soon as it is possible, ie. no folders syncing.
*/
void slotScheduleAppRestart();

/**
* Triggers a sync run once the lock on the given file is removed.
*
Expand Down Expand Up @@ -295,9 +290,6 @@ private slots:
// makes the folder known to the socket api
void registerFolderWithSocketApi(Folder *folder);

// restarts the application (Linux only)
void restartApplication();

/// \returns false when a downgrade of the database is detected, true otherwise.
bool setupFoldersHelper(QSettings &settings, AccountStatePtr account);

Expand Down
3 changes: 3 additions & 0 deletions src/gui/updater/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ target_sources(owncloudCore PRIVATE
updateinfo.h
updater.cpp
updater.h
updatefinisheddialog.cpp
updatefinisheddialog.h
updatefinisheddialog.ui
)

if(SPARKLE_FOUND)
Expand Down
25 changes: 23 additions & 2 deletions src/gui/updater/ocupdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ using namespace std::chrono_literals;

namespace OCC {

UpdaterScheduler::UpdaterScheduler(QObject *parent)
UpdaterScheduler::UpdaterScheduler(SettingsDialog *settingsDialog, QObject *parent)
: QObject(parent)
, _settingsDialog(settingsDialog)
{
connect(&_updateCheckTimer, &QTimer::timeout,
this, &UpdaterScheduler::slotTimerFired);
Expand All @@ -45,7 +46,27 @@ UpdaterScheduler::UpdaterScheduler(QObject *parent)
connect(updater, &OCUpdater::newUpdateAvailable,
this, &UpdaterScheduler::updaterAnnouncement);

connect(updater, &OCUpdater::requestRestart, this, &UpdaterScheduler::requestRestart);
connect(updater, &OCUpdater::requestRestart, this, [this]() {
// prevent dialog from being displayed twice (rather unlikely, but it won't hurt)
if (_updateFinishedDialog == nullptr) {
_updateFinishedDialog = new UpdateFinishedDialog(_settingsDialog);
_updateFinishedDialog->setAttribute(Qt::WA_DeleteOnClose);
_updateFinishedDialog->show();
ownCloudGui::raiseDialog(_updateFinishedDialog);

connect(_updateFinishedDialog, &UpdateFinishedDialog::accepted, this, []() {
if (OC_ENSURE(Utility::isLinux())) {
// restart:
qCInfo(lcUpdater) << "Restarting application NOW, PID" << qApp->applicationPid() << "is ending.";
QTimer::singleShot(0, qApp->quit);
QStringList args = qApp->arguments();
QString prg = args.takeFirst();

QProcess::startDetached(prg, args);
}
});
}
});

connect(updater, &OCUpdater::retryUpdateCheckLater, this, [this]() {
qCInfo(lcUpdater) << "Retrying update check in 10 minutes";
Expand Down
15 changes: 9 additions & 6 deletions src/gui/updater/ocupdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@

#include <QDateTime>
#include <QObject>
#include <QPointer>
#include <QTemporaryFile>
#include <QTimer>
#include <QUrl>
#include <QVersionNumber>

#include "settingsdialog.h"
#include "updater/updatefinisheddialog.h"
#include "updater/updateinfo.h"
#include "updater/updater.h"

Expand Down Expand Up @@ -70,7 +73,7 @@ class UpdaterScheduler : public QObject
{
Q_OBJECT
public:
UpdaterScheduler(QObject *parent);
explicit UpdaterScheduler(SettingsDialog *settingsDialog, QObject *parent = nullptr);

signals:
/**
Expand All @@ -80,16 +83,16 @@ class UpdaterScheduler : public QObject
*/
void updaterAnnouncement(const QString &title, const QString &msg);

/**
* Request restart of the entire application. Used when updating in the background to make the user use the new version after the update has finished.
*/
void requestRestart();

private slots:
void slotTimerFired();

private:
QTimer _updateCheckTimer; /** Timer for the regular update check. */

// make sure we are going to show only one of them at once
QPointer<UpdateFinishedDialog> _updateFinishedDialog = nullptr;

SettingsDialog *_settingsDialog;
};

/**
Expand Down
47 changes: 47 additions & 0 deletions src/gui/updater/updatefinisheddialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) by Fabian Müller <[email protected]>
*
* 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 2 of the License, or
* (at your option) 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.
*/

#include "updatefinisheddialog.h"
#include "common/asserts.h"
#include "ui_updatefinisheddialog.h"

#include <QDialogButtonBox>
#include <QPushButton>

namespace OCC {

UpdateFinishedDialog::UpdateFinishedDialog(QWidget *parent)
: QDialog(parent)
, _ui(new Ui::UpdateFinishedDialog)
{
_ui->setupUi(this);

connect(_ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(_ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);

const auto noButton = _ui->buttonBox->button(QDialogButtonBox::No);
const auto yesButton = _ui->buttonBox->button(QDialogButtonBox::Yes);

noButton->setText(tr("Restart later"));

yesButton->setText(tr("Restart now"));
yesButton->setDefault(true);
}

UpdateFinishedDialog::~UpdateFinishedDialog()
{
delete _ui;
}

} // OCC
39 changes: 39 additions & 0 deletions src/gui/updater/updatefinisheddialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (C) by Fabian Müller <[email protected]>
*
* 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 2 of the License, or
* (at your option) 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.
*/

#pragma once

#include <QDialog>

QT_BEGIN_NAMESPACE
namespace Ui {
class UpdateFinishedDialog;
}
QT_END_NAMESPACE

namespace OCC {

class UpdateFinishedDialog : public QDialog
{
Q_OBJECT

public:
explicit UpdateFinishedDialog(QWidget *parent = nullptr);
~UpdateFinishedDialog() override;

private:
::Ui::UpdateFinishedDialog *_ui;
};

} // OCC
71 changes: 71 additions & 0 deletions src/gui/updater/updatefinisheddialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UpdateFinishedDialog</class>
<widget class="QDialog" name="UpdateFinishedDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>368</width>
<height>172</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Application restart required</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,0">
<property name="spacing">
<number>12</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>350</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>350</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:700;&quot;&gt;Update installed successfully&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Restart the application to finish installing the update.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::No|QDialogButtonBox::Yes</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

0 comments on commit de2533d

Please sign in to comment.