1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-22 20:31:16 +00:00

Remove incorrect assumption that event data is always a map (fixes #1884) (#1917)

This commit is contained in:
Simon Frei 2023-06-17 12:16:53 +02:00 committed by GitHub
parent 4950e628ad
commit 573a1de326
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 9 deletions

View file

@ -8,6 +8,6 @@ public class Event {
public int globalID; public int globalID;
public String type; public String type;
public String time; public String time;
public Map<String, Object> data; public Object data;
} }

View file

@ -99,6 +99,10 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener
*/ */
@Override @Override
public void onEvent(Event event) { public void onEvent(Event event) {
Map<String,Object> mapData = null;
try {
mapData = (Map<String,Object>) event.data;
} catch (ClassCastException e) { }
switch (event.type) { switch (event.type) {
case "ConfigSaved": case "ConfigSaved":
if (mApi != null) { if (mApi != null) {
@ -107,30 +111,30 @@ public class EventProcessor implements Runnable, RestApi.OnReceiveEventListener
} }
break; break;
case "PendingDevicesChanged": case "PendingDevicesChanged":
mapNullable((List<Map<String,String>>) event.data.get("added"), this::onPendingDevicesChanged); mapNullable((List<Map<String,String>>) mapData.get("added"), this::onPendingDevicesChanged);
break; break;
case "FolderCompletion": case "FolderCompletion":
CompletionInfo completionInfo = new CompletionInfo(); CompletionInfo completionInfo = new CompletionInfo();
completionInfo.completion = (Double) event.data.get("completion"); completionInfo.completion = (Double) mapData.get("completion");
mApi.setCompletionInfo( mApi.setCompletionInfo(
(String) event.data.get("device"), // deviceId (String) mapData.get("device"), // deviceId
(String) event.data.get("folder"), // folderId (String) mapData.get("folder"), // folderId
completionInfo completionInfo
); );
break; break;
case "PendingFoldersChanged": case "PendingFoldersChanged":
mapNullable((List<Map<String,String>>) event.data.get("added"), this::onPendingFoldersChanged); mapNullable((List<Map<String,String>>) mapData.get("added"), this::onPendingFoldersChanged);
break; break;
case "ItemFinished": case "ItemFinished":
String folder = (String) event.data.get("folder"); String folder = (String) mapData.get("folder");
String folderPath = null; String folderPath = null;
for (Folder f : mApi.getFolders()) { for (Folder f : mApi.getFolders()) {
if (f.id.equals(folder)) { if (f.id.equals(folder)) {
folderPath = f.path; folderPath = f.path;
} }
} }
File updatedFile = new File(folderPath, (String) event.data.get("item")); File updatedFile = new File(folderPath, (String) mapData.get("item"));
if (!"delete".equals(event.data.get("action"))) { if (!"delete".equals(mapData.get("action"))) {
Log.i(TAG, "Rescanned file via MediaScanner: " + updatedFile.toString()); Log.i(TAG, "Rescanned file via MediaScanner: " + updatedFile.toString());
MediaScannerConnection.scanFile(mContext, new String[]{updatedFile.getPath()}, MediaScannerConnection.scanFile(mContext, new String[]{updatedFile.getPath()},
null, null); null, null);