Skip to content

Commit

Permalink
Bump version to 1.8
Browse files Browse the repository at this point in the history
Delete CheckLocale.sh, use QLocale to get system locale;
Rebuild SwitchGraphicsCardWidget.cpp and .h, adopt uniform design style
as system plugins like "poweroff" "notification", avoid display issues.
  • Loading branch information
zty199 committed Oct 25, 2020
1 parent fe8a352 commit 61a2902
Show file tree
Hide file tree
Showing 18 changed files with 211 additions and 152 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ mesa-utils(运行时依赖)

zenity(运行时依赖)

libnotify4(运行时依赖)

## 源码编译

运行 build.sh 自动编译源码,并生成 dde-dock-graphics-plugin_"$version"_amd64.deb
Expand All @@ -59,7 +61,7 @@ zenity(运行时依赖)

P.S.建议使用自动生成的 deb 安装包进行安装

1. 将 scripts 文件夹下 Initialize.sh,Intel,sh,NVIDIA.sh,CheckConf.sh,ResetConf.sh,Rescue.sh 放置在 /opt/apps/dde-dock-graphics-plugin/files/bin 文件夹下;将 icons 文件夹放置在 /opt/apps/dde-dock-graphics-plugin/files/share 文件夹下
1. 将 scripts 文件夹下 Initialize.sh,Intel,sh,NVIDIA.sh,CheckConf.sh,ResetConf.sh,Rescue.sh 放置在 /opt/apps/dde-dock-graphics-plugin/files/bin 文件夹下。

2. 将编译生成的 libswitch_graphics_card.so 放在 ~/.local/lib/dde-dock/plugins/ 或者 /usr/lib/dde-dock/plugins/ 文件夹下。

Expand Down
31 changes: 22 additions & 9 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,77 +1,90 @@
#!/bin/sh
#!/bin/bash

cd $PWD

# 获取系统语言环境 | Get system locale
LANG=$(locale | grep LANGUAGE | cut -d "=" -f 2 | cut -d "_" -f 1)
LANG=$(locale | grep LANGUAGE | cut -d '=' -f 2 | cut -d '_' -f 1)
if [ "$LANG" != "zh" ] ; then
LANG="en"
fi

readonly TIP1_zh="开始编译......."
readonly TIP1_en="Compiling..."
readonly TIP2_zh="编译完成"
readonly TIP2_en="Complete"
readonly TIP3_zh="构建软件包..."
readonly TIP2_en="Compilation Complete"
readonly TIP3_zh="构建软件包......"
readonly TIP3_en="Building deb..."
readonly TIP4_zh="----------包信息----------"
readonly TIP4_en="---------Control---------"
readonly TIP5_zh="构建完成,软件包位于当前目录"
readonly TIP5_en="Complete. See deb in current dir."
readonly TIP6_zh="清除文件..."
readonly TIP5_en="Complete. See deb in current dir"
readonly TIP6_zh="清除文件......"
readonly TIP6_en="Deleting temp files..."
readonly TIP7_zh="按任意键退出......"
readonly TIP7_en="Press any key to exit..."

eval "TIP1=\$TIP1_${LANG}"
eval "TIP2=\$TIP2_${LANG}"
eval "TIP3=\$TIP3_${LANG}"
eval "TIP4=\$TIP4_${LANG}"
eval "TIP5=\$TIP5_${LANG}"
eval "TIP6=\$TIP6_${LANG}"
eval "TIP7=\$TIP7_${LANG}"

# 编译
echo "$TIP1"
echo -e

mkdir -p build && cd build
cmake ../src
make
make -j4
cd ..

echo -e
echo "$TIP2"
echo -e

# 打包
echo "$TIP3"
echo -e

mkdir -p ./deb_uos/opt/apps/dde-dock-graphics-plugin/files/bin/
mkdir -p ./deb_uos/opt/apps/dde-dock-graphics-plugin/files/plugins/
mkdir -p ./deb_uos/opt/apps/dde-dock-graphics-plugin/files/share/icons/
mkdir -p ./deb_uos/opt/apps/dde-dock-graphics-plugin/files/share/oem-menuextensions/
mkdir -p ./deb_uos/opt/apps/dde-dock-graphics-plugin/files/share/pkexec/

