Skip to content

Commit

Permalink
Implement Feature Request #2760
Browse files Browse the repository at this point in the history
* Implement Feature Request #2760 by adding config option 'notify_file_actions' to notify via the GUI successful actions.
  • Loading branch information
abraunegg committed Sep 2, 2024
1 parent 65432dd commit 9337d41
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 9 deletions.
13 changes: 13 additions & 0 deletions docs/application-config-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Before reading this document, please ensure you are running application version
- [monitor_interval](#monitor_interval)
- [monitor_log_frequency](#monitor_log_frequency)
- [no_remote_delete](#no_remote_delete)
- [notify_file_actions](#notify_file_actions)
- [operation_timeout](#operation_timeout)
- [rate_limit](#rate_limit)
- [read_only_auth_scope](#read_only_auth_scope)
Expand Down Expand Up @@ -468,6 +469,18 @@ _**CLI Option Use:**_ `--no-remote-delete`
> [!IMPORTANT]
> This configuration option can *only* be used in conjunction with `--upload-only`
### notify_file_actions
_**Description:**_ This configuration option controls whether the client will log via GUI notifications successful actions that the client performs.

_**Value Type:**_ Boolean

_**Default Value:**_ False

_**Config Example:**_ `notify_file_actions = "true"`

> [!NOTE]
> GUI Notification Support must be compiled in first, otherwise this option will have zero effect and will not be used.
### operation_timeout
_**Description:**_ This configuration option controls the maximum amount of time (seconds) a file operation is allowed to take. This includes DNS resolution, connecting, data transfer, etc. We recommend users not to tamper with this option unless strictly necessary. This option controls the CURLOPT_TIMEOUT setting of libcurl.

Expand Down
12 changes: 11 additions & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,6 @@ To enable GUI notifications, you must compile the application with GUI Notificat
Without these conditions met, GUI notifications will not function even if the support is compiled in.

Once these conditions have been met, the following application events will trigger a GUI notification within the display manager session by default:

* Aborting a sync if .nosync file is found
* Skipping a particular item due to an invalid name
* Skipping a particular item due to an invalid symbolic link
Expand All @@ -664,6 +663,17 @@ Once these conditions have been met, the following application events will trigg
* Files that fail to upload
* Files that fail to download

Additionally, GUI notifications can also be sent for the following activities:
* Successful file download
* Successful file upload
* Successful deletion locally (files and folders)
* Successful deletion online (files and folders)

To enable these specific notifications, add the following to your 'config' file:
```
notify_file_actions = "true"
```

### Handling a Microsoft OneDrive Account Password Change
If you change your Microsoft OneDrive Account Password, the client will no longer be authorised to sync, and will generate the following error upon next application run:
```text
Expand Down
4 changes: 4 additions & 0 deletions src/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ class ApplicationConfig {
longValues["webhook_renewal_interval"] = 300;
longValues["webhook_retry_interval"] = 60;

// GUI File Transfer and Deletion Notifications
boolValues["notify_file_actions"] = false;

// EXPAND USERS HOME DIRECTORY
// Determine the users home directory.
// Need to avoid using ~ here as expandTilde() below does not interpret correctly when running under init.d or systemd scripts
Expand Down Expand Up @@ -1413,6 +1416,7 @@ class ApplicationConfig {
version(Notifications) {
addLogEntry("Environment var 'XDG_RUNTIME_DIR' = " ~ to!string(xdg_exists));
addLogEntry("Environment var 'DBUS_SESSION_BUS_ADDRESS' = " ~ to!string(dbus_exists));
addLogEntry("Config option 'notify_file_actions' = " ~ to!string(getValueBool("notify_file_actions")));
} else {
addLogEntry("Compile time option --enable-notifications = false");
}
Expand Down
47 changes: 39 additions & 8 deletions src/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,7 @@ class SyncEngine {
// File should have been downloaded
if (!downloadFailed) {
// Download did not fail
addLogEntry("Downloading file: " ~ newItemPath ~ " ... done");
addLogEntry("Downloading file: " ~ newItemPath ~ " ... done", fileTransferNotifications());
// Save this item into the database
saveItem(onedriveJSONItem);

Expand Down Expand Up @@ -2888,9 +2888,9 @@ class SyncEngine {
if (needsRemoval) {
// Log the action
if (item.type == ItemType.file) {
addLogEntry("Deleting local file: " ~ path);
addLogEntry("Deleting local file: " ~ path, fileTransferNotifications());
} else {
addLogEntry("Deleting local directory: " ~ path);
addLogEntry("Deleting local directory: " ~ path, fileTransferNotifications());
}

// Perform the action
Expand Down Expand Up @@ -4186,7 +4186,7 @@ class SyncEngine {
}
} else {
// Upload was successful
addLogEntry("Uploading modified file: " ~ localFilePath ~ " ... done", ["info", "notify"]);
addLogEntry("Uploading modified file: " ~ localFilePath ~ " ... done", fileTransferNotifications());

// What do we save to the DB? Is this a OneDrive Business Shared File?
if ((dbItem.type == ItemType.remote) && (dbItem.remoteType == ItemType.file)) {
Expand Down Expand Up @@ -5748,7 +5748,7 @@ class SyncEngine {
// Attempt to upload the zero byte file using simpleUpload for all account types
uploadResponse = uploadFileOneDriveApiInstance.simpleUpload(fileToUpload, parentItem.driveId, parentItem.id, baseName(fileToUpload));
uploadFailed = false;
addLogEntry("Uploading new file: " ~ fileToUpload ~ " ... done");
addLogEntry("Uploading new file: " ~ fileToUpload ~ " ... done", fileTransferNotifications());

// OneDrive API Instance Cleanup - Shutdown API, free curl object and memory
uploadFileOneDriveApiInstance.releaseCurlEngine();
Expand Down Expand Up @@ -5845,7 +5845,7 @@ class SyncEngine {

if (uploadResponse.type() == JSONType.object) {
uploadFailed = false;
addLogEntry("Uploading new file: " ~ fileToUpload ~ " ... done");
addLogEntry("Uploading new file: " ~ fileToUpload ~ " ... done", fileTransferNotifications());
} else {
addLogEntry("Uploading new file: " ~ fileToUpload ~ " ... failed!", ["info", "notify"]);
uploadFailed = true;
Expand Down Expand Up @@ -5880,7 +5880,7 @@ class SyncEngine {
// We are in a --dry-run scenario
uploadResponse = createFakeResponse(fileToUpload);
uploadFailed = false;
addLogEntry("Uploading new file: " ~ fileToUpload ~ " ... done", ["info", "notify"]);
addLogEntry("Uploading new file: " ~ fileToUpload ~ " ... done", fileTransferNotifications());
}

// Upload has finished
Expand Down Expand Up @@ -6158,7 +6158,7 @@ class SyncEngine {
// Is this a --download-only operation?
if (!appConfig.getValueBool("download_only")) {
// Process the delete - delete the object online
addLogEntry("Deleting item from Microsoft OneDrive: " ~ path);
addLogEntry("Deleting item from Microsoft OneDrive: " ~ path, fileTransferNotifications());
bool flagAsBigDelete = false;

Item[] children;
Expand Down Expand Up @@ -9185,4 +9185,35 @@ class SyncEngine {
}
}
}

// Return an array of the notification parameters when this is called. This implements FR #2760
string[] fileTransferNotifications() {

// Based on the configuration option, send the file transfer actions to the GUI notifications if configured
// GUI notifications are already sent for files that meet this criteria:
// - Skipping a particular item due to an invalid name
// - Skipping a particular item due to an invalid symbolic link
// - Skipping a particular item due to an invalid UTF sequence
// - Skipping a particular item due to an invalid character encoding sequence
// - Files that fail to upload
// - Files that fail to download
//
// This is about notifying on:
// - Successful file download
// - Successful file upload
// - Successful deletion locally
// - Successful deletion online

string[] loggingOptions;

if (appConfig.getValueBool("notify_file_actions")) {
// Add the 'notify' to enable GUI notifications
loggingOptions = ["info", "notify"];
} else {
// Logging to console and/or logfile only
loggingOptions = ["info"];
}

return loggingOptions;
}
}

0 comments on commit 9337d41

Please sign in to comment.