完成1.1.0大多数功能

This commit is contained in:
gfdgd_xi 2022-08-07 22:13:48 +08:00
parent d4f08e0445
commit 943f8cf0a8
11 changed files with 325 additions and 46 deletions

View File

@ -672,4 +672,3 @@ may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

View File

@ -1,34 +0,0 @@
# DtkDemo
这个样例是用Dtk来制作deepin UI的。
如果你想使用Dtk开发程序但是又不知道怎样入手的话你可以克隆这个项目直接在上面开发。这个样例十分的简单但是却已经配置好了Dtk相关的类可以直接使用
---
## 说明
### DtkDemo.pro
修改 TARGET = DtkDemo 为你自己的项目名[ TARGET = DtkDemo ---> TARGET = 你自己的项目名]
### main.cpp
在main.cpp中你可以修改软件名称增加你自己的专属Loga.setProductIcon(QIcon":/images/icon.svg")); //设置Logo
### mainwindow.cpp
在这儿,你可以设置程序的图标,设置窗口大小
### widget.cpp/widget.h/widget.ui
这三个文件是界面文件,你对程序和各种功能的实现和界面设计,应该在这儿进行操作。
在此demo中我在界面(widget.ui)中加入了一个QLable、QPushButton和QTextEdit。
你可以在widget.h和widget.cpp中实现具体的功能。
---
## MIT 协议
---
## 开发平台和依赖说明
开发平台deepin 15.10.1
Qt版本Qt 5.7.1
依赖:
sudo apt-get install libdtkwidget-dev libdtkcore-dev dh-make
sudo apt-get install libdframeworkdbus-dev libqrencode-dev libzbar-dev libdtkwm-dev libdtkcore-bin libqtshadowsocks-dev fakeroot

View File

@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/">
<file>images/logo.svg</file>
<file>images/icon.png</file>
</qresource>
</RCC>

BIN
images/icon.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

4
information.json Normal file
View File

@ -0,0 +1,4 @@
{
"Version": "1.1.0",
"UpdateThings": "※1、程序全部重构语言从 Python 转 C++、GUI 从 Tkinter 转 DTK、布局大改参考了 sgb76 大佬的 Wine 运行器设计图、zty79的桌面快捷方式编辑器的参考布局\n※2、程序新增打包功能"
}

3
launch.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
XDG_CURRENT_DESKTOP="Deepin"
$1 -platformtheme deepin "$@"

View File

