mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 21:55:10 +00:00
Load plugins in the same thread, so we know if they failed or not
This way we can update the capabilities accordingly.
This commit is contained in:
@@ -692,24 +692,20 @@ public class Device implements BaseLink.PackageReceiver {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
private synchronized void addPlugin(final String pluginKey) {
|
||||
private synchronized boolean addPlugin(final String pluginKey) {
|
||||
Plugin existing = plugins.get(pluginKey);
|
||||
if (existing != null) {
|
||||
//Log.w("KDE/addPlugin","plugin already present:" + pluginKey);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
final Plugin plugin = PluginFactory.instantiatePluginForDevice(context, pluginKey, this);
|
||||
if (plugin == null) {
|
||||
Log.e("KDE/addPlugin","could not instantiate plugin: "+pluginKey);
|
||||
failedPlugins.put(pluginKey, null);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
boolean success;
|
||||
try {
|
||||
success = plugin.onCreate();
|
||||
@@ -729,9 +725,7 @@ public class Device implements BaseLink.PackageReceiver {
|
||||
failedPlugins.put(pluginKey, plugin);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
private synchronized boolean removePlugin(String pluginKey) {
|
||||
@@ -816,8 +810,9 @@ public class Device implements BaseLink.PackageReceiver {
|
||||
}
|
||||
|
||||
if (pluginEnabled) {
|
||||
addPlugin(pluginKey);
|
||||
boolean success = addPlugin(pluginKey);
|
||||
|
||||
if (success) {
|
||||
for (String packageType : incomingInterfaces) {
|
||||
ArrayList<String> plugins = newPluginsByIncomingInterface.get(packageType);
|
||||
if (plugins == null) plugins = new ArrayList<>();
|
||||
@@ -830,6 +825,7 @@ public class Device implements BaseLink.PackageReceiver {
|
||||
plugins.add(pluginKey);
|
||||
newPluginsByOutgoingInterface.put(packageType, plugins);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
removePlugin(pluginKey);
|
||||
}
|
||||
|
@@ -25,6 +25,8 @@ import android.content.ClipData;
|
||||
import android.content.Context;
|
||||
import android.content.ClipboardManager;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import org.kde.kdeconnect.Device;
|
||||
import org.kde.kdeconnect.NetworkPackage;
|
||||
@@ -45,6 +47,9 @@ public class ClipboardListener {
|
||||
return;
|
||||
}
|
||||
|
||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
listener = new ClipboardManager.OnPrimaryClipChangedListener() {
|
||||
@Override
|
||||
@@ -68,6 +73,8 @@ public class ClipboardListener {
|
||||
};
|
||||
cm.addPrimaryClipChangedListener(listener);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if(android.os.Build.VERSION.SDK_INT < 11) {
|
||||
|
Reference in New Issue
Block a user