forked from Silverfish/proton-bridge
GODT-1982: updated gRPC and GUI for disk cache.
Other: modified bridge-gui-tester for new cache related gRPC interface. Other: bridge-gui-tester has buttons for cache related errors.
This commit is contained in:
committed by
James Houlahan
parent
93d9ae32fc
commit
d9762010fa
@ -104,12 +104,11 @@ void QMLBackend::connectGrpcEvents()
|
||||
connect(client, &GRPCClient::showMainWindow, this, &QMLBackend::showMainWindow);
|
||||
|
||||
// cache events
|
||||
connect(client, &GRPCClient::diskCachePathChanged, this, &QMLBackend::diskCachePathChanged);
|
||||
connect(client, &GRPCClient::cacheUnavailable, this, &QMLBackend::cacheUnavailable); // _ func() `signal:"cacheUnavailable"`
|
||||
connect(client, &GRPCClient::cacheCantMove, this, &QMLBackend::cacheCantMove);
|
||||
connect(client, &GRPCClient::diskCacheUnavailable, this, &QMLBackend::diskCacheUnavailable); // _ func() `signal:"cacheUnavailable"`
|
||||
connect(client, &GRPCClient::cantMoveDiskCache, this, &QMLBackend::cantMoveDiskCache);
|
||||
connect(client, &GRPCClient::diskFull, this, &QMLBackend::diskFull);
|
||||
connect(client, &GRPCClient::cacheLocationChangeSuccess, this, &QMLBackend::cacheLocationChangeSuccess);
|
||||
connect(client, &GRPCClient::changeLocalCacheFinished, this, &QMLBackend::onChangeLocalCacheFinished);
|
||||
connect(client, &GRPCClient::diskCachePathChanged, this, &QMLBackend::diskCachePathChanged);
|
||||
connect(client, &GRPCClient::diskCachePathChangeFinished, this, &QMLBackend::diskCachePathChangeFinished);
|
||||
|
||||
// login events
|
||||
connect(client, &GRPCClient::loginUsernamePasswordError, this, &QMLBackend::loginUsernamePasswordError);
|
||||
@ -219,6 +218,24 @@ bool QMLBackend::isPortFree(int port)
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return true the native local file path of the given URL.
|
||||
//****************************************************************************************************************************************************
|
||||
QString QMLBackend::nativePath(QUrl const &url)
|
||||
{
|
||||
return QDir::toNativeSeparators(url.toLocalFile());
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return true iff the two URL point to the same local file or folder.
|
||||
//****************************************************************************************************************************************************
|
||||
bool QMLBackend::areSameFileOrFolder(QUrl const &lhs, QUrl const &rhs)
|
||||
{
|
||||
return QFileInfo(lhs.toLocalFile()) == QFileInfo(rhs.toLocalFile());
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
//
|
||||
//****************************************************************************************************************************************************
|
||||
@ -295,6 +312,13 @@ void QMLBackend::changeColorScheme(QString const &scheme)
|
||||
emit colorSchemeNameChanged(this->colorSchemeName());
|
||||
}
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] path The path of the disk cache.
|
||||
//****************************************************************************************************************************************************
|
||||
void QMLBackend::setDiskCachePath(QUrl const &path) const
|
||||
{
|
||||
app().grpc().setDiskCachePath(path);
|
||||
}
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \param[in] makeItActive Should SSL for SMTP be enabled.
|
||||
@ -404,14 +428,3 @@ void QMLBackend::onVersionChanged()
|
||||
emit releaseNotesLinkChanged(releaseNotesLink());
|
||||
emit landingPageLinkChanged(landingPageLink());
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
///
|
||||
//****************************************************************************************************************************************************
|
||||
void QMLBackend::onChangeLocalCacheFinished(bool willRestart)
|
||||
{
|
||||
if (willRestart)
|
||||
emit hideMainWindow();
|
||||
emit changeLocalCacheFinished();
|
||||
}
|
||||
|
||||
@ -48,6 +48,8 @@ public: // member functions.
|
||||
// invokable methods can be called from QML. They generally return a value, which slots cannot do.
|
||||
Q_INVOKABLE static QPoint getCursorPos(); // _ func() *core.QPoint `slot:"getCursorPos"`
|
||||
Q_INVOKABLE static bool isPortFree(int port); // _ func(port int) bool `slot:"isPortFree"`
|
||||
Q_INVOKABLE static QString nativePath(QUrl const &url);
|
||||
Q_INVOKABLE static bool areSameFileOrFolder(QUrl const &lhs, QUrl const &rhs);
|
||||
|
||||
public: // Qt/QML properties. Note that the NOTIFY-er signal is required even for read-only properties (QML warning otherwise)
|
||||
Q_PROPERTY(bool showOnStartup READ showOnStartup NOTIFY showOnStartupChanged) // _ bool `property:showOnStartup`
|
||||
@ -112,7 +114,7 @@ public: // Qt/QML properties. Note that the NOTIFY-er signal is required even fo
|
||||
bool dockIconVisible() const { return getDockIconVisibleState(); };
|
||||
void setDockIconVisible(bool visible) { setDockIconVisibleState(visible); emit dockIconVisibleChanged(visible); }
|
||||
|
||||
signals: // Signal used by the Qt property system. Many of them are unused but required to avoir warning from the QML engine.
|
||||
signals: // Signal used by the Qt property system. Many of them are unused but required to avoid warning from the QML engine.
|
||||
void showSplashScreenChanged(bool value);
|
||||
void showOnStartupChanged(bool value);
|
||||
void goosChanged(QString const &value);
|
||||
@ -147,6 +149,7 @@ public slots: // slot for signals received from QML -> To be forwarded to Bridge
|
||||
void toggleBeta(bool active); // _ func(makeItActive bool) `slot:"toggleBeta"`
|
||||
void changeIsAllMailVisible(bool isVisible); // _ func(isVisible bool) `slot:"changeIsAllMailVisible"`
|
||||
void changeColorScheme(QString const &scheme); // _ func(string) `slot:"changeColorScheme"`
|
||||
void setDiskCachePath(QUrl const& path) const;
|
||||
void login(QString const& username, QString const& password) { app().grpc().login(username, password);} // _ func(username, password string) `slot:"login"`
|
||||
void login2FA(QString const& username, QString const& code) { app().grpc().login2FA(username, code);} // _ func(username, code string) `slot:"login2FA"`
|
||||
void login2Password(QString const& username, QString const& password) { app().grpc().login2Passwords(username, password);} // _ func(username, password string) `slot:"login2Password"`
|
||||
@ -169,15 +172,13 @@ public slots: // slot for signals received from QML -> To be forwarded to Bridge
|
||||
app().grpc().reportBug(description, address, emailClient, includeLogs); } // _ func(description, address, emailClient string, includeLogs bool) `slot:"reportBug"`
|
||||
void onResetFinished(); // _ func() `slot:"onResetFinished"`
|
||||
void onVersionChanged(); // _ func() `slot:"onVersionChanged"`
|
||||
void onChangeLocalCacheFinished(bool willRestart);
|
||||
|
||||
signals: // Signals received from the Go backend, to be forwarded to QML
|
||||
void toggleAutostartFinished(); // _ func() `signal:"toggleAutostartFinished"`
|
||||
void cacheUnavailable(); // _ func() `signal:"cacheUnavailable"`
|
||||
void cacheCantMove(); // _ func() `signal:"cacheCantMove"`
|
||||
void cacheLocationChangeSuccess(); // _ func() `signal:"cacheLocationChangeSuccess"`
|
||||
void diskCacheUnavailable(); // _ func() `signal:"cacheUnavailable"`
|
||||
void cantMoveDiskCache(); // _ func() `signal:"cacheCantMove"`
|
||||
void diskCachePathChangeFinished(); // _ func() `signal:"cacheLocationChangeSuccess"`
|
||||
void diskFull(); // _ func() `signal:"diskFull"`
|
||||
void changeLocalCacheFinished(); // _ func() `signal:"changeLocalCacheFinished"`
|
||||
void loginUsernamePasswordError(QString const &errorMsg); // _ func(errorMsg string) `signal:"loginUsernamePasswordError"`
|
||||
void loginFreeUserError(); // _ func() `signal:"loginFreeUserError"`
|
||||
void loginConnectionError(QString const &errorMsg); // _ func(errorMsg string) `signal:"loginConnectionError"`
|
||||
|
||||
@ -55,7 +55,7 @@ QtObject {
|
||||
|
||||
Connections {
|
||||
target: Backend
|
||||
function onCacheUnavailable() {
|
||||
function onDiskCacheUnavailable() {
|
||||
mainWindow.showAndRise()
|
||||
}
|
||||
function onColorSchemeNameChanged(scheme) { root.setColorScheme() }
|
||||
|
||||
@ -29,8 +29,12 @@ SettingsView {
|
||||
fillHeight: false
|
||||
|
||||
property var notifications
|
||||
property bool _diskCacheEnabled: true
|
||||
property url _diskCachePath: pathDialog.shortcuts.home
|
||||
property url diskCachePath: pathDialog.shortcuts.home
|
||||
|
||||
function refresh() {
|
||||
diskCacheSetting.description = Backend.nativePath(root.diskCachePath)
|
||||
submitButton.enabled = !Backend.areSameFileOrFolder(Backend.diskCachePath, root.diskCachePath)
|
||||
}
|
||||
|
||||
Label {
|
||||
colorScheme: root.colorScheme
|
||||
@ -49,26 +53,12 @@ SettingsView {
|
||||
}
|
||||
|
||||
SettingsItem {
|
||||
colorScheme: root.colorScheme
|
||||
text: qsTr("Enable local cache")
|
||||
description: qsTr("Recommended for optimal performance.")
|
||||
type: SettingsItem.Toggle
|
||||
checked: root._diskCacheEnabled
|
||||
onClicked: root._diskCacheEnabled = !root._diskCacheEnabled
|
||||
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
SettingsItem {
|
||||
id: diskCacheSetting
|
||||
colorScheme: root.colorScheme
|
||||
text: qsTr("Current cache location")
|
||||
actionText: qsTr("Change location")
|
||||
description: Backend.goos === "windows" ?
|
||||
root._diskCachePath.toString().replace("file:///", "").replace(new RegExp("/", 'g'), "\\") + "\\" :
|
||||
root._diskCachePath.toString().replace("file://", "") + "/"
|
||||
descriptionWrap: Text.WrapAnywhere
|
||||
type: SettingsItem.Button
|
||||
enabled: root._diskCacheEnabled
|
||||
onClicked: {
|
||||
pathDialog.open()
|
||||
}
|
||||
@ -78,8 +68,11 @@ SettingsView {
|
||||
FolderDialog {
|
||||
id: pathDialog
|
||||
title: qsTr("Select cache location")
|
||||
currentFolder: root._diskCachePath
|
||||
onAccepted: root._diskCachePath = pathDialog.selectedFolder
|
||||
currentFolder: root.diskCachePath
|
||||
onAccepted: {
|
||||
root.diskCachePath = pathDialog.selectedFolder
|
||||
root.refresh()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,11 +82,7 @@ SettingsView {
|
||||
Button {
|
||||
id: submitButton
|
||||
colorScheme: root.colorScheme
|
||||
text: qsTr("Save and restart")
|
||||
enabled: (
|
||||
Backend.diskCachePath != root._diskCachePath ||
|
||||
Backend.isDiskCacheEnabled != root._diskCacheEnabled
|
||||
)
|
||||
text: qsTr("Save")
|
||||
onClicked: {
|
||||
root.submit()
|
||||
}
|
||||
@ -109,7 +98,7 @@ SettingsView {
|
||||
Connections {
|
||||
target: Backend
|
||||
|
||||
function onChangeLocalCacheFinished() {
|
||||
function onDiskCachePathChangeFinished() {
|
||||
submitButton.loading = false
|
||||
root.setDefaultValues()
|
||||
}
|
||||
@ -120,25 +109,14 @@ SettingsView {
|
||||
root.setDefaultValues()
|
||||
}
|
||||
|
||||
function submit(){
|
||||
if (!root._diskCacheEnabled && Backend.isDiskCacheEnabled) {
|
||||
root.notifications.askDisableLocalCache()
|
||||
return
|
||||
}
|
||||
|
||||
if (root._diskCacheEnabled && !Backend.isDiskCacheEnabled) {
|
||||
root.notifications.askEnableLocalCache(root._diskCachePath)
|
||||
return
|
||||
}
|
||||
|
||||
// Not asking, only changing path
|
||||
function submit() {
|
||||
submitButton.loading = true
|
||||
Backend.changeLocalCache(Backend.isDiskCacheEnabled, root._diskCachePath)
|
||||
Backend.setDiskCachePath(root.diskCachePath)
|
||||
}
|
||||
|
||||
function setDefaultValues(){
|
||||
root._diskCacheEnabled = Backend.isDiskCacheEnabled
|
||||
root._diskCachePath = Backend.diskCachePath
|
||||
root.diskCachePath = Backend.diskCachePath
|
||||
root.refresh();
|
||||
}
|
||||
|
||||
onVisibleChanged: {
|
||||
|
||||
@ -94,16 +94,6 @@ Item {
|
||||
notification: root.notifications.enableSplitMode
|
||||
}
|
||||
|
||||
NotificationDialog {
|
||||
colorScheme: root.colorScheme
|
||||
notification: root.notifications.disableLocalCache
|
||||
}
|
||||
|
||||
NotificationDialog {
|
||||
colorScheme: root.colorScheme
|
||||
notification: root.notifications.enableLocalCache
|
||||
}
|
||||
|
||||
NotificationDialog {
|
||||
colorScheme: root.colorScheme
|
||||
notification: root.notifications.resetBridge
|
||||
|
||||
@ -29,8 +29,6 @@ QtObject {
|
||||
|
||||
signal askEnableBeta()
|
||||
signal askEnableSplitMode(var user)
|
||||
signal askDisableLocalCache()
|
||||
signal askEnableLocalCache(var path)
|
||||
signal askResetBridge()
|
||||
signal askChangeAllMailVisibility(var isVisibleNow)
|
||||
signal askDeleteAccount(var user)
|
||||
@ -70,8 +68,6 @@ QtObject {
|
||||
root.diskFull,
|
||||
root.cacheLocationChangeSuccess,
|
||||
root.enableSplitMode,
|
||||
root.disableLocalCache,
|
||||
root.enableLocalCache,
|
||||
root.resetBridge,
|
||||
root.changeAllMailVisibility,
|
||||
root.deleteAccount,
|
||||
@ -558,7 +554,7 @@ QtObject {
|
||||
|
||||
Connections {
|
||||
target: Backend
|
||||
function onCacheUnavailable() {
|
||||
function onDiskCacheUnavailable() {
|
||||
root.cacheUnavailable.active = true
|
||||
}
|
||||
}
|
||||
@ -591,7 +587,7 @@ QtObject {
|
||||
|
||||
Connections {
|
||||
target: Backend
|
||||
function onCacheCantMove() {
|
||||
function onCantMoveDiskCache() {
|
||||
root.cacheCantMove.active = true
|
||||
}
|
||||
}
|
||||
@ -622,8 +618,8 @@ QtObject {
|
||||
|
||||
Connections {
|
||||
target: Backend
|
||||
function onCacheLocationChangeSuccess() {
|
||||
console.log("notify location changed succesfully")
|
||||
function onDiskCachePathChanged() {
|
||||
console.log("notify location changed successfully")
|
||||
root.cacheLocationChangeSuccess.active = true
|
||||
}
|
||||
}
|
||||
@ -736,99 +732,6 @@ QtObject {
|
||||
]
|
||||
}
|
||||
|
||||
property Notification disableLocalCache: Notification {
|
||||
title: qsTr("Disable local cache?")
|
||||
brief: title
|
||||
description: qsTr("This action will clear your local cache, including locally stored messages. Bridge will restart.")
|
||||
icon: "/qml/icons/ic-question-circle.svg"
|
||||
type: Notification.NotificationType.Warning
|
||||
group: Notifications.Group.Configuration | Notifications.Group.Dialogs
|
||||
|
||||
Connections {
|
||||
target: root
|
||||
function onAskDisableLocalCache() {
|
||||
root.disableLocalCache.active = true
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: Backend
|
||||
function onChangeLocalCacheFinished() {
|
||||
root.disableLocalCache.active = false
|
||||
|
||||
disableLocalCache_disable.loading = false
|
||||
disableLocalCache_cancel.enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
action: [
|
||||
Action {
|
||||
id: disableLocalCache_cancel
|
||||
text: qsTr("Cancel")
|
||||
onTriggered: {
|
||||
root.disableLocalCache.active = false
|
||||
}
|
||||
},
|
||||
Action {
|
||||
id: disableLocalCache_disable
|
||||
text: qsTr("Disable and restart")
|
||||
onTriggered: {
|
||||
disableLocalCache_disable.loading = true
|
||||
disableLocalCache_cancel.enabled = false
|
||||
Backend.changeLocalCache(false, Backend.diskCachePath)
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
property Notification enableLocalCache: Notification {
|
||||
title: qsTr("Enable local cache")
|
||||
brief: title
|
||||
description: qsTr("Bridge will restart.")
|
||||
icon: "/qml/icons/ic-question-circle.svg"
|
||||
type: Notification.NotificationType.Warning
|
||||
group: Notifications.Group.Configuration | Notifications.Group.Dialogs
|
||||
|
||||
property url path
|
||||
|
||||
Connections {
|
||||
target: root
|
||||
function onAskEnableLocalCache(path) {
|
||||
root.enableLocalCache.active = true
|
||||
root.enableLocalCache.path = path
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: Backend
|
||||
function onChangeLocalCacheFinished() {
|
||||
root.enableLocalCache.active = false
|
||||
|
||||
enableLocalCache_enable.loading = false
|
||||
enableLocalCache_cancel.enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
action: [
|
||||
Action {
|
||||
id: enableLocalCache_enable
|
||||
text: qsTr("Enable and restart")
|
||||
onTriggered: {
|
||||
enableLocalCache_enable.loading = true
|
||||
enableLocalCache_cancel.enabled = false
|
||||
Backend.changeLocalCache(true, root.enableLocalCache.path)
|
||||
}
|
||||
},
|
||||
Action {
|
||||
id: enableLocalCache_cancel
|
||||
text: qsTr("Cancel")
|
||||
onTriggered: {
|
||||
root.enableLocalCache.active = false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
property Notification resetBridge: Notification {
|
||||
title: qsTr("Reset Bridge?")
|
||||
brief: title
|
||||
|
||||
Reference in New Issue
Block a user