@ -1,23 +1,59 @@
#include "mainwindow.h"
#include <DApplication>
#include <DWidgetUtil> //Dtk::Widget::moveToCenter(&w); 要调用它就得引用DWidgetUtil
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QMenuBar>
#include <DTitlebar>
#include <QUrl>
#include <QDesktopServices>
#include <QObject>
DWIDGET_USE_NAMESPACE
int main(int argc, char *argv[])
{
DApplication::loadDXcbPlugin(); //让bar处在标题栏中
DApplication a(argc, argv);
DApplication::setAttribute(Qt::AA_EnableHighDpiScaling); // 开启 Hidpi 支持
// 程序内强制添加"-platformtheme deepin"参数喂给Qt让Qt正确使用Deepin主题修复各种奇怪样式问题
QVector<char*> fakeArgs(argc + 2);
fakeArgs[0] = argv[0];
fakeArgs[1] = "-platformtheme";
fakeArgs[2] = "deepin";
for(int i = 1; i < argc; i++) fakeArgs[i + 2] = argv[i];
int fakeArgc = argc + 2; // 为啥DApplication的argc要用引用啊
DApplication a(fakeArgc, fakeArgs.data());
// 信息读取
QFile information(QCoreApplication::applicationDirPath() + "/information.json");
information.open(QIODevice::ReadOnly);
QJsonDocument info = QJsonDocument::fromJson(information.readAll());
QJsonObject object = info.object();
information.close();
a.setAttribute(Qt::AA_UseHighDpiPixmaps);
a.loadTranslator();
a.setOrganizationName("deepin");
a.setApplicationVersion(DApplication::buildVersion("1.0"));
//a.setApplicationAcknowledgementPage("https://你的网站");
//a.setProductIcon(QIcon(":/images/icon.svg")); //设置Logo
//a.setProductName("DtkDemo");
a.setApplicationName("DtkDemo"); //只有在这儿修改窗口标题才有效
a.setOrganizationName("gfdgd xi、为什么您不喜欢熊出没和阿布呢");
a.setApplicationVersion(DApplication::buildVersion(object.value("Version").toString()));
a.setApplicationAcknowledgementPage("https://你的网站");
a.setProductIcon(QIcon(":/images/icon.png")); //设置Logo
a.setProductName("spark-webapp-runtime 运行器");
a.setApplicationDescription("一个为了方便使用 spark-webapp-runtime 的运行工具");
a.setApplicationName("spark-webapp-runtime 运行器"); //只有在这儿修改窗口标题才有效
MainWindow w;
QMenu *menu = new QMenu();
QMenu *websize = new QMenu("程序官网");
QAction *gitee = new QAction("Gitee");
QObject::connect(gitee, &QAction::triggered, &w, [](){QDesktopServices::openUrl(QUrl("https://gitee.com/gfdgd-xi/spark-webapp-runtime-runner"));});
websize->addAction(gitee);
QAction *github = new QAction("Github");
QObject::connect(github, &QAction::triggered, &w, [](){QDesktopServices::openUrl(QUrl("https://github.com/gfdgd-xi/spark-webapp-runtime-runner"));});
websize->addAction(github);
QAction *gitlink = new QAction("Gitlink");
QObject::connect(gitlink, &QAction::triggered, &w, [](){QDesktopServices::openUrl(QUrl("https://gitlink.org.cn/gfdgd_xi/spark-webapp-runtime-runner"));});
websize->addAction(gitlink);
menu->addMenu(websize);
w.titlebar()->setMenu(menu);
w.show();
//让打开时界面显示在正中

237
spark-web-packer Executable file
View File

@ -0,0 +1,237 @@
#!/bin/bash
if [ "${1}" == "-h" -o "$1" == "--help" ]
then
echo "Copyright (c) 2019-2021 The Spark Project"
echo "本工具可以快速打包依赖于spark-webapp-runtime在非UOS/deepin上是swrt-liteweb app应用"
echo
echo "This tool can pack web apps quickly with spark-webapp-runtime(swrt-lite on other distros instead of UOS/deepin)"
echo
echo 用法
echo web-packer 链接 标题 图标路径 软件描述 软件包名 维护者 版本号
echo 如果没有任何参数,将以交互式模式运行
echo
echo Usage:
echo web-packer url title icon_path desciption pkgname maintainer version
echo If there are no parameters, it will run in interactive mode
exit 0
fi
if [ "${1}" == "-v" -o "${1}" == "--version" ];then
echo "Copyright (c) 2019-2021 The Spark Project"
echo
echo "0.1.2"
exit 0
fi
#reset
echo "Copyright (c) 2019-2021 The Spark Project"
echo 本工具可以快速打包依赖于spark-webapp-runtime在非UOS上是swrt-liteweb app应用
echo 本工具只能打包在线网页或本地网页,离线服务器网页等高级操作参考以下链接
echo
echo https://gitee.com/deepin-community-store/spark-web-app-runtime/
cd /tmp
mkdir swrt-app-maker
cd swrt-app-maker
#工作目录应当为/tmp/swrt-maker
while [ ! $url ]
do
if [ ! $1 ]
then
echo "没有检测任何参数,以交互式模式运行"
echo "请输入你要打包的网址(需要填写协议比如https://spark-app.store的https://也是需要的)"
read url
else
echo "检测到url跳过获取"
url="$1"
echo "读取到的url为$url"
fi
if [ ! $url ]
then
echo "没有检测到网址,请重新输入!"
sleep 3
clear
else
echo "网址读取成功检测是否为http/file开头"
fi
urlstring=${url}
urlstr=${urlstring:0:4}
if [ "http" == ${urlstr} -o "file" == ${urlstr} ]
then
echo "检测到http/https/file协议继续"
echo
else
echo "没有检测到http/https/file类型协议请确认你填写了"
sleep 3
unset url
clear
fi
done
while [ ! $title ]
do
if [ ! $2 ]
then
echo "请输入你要打包的应用标题"
echo
read title
else
echo "检测到标题,跳过获取"
title="$2"
echo "读取到的标题为:$title"
fi
done
while [ ! $icon ]
do
if [ ! $3 ]
then
echo "请输入你要打包的应用图标绝对路径可以拖动图标文件到终端只支持png"
read icon
echo
else
echo "检测到图标,跳过获取"
icon="$3"
echo "读取到的图标路径为:$icon"
fi
iconpath=`echo "$icon" | sed $'s/\'//g'`
icon=$iconpath
echo "去除可能的单引号后得到:$icon"
echo
#'
done
while [ ! $des ]
do
if [ ! $4 ]
then
echo "请输入你要打包的应用描述"
read des
echo
else
echo "检测到描述,跳过获取"
des="$4"
echo "读取到的描述为:$des"
fi
done
while [ ! $pkgname ]
do
if [ ! $5 ]
then
echo "请输入你要打包的应用包名一般为web-xxxxxx比如web-baidu.com不能有中文或特殊符号或空格空格用-代替)"
read pkgname
echo
else
echo "检测到包名,跳过获取"
pkgname="$5"
echo "读取到的包名为:$pkgname"
fi
done
while [ ! $maintainer ]
do
if [ ! $6 ]
then
echo "请输入你的昵称这会出现在deb中"
read maintainer
echo
else
echo "检测到维护者名,跳过获取"
maintainer="$6"
echo "读取到的维护者为:$maintainer"
fi
done
while [ ! $version ]
do
if [ ! "$7" -a ! "$6" ]
then
echo "请输入文件版本号这不是必须的。如果你想要更新一个已有的应用那么请输入比1.0大的版本"
echo "如果不是请直接输入回车会默认填写1.0"
read version
echo
if [ ! $version ];then
version="1.0"
fi
elif [ ! $7 -a $6 ];then
echo "在参数模式,但未检测到版本号"
echo "默认版本号为1.0"
version="1.0"
else
echo "检测到版本号,跳过获取"
version="$7"
echo "读取到的版本号为:$version"
fi
done
echo "开始生成deb包"
echo "输出的control文件为"
echo ""
echo "Package: $pkgname"
echo "Version: $version"
echo "Depends: spark-webapp-runtime(>1.5)"
echo "Maintainer: $maintainer"
echo "Description: A webapp of $url packed by $maintainer using spark webapp runtime"
echo "Architecture: amd64"
echo "-----------------------开始生成-----------------------"
mkdir DEBIAN
cd DEBIAN
touch control
echo "Package: $pkgname" >> ./control
echo "Version: $version" >> ./control
echo "Depends: spark-webapp-runtime(>=1.5)" >> ./control
echo "Maintainer: $maintainer" >> ./control
echo "Description: A webapp of $url packed by $maintainer using spark webapp runtime" >> ./control
echo "Architecture: amd64" >> ./control
cd ..
echo "-----------------------开始生成desktop-----------------------"
mkdir -p usr/share/applications
cd usr/share/applications
touch $pkgname.desktop
echo [Desktop Entry] >> $pkgname.desktop
echo Name=$title >> $pkgname.desktop
echo Exec=spark-webapp-runtime -u "$url" -i "/opt/durapps/$pkgname/icon.png" -t "$title" -d "$des" $8 >> $pkgname.desktop
echo Type=Application >> $pkgname.desktop
echo Terminal=false >> $pkgname.desktop
echo StartupNotify=true >> $pkgname.desktop
echo Encoding=UTF-8 >> $pkgname.desktop
echo Comment=$title >> $pkgname.desktop
echo Icon=/opt/durapps/$pkgname/icon.png >> $pkgname.desktop
cat $pkgname.desktop
echo "-----------------------开始复制icon-----------------------"
cd ../../../
mkdir -p opt/durapps/$pkgname
cd opt/durapps/$pkgname
cp $icon ./icon.png
cd ../../
echo "-----------------------开始打包-----------------------"
cd ..
workdir=`pwd`
echo "回退到工作目录,当前目录位于$workdir"
fakeroot dpkg -b . ../
mv ../${pkgname}_${version}_amd64.deb ~/${pkgname}_${version}_amd64.deb
echo "-----------------------打包结束,软件包在您的用户目录-----------------------"
rm -rf /tmp/swrt-app-maker
xdg-open ~ &
echo 按下回车键退出
exit

View File

@ -8,6 +8,10 @@
#include <QFile>
#include <QStandardPaths>
#include <DMessageBox>
#include <DInputDialog>
#include <QDateTime>
#include <QJsonDocument>
#include <QJsonObject>
DWIDGET_USE_NAMESPACE
Widget::Widget(QWidget *parent) :
@ -19,8 +23,16 @@ Widget::Widget(QWidget *parent) :
help.start("spark-webapp-runtime -h");
help.waitForFinished();
ui->moreHelp->setText(help.readAllStandardOutput());
// 信息读取
QFile information(QCoreApplication::applicationDirPath() + "/information.json");
information.open(QIODevice::ReadOnly);
QJsonDocument info = QJsonDocument::fromJson(information.readAll());
informationJson = info.object();
information.close();
// 允许 qDebug() 输出
QLoggingCategory::defaultCategory()->setEnabled(QtDebugMsg, true);
// 设置开发者信息
ui->information->setText("版本:" + informationJson.value("Version").toString() + "\n©2021~" + QDateTime::currentDateTime().toString("yyyy") + " gfdgd xi、为什么您不喜欢熊出没和阿布呢");
}
Widget::~Widget()
@ -122,3 +134,21 @@ void Widget::on_pushButton_5_clicked()
{
WriteDesktop(1);
}
void Widget::on_moreBuild_clicked()
{
QString package = DInputDialog::getText(this, "输入信息", "请输入要打包的包名:");
QString maker = DInputDialog::getText(this, "输入信息", "请输入要打包的维护者:");
QString version = DInputDialog::getText(this, "输入信息", "请输入要打包的版本号:");
QString informationList[3] = {package, maker, version};
for (int i = 0; i < 3; i++) {
if(informationList[i] == "") {
QMessageBox::information(this, "提示", "信息未填写完整,无法继续");
return;
}
}
QProcess process;
QStringList command;
command << "deepin-terminal" << "-e" << QCoreApplication::applicationDirPath() + "/spark-web-packer" << ui->openUrl->text() << ui->openTitle->text() << iconPath << ui->openShowThings->text() << package << maker << version << ui->openOtherOption->text();
process.startDetached(QCoreApplication::applicationDirPath() + "/launch.sh", command);
}

View File

@ -2,6 +2,7 @@
#define WIDGET_H
#include <QWidget>
#include <QJsonObject>
namespace Ui {
class Widget;
@ -33,10 +34,12 @@ private slots:
void on_pushButton_5_clicked();
void on_moreBuild_clicked();
private:
Ui::Widget *ui;
QString iconPath = "";
QJsonObject informationJson;
};
#endif // WIDGET_H

View File

@ -233,8 +233,8 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QLabel" name="information">
<property name="text">
<string>©2021~Now
开发者:gfdgd xi、为什么您不喜欢熊出没和阿布呢</string>
<string>版本:
©2021~Now gfdgd xi、为什么您不喜欢熊出没和阿布呢</string>
</property>
</widget>
</item>