mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-19 02:10:28 +08:00
update: adapt interface draft-2.2
This commit is contained in:
parent
28a7989cd2
commit
75db4ed766
@ -1 +1 @@
|
||||
5223
|
||||
5224
|
@ -48,28 +48,28 @@ namespace Qv2ray::components::plugins
|
||||
info.pluginLoader->unload();
|
||||
continue;
|
||||
}
|
||||
if (plugins.contains(info.pluginInterface->InternalName()))
|
||||
info.metadata = info.pluginInterface->GetMetadata();
|
||||
if (plugins.contains(info.metadata.InternalName))
|
||||
{
|
||||
LOG(MODULE_PLUGINHOST,
|
||||
"Found another plugin with the same internal name: " + info.pluginInterface->InternalName() + ". Skipped")
|
||||
LOG(MODULE_PLUGINHOST, "Found another plugin with the same internal name: " + info.metadata.InternalName + ". Skipped")
|
||||
continue;
|
||||
}
|
||||
|
||||
if (info.pluginInterface->QvPluginInterfaceVersion != QV2RAY_PLUGIN_INTERFACE_VERSION)
|
||||
{
|
||||
// The plugin was built for a not-compactable version of Qv2ray. Don't load the plugin by default.
|
||||
LOG(MODULE_PLUGINHOST, "The plugin " + info.pluginInterface->InternalName() +
|
||||
LOG(MODULE_PLUGINHOST, "The plugin " + info.metadata.InternalName +
|
||||
" is not loaded since it was built against a different version of interface")
|
||||
info.errorMessage = tr("This plugin was built against an incompactable version of Qv2ray Plugin Interface.") + NEWLINE +
|
||||
QObject::tr("Please contact the plugin provider or report the issue to Qv2ray Workgroup.");
|
||||
}
|
||||
|
||||
connect(info.pluginInterface->GetQObject(), SIGNAL(PluginLog(const QString &)), this, SLOT(QvPluginLog(const QString &)));
|
||||
connect(info.pluginInterface->GetQObject(), SIGNAL(PluginErrorMessageBox(const QString &)), this,
|
||||
connect(dynamic_cast<QObject *>(info.pluginInterface), SIGNAL(PluginLog(const QString &)), this,
|
||||
SLOT(QvPluginLog(const QString &)));
|
||||
connect(dynamic_cast<QObject *>(info.pluginInterface), SIGNAL(PluginErrorMessageBox(const QString &)), this,
|
||||
SLOT(QvPluginMessageBox(const QString &)));
|
||||
LOG(MODULE_PLUGINHOST,
|
||||
"Loaded plugin: \"" + info.pluginInterface->Name() + "\" made by: \"" + info.pluginInterface->Author() + "\"")
|
||||
plugins.insert(info.pluginInterface->InternalName(), info);
|
||||
LOG(MODULE_PLUGINHOST, "Loaded plugin: \"" + info.metadata.Name + "\" made by: \"" + info.metadata.Author + "\"")
|
||||
plugins.insert(info.metadata.InternalName, info);
|
||||
}
|
||||
}
|
||||
return plugins.count();
|
||||
@ -78,7 +78,7 @@ namespace Qv2ray::components::plugins
|
||||
const QString QvPluginHost::GetPluginTypeString(const QString &internalName) const
|
||||
{
|
||||
QStringList types;
|
||||
for (auto type : plugins.value(internalName).pluginInterface->SpecialPluginType())
|
||||
for (auto type : plugins.value(internalName).metadata.SpecialPluginType)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
@ -94,15 +94,15 @@ namespace Qv2ray::components::plugins
|
||||
const QString QvPluginHost::GetPluginHookTypeString(const QString &internalName) const
|
||||
{
|
||||
QStringList hooks;
|
||||
for (auto hook : plugins.value(internalName).pluginInterface->PluginHooks())
|
||||
for (auto hook : plugins.value(internalName).metadata.Capabilities)
|
||||
{
|
||||
switch (hook)
|
||||
{
|
||||
case PROCESSTYPE_NONE: hooks << tr("No hook"); break;
|
||||
case PROCESSTYPE_CONNECTIVITY: hooks << tr("Connection State Change"); break;
|
||||
case PROCESSTYPE_ITEM: hooks << tr("Connection Change"); break;
|
||||
case PROCESSTYPE_STATS: hooks << tr("Statistics Event"); break;
|
||||
case PROCESSTYPE_SYSTEMPROXY: hooks << tr("System Proxy"); break;
|
||||
case CAPABILITY_NONE: hooks << tr("No hook"); break;
|
||||
case CAPABILITY_CONNECTIVITY: hooks << tr("Connection State Change"); break;
|
||||
case CAPABILITY_CONNECTION_ENTRY: hooks << tr("Connection Change"); break;
|
||||
case CAPABILITY_STATS: hooks << tr("Statistics Event"); break;
|
||||
case CAPABILITY_SYSTEM_PROXY: hooks << tr("System Proxy"); break;
|
||||
default: hooks << tr("Unknown/unsupported hook type."); break;
|
||||
}
|
||||
}
|
||||
@ -114,7 +114,7 @@ namespace Qv2ray::components::plugins
|
||||
auto _sender = sender();
|
||||
if (auto _interface = qobject_cast<Qv2rayInterface *>(_sender); _interface)
|
||||
{
|
||||
LOG(MODULE_PLUGINCLIENT + "-" + _interface->InternalName(), log)
|
||||
LOG(MODULE_PLUGINCLIENT + "-" + _interface->GetMetadata().InternalName, log)
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -127,7 +127,7 @@ namespace Qv2ray::components::plugins
|
||||
auto _sender = sender();
|
||||
if (auto _interface = qobject_cast<Qv2rayInterface *>(_sender); _interface)
|
||||
{
|
||||
QvMessageBoxWarn(nullptr, _interface->InternalName(), msg);
|
||||
QvMessageBoxWarn(nullptr, _interface->GetMetadata().Name, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -164,7 +164,7 @@ namespace Qv2ray::components::plugins
|
||||
{
|
||||
for (auto &&plugin : plugins)
|
||||
{
|
||||
DEBUG(MODULE_PLUGINHOST, "Unloading: \"" + plugin.pluginInterface->Name() + "\"")
|
||||
DEBUG(MODULE_PLUGINHOST, "Unloading: \"" + plugin.metadata.Name + "\"")
|
||||
plugin.pluginLoader->unload();
|
||||
plugin.pluginLoader->deleteLater();
|
||||
}
|
||||
@ -191,7 +191,7 @@ namespace Qv2ray::components::plugins
|
||||
}
|
||||
|
||||
auto conf = JsonFromString(StringFromFile(QV2RAY_PLUGIN_SETTINGS_DIR + internalName + ".conf"));
|
||||
plugins[internalName].pluginInterface->InitializePlugin(QV2RAY_PLUGIN_SETTINGS_DIR + internalName + "/", conf);
|
||||
plugins[internalName].pluginInterface->Initialize(QV2RAY_PLUGIN_SETTINGS_DIR + internalName + "/", conf);
|
||||
plugins[internalName].isLoaded = true;
|
||||
return true;
|
||||
}
|
||||
@ -201,7 +201,7 @@ namespace Qv2ray::components::plugins
|
||||
for (auto name : plugins.keys())
|
||||
{
|
||||
LOG(MODULE_PLUGINHOST, "Saving plugin settings for: \"" + name + "\"")
|
||||
auto &conf = plugins[name].pluginInterface->GetPluginSettngs();
|
||||
auto &conf = plugins[name].pluginInterface->GetSettngs();
|
||||
StringToFile(JsonToString(conf), QV2RAY_PLUGIN_SETTINGS_DIR + name + ".conf");
|
||||
}
|
||||
ClearPlugins();
|
||||
@ -212,9 +212,9 @@ namespace Qv2ray::components::plugins
|
||||
{
|
||||
for (auto &plugin : plugins)
|
||||
{
|
||||
if (plugin.pluginInterface->PluginHooks().contains(QV2RAY_PLUGIN_PROCESSTYPE::PROCESSTYPE_STATS))
|
||||
if (plugin.metadata.Capabilities.contains(CAPABILITY_STATS))
|
||||
{
|
||||
plugin.pluginInterface->PluginProcessor()->ProcessEvent_ConnectionStats(object);
|
||||
plugin.pluginInterface->GetEventHandler()->ProcessEvent_ConnectionStats(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -222,19 +222,19 @@ namespace Qv2ray::components::plugins
|
||||
{
|
||||
for (auto &plugin : plugins)
|
||||
{
|
||||
if (plugin.pluginInterface->PluginHooks().contains(QV2RAY_PLUGIN_PROCESSTYPE::PROCESSTYPE_CONNECTIVITY))
|
||||
if (plugin.metadata.Capabilities.contains(CAPABILITY_CONNECTIVITY))
|
||||
{
|
||||
plugin.pluginInterface->PluginProcessor()->ProcessEvent_Connectivity(object);
|
||||
plugin.pluginInterface->GetEventHandler()->ProcessEvent_Connectivity(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
void QvPluginHost::Send_ItemEvent(const QvItemEventObject &object)
|
||||
void QvPluginHost::Send_ConnectionEvent(const QvConnectionEntryEventObject &object)
|
||||
{
|
||||
for (auto &plugin : plugins)
|
||||
{
|
||||
if (plugin.pluginInterface->PluginHooks().contains(QV2RAY_PLUGIN_PROCESSTYPE::PROCESSTYPE_ITEM))
|
||||
if (plugin.metadata.Capabilities.contains(CAPABILITY_CONNECTION_ENTRY))
|
||||
{
|
||||
plugin.pluginInterface->PluginProcessor()->ProcessEvent_Item(object);
|
||||
plugin.pluginInterface->GetEventHandler()->ProcessEvent_ConnectionEntry(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -242,9 +242,9 @@ namespace Qv2ray::components::plugins
|
||||
{
|
||||
for (auto &plugin : plugins)
|
||||
{
|
||||
if (plugin.pluginInterface->PluginHooks().contains(QV2RAY_PLUGIN_PROCESSTYPE::PROCESSTYPE_SYSTEMPROXY))
|
||||
if (plugin.metadata.Capabilities.contains(CAPABILITY_SYSTEM_PROXY))
|
||||
{
|
||||
plugin.pluginInterface->PluginProcessor()->ProcessEvent_SystemProxy(object);
|
||||
plugin.pluginInterface->GetEventHandler()->ProcessEvent_SystemProxy(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ namespace Qv2ray::components::plugins
|
||||
bool isLoaded = false;
|
||||
QString libraryPath;
|
||||
QString errorMessage;
|
||||
QvPluginMetadata metadata;
|
||||
QPluginLoader *pluginLoader;
|
||||
Qv2rayInterface *pluginInterface;
|
||||
};
|
||||
@ -41,7 +42,7 @@ namespace Qv2ray::components::plugins
|
||||
//
|
||||
void Send_ConnectionStatsEvent(const QvConnectionStatsEventObject &object);
|
||||
void Send_ConnectivityEvent(const QvConnectivityEventObject &object);
|
||||
void Send_ItemEvent(const QvItemEventObject &object);
|
||||
void Send_ConnectionEvent(const QvConnectionEntryEventObject &object);
|
||||
void Send_SystemProxyEvent(const QvSystemProxyEventObject &object);
|
||||
//
|
||||
private slots:
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit e60b7a06c9b9ba79498500a07b20d2bef44da34e
|
||||
Subproject commit 05cec33cc42bf291de0115f799b5d10920715182
|
@ -223,7 +223,7 @@ namespace Qv2ray::core::handlers
|
||||
{
|
||||
CheckConnectionExistance(id);
|
||||
OnConnectionRenamed(id, connections[id].displayName, newName);
|
||||
PluginHost->Send_ItemEvent({ newName, connections[id].displayName, ConnectionEvent_Renamed });
|
||||
PluginHost->Send_ConnectionEvent({ newName, connections[id].displayName, ConnectionEvent_Renamed });
|
||||
connections[id].displayName = newName;
|
||||
CHSaveConfigData_p();
|
||||
return {};
|
||||
@ -235,7 +235,7 @@ namespace Qv2ray::core::handlers
|
||||
QFile connectionFile((groups[groupId].isSubscription ? QV2RAY_SUBSCRIPTION_DIR : QV2RAY_CONNECTIONS_DIR) + groupId.toString() + "/" +
|
||||
id.toString() + QV2RAY_CONFIG_FILE_EXTENSION);
|
||||
//
|
||||
PluginHost->Send_ItemEvent({ connections[id].displayName, "", ConnectionEvent_Deleted });
|
||||
PluginHost->Send_ConnectionEvent({ connections[id].displayName, "", ConnectionEvent_Deleted });
|
||||
connections.remove(id);
|
||||
groups[groupId].connections.removeAll(id);
|
||||
//
|
||||
@ -283,7 +283,7 @@ namespace Qv2ray::core::handlers
|
||||
groups[newGroupId].connections.append(id);
|
||||
connections[id].groupId = newGroupId;
|
||||
//
|
||||
PluginHost->Send_ItemEvent({ connections[id].displayName, "", ConnectionEvent_Updated });
|
||||
PluginHost->Send_ConnectionEvent({ connections[id].displayName, "", ConnectionEvent_Updated });
|
||||
//
|
||||
emit OnConnectionGroupChanged(id, oldgid, newGroupId);
|
||||
//
|
||||
@ -314,7 +314,7 @@ namespace Qv2ray::core::handlers
|
||||
QDir(QV2RAY_CONNECTIONS_DIR + id.toString()).removeRecursively();
|
||||
}
|
||||
//
|
||||
PluginHost->Send_ItemEvent({ groups[id].displayName, "", ConnectionEvent_Deleted });
|
||||
PluginHost->Send_ConnectionEvent({ groups[id].displayName, "", ConnectionEvent_Deleted });
|
||||
//
|
||||
groups.remove(id);
|
||||
CHSaveConfigData_p();
|
||||
@ -407,7 +407,7 @@ namespace Qv2ray::core::handlers
|
||||
connectionRootCache[id] = root;
|
||||
//
|
||||
emit OnConnectionModified(id);
|
||||
PluginHost->Send_ItemEvent({ connections[id].displayName, "", ConnectionEvent_Updated });
|
||||
PluginHost->Send_ConnectionEvent({ connections[id].displayName, "", ConnectionEvent_Updated });
|
||||
if (!skipRestart && id == currentConnectionId)
|
||||
{
|
||||
emit RestartConnection();
|
||||
@ -421,7 +421,7 @@ namespace Qv2ray::core::handlers
|
||||
groups[id].displayName = displayName;
|
||||
groups[id].isSubscription = isSubscription;
|
||||
groups[id].importDate = system_clock::to_time_t(system_clock::now());
|
||||
PluginHost->Send_ItemEvent({ displayName, "", ConnectionEvent_Created });
|
||||
PluginHost->Send_ConnectionEvent({ displayName, "", ConnectionEvent_Created });
|
||||
emit OnGroupCreated(id, displayName);
|
||||
CHSaveConfigData_p();
|
||||
return id;
|
||||
@ -435,7 +435,7 @@ namespace Qv2ray::core::handlers
|
||||
return tr("Group does not exist");
|
||||
}
|
||||
OnGroupRenamed(id, groups[id].displayName, newName);
|
||||
PluginHost->Send_ItemEvent({ newName, groups[id].displayName, ConnectionEvent_Renamed });
|
||||
PluginHost->Send_ConnectionEvent({ newName, groups[id].displayName, ConnectionEvent_Renamed });
|
||||
groups[id].displayName = newName;
|
||||
return {};
|
||||
}
|
||||
@ -603,7 +603,7 @@ namespace Qv2ray::core::handlers
|
||||
connections[newId].importDate = system_clock::to_time_t(system_clock::now());
|
||||
connections[newId].displayName = displayName;
|
||||
emit OnConnectionCreated(newId, displayName);
|
||||
PluginHost->Send_ItemEvent({ displayName, "", ConnectionEvent_Created });
|
||||
PluginHost->Send_ConnectionEvent({ displayName, "", ConnectionEvent_Created });
|
||||
UpdateConnection(newId, root);
|
||||
CHSaveConfigData_p();
|
||||
return newId;
|
||||
|
@ -12,9 +12,9 @@ PluginManageWindow::PluginManageWindow(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
const auto &info = PluginHost->GetPluginInfo(plugin);
|
||||
auto item = new QListWidgetItem(pluginListWidget);
|
||||
item->setCheckState(PluginHost->GetPluginEnableState(info.pluginInterface->InternalName()) ? Qt::Checked : Qt::Unchecked);
|
||||
item->setData(Qt::UserRole, info.pluginInterface->InternalName());
|
||||
item->setText(info.pluginInterface->Name() + " (" + (info.isLoaded ? tr("Loaded") : tr("Not loaded")) + ")");
|
||||
item->setCheckState(PluginHost->GetPluginEnableState(info.metadata.InternalName) ? Qt::Checked : Qt::Unchecked);
|
||||
item->setData(Qt::UserRole, info.metadata.InternalName);
|
||||
item->setText(info.metadata.Name + " (" + (info.isLoaded ? tr("Loaded") : tr("Not loaded")) + ")");
|
||||
pluginListWidget->addItem(item);
|
||||
}
|
||||
isLoading = false;
|
||||
@ -30,15 +30,15 @@ void PluginManageWindow::on_pluginListWidget_currentItemChanged(QListWidgetItem
|
||||
auto &info = PluginHost->GetPluginInfo(current->data(Qt::UserRole).toString());
|
||||
if (info.pluginInterface)
|
||||
{
|
||||
pluginIconLabel->setPixmap(info.pluginInterface->Icon().pixmap(pluginIconLabel->size() * devicePixelRatio()));
|
||||
pluginIconLabel->setPixmap(info.metadata.Icon.pixmap(pluginIconLabel->size() * devicePixelRatio()));
|
||||
//
|
||||
pluginNameLabel->setText(info.pluginInterface->Name());
|
||||
pluginAuthorLabel->setText(info.pluginInterface->Author());
|
||||
pluginDescriptionLabel->setText(info.pluginInterface->Description());
|
||||
pluginNameLabel->setText(info.metadata.Name);
|
||||
pluginAuthorLabel->setText(info.metadata.Author);
|
||||
pluginDescriptionLabel->setText(info.metadata.Description);
|
||||
pluginLibPathLabel->setText(info.libraryPath);
|
||||
pluginStateLabel->setText(info.isLoaded ? tr("Loaded") : tr("Not loaded"));
|
||||
pluginTypeLabel->setText(PluginHost->GetPluginTypeString(info.pluginInterface->InternalName()));
|
||||
pluginHookTypeLabel->setText(PluginHost->GetPluginHookTypeString(info.pluginInterface->InternalName()));
|
||||
pluginTypeLabel->setText(PluginHost->GetPluginTypeString(info.metadata.InternalName));
|
||||
pluginHookTypeLabel->setText(PluginHost->GetPluginHookTypeString(info.metadata.InternalName));
|
||||
pluginErrMessageTxt->setPlainText(info.errorMessage.isEmpty() ? "OK" : info.errorMessage);
|
||||
}
|
||||
}
|
||||
@ -56,7 +56,7 @@ void PluginManageWindow::on_pluginListWidget_itemChanged(QListWidgetItem *item)
|
||||
auto pluginInternalName = item->data(Qt::UserRole).toString();
|
||||
PluginHost->SetPluginEnableState(pluginInternalName, isEnabled);
|
||||
auto &info = PluginHost->GetPluginInfo(pluginInternalName);
|
||||
item->setText(info.pluginInterface->Name() + " (" + (info.isLoaded ? tr("Loaded") : tr("Not loaded")) + ")");
|
||||
item->setText(info.metadata.Name + " (" + (info.isLoaded ? tr("Loaded") : tr("Not loaded")) + ")");
|
||||
//
|
||||
if (!isEnabled)
|
||||
{
|
||||
@ -96,11 +96,11 @@ void PluginManageWindow::on_pluginEditSettingsJsonBtn_clicked()
|
||||
tr("This plugin has been unloaded or has been disabled, please enable or reload the plugin to continue."));
|
||||
return;
|
||||
}
|
||||
JsonEditor w(info.pluginInterface->GetPluginSettngs());
|
||||
JsonEditor w(info.pluginInterface->GetSettngs());
|
||||
auto newConf = w.OpenEditor();
|
||||
if (w.result() == QDialog::Accepted)
|
||||
{
|
||||
info.pluginInterface->UpdatePluginSettings(newConf);
|
||||
info.pluginInterface->UpdateSettings(newConf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user