Skip to content

Commit

Permalink
fix: 控制中心任务栏首次设置系统监视器展示,需要点击2次,系统监视器图标才会在任务栏中显示
Browse files Browse the repository at this point in the history
通过pluginIsDisable()判断首次安装是否显示,无需应用自己编写配置文件并保存状态

Log: 控制中心任务栏首次设置系统监视器展示,需要点击2次,系统监视器图标才会在任务栏中显示

Bug: https://pms.uniontech.com/bug-view-213941.html
     https://pms.uniontech.com/bug-view-207581.html
  • Loading branch information
feeengli authored and deepin-bot[bot] committed Dec 15, 2023
1 parent 7f31a84 commit 62dbce6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 72 deletions.
2 changes: 1 addition & 1 deletion deepin-system-monitor-plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ qt5_add_translation(APP_QM_FILES ${APP_TS_FILES})
add_custom_target(PLUGIN_QMFILES ALL DEPENDS ${APP_QM_FILES})

INSTALL(FILES com.deepin.dde.dock.module.system-monitor.gschema.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/glib-2.0/schemas)
INSTALL(FILES com.deepin.system.monitor.plugin.gschema.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/glib-2.0/schemas)
#INSTALL(FILES com.deepin.system.monitor.plugin.gschema.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/glib-2.0/schemas)
INSTALL(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib/dde-dock/plugins)
#安装翻译文件
install(FILES ${APP_QM_FILES} DESTINATION ${CMAKE_INSTALL_DATADIR}/deepin-system-monitor-plugin/translations)
Expand Down
70 changes: 14 additions & 56 deletions deepin-system-monitor-plugin/gui/monitor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ MonitorPlugin::MonitorPlugin(QObject *parent)
, m_quickPanelWidget(new QuickPanelWidget)
#endif
{
if (QGSettings::isSchemaInstalled("com.deepin.system.monitor.plugin")) {
m_settings = new QGSettings("com.deepin.system.monitor.plugin", "/com/deepin/system/monitor/plugin/", this);
}

connect(m_refershTimer, &QTimer::timeout, this, &MonitorPlugin::udpateTipsInfo);
qInfo() <<__FUNCTION__ << __LINE__ << "[-MonitorPlugin-]" ;
}
Expand Down Expand Up @@ -94,19 +90,26 @@ QWidget *MonitorPlugin::itemWidget(const QString &itemKey)
return m_quickPanelWidget;
}
#endif
if (itemKey == "system-monitor")
return m_itemWidget;
if (itemKey == "system-monitor")
return m_itemWidget;
#endif
return nullptr;
}

void MonitorPlugin::pluginStateSwitched()
{
#ifndef DDE_DOCK_NEW_VERSION
bool pluginState = !m_proxyInter->getValue(this, constantVal::PLUGIN_STATE_KEY, false).toBool();
m_proxyInter->saveValue(this, constantVal::PLUGIN_STATE_KEY, pluginState);

refreshPluginItemsVisible();
const bool disabledNew = !pluginIsDisable();
m_proxyInter->saveValue(this, "disabled", disabledNew);
if (disabledNew) {
m_proxyInter->itemRemoved(this, pluginName());
} else {
if (!m_pluginLoaded) {
loadPlugin();
return;
}
m_proxyInter->itemAdded(this, pluginName());
}
#endif
}

Expand All @@ -116,7 +119,7 @@ bool MonitorPlugin::pluginIsDisable()
#ifdef USE_API_QUICKPANEL20
return false;
#else
return !m_proxyInter->getValue(this, constantVal::PLUGIN_STATE_KEY, false).toBool();
return m_proxyInter->getValue(this, "disabled", true).toBool();
#endif
}
#endif
Expand Down Expand Up @@ -283,8 +286,6 @@ void MonitorPlugin::loadPlugin()
if (m_pluginLoaded)
return;

initPluginState();

m_pluginLoaded = true;

m_dataTipsLabel.reset(new SystemMonitorTipsWidget);
Expand All @@ -295,54 +296,11 @@ void MonitorPlugin::loadPlugin()

m_itemWidget = new MonitorPluginButtonWidget;

#ifdef DDE_DOCK_NEW_VERSION
// 新版本dde-dock不需要应用自己判断是否显示插件,只添加即可
m_proxyInter->itemAdded(this, pluginName());
#else
if (!m_isFirstInstall) {
// 非初始状态
if (m_proxyInter->getValue(this, constantVal::PLUGIN_STATE_KEY, true).toBool()) {
m_proxyInter->itemAdded(this, pluginName());
} else {
m_proxyInter->saveValue(this, constantVal::PLUGIN_STATE_KEY, false);
m_proxyInter->itemRemoved(this, pluginName());
}
} else {
m_proxyInter->saveValue(this, constantVal::PLUGIN_STATE_KEY, false);
m_proxyInter->itemRemoved(this, pluginName());
}
#endif

displayModeChanged(displayMode());
}

#ifndef DDE_DOCK_NEW_VERSION
void MonitorPlugin::refreshPluginItemsVisible()
{
if (pluginIsDisable()) {
m_proxyInter->itemRemoved(this, pluginName());
} else {
if (!m_pluginLoaded) {
loadPlugin();
return;
}
m_proxyInter->itemAdded(this, pluginName());
}
}
#endif

void MonitorPlugin::initPluginState()
{
if (m_settings == nullptr)
return;
if (m_settings->get("isfirstinstall").toBool()) {
m_isFirstInstall = true;
m_settings->set("isfirstinstall", false);
} else {
m_isFirstInstall = false;
}
}

void MonitorPlugin::calcCpuRate(qlonglong &totalCPU, qlonglong &availableCPU)
{
totalCPU = availableCPU = 0;
Expand Down
15 changes: 0 additions & 15 deletions deepin-system-monitor-plugin/gui/monitor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,6 @@ private slots:
//!
void loadPlugin();

#ifndef DDE_DOCK_NEW_VERSION
//!
//! \brief refreshPluginItemsVisible 刷新插件项显示隐藏
//!
void refreshPluginItemsVisible();
#endif

//!
//! \brief initPluginState 初始化插件状态
//!
void initPluginState();

//!
//! \brief calcCpuRate 计算CPU占用率
//! \param totalCPU 总CPU占用率
Expand Down Expand Up @@ -273,7 +261,6 @@ private slots:
bool m_pluginLoaded;
MonitorPluginButtonWidget *m_itemWidget = nullptr;
QScopedPointer<SystemMonitorTipsWidget> m_dataTipsLabel;
QGSettings *m_settings;

qlonglong m_down = 0;
qlonglong m_upload = 0;
Expand All @@ -284,8 +271,6 @@ private slots:

QString startup;

bool m_isFirstInstall = false;//判断插件是否第一次安装

QString m_cpuStr{"0.0"}; //转换后的cpu数据
QString m_memStr{"0.0"}; //转换后的mem数据
QString m_downloadStr{"0KB/s"}; //转换后的下载数据
Expand Down

0 comments on commit 62dbce6

Please sign in to comment.