Feature Request for Android: Send an intent or other IPC to notify listening apps when a particular share finishes an update

This is in regard to Syncthing/Syncthing Fork on Android.

I’m unfamiliar with android programming, so please bear with me.

Use case: DecsyncCC currently waits for Android’s allowed cycle time before it checks to see if files have changed. This can lead to delays of 15m-1h.

It would be nice if Syncthing sent out a normal broadcast intent whenever a sync has finished updating, akin to "Folder /storage/emulated/0/Sync/SomeSync has been updated.

Then, DecsyncCC could listen for that event, and perform an update when the event is received.

If you wanted to be extra-generous, you could include putExtra data that is a list of the specific files that have been updated. But even just knowing that folder has been updated would be enough, and could trigger a scan of the folder.

Edit: Obviously, that is, when an update that has caused local changes completes. :slight_smile:

Hi,

In the folder tab, you can see the last changed file and completion percent of each folder. Should we broadcast this information? Is there an example code that shows what decsyncc expects it be like?

DecsyncCC doesn’t expect anything, yet – they had mentioned in the related issue that there wasn’t any way to know if Syncthing had done an update.

Probably the simplest to implement by both parties would be:

  • Syncthing sends a broadcast intent when it finishes a folder (reaches 100% after not being at 100%)
  • Syncthing provides some documentation specifying that it is doing this, like “Integrating with Syncthing”
  • Decsync listens to

Syncthing’s side would look something like this:

final Intent i = new Intent();
i.setAction("com.github.catfriend1.syncthingandroid.ACTION_NOTIFY_FOLDER_UPDATE_COMPLETE");
i.putExtra("com.github.catfriend1.syncthingandroid.FOLDER_ROOT_PATH", "/path/to/share_folder_root");
i.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);   # not sure if this line is needed
getApplicationContext().sendBroadcast(i);

setAction should have your app prefixed, as shown (if that’s your app prefix). The action name itself is CAPS_VALID_IDENTIFIER, but the action name is arbitrary otherwise.

putExtra doesn’t need to be prefixed by your app name – it can be whatever key you’d like it to be, and you can put more than one. It could simply be “root_path” instead of “com.github.catfriend1.syncthingandroid.FOLDER_ROOT_PATH”

You can add as many of these intents as you’d like, I don’t think spamming is an issue, it’s a pub/sub model. But, the above would suffice.

Mainly, DecsyncCC needs to know:

  • that an update has occurred, and is finished
  • where it occurred (root folder path) To get that info, the developer of DecsyncCC or anyone else seeking to integrate needs to know the following information, theoretically provided in your documentation:
  • The action key you will be using, prefixed by your app id as in the example
  • The key the relevant data will be stored in
  • The datatype or format of the relevant data (a string, and whether or not that’s JSON, or a double, or a bundle, or… or… or…)

That being the case, I figure in your documentation somewhere, you could have an “Integrating with Syncthing” section that specifies that data for each of the events you’ll be sending.

So, can you send last changed file and completion percent? Sure, particularly if you include the share root. But, my guess is that DecsyncCC will probably just wait for “100%”, then do its own scan. But, they might utilize the individual files if sent. Hard to say. Someone out there might want to hook into Syncthing, and who knows what they’ll want? It’s more about how much dev time you want to do on it.

…an example matching your idea there:

final Intent i = new Intent();
i.setAction("com.github.catfriend1.syncthingandroid.ACTION_NOTIFY_FOLDER_UPDATE_PROGRESS");
i.putExtra("folder_root", "/path/to/share_folder_root");
i.putExtra("percent_complete", "87%");  # or whatever type you want to send that data as
i.putExtra("last_file_changed", "/path/to/share_folder_root/snoo.txt");
i.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);   # not sure if this line is needed
getApplicationContext().sendBroadcast(i);

Hope that’s helpful, sorry if it’s just wall-of-text.

1 Like

Thank you. I’ll take it into consideration. Until it’s done, another app could also subscribe to Syncthing’s RestAPI interface and ask for completionInfo (like the wrapper does).

I expect a problem that some configurations never reach 100% if people ignore stuff “asymmetric” with ignoreDelete and so on. In that case, the consuming app like decsyncc would have to use inotify or be notified of every single file change.

How about security when broadcasting info around? The restApi requires authentication, so same security for integration and the wrapper itself. A broadcast doesn’t seem protected so well on Android (?). If implemented, the user could optIn to send the broadcast in my opinion.

Issue created: → Send an intent to notify listening apps when a shared folder finishes syncing · Issue #1409 · Catfriend1/syncthing-android · GitHub

@eode Can you please post a link to the open issue at DecsyncCC here? I’ve implemented the notification via broadcast intent.

See syncthing-android/wiki/Integrate-your-app-with-Syncthing-receive-folder-sync-status.md at main · Catfriend1/syncthing-android · GitHub

Related DecsyncCC issue:

Thanks for adding this! I not only like it for DecsyncCC, but hope other apps integrate with Syncthing-Fork, too.

Catfriend Goodfriend.

1 Like