Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ubports qt512 and aliases #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions asteroidsyncservice/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
cmake_minimum_required(VERSION 3.15)
find_package(Qt6 COMPONENTS DBus Qml)
if (NOT Qt6_FOUND)
find_package(Qt5 5.15 COMPONENTS DBus Qml REQUIRED)
find_package(Qt5 5.12 COMPONENTS DBus Qml REQUIRED)
add_library(Qt::DBus ALIAS Qt5::DBus)
add_library(Qt::Qml ALIAS Qt5::Qml)
endif()
add_library(asteroidsyncserviceplugin SHARED syncservice_plugin.cpp watch.cpp watches.cpp ${PLATFORM_SOURCE_DIR}/servicecontrol.cpp)
set_target_properties(asteroidsyncserviceplugin PROPERTIES AUTOMOC ON)
target_include_directories(asteroidsyncserviceplugin PRIVATE ${PROJECT_BINARY_DIR} ${PLATFORM_SOURCE_DIR})
target_compile_features(asteroidsyncserviceplugin PUBLIC cxx_std_17)
target_link_libraries(asteroidsyncserviceplugin PRIVATE Qt::DBus Qt::Qml)


# Installation paths
get_target_property(REAL_QMAKE_EXECUTABLE Qt::qmake IMPORTED_LOCATION)
#get_target_property(REAL_QMAKE_EXECUTABLE Qt::qmake IMPORTED_LOCATION)
find_program(REAL_QMAKE_EXECUTABLE NAMES qmake6 qmake)

if (NOT QT_INSTALL_QML)
execute_process(COMMAND "${REAL_QMAKE_EXECUTABLE}" -query QT_INSTALL_QML
Expand Down
41 changes: 25 additions & 16 deletions asteroidsyncservice/platforms/ubuntutouch/servicecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool ServiceControl::serviceFileInstalled() const
qDebug() << "Service name not set.";
return false;
}
QFile f(QDir::homePath() + "/.config/upstart/" + m_serviceName + ".conf");
QFile f(QDir::homePath() + "/.config/systemd/user/"+ m_serviceName + ".service");
return f.exists();
}

Expand All @@ -41,7 +41,7 @@ bool ServiceControl::installServiceFile()
return false;
}

QFile f(QDir::homePath() + "/.config/upstart/" + m_serviceName + ".conf");
QFile f(QDir::homePath() + "/.config/systemd/user/"+ m_serviceName + ".service");
if (f.exists()) {
qDebug() << "Service file already existing...";
return false;
Expand All @@ -56,11 +56,20 @@ bool ServiceControl::installServiceFile()
// Try to replace version with "current" to be more robust against updates
appDir.replace(QRegExp("[0-9].[0-9].[0-9]"), "current");

f.write("start on started unity8\n");
f.write("pre-start script\n");
f.write(" initctl set-env LD_LIBRARY_PATH=" + appDir.toUtf8() + "/usr/bin/../:$LD_LIBRARY_PATH\n");
f.write("end script\n");
f.write("exec " + appDir.toUtf8() + "/usr/bin/" + m_serviceName.toUtf8() + "\n");
f.write("[Unit]\n");
f.write("Description=asteroidsync\n");
f.write("After=graphical.target\n");
f.write("[Service]\n");
f.write("ExecStart=" + appDir.toUtf8() + "/usr/bin/" + m_serviceName.toUtf8() + "\n");

f.write("Restart=always\n");
f.write("RestartSec=5\n");
f.write("Environment=LD_LIBRARY_PATH=" + appDir.toUtf8() + "/usr/bin/../:$LD_LIBRARY_PATH\n");
f.write("Environment=HOME=%h XDG_CONFIG_HOME=/home/%u/.config DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/%U/bus XDG_RUNTIME_DIR=/run/user/%U\n");
f.write("[Install]\n");
f.write("WantedBy=default.target\n");


f.close();
return true;
}
Expand All @@ -71,18 +80,18 @@ bool ServiceControl::removeServiceFile()
qDebug() << "Service name not set.";
return false;
}
QFile f(QDir::homePath() + "/.config/upstart/" + m_serviceName + ".conf");
QFile f(QDir::homePath() + "/.config/systemd/user/"+ m_serviceName + ".service");
return f.remove();
}

bool ServiceControl::serviceRunning() const
{
QProcess p;
p.start("initctl", {"status", m_serviceName});
p.start("systemctl", {"is-active", "--user", m_serviceName});
p.waitForFinished();
QByteArray output = p.readAll();
qDebug() << output;
return output.contains("running");
return output.contains("active");
}

bool ServiceControl::setServiceRunning(bool running)
Expand All @@ -97,21 +106,21 @@ bool ServiceControl::setServiceRunning(bool running)

bool ServiceControl::startService()
{
qDebug() << "start service";
int ret = QProcess::execute("start", {m_serviceName});
int ret = QProcess::execute("systemctl", {"start", "--user", m_serviceName});
qDebug() << "start service" << ret;
return ret == 0;
}

bool ServiceControl::stopService()
{
qDebug() << "stop service";
int ret = QProcess::execute("stop", {m_serviceName});
int ret = QProcess::execute("systemctl", {"stop", "--user", m_serviceName});
qDebug() << "stop service" << ret;
return ret == 0;
}

bool ServiceControl::restartService()
{
qDebug() << "restart service";
int ret = QProcess::execute("restart", {m_serviceName});
int ret = QProcess::execute("systemctl", {"restart", "--user", m_serviceName});
qDebug() << "restart service" << ret;
return ret == 0;
}
4 changes: 4 additions & 0 deletions asteroidsyncserviced/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.15)
find_package(Qt6 COMPONENTS Core Bluetooth DBus Qml)
if (NOT Qt6_FOUND)
find_package(Qt5 COMPONENTS Core Bluetooth DBus Qml REQUIRED)
add_library(Qt::Core ALIAS Qt5::Core)
add_library(Qt::Bluetooth ALIAS Qt5::Bluetooth)
add_library(Qt::DBus ALIAS Qt5::DBus)
add_library(Qt::Qml ALIAS Qt5::Qml)
endif()

add_subdirectory(libasteroid)
Expand Down