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