Skip to content

Commit

Permalink
Add option to delete everything
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed Sep 26, 2022
1 parent f7c9528 commit b661c3a
Show file tree
Hide file tree
Showing 10 changed files with 327 additions and 18 deletions.
3 changes: 3 additions & 0 deletions harbour-bitsailor.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ SOURCES += src/harbour-bitsailor.cpp \
src/appsettings.cpp \
src/bitwardencli.cpp \
src/bitwardencliinstaller.cpp \
src/fileaccessor.cpp \
src/pathhelper.cpp \
src/runtimecache.cpp \
src/secretshandler.cpp \
Expand All @@ -36,6 +37,7 @@ DISTFILES += qml/harbour-bitsailor.qml \
qml/components/Toaster.qml \
qml/cover/CoverPage.qml \
qml/helpers.js \
qml/pages/CleanupPage.qml \
qml/pages/ConfirmSettingPage.qml \
qml/pages/InstallBitwardenCliPage.qml \
qml/pages/ItemDetailPage.qml \
Expand Down Expand Up @@ -73,6 +75,7 @@ HEADERS += \
src/appsettings.h \
src/bitwardencli.h \
src/bitwardencliinstaller.h \
src/fileaccessor.h \
src/pathhelper.h \
src/runtimecache.h \
src/secretshandler.h \
Expand Down
106 changes: 106 additions & 0 deletions qml/pages/CleanupPage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import QtQuick 2.0
import Sailfish.Silica 1.0

import cz.chrastecky.bitsailor 1.0

