Skip to content

Commit

Permalink
notification on incoming changes (#355)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
norbusan authored and abraunegg committed Jan 28, 2019
1 parent 61c40c6 commit 1c6fd5d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ Config option 'sync_dir' = /home/alex/OneDrive
Config option 'skip_file' = ~*
Config option 'skip_symlinks' = false
Config option 'monitor_interval' = 45
Config option 'min_notif_changes' = 5
Config option 'log_dir' = /var/log/onedrive/
Selective sync configured = false
```
Expand Down Expand Up @@ -380,6 +381,7 @@ Available options:
* `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
* `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
Example: `sync_dir="~/MyDirToSync"`
Expand All @@ -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.

### 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 allows you to sync only specific files and directories.
To enable selective sync create a file named `sync_list` in `~/.config/onedrive`.
Expand Down
4 changes: 4 additions & 0 deletions onedrive.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
idle under monitor mode, defaults to \fB"45"\fP
.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
defines the directory where logging output is saved to, needs to end with a slash
.PP
Expand Down
2 changes: 2 additions & 0 deletions src/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ final class Config
setValue("log_dir", "/var/log/onedrive/");
// Configure a default empty value for drive_id
setValue("drive_id", "");
// Minimal changes that trigger a log and notification on sync
setValue("min_notif_changes", "5");

if (!load(userConfigFilePath)) {
// What was the reason for failure?
Expand Down
1 change: 1 addition & 0 deletions src/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ int main(string[] args)
writeln("Config option 'skip_file' = ", cfg.getValue("skip_file"));
writeln("Config option 'skip_symlinks' = ", cfg.getValue("skip_symlinks"));
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"));

// Is config option drive_id configured?
Expand Down
11 changes: 9 additions & 2 deletions src/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import std.exception: enforce;
import std.file, std.json, std.path;
import std.regex;
import std.stdio, std.string, std.uni, std.uri;
import std.conv;
import core.time, core.thread;
import core.stdc.stdlib;
import config, itemdb, onedrive, selective, upload, util;
Expand Down Expand Up @@ -579,8 +580,14 @@ final class SyncEngine

// Are there any changes to process?
if (("value" in changes) != null) {
// There are valid changes
log.vdebug("Number of changes from OneDrive to process: ", count(changes["value"].array));
auto nrChanges = 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) {
bool isRoot = false;
Expand Down

0 comments on commit 1c6fd5d

Please sign in to comment.