From 5d7b4fab841c78156c94236f22ea0debfe4721fb Mon Sep 17 00:00:00 2001 From: SunderB <20426079+SunderB@users.noreply.github.com> Date: Sat, 13 Feb 2021 23:25:57 +0000 Subject: [PATCH] GUI: Fix critical bugs introduced by last commit * Now restart sonic-pi with the args it was given with * Disable some verbose logging * Remove utils/paths.h as it's not needed --- app/gui/qt/CMakeLists.txt | 1 - app/gui/qt/mainwindow.cpp | 35 +++++++++++++++++++++++------- app/gui/qt/mainwindow.h | 4 ++-- app/gui/qt/utils/paths.h | 14 ------------ app/gui/qt/utils/sonic_pi_i18n.cpp | 8 +++---- 5 files changed, 33 insertions(+), 29 deletions(-) delete mode 100644 app/gui/qt/utils/paths.h diff --git a/app/gui/qt/CMakeLists.txt b/app/gui/qt/CMakeLists.txt index 4932ae2283..8e55ed65d4 100644 --- a/app/gui/qt/CMakeLists.txt +++ b/app/gui/qt/CMakeLists.txt @@ -110,7 +110,6 @@ set(SOURCES ${QTAPP_ROOT}/utils/sonic_pi_i18n.h ${QTAPP_ROOT}/utils/ruby_help.h ${QTAPP_ROOT}/utils/lang_list.h - ${QTAPP_ROOT}/utils/paths.h ${QTAPP_ROOT}/model/settings.h ) diff --git a/app/gui/qt/mainwindow.cpp b/app/gui/qt/mainwindow.cpp index e68e792281..ce50866f86 100644 --- a/app/gui/qt/mainwindow.cpp +++ b/app/gui/qt/mainwindow.cpp @@ -81,7 +81,6 @@ using namespace oscpkt; // OSC specific stuff #include "widgets/sonicpilog.h" #include "utils/ruby_help.h" -#include "utils/paths.h" #include "dpi.h" @@ -162,7 +161,7 @@ MainWindow::MainWindow(QApplication& app, QSplashScreen* splash) initPaths(); bool startupOK = false; - this->sonicPii18n = new SonicPii18n(ROOT_PATH); + this->sonicPii18n = new SonicPii18n(rootPath()); this->ui_language = sonicPii18n->determineUILanguage(piSettings->language); std::cout << "Using language: " << ui_language.toUtf8().constData() << std::endl; this->i18n = sonicPii18n->loadTranslations(ui_language); @@ -229,7 +228,7 @@ MainWindow::MainWindow(QApplication& app, QSplashScreen* splash) // The implementation of this method is dynamically generated and can // be found in ruby_help.h: std::cout << "[GUI] - initialising documentation window" << std::endl; - initDocsWindow(ui_language); + initDocsWindow(); //setup autocompletion autocomplete->loadSamples(sample_path); @@ -378,9 +377,23 @@ bool MainWindow::initAndCheckPorts() } #endif +QString MainWindow::rootPath() +{ + // diversity is the spice of life +#if defined(Q_OS_MAC) + return QCoreApplication::applicationDirPath() + "/../Resources"; +#elif defined(Q_OS_WIN) + // CMake builds, the exe is in build/debug/sonic-pi, etc. + // We should pass this to the build instead of wiring it up this way! + return QCoreApplication::applicationDirPath() + "/../../../../.."; +#else + // On linux, CMake builds app into the build folder + return QCoreApplication::applicationDirPath() + "/../../../.."; +#endif +} void MainWindow::initPaths() { - QString root_path = ROOT_PATH; + QString root_path = rootPath(); #ifdef QT_OLD_API #if defined(Q_OS_WIN) @@ -544,7 +557,7 @@ void MainWindow::setupTheme() { // Syntax highlighting QString themeFilename = QDir::homePath() + QDir::separator() + ".sonic-pi" + QDir::separator() + "config" + QDir::separator() + "colour-theme.properties"; - this->theme = new SonicPiTheme(this, themeFilename, ROOT_PATH); + this->theme = new SonicPiTheme(this, themeFilename, rootPath()); } void MainWindow::setupWindowStructure() @@ -1326,7 +1339,7 @@ void MainWindow::startRubyServer() // Register server pid for potential zombie clearing QStringList regServerArgs; #if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) - regServerArgs << QDir::toNativeSeparators(ROOT_PATH + "/app/server/ruby/bin/task-register.rb")<< QString::number(serverProcess->processId()); + regServerArgs << QDir::toNativeSeparators(rootPath() + "/app/server/ruby/bin/task-register.rb")<< QString::number(serverProcess->processId()); #endif QProcess* regServerProcess = new QProcess(); regServerProcess->start(ruby_path, regServerArgs); @@ -3773,8 +3786,15 @@ void MainWindow::restartApp() { //this->hide(); // So it doesn't look like the app's frozen or crashed sleep(4); // Allow cleanup to complete // Create new process + QStringList args = qApp->arguments(); + args.removeFirst(); QProcess process; - process.startDetached("sonic-pi", QStringList()); + bool restart_success = process.startDetached(qApp->arguments()[0], args); + if (restart_success) { + std::cout << "Successfully restarted sonic-pi" << std::endl; + } else { + std::cout << "Failed to restart sonic-pi" << std::endl; + } // Quit app->exit(0); exit(0); @@ -4358,4 +4378,3 @@ SonicPiTheme* MainWindow::GetTheme() const { return theme; } - diff --git a/app/gui/qt/mainwindow.h b/app/gui/qt/mainwindow.h index ccf8c059dd..2100fbc699 100644 --- a/app/gui/qt/mainwindow.h +++ b/app/gui/qt/mainwindow.h @@ -307,6 +307,7 @@ class MainWindow : public QMainWindow private: void initPaths(); + QString rootPath(); QString osDescription(); QSignalMapper *signalMapper; #ifdef QT_OLD_API @@ -334,7 +335,7 @@ class MainWindow : public QMainWindow std::string number_name(int); std::string workspaceFilename(SonicPiScintilla* text); SonicPiScintilla* filenameToWorkspace(std::string filename); - + bool sendOSC(oscpkt::Message m); // void initPrefsWindow(); @@ -363,7 +364,6 @@ class MainWindow : public QMainWindow QString tooltipStrShiftMeta(char key, QString str); QString tooltipStrMeta(char key, QString str); QString readFile(QString name); - QString rootPath(); void addUniversalCopyShortcuts(QTextEdit *te); void updateTranslatedUIText(); diff --git a/app/gui/qt/utils/paths.h b/app/gui/qt/utils/paths.h deleted file mode 100644 index fa4aef9210..0000000000 --- a/app/gui/qt/utils/paths.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef PATHS_H -#define PATHS_H - // diversity is the spice of life - #if defined(Q_OS_MAC) - #define ROOT_PATH QCoreApplication::applicationDirPath() + "/../Resources" - #elif defined(Q_OS_WIN) - // CMake builds, the exe is in build/debug/sonic-pi, etc. - // We should pass this to the build instead of wiring it up this way! - #define ROOT_PATH QCoreApplication::applicationDirPath() + "/../../../../.." - #else - // On linux, CMake builds app into the build folder - #define ROOT_PATH QCoreApplication::applicationDirPath() + "/../../../.." - #endif -#endif diff --git a/app/gui/qt/utils/sonic_pi_i18n.cpp b/app/gui/qt/utils/sonic_pi_i18n.cpp index 76d1a62a17..2a256adf88 100644 --- a/app/gui/qt/utils/sonic_pi_i18n.cpp +++ b/app/gui/qt/utils/sonic_pi_i18n.cpp @@ -36,7 +36,7 @@ SonicPii18n::~SonicPii18n() { QString SonicPii18n::determineUILanguage(QString lang_pref) { QStringList available_languages = getAvailableLanguages(); - std::cout << available_languages.join("\n").toUtf8().constData() << std::endl; + //std::cout << available_languages.join("\n").toUtf8().constData() << std::endl; QLocale locale; if (lang_pref != "system_locale") { @@ -63,14 +63,14 @@ QString SonicPii18n::determineUILanguage(QString lang_pref) { l = preferred_languages[i]; l.replace("-", "_"); - std::cout << preferred_languages[i].toUtf8().constData() << std::endl; + //std::cout << preferred_languages[i].toUtf8().constData() << std::endl; if (available_languages.contains(l)) { return l; } } } - // Fpreferred_languages[i]preferred_languages[i]preferred_languages[i]allback to English + // Fallback to English this->system_language_available = false; return "en"; } @@ -91,7 +91,7 @@ QStringList SonicPii18n::findAvailableLanguages() { locale.truncate(locale.lastIndexOf('.')); // "sonic-pi_pt_BR" locale.remove(0, locale.lastIndexOf("sonic-pi_") + 9); // "pt_BR" //locale.replace("_", "-"); // Replace underscores with dashes so it matches the language codes e.g: "pt-BR" - std::cout << locale.toUtf8().constData() << '\n'; + //std::cout << locale.toUtf8().constData() << '\n'; languages << locale; } // Add the source language