chmod 644 ./build/libswitch_graphics_card.so
cp ./build/libswitch_graphics_card.so ./deb_uos/opt/apps/dde-dock-graphics-plugin/files/plugins
cp ./scripts/* ./deb_uos/opt/apps/dde-dock-graphics-plugin/files/bin/
cp ./icons/* ./deb_uos/opt/apps/dde-dock-graphics-plugin/files/share/icons/
cp ./oem-menuextensions/* ./deb_uos/opt/apps/dde-dock-graphics-plugin/files/share/oem-menuextensions/
cp ./pkexec/* ./deb_uos/opt/apps/dde-dock-graphics-plugin/files/share/pkexec/

find ./deb_uos/opt -type f -print0 | xargs -0 md5sum > ./deb_uos/DEBIAN/md5sums && sed -i "s#./deb_uos/opt#/opt#" ./deb_uos/DEBIAN/md5sums

echo "$TIP4"
echo -e

cat ./deb_uos/DEBIAN/control

echo -e
echo "-------------------------"
echo -e

version=$(cat ./deb_uos/DEBIAN/control | grep "Version" | awk -F ' ' '{print $2}')

fakeroot dpkg -b ./deb_uos ./dde-dock-graphics-plugin_"$version"_amd64.deb

echo "$TIP5"
echo -e

# 清除模板中的文件
echo "$TIP6"
echo -e

rm -rf ./deb_uos/DEBIAN/md5sums
rm -rf ./deb_uos/opt/apps/dde-dock-graphics-plugin/files/*

# rm -rf ./build

echo "$TIP7"
read
6 changes: 3 additions & 3 deletions deb_uos/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Package: dde-dock-graphics-plugin
Version: 1.7.1
Version: 1.8
Maintainer: zty199 <[email protected]>
Section: utils
Source: https://github.com/mywhat/DDESwitchCard
Homepage: https://github.com/zty199/dde-dock-switch_graphics_card
Homepage: https://gitee.com/deepin-opensource/switch-graphics-card
Architecture: amd64
Priority: optional
Depends: mesa-utils, zenity
Depends: mesa-utils, zenity, libnotify4
Conflicts: switch-graphics-card (<= 1.5)
Replaces: switch-graphics-card (<= 1.5)
Description: A simple dde-dock plugin for graphics card switch.
Expand Down
2 changes: 0 additions & 2 deletions deb_uos/DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@
ln -s -f /opt/apps/dde-dock-graphics-plugin/files/plugins/libswitch_graphics_card.so /usr/lib/dde-dock/plugins/

ln -s -f /opt/apps/dde-dock-graphics-plugin/files/share/pkexec/com.deepin.pkexec.dde-dock-graphics-plugin.policy /usr/share/polkit-1/actions/

# pkill -9 dde-dock
2 changes: 1 addition & 1 deletion deb_uos/opt/apps/dde-dock-graphics-plugin/info
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"appid": "dde-dock-graphics-plugin",
"name": "SwitchGraphicsCardPlugin",
"version": "1.7.1",
"version": "1.8",
"arch": ["i386"],
"permissions": {
"autostart": false,
Expand Down
9 changes: 0 additions & 9 deletions scripts/CheckLocale.sh

This file was deleted.

2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN")
# SHARED 表示生成的库应该是动态库,
# 变量 ${PLUGIN_NAME} 和 ${SRCS} 都是前面处理好的,
# 另外 qrc 资源文件也应该追加在后面以编译进目标中。
add_library(${PLUGIN_NAME} SHARED ${SRCS})
add_library(${PLUGIN_NAME} SHARED ${SRCS} SwitchGraphicsCard.qrc)

# 设置目标的生成位置,这里表示生成在执行 make 的目录,
# 另外还有很多可用于设置的属性,可查阅 cmake 文档。
Expand Down
8 changes: 8 additions & 0 deletions src/SwitchGraphicsCard.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<RCC>
<qresource prefix="/icons">
<file>icons/Intel_light.svg</file>
<file>icons/NVIDIA_dark.svg</file>
<file>icons/NVIDIA_light.svg</file>
<file>icons/Intel_dark.svg</file>
</qresource>
</RCC>
40 changes: 7 additions & 33 deletions src/SwitchGraphicsCardAppletWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "SwitchGraphicsCardAppletWidget.h"

SwitchGraphicsCardAppletWidget::SwitchGraphicsCardAppletWidget(QWidget *parent) :
QWidget(parent),
RefreshTimer(new QTimer(this))
QWidget(parent)
{
process = new QProcess();

Expand All @@ -20,19 +19,6 @@ SwitchGraphicsCardAppletWidget::SwitchGraphicsCardAppletWidget(QWidget *parent)

connect(Intel, SIGNAL(clicked(bool)), this, SLOT(switchIntel()));
connect(NVIDIA, SIGNAL(clicked(bool)), this, SLOT(switchNVIDIA()));

/* 可以设置定时刷新 */
// 连接 Timer 超时的信号到更新数据的槽上
//connect(RefreshTimer, &QTimer::timeout, this, &SwitchGraphicsCardAppletWidget::setCardName);
//connect(RefreshTimer, &QTimer::timeout, this, &SwitchGraphicsCardAppletWidget::setLocale);
//connect(RefreshTimer, &QTimer::timeout, this, &SwitchGraphicsCardAppletWidget::refreshButton);

