Skip to content

Commit

Permalink
Enable "Ignore permissions" by default when it makes sense, e.g. on A…
Browse files Browse the repository at this point in the history
…ndroid
  • Loading branch information
Martchus committed Jan 8, 2025
1 parent 431fb29 commit 1e778df
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ additional remarks:
* The app does not automatically trigger media library rescans yet, so e.g. synchronized music
might not show up immediately in your music app. However, you can trigger a rescan manually if
needed. You can do this per folder from the context menu on the folders page.
* It is highly recommended to enable the option "Ignore permissions" on all folders under Android
and when certain file systems are used. The app enables this option therefore by default in
such cases when a path for a new folder has been selected. You can still disable the option
again manually.

### Testing the app without migrating
To only test the app without migrating your setup you can follow the steps of this section. Note
Expand Down
3 changes: 3 additions & 0 deletions tray/gui/qml/AdvancedDirConfigPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ AdvancedConfigPage {
required property string dirId
function makeNewConfig() {
const config = App.connection.rawConfig?.defaults?.folder ?? {};

// for now, give user simply always the chance to edit ignore patterns before syncing
config.paused = true;

// add dirId/dirName as default values for id/label
if (dirId.length > 0) {
config.id = dirId;
}
if (dirName.length > 0) {
config.label = dirName;
}

isNew = true;
return config;
}
Expand Down
19 changes: 16 additions & 3 deletions tray/gui/qml/ObjectConfigPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Page {
dynamicRoles: true
Component.onCompleted: listModel.loadEntries()
function loadEntries() {
const indexByKey = objectConfigPage.indexByKey = {};
listModel.clear();

let index = 0;
let handledKeys = new Set();
let configObject = objectConfigPage.configObject;
if (configObject === undefined) {
return;
Expand All @@ -31,15 +31,19 @@ Page {
if (typeof init === "function") {
configObject[key] = init();
}
indexByKey[key] = index;
listModel.append(objectConfigPage.makeConfigRowForSpecialEntry(specialEntry, configObject[key], index++));
} else {
indexByKey[key] = -1;
}
handledKeys.add(key);
});
if (objectConfigPage.specialEntriesOnly) {
return;
}
Object.entries(configObject).forEach((configEntry) => {
if (!handledKeys.has(configEntry[0])) {
const key = configEntry[0];
if (indexByKey[key] === undefined) {
indexByKey[key] = index;
listModel.append(objectConfigPage.makeConfigRow(configEntry, index++));
}
});
Expand Down Expand Up @@ -82,6 +86,7 @@ Page {

property alias model: objectListView.model
property bool specialEntriesOnly: false
property var indexByKey: ({})
property var specialEntriesByKey: ({
"remoteIgnoredDevices.*": [
{key: "deviceID", label: qsTr("Device ID"), type: "deviceid", desc: qsTr("The ID of the device to be ignored.")},
Expand Down Expand Up @@ -191,6 +196,14 @@ Page {
parentPage.computeArrayElementLabel(parentRow);
objectConfigPage.objectNameLabel.text = objectConfigPage.title = parentRow.label;
}

// update "ignorePerms" when setting "path" to a place where permissions should be ignored
if (key === "path" && configObject.ignorePerms === false && App.shouldIgnorePermissions(value)) {
const ignorePermsIndex = objectConfigPage.indexByKey.ignorePerms;
if (ignorePermsIndex >= 0) {
objectConfigPage.updateValue(ignorePermsIndex, "ignorePerms", true);
}
}
}

function swapObjects(modelData, moveDelta) {
Expand Down
20 changes: 20 additions & 0 deletions tray/gui/quick/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
#include <QJniEnvironment>
#endif

#ifndef Q_OS_ANDROID
#include <QSet>
#include <QStorageInfo>
#endif

#include <cstdlib>
#include <filesystem>
#include <functional>
Expand Down Expand Up @@ -606,6 +611,21 @@ QString App::resolveUrl(const QUrl &url)
#endif
}

bool App::shouldIgnorePermissions(const QString &path)
{
#ifdef Q_OS_ANDROID
// QStorageInfo only returns "fuse" on Android but we can assume that permissions should be generally ignored
Q_UNUSED(path)
return true;
#else
static const auto problematicFileSystems = QSet<QByteArray>({
QByteArrayLiteral("fat"), QByteArrayLiteral("vfat"), QByteArrayLiteral("exfat")
});
const auto storageInfo = QStorageInfo(path);
return storageInfo.isValid() && problematicFileSystems.contains(storageInfo.fileSystemType());
#endif
}

void App::invalidateStatus()
{
m_status.reset();
Expand Down
1 change: 1 addition & 0 deletions tray/gui/quick/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ class App : public QObject {
Q_INVOKABLE bool performHapticFeedback();
Q_INVOKABLE bool showToast(const QString &message);
Q_INVOKABLE QString resolveUrl(const QUrl &url);
Q_INVOKABLE bool shouldIgnorePermissions(const QString &path);
Q_INVOKABLE Data::SyncthingFileModel *createFileModel(const QString &dirId, QObject *parent);
Q_INVOKABLE QtGui::DiffHighlighter *createDiffHighlighter(QTextDocument *parent);
Q_INVOKABLE QVariantList internalErrors() const;
Expand Down

0 comments on commit 1e778df

Please sign in to comment.