From a217545fd6f12f5de5f4a19ba7afed1dbabed811 Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Sun, 26 Sep 2021 16:46:25 -0400 Subject: [PATCH] Speed up post-USBMS: no more reboots! --- mainwindow.cpp | 24 ++++++++++++--------- mainwindow.h | 1 + usbms_splash.cpp | 56 +++++++++++++++++++++++++++++------------------- usbms_splash.h | 1 + 4 files changed, 50 insertions(+), 32 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index e783750..82c4f33 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -496,16 +496,7 @@ MainWindow::MainWindow(QWidget *parent) } // Check for an update and ask if the user wants to install it - if(checkconfig("/mnt/onboard/onboard/.inkbox/can_update") == true) { - if(checkconfig("/tmp/cancelUpdateDialog") == false) { - // I'm sorry. - qDebug() << "An update is available."; - QTimer::singleShot(2000, this, SLOT(openUpdateDialog())); - } - else { - qDebug() << "Not showing update dialog, user dismissed it..."; - } - } + checkForUpdate(); // Check if it's the first boot since an update and confirm that it installed successfully if(checkconfig("/opt/inkbox_genuine") == true) { @@ -1010,3 +1001,16 @@ void MainWindow::openReaderFramework() { connect(readerWindow, SIGNAL(openBookFile(QString, bool)), SLOT(openBookFile(QString, bool))); readerWindow->showFullScreen(); } + +void MainWindow::checkForUpdate() { + if(checkconfig("/mnt/onboard/onboard/.inkbox/can_update") == true) { + if(checkconfig("/tmp/cancelUpdateDialog") == false) { + // I'm sorry. + qDebug() << "An update is available."; + QTimer::singleShot(2000, this, SLOT(openUpdateDialog())); + } + else { + qDebug() << "Not showing update dialog, user dismissed it..."; + } + } +} diff --git a/mainwindow.h b/mainwindow.h index b6c5414..7185fcd 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -87,6 +87,7 @@ private slots: void launchOtaUpdater(); void openBookFile(QString book, bool relativePath); void openReaderFramework(); + void checkForUpdate(); private: Ui::MainWindow *ui; diff --git a/usbms_splash.cpp b/usbms_splash.cpp index 3f6b428..30e98f0 100644 --- a/usbms_splash.cpp +++ b/usbms_splash.cpp @@ -67,26 +67,16 @@ void usbms_splash::usbms_launch() string_writeconfig("/tmp/in_usbms", "true"); QTimer::singleShot(1500, this, SLOT(brightnessDown())); - QString umount_prog ("umount"); - QStringList umount_args; if(global::usbms::koboxExportExtensions == true) { - umount_args << "/dev/loop10"; + string_writeconfig("/opt/ibxd", "kobox_extensions_storage_unmount\n"); } else { - umount_args << "/dev/loop0"; + string_writeconfig("/opt/ibxd", "onboard_unmount\n"); } - QProcess *umount_proc = new QProcess(); - umount_proc->start(umount_prog, umount_args); - umount_proc->waitForFinished(); - umount_proc->deleteLater(); + QThread::msleep(500); - QString rmmod ("rmmod"); - QStringList rmmod_args; - rmmod_args << "g_ether.ko"; - QProcess *rmmod_proc = new QProcess(); - rmmod_proc->start(rmmod, rmmod_args); - rmmod_proc->waitForFinished(); - rmmod_proc->deleteLater(); + string_writeconfig("/opt/ibxd", "usbnet_stop\n"); + QThread::msleep(200); QString prog ("insmod"); QStringList args; @@ -128,13 +118,25 @@ void usbms_splash::usbms_launch() std::string contentstr = content.toStdString(); modules.close(); if(contentstr.find("1") != std::string::npos) { - QString reboot_prog ("/sbin/reboot"); - QStringList reboot_args; - reboot_args << "no_splash"; - QProcess *reboot_proc = new QProcess(); - reboot_proc->start(reboot_prog, reboot_args); - reboot_proc->waitForFinished(); - reboot_proc->deleteLater(); + if(global::usbms::koboxExportExtensions == true) { + reboot(false); + } + else { + QString prog("rmmod"); + QStringList args; + args << "g_mass_storage"; + QProcess * proc = new QProcess(); + proc->start(prog, args); + proc->waitForFinished(); + proc->deleteLater(); + + // NOTE: USBNet is only started if required conditions are met (see https://github.com/Kobo-InkBox/rootfs/blob/master/etc/init.d/usbnet.sh) + string_writeconfig("/opt/ibxd", "usbnet_start\n"); + string_writeconfig("/opt/ibxd", "onboard_mount\n"); + QThread::msleep(500); + + quit_restart(); + } } else { ; @@ -151,3 +153,13 @@ usbms_splash::~usbms_splash() void usbms_splash::brightnessDown() { cinematicBrightness(0, 1); } + +void usbms_splash::quit_restart() { + // If existing, cleaning bookconfig_mount mountpoint + string_writeconfig("/opt/ibxd", "bookconfig_unmount\n"); + + // Restarting InkBox + QProcess process; + process.startDetached("inkbox", QStringList()); + qApp->quit(); +} diff --git a/usbms_splash.h b/usbms_splash.h index 3f3d5e4..75fd48d 100644 --- a/usbms_splash.h +++ b/usbms_splash.h @@ -19,6 +19,7 @@ public: private slots: void brightnessDown(); + void quit_restart(); private: Ui::usbms_splash *ui;