mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 13:47:41 +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:
parent
6940bac3e6
commit
9c29cbf594
@ -692,46 +692,40 @@ 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();
|
||||
} catch (Exception e) {
|
||||
success = false;
|
||||
e.printStackTrace();
|
||||
Log.e("KDE/addPlugin", "Exception loading plugin " + pluginKey);
|
||||
}
|
||||
|
||||
boolean success;
|
||||
try {
|
||||
success = plugin.onCreate();
|
||||
} catch (Exception e) {
|
||||
success = false;
|
||||
e.printStackTrace();
|
||||
Log.e("KDE/addPlugin", "Exception loading plugin " + pluginKey);
|
||||
}
|
||||
|
||||
if (success) {
|
||||
//Log.e("addPlugin","added " + pluginKey);
|
||||
failedPlugins.remove(pluginKey);
|
||||
plugins.put(pluginKey, plugin);
|
||||
} else {
|
||||
Log.e("KDE/addPlugin", "plugin failed to load " + pluginKey);
|
||||
plugins.remove(pluginKey);
|
||||
failedPlugins.put(pluginKey, plugin);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
if (success) {
|
||||
//Log.e("addPlugin","added " + pluginKey);
|
||||
failedPlugins.remove(pluginKey);
|
||||
plugins.put(pluginKey, plugin);
|
||||
} else {
|
||||
Log.e("KDE/addPlugin", "plugin failed to load " + pluginKey);
|
||||
plugins.remove(pluginKey);
|
||||
failedPlugins.put(pluginKey, plugin);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
private synchronized boolean removePlugin(String pluginKey) {
|
||||
@ -816,19 +810,21 @@ public class Device implements BaseLink.PackageReceiver {
|
||||
}
|
||||
|
||||
if (pluginEnabled) {
|
||||
addPlugin(pluginKey);
|
||||
boolean success = addPlugin(pluginKey);
|
||||
|
||||
for (String packageType : incomingInterfaces) {
|
||||
ArrayList<String> plugins = newPluginsByIncomingInterface.get(packageType);
|
||||
if (plugins == null) plugins = new ArrayList<>();
|
||||
plugins.add(pluginKey);
|
||||
newPluginsByIncomingInterface.put(packageType, plugins);
|
||||
}
|
||||
for (String packageType : outgoingInterfaces) {
|
||||
ArrayList<String> plugins = newPluginsByOutgoingInterface.get(packageType);
|
||||
if (plugins == null) plugins = new ArrayList<>();
|
||||
plugins.add(pluginKey);
|
||||
newPluginsByOutgoingInterface.put(packageType, plugins);
|
||||
if (success) {
|
||||
for (String packageType : incomingInterfaces) {
|
||||
ArrayList<String> plugins = newPluginsByIncomingInterface.get(packageType);
|
||||
if (plugins == null) plugins = new ArrayList<>();
|
||||
plugins.add(pluginKey);
|
||||
newPluginsByIncomingInterface.put(packageType, plugins);
|
||||
}
|
||||
for (String packageType : outgoingInterfaces) {
|
||||
ArrayList<String> plugins = newPluginsByOutgoingInterface.get(packageType);
|
||||
if (plugins == null) plugins = new ArrayList<>();
|
||||
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,28 +47,33 @@ public class ClipboardListener {
|
||||
return;
|
||||
}
|
||||
|
||||
cm = (ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
listener = new ClipboardManager.OnPrimaryClipChangedListener() {
|
||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||
@Override
|
||||
public void onPrimaryClipChanged() {
|
||||
try {
|
||||
public void run() {
|
||||
cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
listener = new ClipboardManager.OnPrimaryClipChangedListener() {
|
||||
@Override
|
||||
public void onPrimaryClipChanged() {
|
||||
try {
|
||||
|
||||
ClipData.Item item = cm.getPrimaryClip().getItemAt(0);
|
||||
String content = item.coerceToText(context).toString();
|
||||
ClipData.Item item = cm.getPrimaryClip().getItemAt(0);
|
||||
String content = item.coerceToText(context).toString();
|
||||
|
||||
if (!content.equals(currentContent)) {
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_CLIPBOARD);
|
||||
np.set("content", content);
|
||||
device.sendPackage(np);
|
||||
currentContent = content;
|
||||
if (!content.equals(currentContent)) {
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_CLIPBOARD);
|
||||
np.set("content", content);
|
||||
device.sendPackage(np);
|
||||
currentContent = content;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
//Probably clipboard was not text
|
||||
}
|
||||
}
|
||||
|
||||
} catch(Exception e) {
|
||||
//Probably clipboard was not text
|
||||
}
|
||||
};
|
||||
cm.addPrimaryClipChangedListener(listener);
|
||||
}
|
||||
};
|
||||
cm.addPrimaryClipChangedListener(listener);
|
||||
});
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user