Page {
property var secretsCleared: null
property var loggedOut: null
property var temporaryFilesDeleted: null
property var permanentFilesDeleted: null
property var configFilesDeleted: null

id: page
allowedOrientations: Orientation.All

BitwardenCli {
id: cli
onLogoutFinished: {
loggedOut = true;
secretsCleared = true;
}
}

SecretsHandler {
id: secrets
}

FileAccessor {
id: fileAccessor
}

SilicaFlickable {
anchors.fill: parent
contentHeight: column.height

Column {
id: column

width: page.width
spacing: Theme.paddingLarge
PageHeader {
title: qsTr("Cleaning Up")
}

IconTextSwitch {
property alias propertyToCheck: page.secretsCleared
property string iconName: propertyToCheck === null ? "icon-m-clock" : propertyToCheck ? "icon-m-certificates" : "icon-m-cancel"
icon.source: "image://theme/" + iconName
icon.color: propertyToCheck === null ? Theme.primaryColor : propertyToCheck ? Theme.secondaryHighlightColor : Theme.errorColor
text: qsTr("Deleted all secrets")
automaticCheck: false
checked: propertyToCheck
description: qsTr("Includes secrets like your password, username or PIN code.")
}
IconTextSwitch {
property alias propertyToCheck: page.loggedOut
property string iconName: propertyToCheck === null ? "icon-m-clock" : propertyToCheck ? "icon-m-certificates" : "icon-m-cancel"
icon.source: "image://theme/" + iconName
icon.color: propertyToCheck === null ? Theme.primaryColor : propertyToCheck ? Theme.secondaryHighlightColor : Theme.errorColor
text: qsTr("Logged out of Bitwarden CLI")
automaticCheck: false
checked: propertyToCheck
description: qsTr("The Bitwarden CLI could be used on its own even without this app, that's why it's safer to log out.")
}
IconTextSwitch {
property alias propertyToCheck: page.temporaryFilesDeleted
property string iconName: propertyToCheck === null ? "icon-m-clock" : propertyToCheck ? "icon-m-certificates" : "icon-m-cancel"
icon.source: "image://theme/" + iconName
icon.color: propertyToCheck === null ? Theme.primaryColor : propertyToCheck ? Theme.secondaryHighlightColor : Theme.errorColor
text: qsTr("Deleted temporary files")
automaticCheck: false
checked: propertyToCheck
description: qsTr("Temporary files include your cached vault for faster loading.")
}
IconTextSwitch {
property alias propertyToCheck: page.permanentFilesDeleted
property string iconName: propertyToCheck === null ? "icon-m-clock" : propertyToCheck ? "icon-m-certificates" : "icon-m-cancel"
icon.source: "image://theme/" + iconName
icon.color: propertyToCheck === null ? Theme.primaryColor : propertyToCheck ? Theme.secondaryHighlightColor : Theme.errorColor
text: qsTr("Deleted all permanent files")
automaticCheck: false
checked: propertyToCheck
description: qsTr("Permanent files include Bitwarden CLI (if it was installed using this app).")
}
IconTextSwitch {
property alias propertyToCheck: page.configFilesDeleted
property string iconName: propertyToCheck === null ? "icon-m-clock" : propertyToCheck ? "icon-m-certificates" : "icon-m-cancel"
icon.source: "image://theme/" + iconName
icon.color: propertyToCheck === null ? Theme.primaryColor : propertyToCheck ? Theme.secondaryHighlightColor : Theme.errorColor
text: qsTr("Deleted all config files")
automaticCheck: false
checked: propertyToCheck
description: qsTr("Config files include all the settings you have made in this app.")
}
}
}

onStatusChanged: {
if (status === PageStatus.Active) {
cli.logout();
temporaryFilesDeleted = fileAccessor.deleteTemporaryFilesDirectory();
permanentFilesDeleted = fileAccessor.deletePermanentFilesDirectory();
configFilesDeleted = fileAccessor.deleteConfigDirectory();
}
}
}
26 changes: 25 additions & 1 deletion qml/pages/SettingsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Page {
property string errorText
property string authCheckType

property var doAfterLoad: []


id: page
allowedOrientations: Orientation.All
Expand Down Expand Up @@ -55,6 +57,22 @@ Page {
contentHeight: column.height
visible: !busyIndicator.running

PushUpMenu {
MenuItem {
text: qsTr("Clean Up Everything");
onClicked: {
const dialog = pageStack.push("ConfirmSettingPage.qml", {
description: qsTr("This will delete everything that this app stores on your system, including system secrets collection, Bitwarden CLI (if it was installed via this app), temporary files etc. Bitwarden CLI will also be logged out. Do you wish to continue?")
});
dialog.accepted.connect(function() {
doAfterLoad.push(function() {
pageStack.replace("CleanupPage.qml");
});
});
}
}
}

Column {
id: column

Expand Down Expand Up @@ -228,6 +246,12 @@ Page {
}
}

Component.onCompleted: {
onStatusChanged: {
if (status == PageStatus.Active) {
while (doAfterLoad.length) {
const callable = doAfterLoad.shift();
callable();
}
}
}
}
3 changes: 2 additions & 1 deletion rpm/harbour-bitsailor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ Requires:
- sailfishsilica-qt5 >= 0.10.9
- sailfishsecretsdaemon-secretsplugins-default
- sailfish-polkit-agent
- nodejs >= 18
- nodejs
- npm

# All installed files
Files:
Expand Down
32 changes: 32 additions & 0 deletions src/fileaccessor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "fileaccessor.h"

#include "pathhelper.h"

#include <QDir>
#include <QStandardPaths>

FileAccessor::FileAccessor(QObject *parent) : QObject(parent)
{

}

bool FileAccessor::deleteConfigDirectory()
{
return deleteDirectory(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
}

bool FileAccessor::deleteTemporaryFilesDirectory()
{
return deleteDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
}

bool FileAccessor::deletePermanentFilesDirectory()
{
return deleteDirectory(getDataPath());
}

bool FileAccessor::deleteDirectory(QString path)
{
QDir dir(path);
return dir.removeRecursively();
}
18 changes: 18 additions & 0 deletions src/fileaccessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef FILEACCESSOR_H
#define FILEACCESSOR_H

#include <QObject>

class FileAccessor : public QObject
{
Q_OBJECT
public:
explicit FileAccessor(QObject *parent = nullptr);
Q_INVOKABLE bool deleteConfigDirectory();
Q_INVOKABLE bool deleteTemporaryFilesDirectory();
Q_INVOKABLE bool deletePermanentFilesDirectory();
private:
bool deleteDirectory(QString path);
};

#endif // FILEACCESSOR_H
2 changes: 2 additions & 0 deletions src/harbour-bitsailor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "appsettings.h"
#include "runtimecache.h"
#include "systemauthchecker.h"
#include "fileaccessor.h"

int main(int argc, char *argv[])
{
Expand All @@ -28,6 +29,7 @@ int main(int argc, char *argv[])
qmlRegisterType<BitwardenCli>("cz.chrastecky.bitsailor", 1, 0, "BitwardenCli");
qmlRegisterType<SecretsHandler>("cz.chrastecky.bitsailor", 1, 0, "SecretsHandler");
qmlRegisterType<SystemAuthChecker>("cz.chrastecky.bitsailor", 1, 0, "SystemAuthChecker");
qmlRegisterType<FileAccessor>("cz.chrastecky.bitsailor", 1, 0, "FileAccessor");

v->rootContext()->setContextProperty("settings", new AppSettings(app.data()));
v->rootContext()->setContextProperty("runtimeCache", RuntimeCache::getInstance(app.data()));
Expand Down
2 changes: 1 addition & 1 deletion src/secretshandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SecretsHandler : public QObject
Q_INVOKABLE void removePassword();
Q_INVOKABLE bool hasSessionId();
Q_INVOKABLE void removeSessionId();
bool clearAllSecrets();
Q_INVOKABLE bool clearAllSecrets();

void setSessionId(const QString &sessionId);
void setUsername(const QString &username);
Expand Down
Loading

0 comments on commit b661c3a

Please sign in to comment.