Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
DFN2
ocs-manager
Commits
fd519cbb
Verified
Commit
fd519cbb
authored
Sep 10, 2019
by
azubieta
Browse files
Trigger check updates from the wsServer
parent
7d1db270
Changes
11
Hide whitespace changes
Inline
Side-by-side
app/src/handlers/updatehandler.cpp
View file @
fd519cbb
...
...
@@ -13,10 +13,17 @@
#include
"updaters/appimageupdater.h"
#endif
#include
"updaters/appupdater.h"
UpdateHandler
::
UpdateHandler
(
ConfigHandler
*
configHandler
,
QObject
*
parent
)
:
QObject
(
parent
),
configHandler_
(
configHandler
)
:
QObject
(
parent
),
configHandler_
(
configHandler
)
,
appUpdater_
(
nullptr
)
{}
void
UpdateHandler
::
setAppFile
(
const
QString
&
appFile
)
{
appFile_
=
appFile
;
}
void
UpdateHandler
::
checkAll
()
{
// Resets data
...
...
@@ -91,6 +98,28 @@ void UpdateHandler::update(const QString &itemKey)
#endif
}
void
UpdateHandler
::
checkAppUpdates
()
{
if
(
appUpdater_
==
nullptr
)
appUpdater_
=
new
AppUpdater
(
appFile_
,
this
);
appUpdater_
->
setSilentLookup
(
false
);
if
(
!
appUpdater_
->
isRunning
())
appUpdater_
->
doUpdateLookUp
();
}
void
UpdateHandler
::
silentCheckAppUpdates
()
{
if
(
appUpdater_
==
nullptr
)
appUpdater_
=
new
AppUpdater
(
appFile_
,
this
);
appUpdater_
->
setSilentLookup
(
true
);
if
(
!
appUpdater_
->
isRunning
())
appUpdater_
->
doUpdateLookUp
();
}
#ifdef APP_DESKTOP
void
UpdateHandler
::
appImageUpdaterFinished
(
AppImageUpdater
*
updater
)
{
...
...
app/src/handlers/updatehandler.h
View file @
fd519cbb
...
...
@@ -9,6 +9,8 @@ class ConfigHandler;
class
AppImageUpdater
;
#endif
class
AppUpdater
;
class
UpdateHandler
:
public
QObject
{
Q_OBJECT
...
...
@@ -16,6 +18,12 @@ class UpdateHandler : public QObject
public:
explicit
UpdateHandler
(
ConfigHandler
*
configHandler
,
QObject
*
parent
=
nullptr
);
/**
* @brief set application file to be used when performing self updates
* @param appFile
*/
void
setAppFile
(
const
QString
&
appFile
);
signals:
void
checkAllStarted
(
bool
status
);
void
checkAllFinished
(
bool
status
);
...
...
@@ -27,6 +35,9 @@ public slots:
void
checkAll
();
void
update
(
const
QString
&
itemKey
);
void
checkAppUpdates
();
void
silentCheckAppUpdates
();
private
slots
:
#ifdef APP_DESKTOP
void
appImageUpdaterFinished
(
AppImageUpdater
*
updater
);
...
...
@@ -37,6 +48,8 @@ private:
void
updateAppImage
(
const
QString
&
itemKey
);
#endif
QString
appFile_
;
ConfigHandler
*
configHandler_
;
QJsonObject
metadataSet_
;
AppUpdater
*
appUpdater_
;
};
app/src/main.cpp
View file @
fd519cbb
...
...
@@ -9,6 +9,7 @@
#include
<QDebug>
#include
"handlers/confighandler.h"
#include
"handlers/updatehandler.h"
#include
"websockets/websocketserver.h"
#include
"updaters/appupdater.h"
...
...
@@ -23,6 +24,8 @@ int main(int argc, char *argv[])
auto
*
configHandler
=
new
ConfigHandler
(
&
app
);
auto
appConfigApplication
=
configHandler
->
getAppConfigApplication
();
auto
updateHandler
=
new
UpdateHandler
(
configHandler
,
&
app
);
app
.
setApplicationName
(
appConfigApplication
[
"name"
].
toString
());
app
.
setApplicationVersion
(
appConfigApplication
[
"version"
].
toString
());
app
.
setOrganizationName
(
appConfigApplication
[
"organization"
].
toString
());
...
...
@@ -52,17 +55,14 @@ int main(int argc, char *argv[])
clParser
.
process
(
app
);
// Setup AppUpdater
auto
appFile
=
clParser
.
value
(
clOptionAppPath
);
AppUpdater
appUpdater
(
appFile
);
appUpdater
.
setSilentLookup
(
true
);
appUpdater
.
doUpdateLookUp
();
auto
port
=
clParser
.
value
(
clOptionPort
).
toUShort
();
// Setup websocket server
auto
*
wsServer
=
new
WebSocketServer
(
configHandler
,
appConfigApplication
[
"id"
].
toString
(),
port
,
&
app
);
QObject
::
connect
(
wsServer
,
&
WebSocketServer
::
stopped
,
&
app
,
&
QGuiApplication
::
quit
);
wsServer
->
setUpdateHandler
(
updateHandler
);
QObject
::
connect
(
wsServer
,
&
WebSocketServer
::
stopped
,
&
app
,
&
QGuiApplication
::
quit
);
if
(
wsServer
->
start
())
{
qInfo
()
<<
"Websocket server started at:"
<<
wsServer
->
serverUrl
().
toString
();
...
...
@@ -72,5 +72,8 @@ int main(int argc, char *argv[])
return
1
;
}
updateHandler
->
setAppFile
(
appFile
);
updateHandler
->
checkAppUpdates
();
return
app
.
exec
();
}
app/src/updaters/appimageupdatedialog.ui
View file @
fd519cbb
...
...
@@ -69,7 +69,7 @@ Do you want to download it?</string>
<widget
class=
"QWidget"
name=
"progressPage"
>
<layout
class=
"QVBoxLayout"
name=
"verticalLayout_2"
>
<item>
<widget
class=
"QLabel"
name=
"
title
"
>
<widget
class=
"QLabel"
name=
"
progressLabel
"
>
<property
name=
"text"
>
<string>
Downloading update contents
</string>
</property>
...
...
app/src/updaters/appupdatedialog.cpp
View file @
fd519cbb
...
...
@@ -16,6 +16,16 @@ AppUpdateDialog::~AppUpdateDialog()
delete
ui
;
}
void
AppUpdateDialog
::
showLookingForUpdates
()
{
setWindowTitle
(
tr
(
"Looking for Pling Store Updates"
));
ui
->
progressLabel
->
setText
(
tr
(
"Looking for Pling Store Updates"
));
ui
->
progressBar
->
setRange
(
0
,
0
);
ui
->
stackedWidget
->
setCurrentWidget
(
ui
->
progressPage
);
show
();
}
void
AppUpdateDialog
::
showUpdateConfirmationMessage
()
{
setWindowTitle
(
tr
(
"Pling Store Update Available"
));
...
...
@@ -60,6 +70,7 @@ void AppUpdateDialog::showProgress(int progress)
setWindowTitle
(
tr
(
"Pling Store Update"
));
ui
->
progressBar
->
setValue
(
progress
);
ui
->
progressBar
->
setRange
(
0
,
100
);
ui
->
progressPage
->
show
();
ui
->
stackedWidget
->
setCurrentWidget
(
ui
->
progressPage
);
...
...
app/src/updaters/appupdatedialog.h
View file @
fd519cbb
...
...
@@ -27,6 +27,8 @@ signals:
void
updateRequested
();
public
slots
:
void
showLookingForUpdates
();
void
showUpdateConfirmationMessage
();
void
showErrorMessage
(
const
QString
&
msg
);
...
...
app/src/updaters/appupdater.cpp
View file @
fd519cbb
...
...
@@ -18,6 +18,11 @@ void AppUpdater::setSilentLookup(bool value)
silentLookup
=
value
;
}
bool
AppUpdater
::
isRunning
()
{
return
progressCheckTimer
.
isActive
();
}
void
AppUpdater
::
doUpdateLookUp
()
{
if
(
appImagePath
.
isEmpty
())
{
...
...
@@ -26,7 +31,7 @@ void AppUpdater::doUpdateLookUp()
}
if
(
!
silentLookup
)
updateDialog
.
show
();
updateDialog
.
show
LookingForUpdates
();
QtConcurrent
::
run
([
=
]()
{
appimage
::
update
::
Updater
updater
(
appImagePath
.
toStdString
());
...
...
app/src/updaters/appupdater.cpp.autosave
deleted
100644 → 0
View file @
7d1db270
#include <QDebug>
#include <QtConcurrent/QtConcurrent>
#include "appimage/update.h"
#include "appupdater.h"
AppUpdater::AppUpdater(const QString &appImagePath, QObject *parent) : QObject(parent), appImagePath(appImagePath), updateHelper(nullptr)
{
connect(this, &AppUpdater::updateAvailable, &updateDialog, &AppUpdateDialog::showUpdateConfirmationMessage);
connect(&updateDialog, &AppUpdateDialog::updateRequested, this, &AppUpdater::doUpdate);
connect(&updateDialog, &AppUpdateDialog::restartRequested, this, &AppUpdater::doRestart);
connect(&updateDialog, &AppUpdateDialog::rejected, this, &AppUpdater::stop);
}
void AppUpdater::setSilentLookup(bool value)
{
silentLookup = value;
}
void AppUpdater::doUpdateLookUp()
{
if (appImagePath.isEmpty()) {
qWarning() << "Self-updates disabled: No app file provided.";
return;
}
if (!silentLookup)
updateDialog.show();
QtConcurrent::run([=]() {
appimage::update::Updater updater(appImagePath.toStdString());
bool updateAvailable; // this is an output parameter!!!
updater.checkForChanges(updateAvailable);
if (updateAvailable) {
qDebug() << "Update available";
emit this->updateAvailable();
}
});
}
void AppUpdater::doUpdate()
{
if (appImagePath.isEmpty()) {
qWarning() << "Self-updates disabled: No app file provided.";
return;
}
if (updateHelper !=nullptr)
delete updateHelper;
updateHelper = new appimage::update::Updater(appImagePath.toStdString());
updateHelper->start();
progressCheckTimer.setInterval(200);
progressCheckTimer.start();
connect(&progressCheckTimer, &QTimer::timeout, this, &AppUpdater::checkUpdateProgress);
}
void AppUpdater::doRestart()
{
QProcess::startDetached("killall", {"pling-store"});
if (updateHelper != nullptr) {
std::string pathToNewFile;
updateHelper->pathToNewFile(pathToNewFile);
if (!pathToNewFile.empty()) {
QString path = QString::fromStdString(pathToNewFile);
QFile::setPermissions(path, QFileDevice::ReadUser | QFileDevice::ExeUser);
QProcess proc;
proc.setEnvironment(getCleanSystemEnvironment());
qDebug() << proc.environment();
if (proc.startDetached(path)) {
updateDialog.accept();
} else
updateDialog.showErrorMessage("Unable to start: " + path);
}
}
}
void AppUpdater::stop()
{
}
void AppUpdater::checkUpdateProgress()
{
using namespace appimage::update;
auto state = updateHelper->state();
switch (state) {
case Updater::INITIALIZED:
break;
case Updater::RUNNING:
double progress;
updateHelper->progress(progress);
updateDialog.showProgress(progress*100);
break;
case Updater::STOPPING:
break;
case Updater::SUCCESS:
updateDialog.showCompletionMessage();
progressCheckTimer.stop();
break;
case Updater::ERROR:
updateDialog.showErrorMessage(tr("Update failed"));
progressCheckTimer.stop();
break;
}
}
QStringList AppUpdater::getCleanSystemEnvironment()
{
QString appDirPath = qgetenv("APPDIR");
QProcessEnvironment systenEnvironemnt = QProcessEnvironment::systemEnvironment();
QProcessEnvironment processEnvironment;
for (QString key: systenEnvironemnt.keys()) {
QString value = systenEnvironemnt.value(key);
QStringList oldValue = value.split(":");
QStringList newVaule;
for (const QString &valueSection: oldValue)
if (!valueSection.contains(appDirPath))
newVaule << valueSection;
if (!newVaule.empty())
processEnvironment.insert(key, newVaule.join(":"));
}
return processEnvironment.toStringList();
// return {"DISPLAY=:0"};
}
app/src/updaters/appupdater.h
View file @
fd519cbb
...
...
@@ -17,9 +17,9 @@ class AppUpdater : public QObject
public:
explicit
AppUpdater
(
const
QString
&
appImagePath
,
QObject
*
parent
=
nullptr
);
void
setSilentLookup
(
bool
value
);
bool
isRunning
();
signals:
void
updateAvailable
();
void
restartApp
(
QString
appPath
);
...
...
app/src/websockets/websocketserver.cpp
View file @
fd519cbb
...
...
@@ -25,7 +25,6 @@ WebSocketServer::WebSocketServer(ConfigHandler *configHandler, const QString &se
systemHandler_
=
new
SystemHandler
(
this
);
ocsApiHandler_
=
new
OcsApiHandler
(
configHandler_
,
this
);
itemHandler_
=
new
ItemHandler
(
configHandler_
,
this
);
updateHandler_
=
new
UpdateHandler
(
configHandler_
,
this
);
desktopThemeHandler_
=
new
DesktopThemeHandler
(
this
);
connect
(
itemHandler_
,
&
ItemHandler
::
metadataSetChanged
,
this
,
&
WebSocketServer
::
itemHandlerMetadataSetChanged
);
...
...
@@ -38,12 +37,6 @@ WebSocketServer::WebSocketServer(ConfigHandler *configHandler, const QString &se
connect
(
itemHandler_
,
&
ItemHandler
::
installFinished
,
this
,
&
WebSocketServer
::
itemHandlerInstallFinished
);
connect
(
itemHandler_
,
&
ItemHandler
::
uninstallStarted
,
this
,
&
WebSocketServer
::
itemHandlerUninstallStarted
);
connect
(
itemHandler_
,
&
ItemHandler
::
uninstallFinished
,
this
,
&
WebSocketServer
::
itemHandlerUninstallFinished
);
connect
(
updateHandler_
,
&
UpdateHandler
::
checkAllStarted
,
this
,
&
WebSocketServer
::
updateHandlerCheckAllStarted
);
connect
(
updateHandler_
,
&
UpdateHandler
::
checkAllFinished
,
this
,
&
WebSocketServer
::
updateHandlerCheckAllFinished
);
connect
(
updateHandler_
,
&
UpdateHandler
::
updateStarted
,
this
,
&
WebSocketServer
::
updateHandlerUpdateStarted
);
connect
(
updateHandler_
,
&
UpdateHandler
::
updateFinished
,
this
,
&
WebSocketServer
::
updateHandlerUpdateFinished
);
connect
(
updateHandler_
,
&
UpdateHandler
::
updateProgress
,
this
,
&
WebSocketServer
::
updateHandlerUpdateProgress
);
}
WebSocketServer
::~
WebSocketServer
()
...
...
@@ -52,6 +45,17 @@ WebSocketServer::~WebSocketServer()
wsServer_
->
deleteLater
();
}
void
WebSocketServer
::
setUpdateHandler
(
UpdateHandler
*
updateHandler
)
{
updateHandler_
=
updateHandler
;
connect
(
updateHandler_
,
&
UpdateHandler
::
checkAllStarted
,
this
,
&
WebSocketServer
::
updateHandlerCheckAllStarted
);
connect
(
updateHandler_
,
&
UpdateHandler
::
checkAllFinished
,
this
,
&
WebSocketServer
::
updateHandlerCheckAllFinished
);
connect
(
updateHandler_
,
&
UpdateHandler
::
updateStarted
,
this
,
&
WebSocketServer
::
updateHandlerUpdateStarted
);
connect
(
updateHandler_
,
&
UpdateHandler
::
updateFinished
,
this
,
&
WebSocketServer
::
updateHandlerUpdateFinished
);
connect
(
updateHandler_
,
&
UpdateHandler
::
updateProgress
,
this
,
&
WebSocketServer
::
updateHandlerUpdateProgress
);
}
bool
WebSocketServer
::
start
()
{
if
(
wsServer_
->
listen
(
QHostAddress
::
Any
,
serverPort_
))
{
...
...
@@ -382,7 +386,10 @@ void WebSocketServer::receiveMessage(const QString &id, const QString &func, con
}
else
if
(
func
==
"UpdateHandler::update"
)
{
updateHandler_
->
update
(
data
.
at
(
0
).
toString
());
}
else
if
(
func
==
"UpdateHandler::checkAppUpdate"
)
{
updateHandler_
->
checkAppUpdates
();
}
// DesktopThemeHandler
else
if
(
func
==
"DesktopThemeHandler::desktopEnvironment"
)
{
resultData
.
append
(
desktopThemeHandler_
->
desktopEnvironment
());
...
...
app/src/websockets/websocketserver.h
View file @
fd519cbb
...
...
@@ -23,6 +23,7 @@ public:
explicit
WebSocketServer
(
ConfigHandler
*
configHandler
,
const
QString
&
serverName
=
QString
(
"WebSocketServer"
),
quint16
serverPort
=
0
,
QObject
*
parent
=
nullptr
);
~
WebSocketServer
();
void
setUpdateHandler
(
UpdateHandler
*
updateHandler
);
signals:
void
started
();
void
stopped
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment