fix: 去掉插件中读取禁用当前插件的配置

需求:在新的需求中,通过从控制中心中勾选或者取消勾选插件的显示功能,不再从系统中移除插件,插件中无需通过配置的功能来决定是否加载插件,而变成在插件内部根据当前插件是否需要加载来决定是否加载,例如蓝牙,只要系统中存在蓝牙,就始终加载蓝牙插件

Log: 插件始终都要加载
Influence: 插入蓝牙观察是否有蓝牙图标
Bug: https://pms.uniontech.com/bug-view-175085.html
Change-Id: I1a07ce0d6bd658a03e349e94283768082794684d
This commit is contained in:
donghualin 2022-12-01 19:36:53 +08:00
parent 7b11668d04
commit 4c4d06310b
9 changed files with 21 additions and 159 deletions

View File

@ -45,26 +45,21 @@ const QString AirplaneModePlugin::pluginDisplayName() const
void AirplaneModePlugin::init(PluginProxyInterface *proxyInter) void AirplaneModePlugin::init(PluginProxyInterface *proxyInter)
{ {
if (m_proxyInter == proxyInter)
return;
m_proxyInter = proxyInter; m_proxyInter = proxyInter;
if (!pluginIsDisable()) m_proxyInter->itemAdded(this, AIRPLANEMODE_KEY);
m_proxyInter->itemAdded(this, AIRPLANEMODE_KEY);
refreshAirplaneEnableState(); refreshAirplaneEnableState();
} }
void AirplaneModePlugin::pluginStateSwitched() void AirplaneModePlugin::pluginStateSwitched()
{ {
m_proxyInter->saveValue(this, STATE_KEY, pluginIsDisable());
refreshAirplaneEnableState(); refreshAirplaneEnableState();
} }
bool AirplaneModePlugin::pluginIsDisable()
{
return !m_proxyInter->getValue(this, STATE_KEY, true).toBool();
}
QWidget *AirplaneModePlugin::itemWidget(const QString &itemKey) QWidget *AirplaneModePlugin::itemWidget(const QString &itemKey)
{ {
if (itemKey == AIRPLANEMODE_KEY) { if (itemKey == AIRPLANEMODE_KEY) {

View File

@ -40,7 +40,6 @@ public:
void init(PluginProxyInterface *proxyInter) Q_DECL_OVERRIDE; void init(PluginProxyInterface *proxyInter) Q_DECL_OVERRIDE;
void pluginStateSwitched() Q_DECL_OVERRIDE; void pluginStateSwitched() Q_DECL_OVERRIDE;
bool pluginIsAllowDisable() Q_DECL_OVERRIDE { return true; } bool pluginIsAllowDisable() Q_DECL_OVERRIDE { return true; }
bool pluginIsDisable() Q_DECL_OVERRIDE;
QWidget *itemWidget(const QString &itemKey) Q_DECL_OVERRIDE; QWidget *itemWidget(const QString &itemKey) Q_DECL_OVERRIDE;
QWidget *itemTipsWidget(const QString &itemKey) Q_DECL_OVERRIDE; QWidget *itemTipsWidget(const QString &itemKey) Q_DECL_OVERRIDE;
int itemSortKey(const QString &itemKey) Q_DECL_OVERRIDE; int itemSortKey(const QString &itemKey) Q_DECL_OVERRIDE;

View File

@ -60,35 +60,19 @@ void BluetoothPlugin::init(PluginProxyInterface *proxyInter)
m_bluetoothWidget.reset(new BluetoothMainWidget(m_adapterManager)); m_bluetoothWidget.reset(new BluetoothMainWidget(m_adapterManager));
connect(m_bluetoothItem.data(), &BluetoothItem::justHasAdapter, [&] { connect(m_bluetoothItem.data(), &BluetoothItem::justHasAdapter, [&] {
m_enableState = true; m_proxyInter->itemAdded(this, BLUETOOTH_KEY);
refreshPluginItemsVisible();
}); });
connect(m_bluetoothItem.data(), &BluetoothItem::noAdapter, [&] { connect(m_bluetoothItem.data(), &BluetoothItem::noAdapter, [&] {
m_enableState = false; m_proxyInter->itemRemoved(this, BLUETOOTH_KEY);
refreshPluginItemsVisible();
}); });
connect(m_bluetoothWidget.data(), &BluetoothMainWidget::requestExpand, this, [ = ] { connect(m_bluetoothWidget.data(), &BluetoothMainWidget::requestExpand, this, [ = ] {
m_proxyInter->requestSetAppletVisible(this, QUICK_ITEM_KEY, true); m_proxyInter->requestSetAppletVisible(this, QUICK_ITEM_KEY, true);
}); });
m_enableState = m_bluetoothItem->hasAdapter(); if (m_bluetoothItem->hasAdapter())
if (!pluginIsDisable())
m_proxyInter->itemAdded(this, BLUETOOTH_KEY); m_proxyInter->itemAdded(this, BLUETOOTH_KEY);
} }
void BluetoothPlugin::pluginStateSwitched()
{
m_proxyInter->saveValue(this, STATE_KEY, pluginIsDisable());
refreshPluginItemsVisible();
}
bool BluetoothPlugin::pluginIsDisable()
{
return !m_proxyInter->getValue(this, STATE_KEY, m_enableState).toBool();
}
QWidget *BluetoothPlugin::itemWidget(const QString &itemKey) QWidget *BluetoothPlugin::itemWidget(const QString &itemKey)
{ {
if (itemKey == BLUETOOTH_KEY) { if (itemKey == BLUETOOTH_KEY) {
@ -151,11 +135,6 @@ void BluetoothPlugin::refreshIcon(const QString &itemKey)
} }
} }
void BluetoothPlugin::pluginSettingsChanged()
{
refreshPluginItemsVisible();
}
QIcon BluetoothPlugin::icon(const DockPart &dockPart) QIcon BluetoothPlugin::icon(const DockPart &dockPart)
{ {
if (dockPart == DockPart::QuickPanel) if (dockPart == DockPart::QuickPanel)
@ -201,10 +180,3 @@ PluginFlags BluetoothPlugin::flags() const
| PluginFlag::Attribute_CanSetting; | PluginFlag::Attribute_CanSetting;
} }
void BluetoothPlugin::refreshPluginItemsVisible()
{
if (pluginIsDisable())
m_proxyInter->itemRemoved(this, BLUETOOTH_KEY);
else
m_proxyInter->itemAdded(this, BLUETOOTH_KEY);
}

View File

@ -44,9 +44,7 @@ public:
const QString pluginName() const override; const QString pluginName() const override;
const QString pluginDisplayName() const override; const QString pluginDisplayName() const override;
void init(PluginProxyInterface *proxyInter) override; void init(PluginProxyInterface *proxyInter) override;
void pluginStateSwitched() override;
bool pluginIsAllowDisable() override { return true; } bool pluginIsAllowDisable() override { return true; }
bool pluginIsDisable() override;
QWidget *itemWidget(const QString &itemKey) override; QWidget *itemWidget(const QString &itemKey) override;
QWidget *itemTipsWidget(const QString &itemKey) override; QWidget *itemTipsWidget(const QString &itemKey) override;
QWidget *itemPopupApplet(const QString &itemKey) override; QWidget *itemPopupApplet(const QString &itemKey) override;
@ -54,7 +52,6 @@ public:
int itemSortKey(const QString &itemKey) override; int itemSortKey(const QString &itemKey) override;
void setSortKey(const QString &itemKey, const int order) override; void setSortKey(const QString &itemKey, const int order) override;
void refreshIcon(const QString &itemKey) override; void refreshIcon(const QString &itemKey) override;
void pluginSettingsChanged() override;
QIcon icon(const DockPart &) override; QIcon icon(const DockPart &) override;
QIcon icon(const DockPart &dockPart, int themeType) override; QIcon icon(const DockPart &dockPart, int themeType) override;
@ -62,9 +59,6 @@ public:
QString description() const override; QString description() const override;
PluginFlags flags() const override; PluginFlags flags() const override;
private:
void refreshPluginItemsVisible();
private: private:
AdaptersManager *m_adapterManager; AdaptersManager *m_adapterManager;
QScopedPointer<BluetoothItem> m_bluetoothItem; QScopedPointer<BluetoothItem> m_bluetoothItem;

View File

@ -186,11 +186,10 @@ AdaptersManager *BluetoothApplet::adaptersManager()
void BluetoothApplet::onAdapterAdded(Adapter *adapter) void BluetoothApplet::onAdapterAdded(Adapter *adapter)
{ {
if (!m_adapterItems.size()) { bool needJustHasAdapter = (m_adapterItems.size() == 0);
emit justHasAdapter();
}
if (m_adapterItems.contains(adapter->id())) { if (m_adapterItems.contains(adapter->id())) {
onAdapterRemoved(m_adapterItems.value(adapter->id())->adapter()); onAdapterRemoved(m_adapterItems.value(adapter->id())->adapter());
needJustHasAdapter = (m_adapterItems.size() == 0);
} }
BluetoothAdapterItem *adapterItem = new BluetoothAdapterItem(adapter, this); BluetoothAdapterItem *adapterItem = new BluetoothAdapterItem(adapter, this);
@ -207,6 +206,9 @@ void BluetoothApplet::onAdapterAdded(Adapter *adapter)
m_contentLayout->insertWidget(m_contentLayout->count() - 1, adapterItem, Qt::AlignTop | Qt::AlignVCenter); m_contentLayout->insertWidget(m_contentLayout->count() - 1, adapterItem, Qt::AlignTop | Qt::AlignVCenter);
updateBluetoothPowerState(); updateBluetoothPowerState();
updateSize(); updateSize();
if (needJustHasAdapter)
emit justHasAdapter();
} }
void BluetoothApplet::onAdapterRemoved(Adapter *adapter) void BluetoothApplet::onAdapterRemoved(Adapter *adapter)

View File

@ -33,7 +33,6 @@ DGUI_USE_NAMESPACE
using namespace Dock; using namespace Dock;
MultitaskingPlugin::MultitaskingPlugin(QObject *parent) MultitaskingPlugin::MultitaskingPlugin(QObject *parent)
: QObject(parent) : QObject(parent)
, m_pluginLoaded(false)
, m_multitaskingWidget(nullptr) , m_multitaskingWidget(nullptr)
, m_tipsLabel(new TipsWidget) , m_tipsLabel(new TipsWidget)
{ {
@ -41,10 +40,10 @@ MultitaskingPlugin::MultitaskingPlugin(QObject *parent)
m_tipsLabel->setObjectName("multitasking"); m_tipsLabel->setObjectName("multitasking");
connect(DWindowManagerHelper::instance(), &DWindowManagerHelper::hasCompositeChanged, this, [ = ] { connect(DWindowManagerHelper::instance(), &DWindowManagerHelper::hasCompositeChanged, this, [ = ] {
if (!m_proxyInter || !m_pluginLoaded) if (!m_proxyInter)
return; return;
if (DWindowManagerHelper::instance()->hasComposite() && !pluginIsDisable()) if (DWindowManagerHelper::instance()->hasComposite())
m_proxyInter->itemAdded(this, PLUGIN_KEY); m_proxyInter->itemAdded(this, PLUGIN_KEY);
else else
m_proxyInter->itemRemoved(this, PLUGIN_KEY); m_proxyInter->itemRemoved(this, PLUGIN_KEY);
@ -80,24 +79,13 @@ QWidget *MultitaskingPlugin::itemTipsWidget(const QString &itemKey)
void MultitaskingPlugin::init(PluginProxyInterface *proxyInter) void MultitaskingPlugin::init(PluginProxyInterface *proxyInter)
{ {
m_proxyInter = proxyInter; m_proxyInter = proxyInter;
m_multitaskingWidget.reset(new MultitaskingWidget);
if (!pluginIsDisable()) { if (DWindowManagerHelper::instance()->hasComposite()) {
loadPlugin(); m_proxyInter->itemAdded(this, pluginName());
} }
} }
void MultitaskingPlugin::pluginStateSwitched()
{
m_proxyInter->saveValue(this, PLUGIN_STATE_KEY, pluginIsDisable());
refreshPluginItemsVisible();
}
bool MultitaskingPlugin::pluginIsDisable()
{
return !m_proxyInter->getValue(this, PLUGIN_STATE_KEY, true).toBool();
}
const QString MultitaskingPlugin::itemCommand(const QString &itemKey) const QString MultitaskingPlugin::itemCommand(const QString &itemKey)
{ {
if (itemKey == PLUGIN_KEY) if (itemKey == PLUGIN_KEY)
@ -174,11 +162,6 @@ void MultitaskingPlugin::setSortKey(const QString &itemKey, const int order)
m_proxyInter->saveValue(this, key, order); m_proxyInter->saveValue(this, key, order);
} }
void MultitaskingPlugin::pluginSettingsChanged()
{
refreshPluginItemsVisible();
}
PluginsItemInterface::PluginType MultitaskingPlugin::type() PluginsItemInterface::PluginType MultitaskingPlugin::type()
{ {
return PluginType::Fixed; return PluginType::Fixed;
@ -188,40 +171,3 @@ PluginFlags MultitaskingPlugin::flags() const
{ {
return PluginFlag::Type_Fixed; return PluginFlag::Type_Fixed;
} }
void MultitaskingPlugin::updateVisible()
{
if (pluginIsDisable() || !DWindowManagerHelper::instance()->hasComposite()) {
m_proxyInter->itemRemoved(this, PLUGIN_KEY);
} else {
m_proxyInter->itemAdded(this, PLUGIN_KEY);
}
}
void MultitaskingPlugin::loadPlugin()
{
if (m_pluginLoaded) {
return;
}
m_pluginLoaded = true;
m_multitaskingWidget.reset(new MultitaskingWidget);
m_proxyInter->itemAdded(this, pluginName());
updateVisible();
}
void MultitaskingPlugin::refreshPluginItemsVisible()
{
if (pluginIsDisable()) {
m_proxyInter->itemRemoved(this, PLUGIN_KEY);
} else {
if (!m_pluginLoaded) {
loadPlugin();
return;
}
updateVisible();
}
}

View File

@ -42,9 +42,7 @@ public:
const QString pluginName() const override; const QString pluginName() const override;
const QString pluginDisplayName() const override; const QString pluginDisplayName() const override;
void init(PluginProxyInterface *proxyInter) override; void init(PluginProxyInterface *proxyInter) override;
void pluginStateSwitched() override;
bool pluginIsAllowDisable() override { return true; } bool pluginIsAllowDisable() override { return true; }
bool pluginIsDisable() override;
QWidget *itemWidget(const QString &itemKey) override; QWidget *itemWidget(const QString &itemKey) override;
QWidget *itemTipsWidget(const QString &itemKey) override; QWidget *itemTipsWidget(const QString &itemKey) override;
const QString itemCommand(const QString &itemKey) override; const QString itemCommand(const QString &itemKey) override;
@ -53,18 +51,10 @@ public:
void refreshIcon(const QString &itemKey) override; void refreshIcon(const QString &itemKey) override;
int itemSortKey(const QString &itemKey) override; int itemSortKey(const QString &itemKey) override;
void setSortKey(const QString &itemKey, const int order) override; void setSortKey(const QString &itemKey, const int order) override;
void pluginSettingsChanged() override;
PluginType type() override; PluginType type() override;
PluginFlags flags() const override; PluginFlags flags() const override;
private: private:
void updateVisible();
void loadPlugin();
void refreshPluginItemsVisible();
private:
bool m_pluginLoaded;
QScopedPointer<MultitaskingWidget> m_multitaskingWidget; QScopedPointer<MultitaskingWidget> m_multitaskingWidget;
QScopedPointer<Dock::TipsWidget> m_tipsLabel; QScopedPointer<Dock::TipsWidget> m_tipsLabel;
}; };

View File

@ -93,21 +93,7 @@ void PowerPlugin::init(PluginProxyInterface *proxyInter)
{ {
m_proxyInter = proxyInter; m_proxyInter = proxyInter;
if (!pluginIsDisable()) { loadPlugin();
loadPlugin();
}
}
void PowerPlugin::pluginStateSwitched()
{
m_proxyInter->saveValue(this, PLUGIN_STATE_KEY, pluginIsDisable());
refreshPluginItemsVisible();
}
bool PowerPlugin::pluginIsDisable()
{
return !m_proxyInter->getValue(this, PLUGIN_STATE_KEY, true).toBool();
} }
const QString PowerPlugin::itemCommand(const QString &itemKey) const QString PowerPlugin::itemCommand(const QString &itemKey)
@ -169,11 +155,6 @@ void PowerPlugin::setSortKey(const QString &itemKey, const int order)
m_proxyInter->saveValue(this, key, order); m_proxyInter->saveValue(this, key, order);
} }
void PowerPlugin::pluginSettingsChanged()
{
refreshPluginItemsVisible();
}
QIcon PowerPlugin::icon(const DockPart &dockPart, int themeType) QIcon PowerPlugin::icon(const DockPart &dockPart, int themeType)
{ {
// 电池插件不显示在快捷面板上,因此此处返回空图标 // 电池插件不显示在快捷面板上,因此此处返回空图标
@ -197,10 +178,10 @@ void PowerPlugin::updateBatteryVisible()
{ {
const bool exist = !m_powerInter->batteryPercentage().isEmpty(); const bool exist = !m_powerInter->batteryPercentage().isEmpty();
if (!exist) if (exist)
m_proxyInter->itemRemoved(this, POWER_KEY);
else if (exist && !pluginIsDisable())
m_proxyInter->itemAdded(this, POWER_KEY); m_proxyInter->itemAdded(this, POWER_KEY);
else
m_proxyInter->itemRemoved(this, POWER_KEY);
} }
void PowerPlugin::loadPlugin() void PowerPlugin::loadPlugin()
@ -239,19 +220,6 @@ void PowerPlugin::loadPlugin()
onGSettingsChanged("showtimetofull"); onGSettingsChanged("showtimetofull");
} }
void PowerPlugin::refreshPluginItemsVisible()
{
if (pluginIsDisable()) {
m_proxyInter->itemRemoved(this, POWER_KEY);
} else {
if (!m_pluginLoaded) {
loadPlugin();
return;
}
updateBatteryVisible();
}
}
void PowerPlugin::onGSettingsChanged(const QString &key) void PowerPlugin::onGSettingsChanged(const QString &key)
{ {
if (key != "showtimetofull") { if (key != "showtimetofull") {

View File

@ -46,9 +46,7 @@ public:
const QString pluginName() const override; const QString pluginName() const override;
const QString pluginDisplayName() const override; const QString pluginDisplayName() const override;
void init(PluginProxyInterface *proxyInter) override; void init(PluginProxyInterface *proxyInter) override;
void pluginStateSwitched() override;
bool pluginIsAllowDisable() override { return true; } bool pluginIsAllowDisable() override { return true; }
bool pluginIsDisable() override;
QWidget *itemWidget(const QString &itemKey) override; QWidget *itemWidget(const QString &itemKey) override;
QWidget *itemTipsWidget(const QString &itemKey) override; QWidget *itemTipsWidget(const QString &itemKey) override;
const QString itemCommand(const QString &itemKey) override; const QString itemCommand(const QString &itemKey) override;
@ -56,14 +54,12 @@ public:
void refreshIcon(const QString &itemKey) override; void refreshIcon(const QString &itemKey) override;
int itemSortKey(const QString &itemKey) override; int itemSortKey(const QString &itemKey) override;
void setSortKey(const QString &itemKey, const int order) override; void setSortKey(const QString &itemKey, const int order) override;
void pluginSettingsChanged() override;
QIcon icon(const DockPart &dockPart, int themeType) override; QIcon icon(const DockPart &dockPart, int themeType) override;
PluginFlags flags() const override; PluginFlags flags() const override;
private: private:
void updateBatteryVisible(); void updateBatteryVisible();
void loadPlugin(); void loadPlugin();
void refreshPluginItemsVisible();
void onGSettingsChanged(const QString &key); void onGSettingsChanged(const QString &key);
void refreshTipsData(); void refreshTipsData();