notification on incoming changes (#355)

* When notifications are enabled, display the number of OneDrive changes to process if any are found
* Add 'config' option 'min_notif_changes' for minimum number of changes to notify on, default = 5
* Update readme, manual page for new option
This commit is contained in:
Norbert Preining 2019-01-29 02:54:03 +09:00 committed by abraunegg
parent 61c40c6cb1
commit 1c6fd5df39
5 changed files with 23 additions and 2 deletions

View file

@ -251,6 +251,7 @@ Config option 'sync_dir' = /home/alex/OneDrive
Config option 'skip_file' = ~* Config option 'skip_file' = ~*
Config option 'skip_symlinks' = false Config option 'skip_symlinks' = false
Config option 'monitor_interval' = 45 Config option 'monitor_interval' = 45
Config option 'min_notif_changes' = 5
Config option 'log_dir' = /var/log/onedrive/ Config option 'log_dir' = /var/log/onedrive/
Selective sync configured = false Selective sync configured = false
``` ```
@ -380,6 +381,7 @@ Available options:
* `skip_file`: any files or directories that match this pattern will be skipped during sync * `skip_file`: any files or directories that match this pattern will be skipped during sync
* `skip_symlinks`: any files or directories that are symlinked will be skipped during sync * `skip_symlinks`: any files or directories that are symlinked will be skipped during sync
* `monitor_interval`: time interval in seconds by which the monitor process will process local and remote changes * `monitor_interval`: time interval in seconds by which the monitor process will process local and remote changes
* `min_notif_changes`: minimum number of pending incoming changes to trigger a desktop notification
### sync_dir ### sync_dir
Example: `sync_dir="~/MyDirToSync"` Example: `sync_dir="~/MyDirToSync"`
@ -406,6 +408,11 @@ Example: `monitor_interval = "300"`
The monitor interval is defined as the wait time 'between' sync's when running in monitor mode. By default without configuration, the monitor_interval is set to 45 seconds. Setting this value to 300 will run the sync process every 5 minutes. The monitor interval is defined as the wait time 'between' sync's when running in monitor mode. By default without configuration, the monitor_interval is set to 45 seconds. Setting this value to 300 will run the sync process every 5 minutes.
### min_notif_changes
Example: `min_notif_changes = "5"`
This option defines the minimum number of pending incoming changes necessary to trigger a desktop notification. This allows controlling the frequency of notifications.
### Selective sync ### Selective sync
Selective sync allows you to sync only specific files and directories. Selective sync allows you to sync only specific files and directories.
To enable selective sync create a file named `sync_list` in `~/.config/onedrive`. To enable selective sync create a file named `sync_list` in `~/.config/onedrive`.

View file

@ -147,6 +147,10 @@ skip symbolic links during sync, defaults to \fB"false"\fP
the number of seconds by which each sync operation is undertaken when the number of seconds by which each sync operation is undertaken when
idle under monitor mode, defaults to \fB"45"\fP idle under monitor mode, defaults to \fB"45"\fP
.TP .TP
\fBmin_notif_changes\fP
the minimum number of pending incoming changes necessary to trigger
a desktop notification, defaults to \fB"5"\fP
.TP
\fBlog_dir\fP \fBlog_dir\fP
defines the directory where logging output is saved to, needs to end with a slash defines the directory where logging output is saved to, needs to end with a slash
.PP .PP

View file

@ -41,6 +41,8 @@ final class Config
setValue("log_dir", "/var/log/onedrive/"); setValue("log_dir", "/var/log/onedrive/");
// Configure a default empty value for drive_id // Configure a default empty value for drive_id
setValue("drive_id", ""); setValue("drive_id", "");
// Minimal changes that trigger a log and notification on sync
setValue("min_notif_changes", "5");
if (!load(userConfigFilePath)) { if (!load(userConfigFilePath)) {
// What was the reason for failure? // What was the reason for failure?

View file

@ -298,6 +298,7 @@ int main(string[] args)
writeln("Config option 'skip_file' = ", cfg.getValue("skip_file")); writeln("Config option 'skip_file' = ", cfg.getValue("skip_file"));
writeln("Config option 'skip_symlinks' = ", cfg.getValue("skip_symlinks")); writeln("Config option 'skip_symlinks' = ", cfg.getValue("skip_symlinks"));
writeln("Config option 'monitor_interval' = ", cfg.getValue("monitor_interval")); writeln("Config option 'monitor_interval' = ", cfg.getValue("monitor_interval"));
writeln("Config option 'min_notif_changes' = ", cfg.getValue("min_notif_changes"));
writeln("Config option 'log_dir' = ", cfg.getValue("log_dir")); writeln("Config option 'log_dir' = ", cfg.getValue("log_dir"));
// Is config option drive_id configured? // Is config option drive_id configured?

View file

@ -5,6 +5,7 @@ import std.exception: enforce;
import std.file, std.json, std.path; import std.file, std.json, std.path;
import std.regex; import std.regex;
import std.stdio, std.string, std.uni, std.uri; import std.stdio, std.string, std.uni, std.uri;
import std.conv;
import core.time, core.thread; import core.time, core.thread;
import core.stdc.stdlib; import core.stdc.stdlib;
import config, itemdb, onedrive, selective, upload, util; import config, itemdb, onedrive, selective, upload, util;
@ -579,8 +580,14 @@ final class SyncEngine
// Are there any changes to process? // Are there any changes to process?
if (("value" in changes) != null) { if (("value" in changes) != null) {
// There are valid changes auto nrChanges = count(changes["value"].array);
log.vdebug("Number of changes from OneDrive to process: ", count(changes["value"].array));
if (nrChanges >= to!long(cfg.getValue("min_notif_changes"))) {
log.logAndNotify("Processing ", nrChanges, " changes");
} else {
// There are valid changes
log.vdebug("Number of changes from OneDrive to process: ", nrChanges);
}
foreach (item; changes["value"].array) { foreach (item; changes["value"].array) {
bool isRoot = false; bool isRoot = false;