v0.0.0.1 custom startup app commit 1
This commit is contained in:
commit
f3b7ba811e
8 changed files with 25712 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
build/*
|
||||||
BIN
.ninja_deps
Normal file
BIN
.ninja_deps
Normal file
Binary file not shown.
6
.ninja_log
Normal file
6
.ninja_log
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
# ninja log v6
|
||||||
|
1 62 1754932580772976334 helloworld_autogen/timestamp 7853c8a1c93b2124
|
||||||
|
1 62 1754932580772976334 helloworld_autogen/mocs_compilation.cpp 7853c8a1c93b2124
|
||||||
|
1 62 1754932580772976334 /home/alfred/custom_start_up_build/helloworld_autogen/timestamp 7853c8a1c93b2124
|
||||||
|
1 62 1754932580772976334 /home/alfred/custom_start_up_build/helloworld_autogen/mocs_compilation.cpp 7853c8a1c93b2124
|
||||||
|
62 80 1754932580784976334 CMakeFiles/helloworld.dir/helloworld_autogen/mocs_compilation.cpp.o 6c2b962c6a90f545
|
||||||
45
.qt/QtDeploySupport.cmake
Normal file
45
.qt/QtDeploySupport.cmake
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
cmake_minimum_required(VERSION 3.16...3.21)
|
||||||
|
|
||||||
|
# These are part of the public API. Projects should use them to provide a
|
||||||
|
# consistent set of prefix-relative destinations.
|
||||||
|
if(NOT QT_DEPLOY_BIN_DIR)
|
||||||
|
set(QT_DEPLOY_BIN_DIR "bin")
|
||||||
|
endif()
|
||||||
|
if(NOT QT_DEPLOY_LIB_DIR)
|
||||||
|
set(QT_DEPLOY_LIB_DIR "lib")
|
||||||
|
endif()
|
||||||
|
if(NOT QT_DEPLOY_PLUGINS_DIR)
|
||||||
|
set(QT_DEPLOY_PLUGINS_DIR "plugins")
|
||||||
|
endif()
|
||||||
|
if(NOT QT_DEPLOY_QML_DIR)
|
||||||
|
set(QT_DEPLOY_QML_DIR "qml")
|
||||||
|
endif()
|
||||||
|
if(NOT QT_DEPLOY_PREFIX)
|
||||||
|
set(QT_DEPLOY_PREFIX "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}")
|
||||||
|
endif()
|
||||||
|
if(QT_DEPLOY_PREFIX STREQUAL "")
|
||||||
|
set(QT_DEPLOY_PREFIX .)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# These are internal implementation details. They may be removed at any time.
|
||||||
|
set(__QT_DEPLOY_SYSTEM_NAME "Linux")
|
||||||
|
set(__QT_DEPLOY_IS_SHARED_LIBS_BUILD "ON")
|
||||||
|
set(__QT_DEPLOY_TOOL "")
|
||||||
|
set(__QT_DEPLOY_IMPL_DIR "/home/alfred/custom_start_up_build/.qt")
|
||||||
|
set(__QT_DEPLOY_VERBOSE "")
|
||||||
|
set(__QT_CMAKE_EXPORT_NAMESPACE "Qt6")
|
||||||
|
set(__QT_DEPLOY_GENERATOR_IS_MULTI_CONFIG "0")
|
||||||
|
set(__QT_DEPLOY_ACTIVE_CONFIG "")
|
||||||
|
set(__QT_NO_CREATE_VERSIONLESS_FUNCTIONS "")
|
||||||
|
set(__QT_DEFAULT_MAJOR_VERSION "6")
|
||||||
|
|
||||||
|
# Define the CMake commands to be made available during deployment.
|
||||||
|
set(__qt_deploy_support_files
|
||||||
|
"/usr/lib/aarch64-linux-gnu/cmake/Qt6Core/Qt6CoreDeploySupport.cmake"
|
||||||
|
)
|
||||||
|
foreach(__qt_deploy_support_file IN LISTS __qt_deploy_support_files)
|
||||||
|
include("${__qt_deploy_support_file}")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
unset(__qt_deploy_support_file)
|
||||||
|
unset(__qt_deploy_support_files)
|
||||||
14
CMakeLists.txt
Normal file
14
CMakeLists.txt
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
|
project(helloworld VERSION 1.0.0 LANGUAGES CXX)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(Qt6_DIR "/home/ud/Qt/6.9.2/gcc_64/lib/cmake/Qt6")
|
||||||
|
|
||||||
|
find_package(Boost CONFIG)
|
||||||
|
find_package(Qt6 REQUIRED COMPONENTS Core)
|
||||||
|
|
||||||
|
qt_add_executable(StartUpRunner main.cpp)
|
||||||
|
|
||||||
|
target_link_libraries(StartUpRunner PRIVATE Qt6::Core)
|
||||||
109
main.cpp
Normal file
109
main.cpp
Normal file
|
|
@ -0,0 +1,109 @@
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <chrono>
|
||||||
|
#include <format>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <QString>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QProcess>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
char *get_current_time() {
|
||||||
|
const auto now = std::chrono::system_clock::now();
|
||||||
|
const std::time_t t_c = std::chrono::system_clock::to_time_t(now);
|
||||||
|
return std::ctime(&t_c);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
|
if(!std::filesystem::exists("/home/ud/logs/")) {
|
||||||
|
std::filesystem::create_directory("/home/ud/logs");
|
||||||
|
}
|
||||||
|
std::fstream log_file("/home/ud/logs/StartUpRunner.log", std::fstream::app);
|
||||||
|
if(!log_file.is_open()) {
|
||||||
|
log_file.open("/home/ud/logs/StartUpRunner.log", std::fstream::out);
|
||||||
|
}
|
||||||
|
log_file << "-------- Starting app: " << get_current_time();
|
||||||
|
log_file << "Current path: " << std::filesystem::current_path() << "\n";
|
||||||
|
if(!std::filesystem::exists("startup_apps.json")) {
|
||||||
|
log_file << "startup_apps.json not found exiting.\n";
|
||||||
|
log_file.flush();
|
||||||
|
log_file.close();
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
std::string data = "";
|
||||||
|
std::string t_data = "";
|
||||||
|
std::fstream json_file;
|
||||||
|
json_file.open("startup_apps.json", std::fstream::in);
|
||||||
|
if(!json_file.is_open()) {
|
||||||
|
std::cout << "Why is the startup_apps.json file not open?" << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
std::stringstream test;
|
||||||
|
test << json_file.rdbuf();
|
||||||
|
json_file.close();
|
||||||
|
QByteArray arr_data = QByteArray::fromStdString(test.str());
|
||||||
|
QJsonArray top = QJsonDocument::fromJson(arr_data).array();
|
||||||
|
std::vector<QProcess *> active_process_list;
|
||||||
|
for(auto i: top) {
|
||||||
|
auto object = i.toObject();
|
||||||
|
std::string name = object["app_name"].toString().toStdString();
|
||||||
|
std::string args = "";
|
||||||
|
QStringList sargs;
|
||||||
|
for(auto k: object["app_args"].toArray()) {
|
||||||
|
args += k.toString().toStdString();
|
||||||
|
sargs << k.toString();
|
||||||
|
}
|
||||||
|
QString mode = object["mode"].toString("wait");
|
||||||
|
QString working_dir = object["working_dir"].toString("/home/ud/StartUpApps/");
|
||||||
|
std::string file_name = std::filesystem::path(name).stem().string();
|
||||||
|
std::string log_file_name = std::format("/home/ud/logs/{}.log", file_name);
|
||||||
|
bool create_log_file = object["create_log"].toBool();
|
||||||
|
std::string command;
|
||||||
|
if(create_log_file)
|
||||||
|
command = std::format("{} {} > {}", name, args, log_file_name);
|
||||||
|
else
|
||||||
|
command = std::format("{} {}", name, args);
|
||||||
|
log_file << "Running: " << command << "\n";
|
||||||
|
QProcess *proc = new QProcess();
|
||||||
|
QObject::connect(proc, &QProcess::started, [&, command, proc] () {
|
||||||
|
log_file << "Started process: " << command << " with pid: " << QString::number(proc->processId()).toStdString() << std::endl;
|
||||||
|
});
|
||||||
|
if (mode == "wait") {
|
||||||
|
|
||||||
|
QObject::connect(proc, &QProcess::finished, [&, command, proc] (int exitcode, QProcess::ExitStatus status) {
|
||||||
|
auto process = proc;
|
||||||
|
if(status == QProcess::NormalExit)
|
||||||
|
log_file << "Process: " << command << " with pid: " << QString::number(proc->processId()).toStdString() << std::endl << " exited with exit code: " << exitcode << std::endl;
|
||||||
|
else
|
||||||
|
log_file << "Process: " << command << " with pid: " << QString::number(proc->processId()).toStdString() << std::endl << " CRASHED with exit code: " << exitcode << std::endl;
|
||||||
|
auto it = std::find(active_process_list.begin(), active_process_list.end(), process);
|
||||||
|
active_process_list.erase(it);
|
||||||
|
if(active_process_list.size() == 0) {
|
||||||
|
log_file << "-------- All processes finished." << std::endl;
|
||||||
|
log_file.flush();
|
||||||
|
log_file.close();
|
||||||
|
app.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
active_process_list.push_back(proc);
|
||||||
|
}
|
||||||
|
if(!working_dir.isEmpty())
|
||||||
|
proc->setWorkingDirectory(working_dir);
|
||||||
|
proc->setStandardOutputFile(QString::fromStdString(log_file_name));
|
||||||
|
proc->setProgram(QString::fromStdString(name));
|
||||||
|
proc->setArguments(sargs);
|
||||||
|
if(mode == "wait")
|
||||||
|
proc->start(QString::fromStdString(name), sargs);
|
||||||
|
else
|
||||||
|
proc->startDetached(QString::fromStdString(name), sargs);
|
||||||
|
}
|
||||||
|
return app.exec();
|
||||||
|
}
|
||||||
|
|
||||||
11
startup_apps.json
Normal file
11
startup_apps.json
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"app_name": "/home/ud/StartUpApps/piFinder",
|
||||||
|
"app_args": [],
|
||||||
|
"mode": "no-wait"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"app_name": "/home/ud/git_external/acer-predator-turbo-and-rgb-keyboard-linux-module/install.sh",
|
||||||
|
"working_dir": "/home/ud/git_external/acer-predator-turbo-and-rgb-keyboard-linux-module/"
|
||||||
|
}
|
||||||
|
]
|
||||||
Loading…
Reference in a new issue