Skip to content

Commit

Permalink
Add delay to start the new version, make the final dialog pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
antony-jr committed May 22, 2020
1 parent bd79e7f commit 0f45f5b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
3 changes: 2 additions & 1 deletion include/appimageupdaterdialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class AppImageUpdaterDialog : public QDialog {
};

AppImageUpdaterDialog(QPixmap img = QPixmap(),
QWidget *parent = nullptr, int flags = Default);
QWidget *parent = nullptr, int flags = Default, int delaySecs = 10);
~AppImageUpdaterDialog();

public Q_SLOTS:
Expand Down Expand Up @@ -111,6 +111,7 @@ class AppImageUpdaterDialog : public QDialog {

private:
bool b_Busy = false;
int delay = 0;
int p_Flags = 0;
QString m_ApplicationName;
QString s_CurrentAppImagePath; /* Used only for error dialog box. */
Expand Down
36 changes: 26 additions & 10 deletions src/appimageupdaterdialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@

using namespace AppImageUpdaterBridge;

AppImageUpdaterDialog::AppImageUpdaterDialog(QPixmap img, QWidget *parent, int flags)
AppImageUpdaterDialog::AppImageUpdaterDialog(QPixmap img, QWidget *parent, int flags, int delaySecs)
: QDialog(parent),
p_Flags(flags) {
p_Flags(flags),
delay(delaySecs) {
bool found = false;
m_Ui.reset(new Ui::AppImageUpdaterDialog);

Expand Down Expand Up @@ -88,8 +89,7 @@ AppImageUpdaterDialog::~AppImageUpdaterDialog() {
}

void AppImageUpdaterDialog::init(AppImageDeltaRevisioner *revisioner,
const QString &applicationName) {

const QString &applicationName){
getMethod(this, "doInit(QObject*,const QString&)")
.invoke(this, Qt::QueuedConnection, Q_ARG(QObject*, revisioner),Q_ARG(QString,applicationName));
}
Expand Down Expand Up @@ -254,14 +254,22 @@ void AppImageUpdaterDialog::handleFinished(QJsonObject newVersion, QString oldVe
bool show = p_Flags & ShowFinishedDialog;

if(show) {
QString currentAppImageName = QFileInfo(oldVersionPath).fileName();
auto curinfo = QFileInfo(oldVersionPath);
QString currentAppImageName = curinfo.fileName();
QString currentAppImageAbsPath = curinfo.absolutePath();

QMessageBox box(this);
box.setWindowTitle(QString::fromUtf8("Update Completed!"));
box.setText(QString::fromUtf8("Update completed successfully for ") +
box.setIcon(QMessageBox::Information);
box.setDetailedText(
QString::fromUtf8("Old version is at: ") +
currentAppImageAbsPath + QString::fromUtf8("/") + currentAppImageName +
QString::fromUtf8("\n\n") +
QString::fromUtf8("New version is saved at: ") +
newVersion["AbsolutePath"].toString());
box.setText(QString::fromUtf8("Update completed successfully for <b>") +
currentAppImageName +
QString::fromUtf8(", the new version is saved at '") +
newVersion["AbsolutePath"].toString() +
QString::fromUtf8("', do you want to open it?"));
QString::fromUtf8("</b>, do you want to launch the new version? View details for more information."));
box.addButton(QMessageBox::Yes);
box.addButton(QMessageBox::No);
execute = (box.exec() == QMessageBox::Yes);
Expand All @@ -278,7 +286,15 @@ void AppImageUpdaterDialog::handleFinished(QJsonObject newVersion, QString oldVe
info.permissions());
}
}
QProcess::startDetached(newVersion["AbsolutePath"].toString());
QProcess::startDetached("sh",
QStringList()
<< "-c"
<< (
QString::fromUtf8("sleep ") +
QString::number(delay) +
QString::fromUtf8("; ") +
newVersion["AbsolutePath"].toString()
));
emit quit();
}
hide();
Expand Down

0 comments on commit 0f45f5b

Please sign in to comment.