From 836e23f5cf60391aa7dccbfc266c597debbd81bc Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Thu, 26 Sep 2019 16:32:25 -0700 Subject: [PATCH] override defualt latest build url and add commandlineOption --- launchers/qt/CMakeLists.txt | 2 ++ launchers/qt/resources/qml/HFBase/Error.qml | 4 +++ launchers/qt/resources/qml/root.qml | 2 +- launchers/qt/src/CommandlineOptions.cpp | 30 ++++++++++++++++ launchers/qt/src/CommandlineOptions.h | 16 +++++++++ launchers/qt/src/Helper_darwin.mm | 2 +- launchers/qt/src/Launcher.cpp | 1 - launchers/qt/src/LauncherState.cpp | 39 ++++++++++----------- launchers/qt/src/LauncherState.h | 2 ++ launchers/qt/src/main.cpp | 23 ++++-------- 10 files changed, 81 insertions(+), 40 deletions(-) create mode 100644 launchers/qt/src/CommandlineOptions.cpp create mode 100644 launchers/qt/src/CommandlineOptions.h diff --git a/launchers/qt/CMakeLists.txt b/launchers/qt/CMakeLists.txt index 831895c3ab..53b1f54796 100644 --- a/launchers/qt/CMakeLists.txt +++ b/launchers/qt/CMakeLists.txt @@ -139,6 +139,8 @@ set(src_files src/Unzipper.cpp src/Helper.h src/Helper.cpp + src/CommandlineOptions.h + src/CommandlineOptions.cpp deps/miniz/miniz.h deps/miniz/miniz.cpp #${RES_SOURCES} diff --git a/launchers/qt/resources/qml/HFBase/Error.qml b/launchers/qt/resources/qml/HFBase/Error.qml index d05ef01413..f488a3e9bf 100644 --- a/launchers/qt/resources/qml/HFBase/Error.qml +++ b/launchers/qt/resources/qml/HFBase/Error.qml @@ -78,6 +78,10 @@ Item { topMargin: 15 horizontalCenter: description.horizontalCenter } + + onClicked: { + LauncherState.restart(); + } } diff --git a/launchers/qt/resources/qml/root.qml b/launchers/qt/resources/qml/root.qml index bfd704fa50..3c755c2a6b 100644 --- a/launchers/qt/resources/qml/root.qml +++ b/launchers/qt/resources/qml/root.qml @@ -15,7 +15,7 @@ Item { } Component.onCompleted: { - loader.source = LauncherState.getCurrentUISource(); + loader.source = "./SplashScreen.qml"; LauncherState.updateSourceUrl.connect(function(url) { loader.source = url; }); diff --git a/launchers/qt/src/CommandlineOptions.cpp b/launchers/qt/src/CommandlineOptions.cpp new file mode 100644 index 0000000000..162d3414f3 --- /dev/null +++ b/launchers/qt/src/CommandlineOptions.cpp @@ -0,0 +1,30 @@ +#include "CommandlineOptions.h" + +#include +#include + +bool isCommandlineOption(const std::string& option) { + if (option.rfind("--", 0) == 0 && option.at(2) != '-') { + return true; + } + return false; +} +bool CommandlineOptions::contains(const std::string& option) { + auto iter = std::find(_commandlineOptions.begin(), _commandlineOptions.end(), option); + return (iter != _commandlineOptions.end()); +} + +void CommandlineOptions::parse(const int argc, char** argv) { + for (int index = 1; index < argc; index++) { + std::string option = argv[index]; + if (isCommandlineOption(option)) { + std::cout << "adding commandline option: " << option << "\n"; + _commandlineOptions.push_back(option); + } + } +} + +CommandlineOptions* CommandlineOptions::getInstance() { + static CommandlineOptions commandlineOptions; + return &commandlineOptions; +} diff --git a/launchers/qt/src/CommandlineOptions.h b/launchers/qt/src/CommandlineOptions.h new file mode 100644 index 0000000000..4a34bd1337 --- /dev/null +++ b/launchers/qt/src/CommandlineOptions.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +class CommandlineOptions { +public: + CommandlineOptions() = default; + ~CommandlineOptions() = default; + + void parse(const int argc, char** argv); + bool contains(const std::string& option); + static CommandlineOptions* getInstance(); +private: + std::vector _commandlineOptions; +}; diff --git a/launchers/qt/src/Helper_darwin.mm b/launchers/qt/src/Helper_darwin.mm index 417abbb647..5ffde89caf 100644 --- a/launchers/qt/src/Helper_darwin.mm +++ b/launchers/qt/src/Helper_darwin.mm @@ -7,7 +7,7 @@ #include void launchClient(const QString& clientPath, const QString& homePath, const QString& defaultScriptOverride, - const QString& displayName, const QString& contentCachePath, QString& loginTokenResponse) { + const QString& displayName, const QString& contentCachePath, QString loginTokenResponse) { NSString* homeBookmark = [[NSString stringWithFormat:@"hqhome="] stringByAppendingString:homePath.toNSString()]; NSArray* arguments; diff --git a/launchers/qt/src/Launcher.cpp b/launchers/qt/src/Launcher.cpp index 2d5fd8dc21..96da608f7d 100644 --- a/launchers/qt/src/Launcher.cpp +++ b/launchers/qt/src/Launcher.cpp @@ -13,7 +13,6 @@ Launcher::Launcher(int& argc, char**argv) : QGuiApplication(argc, argv) { qDebug() << "resources.rcc path: " << resourceBinaryLocation; QResource::registerResource(resourceBinaryLocation); _launcherState = std::make_shared(); - //_launcherState->setUIState(LauncherState::SPLASH_SCREEN); _launcherWindow = std::make_unique(); _launcherWindow->rootContext()->setContextProperty("LauncherState", _launcherState.get()); _launcherWindow->rootContext()->setContextProperty("PathUtils", new PathUtils()); diff --git a/launchers/qt/src/LauncherState.cpp b/launchers/qt/src/LauncherState.cpp index f9ada2bc41..c6345522b2 100644 --- a/launchers/qt/src/LauncherState.cpp +++ b/launchers/qt/src/LauncherState.cpp @@ -151,12 +151,25 @@ void LauncherState::requestBuilds() { setApplicationState(ApplicationState::RequestingBuilds); // TODO Show splash screen until this request is complete - auto request = new QNetworkRequest(QUrl("https://thunder.highfidelity.com/builds/api/tags/latest/?format=json")); + + QString latestBuildRequestUrl { "https://thunder.highfidelity.com/builds/api/tags/latest/?format=json" }; + QProcessEnvironment processEnvironment =QProcessEnvironment::systemEnvironment(); + + if (processEnvironment.contains("HQ_LAUNCHER_BUILDS_URL")) { + latestBuildRequestUrl = processEnvironment.value("HQ_LAUNCHER_BUILDS_URL"); + } + + auto request = new QNetworkRequest(QUrl(latestBuildRequestUrl)); auto reply = _networkAccessManager.get(*request); QObject::connect(reply, &QNetworkReply::finished, this, &LauncherState::receivedBuildsReply); } +void LauncherState::restart() { + setApplicationState(ApplicationState::Init); + requestBuilds(); +} + void LauncherState::receivedBuildsReply() { auto reply = static_cast(sender()); @@ -219,7 +232,7 @@ void LauncherState::receivedBuildsReply() { } if (shouldDownloadLauncher()) { - downloadLauncher(); + //downloadLauncher(); } getCurrentClientVersion(); } @@ -239,27 +252,12 @@ void LauncherState::getCurrentClientVersion() { //connect(&client, &QProcess::errorOccurred, &loop, &QEventLoop::exit); connect(&client, QOverload::of(&QProcess::finished), &loop, &QEventLoop::exit); - /* - connect(&client, QOverload::of(&QProcess::finished), [&]() { - qDebug() << "Finished"; - }); - connect(&client, &QProcess::errorOccurred, [&](QProcess::ProcessError err) { - qDebug() << "Error occurred" << err << client.error(); - }); - connect(&client, &QProcess::started, [&]() { - qDebug() << "Started"; - }); - connect(&client, &QProcess::stateChanged, [&]() { - qDebug() << "State changed " << client.state(); - }); - */ + connect(&client, &QProcess::errorOccurred, &loop, &QEventLoop::exit, Qt::QueuedConnection); - //qDebug() << "Starting client"; client.start(getClientExecutablePath(), { "--version" }); - //qDebug() << "Started" << client.error(); if (client.state() != QProcess::NotRunning) { - //qDebug() << "Starting loop"; + loop.exec(); } else { qDebug() << "Not waiting for client, there was an error starting it: " << client.error(); @@ -389,12 +387,13 @@ void LauncherState::receivedSettingsReply() { } _homeLocation = "hifi://hq"; + _contentCacheURL = "http://orgs.highfidelity.com/host-content-cache/" + QUrl(_homeLocation).host() + ".zip"; if (root["data"].toObject().contains("home_location")) { auto homeLocation = root["data"].toObject()["home_location"]; if (homeLocation.isString()) { _homeLocation = homeLocation.toString(); auto host = QUrl(_homeLocation).host(); - _contentCacheURL = "http://orgs.highfidelity.com/host-content-cache/" + host + ".zip"; + //_contentCacheURL = "http://orgs.highfidelity.com/host-content-cache/" + host + ".zip"; qDebug() << "Home location is: " << _homeLocation; qDebug() << "Content cache url is: " << _contentCacheURL; } diff --git a/launchers/qt/src/LauncherState.h b/launchers/qt/src/LauncherState.h index f3a3c4a313..b66d9e90e3 100644 --- a/launchers/qt/src/LauncherState.h +++ b/launchers/qt/src/LauncherState.h @@ -110,6 +110,8 @@ public: void requestSettings(); Q_INVOKABLE void receivedSettingsReply(); + Q_INVOKABLE void restart(); + // Launcher void downloadLauncher(); void installLauncher(); diff --git a/launchers/qt/src/main.cpp b/launchers/qt/src/main.cpp index 3c810434e7..ed5cbe8138 100644 --- a/launchers/qt/src/main.cpp +++ b/launchers/qt/src/main.cpp @@ -2,6 +2,7 @@ #include "LauncherWindow.h" #include "Launcher.h" +#include "CommandlineOptions.h" #include #include #include "Helper.h" @@ -27,31 +28,19 @@ bool hasSuffix(const std::string path, const std::string suffix) { return false; } -bool containsOption(int argc, char* argv[], const std::string& option) { - for (int index = 0; index < argc; index++) { - if (option.compare(argv[index]) == 0) { - return true; - } - } - return false; -} - int main(int argc, char *argv[]) { - //std::cout << "Launcher version: " << LAUNCHER_BUILD_VERSION; #ifdef Q_OS_MAC // auto updater if (argc == 3) { if (hasSuffix(argv[1], "app") && hasSuffix(argv[2], "app")) { - std::cout << "swapping launcher \n"; swapLaunchers(argv[1], argv[2]); - } else { - std::cout << "not swapping launcher \n"; } } -#elif defined(Q_OS_WIN) - // try-install - - if (containsOption(argc, argv, "--restart")) { +#endif + CommandlineOptions* options = CommandlineOptions::getInstance(); + options->parse(argc, argv); +#ifdef Q_OS_WIN + if (options->contains("--restart")) { LauncherInstaller launcherInstaller(argv[0]); launcherInstaller.install(); }