// 设置 Timer 超时为 10s,即每 10s 更新一次控件上的数据,并启动这个定时器
//RefreshTimer->start(10000);

//setCardName();
//setLocale();
//refreshButton();
}

void SwitchGraphicsCardAppletWidget::setCardName()
Expand All @@ -52,12 +38,10 @@ QString SwitchGraphicsCardAppletWidget::getCardName()

void SwitchGraphicsCardAppletWidget::setLocale()
{
// 获取系统语言环境(如果直接使用 QProcess 执行 locale 命令,会受到 tty 环境配置影响,原因未知)
process->start("/opt/apps/dde-dock-graphics-plugin/files/bin/CheckLocale.sh");
process->waitForFinished();
Locale = process->readAllStandardOutput();
process->close();
Locale.chop(1);
// 获取系统语言环境
QString locale = QLocale::system().name();
QStringList list = locale.split("_");
Locale = list.at(0);
}

QString SwitchGraphicsCardAppletWidget::getLocale()
Expand All @@ -70,16 +54,10 @@ void SwitchGraphicsCardAppletWidget::switchIntel()
if(this->CardName == "Intel")
{
if(this->Locale == "zh")
{
// QMessageBox::warning(NULL, "警告", "已经是 Intel 显卡!");
// 使用 notify-send 向通知中心发送系统通知
system("notify-send -t 2000 -a dde-dock-graphics-plugin -i dialog-warning \"已经是 Intel 显卡\"");
}
else
{
// QMessageBox::warning(NULL, "Warning", "Intel graphics is already in use!");
system("notify-send -t 2000 -a dde-dock-graphics-plugin -i dialog-warning \"Intel graphics is already in use\"");
}
return;
}

Expand All @@ -93,6 +71,7 @@ void SwitchGraphicsCardAppletWidget::switchIntel()
system("notify-send -t 3000 -a dde-dock-graphics-plugin -i deepin-graphics-driver-manager \"Preparing to switch graphics card and logout, please save your work in progress in time\"");
system("notify-send -t 10000 -a dde-dock-graphics-plugin -i deepin-graphics-driver-manager \"Updating initramfs, please wait...\"");
}

system("pkexec /opt/apps/dde-dock-graphics-plugin/files/bin/Intel.sh");
}

Expand All @@ -101,15 +80,9 @@ void SwitchGraphicsCardAppletWidget::switchNVIDIA()
if(this->CardName == "NVIDIA")
{
if(this->Locale == "zh")
{
// QMessageBox::warning(NULL, "警告", "已经是 NVIDIA 显卡!");
system("notify-send -t 2000 -a dde-dock-graphics-plugin -i dialog-warning \"已经是 NVIDIA 显卡\"");
}
else
{
// QMessageBox::warning(NULL, "Warning", "NVIDIA graphics is already in use!");
system("notify-send -t 2000 -a dde-dock-graphics-plugin -i dialog-warning \"NVIDIA graphics is already in use\"");
}
return;
}

Expand All @@ -123,6 +96,7 @@ void SwitchGraphicsCardAppletWidget::switchNVIDIA()
system("notify-send -t 3000 -a dde-dock-graphics-plugin -i deepin-graphics-driver-manager \"Preparing to switch graphics card and logout, please save your work in progress in time\"");
system("notify-send -t 10000 -a dde-dock-graphics-plugin -i deepin-graphics-driver-manager \"Updating initramfs, please wait...\"");
}

system("pkexec /opt/apps/dde-dock-graphics-plugin/files/bin/NVIDIA.sh");
}

Expand Down
6 changes: 0 additions & 6 deletions src/SwitchGraphicsCardAppletWidget.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
#ifndef SWITCHITEMWIDGET_H
#define SWITCHITEMWIDGET_H

#include <QPushButton>
#include <QMessageBox>
#include <QTimer>

#include "ddeUtil.h"

class SwitchGraphicsCardAppletWidget : public QWidget
{
Q_OBJECT

private:
QTimer *RefreshTimer;

QPushButton *Intel;
QPushButton *NVIDIA;
QProcess *process;
Expand Down
4 changes: 1 addition & 3 deletions src/SwitchGraphicsCardPlugin.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#ifndef SWITCHCARD_H
#define SWITCHCARD_H

#include "ddeUtil.h"
#include <dde-dock/pluginsiteminterface.h>
#include <QObject>
#include <QLabel>

#include "ddeUtil.h"
#include "SwitchGraphicsCardWidget.h"
#include "SwitchGraphicsCardAppletWidget.h"

Expand Down
Loading

0 comments on commit 61a2902

Please sign in to comment.