2021-03-26 16:10:26 -07:00
|
|
|
/*
|
|
|
|
InkBox: Open-source Qt-based eBook reader
|
2023-01-01 09:40:31 -08:00
|
|
|
Copyright (C) 2021-2023 Nicolas Mailloux <nicolecrivain@gmail.com>
|
2021-03-26 16:10:26 -07:00
|
|
|
SPDX-License-Identifier: GPL-3.0-only
|
2021-04-29 20:36:25 -07:00
|
|
|
|
2021-03-26 16:10:26 -07:00
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation.
|
2021-04-29 20:36:25 -07:00
|
|
|
|
2021-03-26 16:10:26 -07:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-03-25 05:00:19 -07:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "alert.h"
|
2021-04-01 05:58:37 -07:00
|
|
|
#include "generaldialog.h"
|
2021-04-05 06:50:58 -07:00
|
|
|
#include "functions.h"
|
2021-04-05 12:35:25 -07:00
|
|
|
#include "reader.h"
|
2021-10-08 20:37:32 -07:00
|
|
|
#include "encryptionmanager.h"
|
2022-07-25 21:29:13 -07:00
|
|
|
#include "sleepthread.h"
|
|
|
|
#include "sleepdialog.h"
|
2021-04-23 05:47:05 -07:00
|
|
|
|
2021-03-25 05:00:19 -07:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QTextStream>
|
2021-03-26 15:53:02 -07:00
|
|
|
#include <QRect>
|
|
|
|
#include <QScreen>
|
2022-07-19 09:03:58 -07:00
|
|
|
#include <QTextCodec>
|
2021-03-25 05:00:19 -07:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2022-07-19 09:03:58 -07:00
|
|
|
QApplication a(argc, argv);
|
|
|
|
QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf8"));
|
|
|
|
|
2022-04-04 21:47:15 -07:00
|
|
|
if(char * debug = std::getenv("DEBUG")) {
|
|
|
|
if(std::atoi(debug) == 1) {
|
|
|
|
global::logger::status = true;
|
|
|
|
}
|
|
|
|
}
|
2022-08-15 12:10:32 -07:00
|
|
|
|
2022-04-06 20:24:16 -07:00
|
|
|
global::deviceID = readFile("/opt/inkbox_device");
|
2022-04-16 20:20:24 -07:00
|
|
|
log("Running on device " + global::deviceID, "main", true);
|
2022-04-04 21:47:15 -07:00
|
|
|
|
2022-06-20 09:57:55 -07:00
|
|
|
// Tell the OS that we're currently running
|
|
|
|
string_writeconfig("/tmp/inkbox_running", "true");
|
|
|
|
|
2021-10-08 20:37:32 -07:00
|
|
|
setDefaultWorkDir();
|
2022-04-16 16:40:30 -07:00
|
|
|
if(checkconfig("/run/wifi_able") == true) {
|
|
|
|
log("Device has Wi-Fi capabilities", "main");
|
|
|
|
global::device::isWifiAble = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
log("Device does not have Wi-Fi capabilities", "main");
|
|
|
|
global::device::isWifiAble = false;
|
|
|
|
}
|
2022-06-18 06:26:52 -07:00
|
|
|
|
2022-07-26 20:09:12 -07:00
|
|
|
if(QFile::exists("/tmp/currentlyRunningUserApplication")) {
|
|
|
|
QFile::remove("/tmp/currentlyRunningUserApplication");
|
|
|
|
}
|
|
|
|
|
2022-06-18 06:26:52 -07:00
|
|
|
if(QFile::exists("/tmp/rescan_userapps")) {
|
|
|
|
QFile::remove("/tmp/rescan_userapps");
|
|
|
|
log("Re-scanning user applications from explicit request", "main");
|
2022-06-20 09:57:55 -07:00
|
|
|
string_writeconfig("/opt/ibxd", "gui_apps_stop\n");
|
|
|
|
QThread::msleep(1000);
|
|
|
|
string_writeconfig("/opt/ibxd", "gui_apps_start\n");
|
|
|
|
while(true) {
|
|
|
|
if(QFile::exists("/tmp/gui_apps_started")) {
|
|
|
|
if(checkconfig("/tmp/gui_apps_started") == true) {
|
2022-06-20 15:12:20 -07:00
|
|
|
log("GUI apps service started successfully", "main");
|
2022-06-20 09:57:55 -07:00
|
|
|
QFile::remove("/tmp/gui_apps_started");
|
|
|
|
updateUserAppsMainJsonFile();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
log("GUI apps service failed to start", "main");
|
|
|
|
QFile::remove("/tmp/gui_apps_started");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-18 06:26:52 -07:00
|
|
|
updateUserAppsMainJsonFile();
|
|
|
|
}
|
|
|
|
|
2022-07-25 21:29:13 -07:00
|
|
|
// Power daemon-related stuff
|
|
|
|
sleepDialog * sleepDialogWindow = new sleepDialog;
|
|
|
|
// https://wiki.qt.io/QThreads_general_usage
|
|
|
|
QThread * IPDThread = new QThread();
|
|
|
|
sleepThread * sleepThreadWindow = new sleepThread();
|
|
|
|
sleepThreadWindow->moveToThread(IPDThread);
|
|
|
|
QObject::connect(IPDThread, &QThread::started, sleepThreadWindow, &sleepThread::start);
|
|
|
|
QObject::connect(sleepThreadWindow, &sleepThread::startDialog, sleepDialogWindow, &sleepDialog::launchSleepDialog);
|
|
|
|
QObject::connect(sleepThreadWindow, &sleepThread::stopDialog, sleepDialogWindow, &sleepDialog::hideSleepDialog);
|
|
|
|
IPDThread->start();
|
|
|
|
|
2021-10-10 09:53:24 -07:00
|
|
|
if(checkconfig(".config/18-encrypted_storage/status") == true and checkconfig("/external_root/run/encfs_mounted") == false) {
|
2021-10-08 20:37:32 -07:00
|
|
|
// Open Encryption Manager to unlock encrypted storage
|
|
|
|
encryptionManager w;
|
2021-09-05 08:47:09 -07:00
|
|
|
const QScreen * screen = qApp->primaryScreen();
|
2021-11-14 19:23:09 -08:00
|
|
|
w.setGeometry(QRect(QPoint(0,0), screen->geometry().size()));
|
|
|
|
w.show();
|
|
|
|
return a.exec();
|
|
|
|
}
|
|
|
|
else if(checkconfig("/external_root/run/encfs_mounted") == true and checkconfig("/external_root/run/encfs_repack") == true) {
|
2022-04-15 17:27:58 -07:00
|
|
|
log("Launching encryptionManager", "main");
|
2021-11-14 19:23:09 -08:00
|
|
|
encryptionManager w;
|
|
|
|
const QScreen * screen = qApp->primaryScreen();
|
2021-04-05 12:35:25 -07:00
|
|
|
w.setGeometry(QRect(QPoint(0,0), screen->geometry().size()));
|
|
|
|
w.show();
|
|
|
|
return a.exec();
|
|
|
|
}
|
2021-10-08 20:37:32 -07:00
|
|
|
else {
|
|
|
|
// Variables
|
|
|
|
global::reader::startBatteryWatchdog = false;
|
|
|
|
global::reader::startUsbmsPrompt = false;
|
|
|
|
|
|
|
|
// Checking if battery level is critical; if true (and if it is not charging), then display a "Please charge your eReader" splash and power off.
|
2022-04-02 13:49:18 -07:00
|
|
|
if(global::deviceID != "emu\n") {
|
2021-12-21 19:27:10 -08:00
|
|
|
if(isBatteryCritical() == true) {
|
2022-06-07 11:10:06 -07:00
|
|
|
if(!isUsbPluggedIn()) {
|
2021-12-21 19:27:10 -08:00
|
|
|
global::battery::showCriticalBatteryAlert = true;
|
|
|
|
alert w;
|
2021-10-08 20:37:32 -07:00
|
|
|
|
2022-08-01 20:14:33 -07:00
|
|
|
const QScreen * screen = qApp->primaryScreen();
|
2021-12-21 19:27:10 -08:00
|
|
|
w.setGeometry(QRect(QPoint(0,0), screen->geometry().size()));
|
|
|
|
w.show();
|
|
|
|
return a.exec();
|
|
|
|
}
|
2021-10-08 20:37:32 -07:00
|
|
|
}
|
2021-06-26 07:09:51 -07:00
|
|
|
}
|
2021-10-08 20:37:32 -07:00
|
|
|
|
|
|
|
// Checking if there has been an ALERT flag set up, and if there is, show a big warning
|
|
|
|
if(checkconfig("/external_root/boot/flags/ALERT") == true) {
|
|
|
|
alert w;
|
|
|
|
|
|
|
|
const QScreen * screen = qApp->primaryScreen();
|
|
|
|
w.setGeometry(QRect(QPoint(0,0), screen->geometry().size()));
|
|
|
|
w.show();
|
|
|
|
return a.exec();
|
2021-06-26 07:09:51 -07:00
|
|
|
}
|
2021-10-08 20:37:32 -07:00
|
|
|
// If we're waking from sleep and we have the lockscreen enabled, we'll "resume" the book from scratch
|
|
|
|
else if(checkconfig("/tmp/suspendBook") == true && checkconfig("/inkbox/bookIsEpub") == false) {
|
|
|
|
// Start the low/critical battery alert timer from the Reader framework since MainWindow is not going to be shown
|
|
|
|
global::runningInstanceIsReaderOnly = true;
|
|
|
|
global::reader::startBatteryWatchdog = true;
|
|
|
|
global::reader::startUsbmsPrompt = true;
|
|
|
|
global::reader::skipOpenDialog = true;
|
|
|
|
|
|
|
|
string_writeconfig("/inkbox/skip_opendialog", "true");
|
2022-04-02 13:49:18 -07:00
|
|
|
if(global::deviceID == "n705\n") {
|
2021-10-08 20:37:32 -07:00
|
|
|
global::isN705 = true;
|
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
else if(global::deviceID == "n905\n") {
|
2021-10-08 20:37:32 -07:00
|
|
|
global::isN905C = true;
|
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
else if(global::deviceID == "n613\n") {
|
2021-10-08 20:37:32 -07:00
|
|
|
global::isN613 = true;
|
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
else if(global::deviceID == "n873\n") {
|
2021-10-08 20:37:32 -07:00
|
|
|
global::isN873 = true;
|
2022-01-27 12:16:48 -08:00
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
else if(global::deviceID == "n236\n") {
|
2022-01-27 12:16:48 -08:00
|
|
|
global::isN236 = true;
|
2022-02-06 19:49:06 -08:00
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
else if(global::deviceID == "n437\n") {
|
2022-02-06 19:49:06 -08:00
|
|
|
global::isN437 = true;
|
2022-02-19 16:21:09 -08:00
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
else if(global::deviceID == "n306\n") {
|
2022-02-19 16:21:09 -08:00
|
|
|
global::isN306 = true;
|
2021-10-08 20:37:32 -07:00
|
|
|
}
|
2022-05-22 12:38:02 -07:00
|
|
|
else if(global::deviceID == "kt\n") {
|
|
|
|
global::isKT = true;
|
|
|
|
}
|
2021-10-08 20:37:32 -07:00
|
|
|
else {
|
|
|
|
;
|
|
|
|
}
|
2021-06-26 07:09:51 -07:00
|
|
|
|
2021-10-08 20:37:32 -07:00
|
|
|
reader w;
|
2021-04-05 12:35:25 -07:00
|
|
|
|
2021-10-08 20:37:32 -07:00
|
|
|
const QScreen* screen = qApp->primaryScreen();
|
|
|
|
w.setGeometry(QRect(QPoint(0,0), screen->geometry().size()));
|
|
|
|
w.show();
|
|
|
|
return a.exec();
|
2021-04-23 05:47:05 -07:00
|
|
|
|
2021-06-29 09:26:30 -07:00
|
|
|
}
|
|
|
|
else {
|
2022-03-06 16:48:32 -08:00
|
|
|
QProcess::execute("remount_tmpfs_launch.sh", QStringList());
|
2021-06-29 09:26:30 -07:00
|
|
|
|
2021-10-08 20:37:32 -07:00
|
|
|
MainWindow w;
|
|
|
|
|
|
|
|
QApplication::setStyle("windows");
|
2022-04-03 20:26:15 -07:00
|
|
|
QFile stylesheetFile("/mnt/onboard/.adds/inkbox/eink.qss");
|
2021-10-08 20:37:32 -07:00
|
|
|
stylesheetFile.open(QFile::ReadOnly);
|
|
|
|
w.setStyleSheet(stylesheetFile.readAll());
|
|
|
|
stylesheetFile.close();
|
|
|
|
|
2022-04-02 13:49:18 -07:00
|
|
|
if(global::deviceID == "n705\n") {
|
2021-10-08 20:37:32 -07:00
|
|
|
global::isN705 = true;
|
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
else if(global::deviceID == "n905\n") {
|
2021-10-08 20:37:32 -07:00
|
|
|
global::isN905C = true;
|
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
else if(global::deviceID == "n613\n") {
|
2021-10-08 20:37:32 -07:00
|
|
|
global::isN613 = true;
|
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
else if(global::deviceID == "n873\n") {
|
2021-10-08 20:37:32 -07:00
|
|
|
global::isN873 = true;
|
2022-01-27 12:16:48 -08:00
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
else if(global::deviceID == "n236\n") {
|
2022-01-27 12:16:48 -08:00
|
|
|
global::isN236 = true;
|
2022-02-06 19:49:06 -08:00
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
else if(global::deviceID == "n437\n") {
|
2022-02-06 19:49:06 -08:00
|
|
|
global::isN437 = true;
|
2022-02-19 16:21:09 -08:00
|
|
|
}
|
2022-04-02 13:49:18 -07:00
|
|
|
else if(global::deviceID == "n306\n") {
|
2022-02-19 16:21:09 -08:00
|
|
|
global::isN306 = true;
|
2021-10-08 20:37:32 -07:00
|
|
|
}
|
2022-05-22 12:38:02 -07:00
|
|
|
else if(global::deviceID == "kt\n") {
|
|
|
|
global::isKT = true;
|
|
|
|
}
|
2021-10-08 20:37:32 -07:00
|
|
|
else {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QScreen * screen = qApp->primaryScreen();
|
2022-08-15 12:10:32 -07:00
|
|
|
w.setGeometry(QRect(QPoint(0,0), screen->geometry().size()));
|
2021-10-08 20:37:32 -07:00
|
|
|
w.show();
|
|
|
|
return a.exec();
|
2021-06-26 07:09:51 -07:00
|
|
|
}
|
2021-03-25 05:00:19 -07:00
|
|
|
}
|
|
|
|
}
|