aboutsummaryrefslogtreecommitdiff
path: root/src/qt/TailsOS.cpp
diff options
context:
space:
mode:
authordsc <xmrdsc@protonmail.com>2019-07-03 05:13:51 +0200
committerdsc <xmrdsc@protonmail.com>2019-07-16 18:33:44 +0200
commit0b6132897101c4cd1618c79049d5685c5e9874fa (patch)
treee59e9bf4eaff9296b9c10a9d9a7207b565a2ae1c /src/qt/TailsOS.cpp
parentcfec9dde968cb89f8fe5293958b82181348111ea (diff)
downloadmonzero-gui-0b6132897101c4cd1618c79049d5685c5e9874fa.tar.gz
monzero-gui-0b6132897101c4cd1618c79049d5685c5e9874fa.tar.xz
monzero-gui-0b6132897101c4cd1618c79049d5685c5e9874fa.zip
Detect tails, support data persistence
Co-authored-by: Thotbot <thotbot@protonmail.com> Co-authored-by: Selsta <selsta@sent.at>
Diffstat (limited to 'src/qt/TailsOS.cpp')
-rw-r--r--src/qt/TailsOS.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/qt/TailsOS.cpp b/src/qt/TailsOS.cpp
new file mode 100644
index 00000000..df2fa92b
--- /dev/null
+++ b/src/qt/TailsOS.cpp
@@ -0,0 +1,100 @@
+#include <QRegExp>
+#include <QMessageBox>
+#include <QPixmap>
+#include <QTranslator>
+
+#include "TailsOS.h"
+#include "utils.h"
+
+bool TailsOS::usePersistence = false;
+QString TailsOS::tailsPathData = QString("/live/persistence/TailsData_unlocked/");
+
+bool TailsOS::detect()
+{
+ if (!fileExists("/etc/os-release"))
+ return false;
+
+ QByteArray data = fileOpen("/etc/os-release");
+ QRegularExpression re("TAILS_PRODUCT_NAME=\"Tails\"");
+ QRegularExpressionMatch os_match = re.match(data);
+ bool matched = os_match.hasMatch();
+
+#ifdef QT_DEBUG
+ if (matched)
+ qDebug() << "Tails OS detected";
+#endif
+
+ return matched;
+}
+
+bool TailsOS::detectDataPersistence()
+{
+ return QDir(QDir::homePath() + "/Persistent").exists();
+}
+
+bool TailsOS::detectDotPersistence()
+{
+ return QDir(tailsPathData + "dotfiles").exists();
+}
+
+void TailsOS::showDataPersistenceDisabledWarning()
+{
+ QMessageBox msgBox;
+ msgBox.setText(QObject::tr("Warning: persistence disabled"));
+ msgBox.setWindowTitle(QObject::tr("Warning: persistence disabled"));
+ msgBox.setInformativeText(
+ QObject::tr("Monero GUI has detected that Tails persistence is "
+ "currently disabled. Any configurations you make inside "
+ "the Monero GUI will not be saved."
+ "\n\n"
+ "In addition, make sure to not save your wallet on the "
+ "filesystem, as it will be lost at shutdown."
+ "\n\n"
+ "To enable Tails persistence, setup an encrypted volume "
+ "and restart Tails. To gain a startup menu item, "
+ "enable the Tails \"dotfiles\" feature."));
+
+ msgBox.setStandardButtons(QMessageBox::Ok);
+ msgBox.setDefaultButton(QMessageBox::Ok);
+ msgBox.setIconPixmap(QPixmap(":/images/tails-grey.png"));
+ msgBox.exec();
+}
+
+void TailsOS::askPersistence()
+{
+ QMessageBox msgBox;
+ msgBox.setWindowTitle(QObject::tr("Monero GUI"));
+ msgBox.setText(QObject::tr("Use Tails persistence?"));
+ msgBox.setInformativeText(
+ QObject::tr("Persist wallet files and configuration on the encrypted volume?"
+ "\n\n"
+ "In addition, you can enable Tails dotfiles persistence "
+ "to gain a start menu entry.\n"));
+
+ msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+ msgBox.setDefaultButton(QMessageBox::Yes);
+ msgBox.setIconPixmap(QPixmap(":/images/tails-grey.png"));
+ TailsOS::usePersistence = (msgBox.exec() == QMessageBox::Yes);
+}
+
+void TailsOS::persistXdgMime(QString filePath, QString data)
+{
+ QFileInfo file(filePath);
+ QString tailsPath = tailsPathData + "dotfiles/.local/share/applications/";
+
+ // write to persistent volume
+#ifdef QT_DEBUG
+ qDebug() << "Writing xdg mime: " << tailsPath + file.fileName();
+#endif
+
+ QDir().mkpath(tailsPath); // ensure directory exists
+ fileWrite(tailsPath + file.fileName(), data);
+
+ // write to current session
+#ifdef QT_DEBUG
+ qDebug() << "Writing xdg mime: " << file.filePath();
+#endif
+
+ QDir().mkpath(file.path()); // ensure directory exists
+ fileWrite(file.filePath(), data);
+}