mirror of
https://gitee.com/spark-store-project/spark-web-app-runtime.git
synced 2025-07-03 12:16:01 +08:00
Compare commits
49 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
f2b69ceb5e | ||
bf6a6893b3 | |||
|
c18a5b5b36 | ||
64d5e51ef3 | |||
290c57e1bc | |||
|
7e5525d4e9 | ||
c4e34eb048 | |||
3ded131e34 | |||
8a950603d9 | |||
19233d8c22 | |||
4e4bf8a80f | |||
d197bd3a04 | |||
|
a95e7e1beb | ||
|
23b40dd231 | ||
|
edff5b7b31 | ||
|
6b8b31ebf6 | ||
|
faa613d671 | ||
|
fa54612642 | ||
|
4a81898cd3 | ||
|
eb2bdaca63 | ||
|
6b25b50696 | ||
c6b6734c9e | |||
6202da0b1d | |||
|
1b3d161f4d | ||
|
1aed5532a3 | ||
d6b5895812 | |||
5fa7bb5086 | |||
ab56306b3d | |||
97441a9e07 | |||
f4e3e760b1 | |||
f7f03b36b9 | |||
2ad0147477 | |||
|
20da4c852d | ||
c303cde973 | |||
|
1db592eb50 | ||
e084d58377 | |||
|
2453752bd7 | ||
|
2f38b9dd76 | ||
|
f6542879de | ||
77a999e22e | |||
8da4f87164 | |||
|
0f256ff27b | ||
c412743642 | |||
e808bd2af7 | |||
0744089adc | |||
a3da6e964f | |||
17bd206e18 | |||
3b54057d49 | |||
4b3cc4276d |
.github/workflows
.gitignoreLICENSEREADME.mddebian
spark-webapp-runtime.prospark-webapp-runtime
LICENSEapplication.cppapplication.hglobaldefine.h
translate_generation.shtranslate_update.shimages
main.cppmainwindow.cppmainwindow.hresources
spark-webapp-runtime.protranslations
webenginepage.cppwebenginepage.hwebengineurlrequestinterceptor.cppwebengineurlrequestinterceptor.hwebengineview.cppwebengineview.hwidget.cppwidget.h
13
.github/workflows/program-builder.yml
vendored
Normal file
13
.github/workflows/program-builder.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
name: Building Program
|
||||
run-name: Building ${{ GITHUB.REPOSITORY }}
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
tags:
|
||||
- "*"
|
||||
|
||||
jobs:
|
||||
call:
|
||||
uses: GXDE-OS/GXDE/.github/workflows/building-deb.yml@master
|
||||
secrets: inherit
|
11
.gitignore
vendored
11
.gitignore
vendored
@ -41,3 +41,14 @@ target_wrapper.*
|
||||
|
||||
# QtCreator CMake
|
||||
CMakeLists.txt.user*
|
||||
|
||||
# Qt qm files
|
||||
*.qm
|
||||
|
||||
# Debian dpkg-buildpackage
|
||||
debian/*.debhelper*
|
||||
debian/files
|
||||
debian/*.substvars
|
||||
debian/spark-webapp-runtime
|
||||
|
||||
build
|
||||
|
8
LICENSE
8
LICENSE
@ -1,7 +1,7 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found.
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box".
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
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>.
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
|
53
README.md
53
README.md
@ -4,24 +4,42 @@
|
||||
|
||||
|
||||
```shell
|
||||
用法:./spark-webapp-runtime [选项]
|
||||
描述: 星火网页应用运行时
|
||||
帮助:
|
||||
第一种用法:
|
||||
|
||||
spark-webapp-runtime 应用标题 目标网址 应用窗口宽度 应用窗口高度
|
||||
|
||||
第二种用法:
|
||||
|
||||
运行 "spark-webapp-runtime -h" 查看命令行帮助信息
|
||||
|
||||
|
||||
用法:./spark-webapp-runtime [选项]
|
||||
描述: 星火网页应用运行环境
|
||||
|
||||
选项:
|
||||
-h, --help 显示这个此帮助。
|
||||
-v, --version 显示版本信息。
|
||||
-p, --parser 启用参数解析方式。默认为顺序解析方式。
|
||||
-t, --title <title> 设置应用的标题。默认为
|
||||
星火网页应用运行环境。
|
||||
-u, --url <url> 设置要打开的目标 URL。默认为空。
|
||||
-w, --width <width> 设置应用的窗口宽度。默认为 1024。
|
||||
-H, --height <height> 设置应用的窗口高度。默认为 768。
|
||||
-T, --tray 启用托盘图标。默认不启用。
|
||||
--full-screen 以全屏模式运行。默认关闭该功能。
|
||||
--fix-size 固定窗口大小。默认关闭该功能。
|
||||
--hide-buttons 隐藏控制按钮。默认关闭该功能。
|
||||
-i, --ico <ico> 设置应用的图标。
|
||||
-d, --desc <desc> 设置应用的描述信息。
|
||||
-c, --cfg <cfg> 设置应用的配置文件。
|
||||
-r, --root <root> 设置内置 WebServer 的根路径。
|
||||
-P, --port <port> 设置内置 WebServer 的监听端口号。
|
||||
-G, --GPU <0/1> 设置启用 GPU 渲染加速,默认开启。
|
||||
|
||||
|
||||
需要注意的是, 命令行会覆盖配置文件信息。
|
||||
|
||||
选项:
|
||||
-h, --help 显示这个此帮助。
|
||||
-v, --version 显示版本信息。
|
||||
-p, --parser 启用参数解析方式。默认顺序解析方式。
|
||||
-t, --title \<title\> 设置程序的运行标题。默认是 星火网页应用运行环境。
|
||||
-u, --url \<url\> 设置要打开的目标 URL。默认为空。
|
||||
-w, --width \<width\> 设置程序运行的宽度。默认为 1024。
|
||||
-H, --height \<height\> 设置程序运行的高度。默认为 768。
|
||||
--fix-size 固定窗口大小。默认关闭该功能。
|
||||
--hide-buttons 隐藏控制按钮。默认关闭该功能。
|
||||
-i, --ico \<ico\> 设置程序运行的图标。
|
||||
-d, --desc \<desc\> 设置程序的描述信息。
|
||||
-c, --cfg \<cfg\> 设置程序运行的配置文件。
|
||||
-r, --root \<root\> 设置内置 WebServer 的根路径。
|
||||
-P, --port \<port\> 设置内置 WebServer 的监听端口号。
|
||||
```
|
||||
|
||||
这里给大家附送两个例子,帮助大家理解使用
|
||||
@ -56,7 +74,6 @@
|
||||
|
||||
# 0.配置环境
|
||||
|
||||
作为星火系列应用,我们的设计哲学是M.I.S.(Make it Simple)没错我就是从KISS抄的
|
||||
|
||||
配置 spark-webapp-runtime 环境是非常简单的
|
||||
|
||||
|
25
debian/changelog
vendored
Normal file
25
debian/changelog
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
spark-webapp-runtime (1.8) stable; urgency=medium
|
||||
|
||||
* Fix: Now won't lock cookies.
|
||||
* Feat: Support local html files
|
||||
|
||||
-- shenmo <shenmo@spark-app.store> Mon, 19 Dec 2022 10:00:00 +0800
|
||||
|
||||
|
||||
spark-webapp-runtime (1.6.6-1) stable; urgency=medium
|
||||
|
||||
* Enable Chromium Dark Mode when startup if DTK theme is DarkType (Qt >= 5.15)
|
||||
* Fix a bug in UOS that some websites will always be loading and never finished
|
||||
|
||||
-- shenmo <shenmo@spark-app.store> Mon, 21 Nov 2022 15:00:00 +0800
|
||||
|
||||
|
||||
spark-webapp-runtime (1.6.5-1) stable; urgency=medium
|
||||
|
||||
* Support dpkg-buildpackage
|
||||
* Support open external links in default browser
|
||||
* Add single instance limitation for apps using same title
|
||||
* Fix wrong Accept-Language http request header
|
||||
|
||||
-- shenmo <shenmo@spark-app.store> Sun, 20 Nov 2022 17:00:00 +0800
|
||||
|
1
debian/compat
vendored
Normal file
1
debian/compat
vendored
Normal file
@ -0,0 +1 @@
|
||||
11
|
27
debian/control
vendored
Normal file
27
debian/control
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
Source: spark-webapp-runtime
|
||||
Maintainer: shenmo <shenmo@spark-app.store>
|
||||
Section: utils
|
||||
Priority: optional
|
||||
Build-Depends:
|
||||
debhelper (>= 9),
|
||||
pkg-config,
|
||||
qtchooser (>= 55-gc9562a1-1~),
|
||||
qtbase5-dev,
|
||||
libqt5svg5-dev,
|
||||
qtwebengine5-dev,
|
||||
qttools5-dev-tools,
|
||||
libdtkcore-dev (>= 5.0),
|
||||
libdtkgui-dev (>= 5.0),
|
||||
libdtkwidget-dev (>= 5.0)
|
||||
Standards-Version: 1.0
|
||||
Homepage: https://gitee.com/deepin-community-store/spark-web-app-runtime
|
||||
|
||||
|
||||
Package: spark-webapp-runtime
|
||||
Architecture: any
|
||||
Depends:${shlibs:Depends}, ${misc:Depends}
|
||||
Conflicts: store.spark-app.spark-webapp-runtime
|
||||
Provides: store.spark-app.spark-webapp-runtime
|
||||
Replaces: store.spark-app.spark-webapp-runtime
|
||||
Description: Spark WebApp Runtime
|
||||
A simple solution for packaging web apps.
|
22
debian/copyright
vendored
Normal file
22
debian/copyright
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
|
||||
Upstream-Name: spark-webapp-runtime
|
||||
Source: https://gitee.com/deepin-community-store/spark-web-app-runtime
|
||||
|
||||
Files: *
|
||||
Copyright: The Spark Project Developers
|
||||
|
||||
License: GPL-3+
|
||||
This package is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
.
|
||||
This package is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
.
|
||||
On Debian systems, the complete text of the GNU General
|
40
debian/rules
vendored
Executable file
40
debian/rules
vendored
Executable file
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/make -f
|
||||
|
||||
export QT_SELECT = qt5
|
||||
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
|
||||
include /usr/share/dpkg/default.mk
|
||||
|
||||
DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)
|
||||
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
|
||||
|
||||
# Uncomment this to turn on verbose mode.
|
||||
#export DH_VERBOSE=1
|
||||
|
||||
%:
|
||||
dh $@ --parallel
|
||||
|
||||
override_dh_auto_clean:
|
||||
rm -rf $(CURDIR)/build-$(DEB_HOST_MULTIARCH)
|
||||
|
||||
|
||||
override_dh_auto_configure:
|
||||
mkdir -p $(CURDIR)/build-$(DEB_HOST_MULTIARCH)
|
||||
|
||||
qmake BUILD_VERSION=$(DEB_VERSION_UPSTREAM) spark-webapp-runtime.pro \
|
||||
-spec linux-g++ CONFIG+=force_debug_info \
|
||||
-o $(CURDIR)/build-$(DEB_HOST_MULTIARCH)/
|
||||
|
||||
|
||||
override_dh_auto_build:
|
||||
make -C $(CURDIR)/build-$(DEB_HOST_MULTIARCH) -j$(JOBS)
|
||||
|
||||
|
||||
override_dh_auto_install:
|
||||
make -C $(CURDIR)/build-$(DEB_HOST_MULTIARCH) install \
|
||||
INSTALL_ROOT=$(CURDIR)/debian/spark-webapp-runtime
|
||||
|
||||
|
||||
# Ignore the dpkg-shlibdeps: warning (it uses none of the library's symbols)
|
||||
# Qt Mutidedia lib will ref to network libraray.
|
||||
override_dh_shlibdeps:
|
||||
dh_shlibdeps --dpkg-shlibdeps-params=--warnings=0
|
1
debian/source/format
vendored
Normal file
1
debian/source/format
vendored
Normal file
@ -0,0 +1 @@
|
||||
1.0
|
12
debian/spark-webapp-runtime.postinst
vendored
Executable file
12
debian/spark-webapp-runtime.postinst
vendored
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
case "$1" in
|
||||
configure)
|
||||
# Create symbol links for binary files
|
||||
ln -s -f /opt/durapps/spark-webapp-runtime/bin/spark-webapp-runtime /usr/bin/spark-webapp-runtime
|
||||
ln -s -f /opt/durapps/spark-webapp-runtime/share/spark-webapp-runtime /usr/share/spark-webapp-runtime
|
||||
;;
|
||||
|
||||
*)
|
||||
;;
|
||||
esac
|
7
debian/spark-webapp-runtime.prerm
vendored
Executable file
7
debian/spark-webapp-runtime.prerm
vendored
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$1" = "remove" -o "$1" = "purge" ] ; then
|
||||
# Remove residual symbol links
|
||||
rm -f /usr/bin/spark-webapp-runtime
|
||||
rm -rf /usr/share/spark-webapp-runtime
|
||||
fi
|
@ -1,6 +1,13 @@
|
||||
TARGET = spark-webapp-runtime
|
||||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS += \
|
||||
spark-webapp-runtime
|
||||
|
||||
CONFIG += ordered
|
||||
|
||||
SUBDIRS += \
|
||||
spark-webapp-runtime
|
||||
|
||||
# Update translation files
|
||||
CONFIG(release, debug|release) {
|
||||
system(bash $${PWD}/translate_update.sh)
|
||||
system(bash $${PWD}/translate_generation.sh)
|
||||
}
|
||||
|
@ -1,674 +0,0 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
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
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
89
spark-webapp-runtime/application.cpp
Normal file
89
spark-webapp-runtime/application.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
#include "application.h"
|
||||
#include "globaldefine.h"
|
||||
|
||||
#include <DPlatformWindowHandle>
|
||||
#include <DAboutDialog>
|
||||
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
const QString websiteLinkTemplate = "<a href='%1' style='text-decoration: none; color: rgba(0,129,255,0.9);'>%2</a>";
|
||||
|
||||
Application::Application(int &argc, char **argv)
|
||||
: DApplication(argc, argv)
|
||||
{
|
||||
saveLaunchParams(argc, argv);
|
||||
|
||||
loadTranslator();
|
||||
|
||||
setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
if (!DPlatformWindowHandle::pluginVersion().isEmpty()) {
|
||||
setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true);
|
||||
}
|
||||
|
||||
setOrganizationName(ORGANIZATION_NAME); // 添加组织名称,和商店主体的文件夹同在 ~/.local/share/spark-union 文件夹下
|
||||
setApplicationName(PROJECT_NAME); // 这里不要翻译,否则 ~/.local/share 中文件夹名也会被翻译
|
||||
setApplicationVersion(APP_VERSION);
|
||||
setApplicationDisplayName(DEFAULT_TITLE);
|
||||
setWindowIcon(QIcon(":/images/spark-webapp-runtime.svg"));
|
||||
|
||||
setProductIcon(QIcon(":/images/spark-webapp-runtime.svg"));
|
||||
setProductName(websiteLinkTemplate.arg("https://gitee.com/spark-store-project/spark-web-app-runtime", DEFAULT_TITLE));
|
||||
setApplicationDescription(QObject::tr("Presented By Spark developers # HadesStudio"));
|
||||
setApplicationLicense(websiteLinkTemplate.arg("https://gitee.com/spark-store-project/spark-web-app-runtime/blob/master/LICENSE", "GPLv3"));
|
||||
}
|
||||
|
||||
void Application::triggerAboutAction()
|
||||
{
|
||||
handleAboutAction();
|
||||
}
|
||||
|
||||
QStringList Application::launchParams() const
|
||||
{
|
||||
return m_argv;
|
||||
}
|
||||
|
||||
void Application::setMainWindow(MainWindow *window)
|
||||
{
|
||||
m_mainWindow = window;
|
||||
}
|
||||
|
||||
MainWindow *Application::mainWindow()
|
||||
{
|
||||
return m_mainWindow;
|
||||
}
|
||||
|
||||
void Application::handleAboutAction()
|
||||
{
|
||||
DApplication::handleAboutAction();
|
||||
|
||||
DAboutDialog *dialog = aboutDialog();
|
||||
if (dialog) {
|
||||
// CompanyLogo
|
||||
dialog->setCompanyLogo(QPixmap(":/images/Logo-Spark.png"));
|
||||
// WebsiteName
|
||||
dialog->setWebsiteName("Spark Project");
|
||||
// WebsiteLink
|
||||
dialog->setWebsiteLink("https://gitee.com/spark-store-project/");
|
||||
}
|
||||
}
|
||||
|
||||
void Application::saveLaunchParams(int &argc, char **argv)
|
||||
{
|
||||
m_argc = argc;
|
||||
|
||||
m_argv.clear();
|
||||
for (int i = 0; i < m_argc; i++) {
|
||||
m_argv.append(argv[i]);
|
||||
}
|
||||
|
||||
qDebug() << Q_FUNC_INFO << m_argc << m_argv;
|
||||
}
|
||||
|
||||
void Application::slotMainWindowClose()
|
||||
{
|
||||
if (aboutDialog()) {
|
||||
aboutDialog()->close();
|
||||
}
|
||||
}
|
42
spark-webapp-runtime/application.h
Normal file
42
spark-webapp-runtime/application.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef APPLICATION_H
|
||||
#define APPLICATION_H
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <DApplication>
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
class Application : public DApplication
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Application(int &argc, char **argv);
|
||||
void triggerAboutAction();
|
||||
|
||||
QStringList launchParams() const;
|
||||
|
||||
void setMainWindow(MainWindow *window);
|
||||
MainWindow *mainWindow();
|
||||
|
||||
protected:
|
||||
void handleAboutAction() override;
|
||||
|
||||
private:
|
||||
void saveLaunchParams(int &argc, char **argv);
|
||||
|
||||
signals:
|
||||
void sigQuit();
|
||||
|
||||
public slots:
|
||||
void slotMainWindowClose();
|
||||
|
||||
private:
|
||||
MainWindow *m_mainWindow = nullptr;
|
||||
|
||||
int m_argc;
|
||||
QStringList m_argv;
|
||||
};
|
||||
|
||||
#endif // APPLICATION_H
|
@ -3,18 +3,18 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#define DEFAULT_TITLE QObject::tr("SparkWebAppRuntime")
|
||||
#define DEFAULT_URL QString("qrc:/help/help.html")
|
||||
#define DEFAULT_WIDTH (1024)
|
||||
#define DEFAULT_HEIGHT (768)
|
||||
#define DEFAULT_TITLE QObject::tr("SparkWebAppRuntime")
|
||||
#define ORGANIZATION_NAME QString("spark-union")
|
||||
#define DEFAULT_URL QString("qrc:/help/help.html")
|
||||
#define DEFAULT_WIDTH (1024)
|
||||
#define DEFAULT_HEIGHT (768)
|
||||
|
||||
#define DEFAULT_DESC QString()
|
||||
#define DEFAULT_ICON QString()
|
||||
#define DEFAULT_CFG QString()
|
||||
#define DEFAULT_ICON QString()
|
||||
#define DEFAULT_DESC QString()
|
||||
#define DEFAULT_CFG QString()
|
||||
|
||||
#define DEFAULT_ROOT QString()
|
||||
#define DEFAULT_PORT 0
|
||||
|
||||
#define CURRENT_VER (1.6)
|
||||
#define DEFAULT_ROOT QString()
|
||||
#define DEFAULT_PORT 0
|
||||
#define DEFAULT_GPU 1
|
||||
|
||||
#endif // GLOBALDEFINE_H
|
||||
|
Binary file not shown.
Before ![]() (image error) Size: 43 KiB |
@ -1,25 +0,0 @@
|
||||
<svg width="570" height="518" viewBox="0 0 570 518" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="277" cy="256" r="256" fill="#545454"/>
|
||||
<g filter="url(#filter0_b)">
|
||||
<circle cx="58" cy="98" r="58" fill="#E6B403" fill-opacity="0.65"/>
|
||||
</g>
|
||||
<g filter="url(#filter1_b)">
|
||||
<circle cx="452.5" cy="400.5" r="117.5" fill="#F2C213" fill-opacity="0.83"/>
|
||||
</g>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M267.656 387.599C256.927 389.34 246.885 394.251 238.876 401.8L235.242 405.677C230.09 411.095 220.173 413.528 213.12 410.975C213.12 410.975 206.837 408.735 192.298 400.403C177.759 392.095 172.608 387.761 172.608 387.761C166.855 382.896 164.038 373.12 166.205 366.04L167.721 360.983C170.964 347.421 168.862 333.13 161.851 321.077C154.841 309.025 143.461 300.135 130.074 296.253L124.922 295.049C117.58 293.411 110.503 286.067 109.204 278.722C109.204 278.722 108 272.172 108 255.508C108 238.844 109.179 232.269 109.179 232.269C110.503 224.925 117.653 217.58 124.898 215.943L130.194 214.763C143.557 210.876 154.915 201.999 161.918 189.968C168.921 177.937 171.033 163.674 167.818 150.129L166.229 144.952C164.038 137.799 166.879 128.095 172.632 123.279C172.632 123.279 177.735 118.968 192.25 110.564C206.789 102.304 213.096 100.04 213.096 100.04C216.925 98.8738 220.995 98.7497 224.888 99.6809C228.781 100.612 232.355 102.565 235.242 105.338L238.949 109.263C249.099 118.855 262.538 124.19 276.5 124.17C290.428 124.229 303.85 118.946 314.003 109.408L317.807 105.338C322.982 99.8959 332.875 97.4637 339.952 100.016C339.952 100.016 346.235 102.328 360.75 110.564C375.289 118.92 380.465 123.255 380.465 123.255C383.371 125.969 385.498 129.414 386.624 133.229C387.75 137.045 387.834 141.093 386.867 144.952L385.134 150.081C381.857 163.604 383.945 177.871 390.96 189.887C392.621 192.739 394.526 195.415 396.645 197.89L338.866 230.638C328.916 206.127 304.716 188.827 276.5 188.827C239.382 188.827 209.341 218.688 209.341 255.532C209.341 289.396 234.76 317.361 267.656 321.663V387.599Z" fill="white"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M474.383 225.868C482.842 227.761 491.023 236.335 492.553 244.741C492.553 244.741 493.917 252.341 494 271.659C494 290.922 492.637 298.521 492.637 298.521C491.106 307.011 482.842 315.501 474.439 317.394L468.484 318.758C453.514 323.156 440.075 333.094 431.671 347.569C423.601 361.401 421.198 377.822 424.965 393.388L426.802 399.456C429.306 407.696 426.023 418.997 419.4 424.537C419.4 424.537 413.501 429.547 396.695 439.179C379.916 448.727 372.57 451.371 372.57 451.371C368.145 452.72 363.439 452.863 358.94 451.786C354.44 450.71 350.308 448.453 346.971 445.247L342.797 440.765C331.5 430.076 316.141 423.479 299.251 423.479C295.796 423.472 292.369 423.748 289 424.294V348.075C292.345 348.512 295.758 348.738 299.223 348.738C319.742 348.805 339.448 340.722 354.014 326.265C368.58 311.808 376.815 292.158 376.911 271.631C376.911 261.459 374.924 251.747 371.315 242.856L438.104 205C445.949 214.166 456.321 220.949 468.039 224.421L474.383 225.868Z" fill="white"/>
|
||||
<defs>
|
||||
<filter id="filter0_b" x="-45" y="-5" width="206" height="206" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
|
||||
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
|
||||
<feGaussianBlur in="BackgroundImage" stdDeviation="22.5"/>
|
||||
<feComposite in2="SourceAlpha" operator="in" result="effect1_backgroundBlur"/>
|
||||
<feBlend mode="normal" in="SourceGraphic" in2="effect1_backgroundBlur" result="shape"/>
|
||||
</filter>
|
||||
<filter id="filter1_b" x="292" y="240" width="321" height="321" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
|
||||
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
|
||||
<feGaussianBlur in="BackgroundImage" stdDeviation="21.5"/>
|
||||
<feComposite in2="SourceAlpha" operator="in" result="effect1_backgroundBlur"/>
|
||||
<feBlend mode="normal" in="SourceGraphic" in2="effect1_backgroundBlur" result="shape"/>
|
||||
</filter>
|
||||
</defs>
|
||||
</svg>
|
Before (image error) Size: 3.8 KiB |
@ -1,132 +1,143 @@
|
||||
/*
|
||||
*
|
||||
/**
|
||||
* Spark WebApp Runtime
|
||||
* 星火网页应用运行环境
|
||||
*/
|
||||
*/
|
||||
#include "application.h"
|
||||
#include "mainwindow.h"
|
||||
#include "webengineview.h"
|
||||
#include "httpd.h"
|
||||
|
||||
#include <DApplication>
|
||||
#include <DMainWindow>
|
||||
#include <DSysInfo>
|
||||
#include <DApplicationSettings>
|
||||
|
||||
#include <QCommandLineParser>
|
||||
#include <QCommandLineOption>
|
||||
#include <QFileInfo>
|
||||
#include <QSettings>
|
||||
|
||||
#include "globaldefine.h"
|
||||
#include "httpd.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
DApplication a(argc, argv);
|
||||
// 龙芯机器配置,使得 DApplication 能正确加载 QTWEBENGINE
|
||||
qputenv("DTK_FORCE_RASTER_WIDGETS", "FALSE");
|
||||
|
||||
a.loadTranslator();
|
||||
// 开启 HiDPI 缩放支持
|
||||
DApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
|
||||
a.setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
a.setApplicationVersion(QString::number(CURRENT_VER));
|
||||
a.setOrganizationName("spark-union"); // 添加组织名称,和商店主体的文件夹同在 ~/.local/share/spark-union 文件夹下
|
||||
a.setApplicationName("SparkWebAppRuntime"); // 这里不要翻译,否则 ~/.local/share 中文件夹名也会被翻译
|
||||
|
||||
DAboutDialog *dialog = new DAboutDialog;
|
||||
a.setAboutDialog(dialog);
|
||||
|
||||
// WindowIcon
|
||||
dialog->setWindowIcon(QIcon(":/images/spark-webapp-runtime.svg"));
|
||||
// ProductIcon
|
||||
dialog->setProductIcon(QIcon(":/images/spark-webapp-runtime.svg"));
|
||||
// ProductName
|
||||
dialog->setProductName(QString("<span>%1</span>").arg(DEFAULT_TITLE));
|
||||
// Version
|
||||
dialog->setVersion(QString("%1 %2").arg(QObject::tr("Version:")).arg(CURRENT_VER));
|
||||
// CompanyLogo
|
||||
dialog->setCompanyLogo(QPixmap(":/images/Logo-Spark.png"));
|
||||
// Description
|
||||
QString szDefaultDesc = QString("<a href='https://gitee.com/deepin-community-store/spark-web-app-runtime'><span style='font-size:12pt;font-weight:500;'>%1</span></a><br/>"
|
||||
"<span style='font-size:12pt;'>%2</span>")
|
||||
.arg(DEFAULT_TITLE)
|
||||
.arg(QObject::tr("Presented By Spark developers # HadesStudio"));
|
||||
dialog->setDescription(szDefaultDesc);
|
||||
// WebsiteName
|
||||
dialog->setWebsiteName("Spark Project");
|
||||
// WebsiteLink
|
||||
dialog->setWebsiteLink("https://gitee.com/deepin-community-store/");
|
||||
// License
|
||||
dialog->setLicense(QObject::tr("This program is open source under GPLv3")); // 本程序按GPL第三版开源
|
||||
// 强制使用 DTK 平台插件
|
||||
int fakeArgc = argc + 2;
|
||||
QVector<char *> fakeArgv(fakeArgc);
|
||||
fakeArgv[0] = argv[0];
|
||||
fakeArgv[1] = const_cast<char *>("-platformtheme");
|
||||
fakeArgv[2] = const_cast<char *>("deepin");
|
||||
for (int i = 1; i < argc; i++) {
|
||||
fakeArgv[i + 2] = argv[i];
|
||||
}
|
||||
Application a(fakeArgc, fakeArgv.data());
|
||||
|
||||
// 解析命令行启动参数
|
||||
QCommandLineParser parser;
|
||||
|
||||
parser.setApplicationDescription(QObject::tr("Description: %1").arg(DEFAULT_TITLE));
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
|
||||
QCommandLineOption optParser(QStringList() << "p" << "parser",
|
||||
QCommandLineOption optParser(QStringList() << "p"
|
||||
<< "parser",
|
||||
QObject::tr("Enable CommandLineParser. Default is false."));
|
||||
parser.addOption(optParser);
|
||||
|
||||
QCommandLineOption optTitle(QStringList() << "t" << "title",
|
||||
QCommandLineOption optTitle(QStringList() << "t"
|
||||
<< "title",
|
||||
QObject::tr("The Title of Application. Default is %1.").arg(DEFAULT_TITLE),
|
||||
"title",
|
||||
DEFAULT_TITLE);
|
||||
parser.addOption(optTitle);
|
||||
|
||||
QCommandLineOption optUrl(QStringList() << "u" << "url",
|
||||
QCommandLineOption optUrl(QStringList() << "u"
|
||||
<< "url",
|
||||
QObject::tr("The target URL. Default is Blank."),
|
||||
"url",
|
||||
DEFAULT_URL);
|
||||
parser.addOption(optUrl);
|
||||
|
||||
QCommandLineOption optWidth(QStringList() << "w" << "width",
|
||||
QCommandLineOption optWidth(QStringList() << "w"
|
||||
<< "width",
|
||||
QObject::tr("The Width of Application. Default is %1.").arg(DEFAULT_WIDTH),
|
||||
"width",
|
||||
QString::number(DEFAULT_WIDTH));
|
||||
parser.addOption(optWidth);
|
||||
|
||||
QCommandLineOption optHeight(QStringList() << "H" << "height",
|
||||
QCommandLineOption optHeight(QStringList() << "H"
|
||||
<< "height",
|
||||
QObject::tr("The Height of Application. Default is %1.").arg(DEFAULT_HEIGHT),
|
||||
"height",
|
||||
QString::number(DEFAULT_HEIGHT));
|
||||
parser.addOption(optHeight);
|
||||
|
||||
QCommandLineOption optTray(QStringList() << "T"
|
||||
<< "tray",
|
||||
QObject::tr("Enable Tray Icon. Default is false."));
|
||||
parser.addOption(optTray);
|
||||
|
||||
QCommandLineOption optFullScreen("full-screen",
|
||||
QObject::tr("Run in Fullscreen Mode. Default is false."));
|
||||
parser.addOption(optFullScreen);
|
||||
|
||||
QCommandLineOption optFixSize("fix-size",
|
||||
QObject::tr("Fix Window Size. Default is false."));
|
||||
parser.addOption(optFixSize);
|
||||
|
||||
QCommandLineOption optHideButtons("hide-buttons",
|
||||
QObject::tr("Hide Control Buttons. Default is false."));
|
||||
QObject::tr("Hide Control Buttons. Default is false."));
|
||||
parser.addOption(optHideButtons);
|
||||
|
||||
QCommandLineOption optIcon(QStringList() << "i" << "ico",
|
||||
QCommandLineOption optIcon(QStringList() << "i"
|
||||
<< "ico",
|
||||
QObject::tr("The ICON of Application."),
|
||||
"ico",
|
||||
DEFAULT_ICON);
|
||||
parser.addOption(optIcon);
|
||||
|
||||
QCommandLineOption optDesc(QStringList() << "d" << "desc",
|
||||
QCommandLineOption optDesc(QStringList() << "d"
|
||||
<< "desc",
|
||||
QObject::tr("The Description of Application."),
|
||||
"desc",
|
||||
DEFAULT_DESC);
|
||||
parser.addOption(optDesc);
|
||||
|
||||
QCommandLineOption optCfgFile(QStringList() << "c" << "cfg",
|
||||
QCommandLineOption optCfgFile(QStringList() << "c"
|
||||
<< "cfg",
|
||||
QObject::tr("The Configuration file of Application."),
|
||||
"cfg",
|
||||
DEFAULT_CFG);
|
||||
parser.addOption(optCfgFile);
|
||||
|
||||
QCommandLineOption optRootPath(QStringList() << "r" << "root",
|
||||
QCommandLineOption optRootPath(QStringList() << "r"
|
||||
<< "root",
|
||||
QObject::tr("The root path of the program web service."),
|
||||
"root",
|
||||
DEFAULT_ROOT);
|
||||
parser.addOption(optRootPath);
|
||||
|
||||
|
||||
QCommandLineOption optPort(QStringList() << "P" << "port",
|
||||
QCommandLineOption optPort(QStringList() << "P"
|
||||
<< "port",
|
||||
QObject::tr("The port number of the program web service."),
|
||||
"port",
|
||||
DEFAULT_PORT);
|
||||
QString::number(DEFAULT_PORT));
|
||||
parser.addOption(optPort);
|
||||
|
||||
QCommandLineOption useGPU(QStringList() << "G"
|
||||
<< "GPU",
|
||||
QObject::tr("To use GPU instead of CPU to decoding. Default True."),
|
||||
"GPU",
|
||||
QString::number(DEFAULT_GPU));
|
||||
parser.addOption(useGPU);
|
||||
|
||||
#if SSL_SERVER
|
||||
QCommandLineOption optSSLPort(QStringList() << "s" << "sslport",
|
||||
QCommandLineOption optSSLPort(QStringList() << "s"
|
||||
<< "sslport",
|
||||
QObject::tr("The ssl port number of the program web service."),
|
||||
"sslport",
|
||||
DEFAULT_PORT);
|
||||
@ -139,38 +150,41 @@ int main(int argc, char *argv[])
|
||||
QString szUrl = DEFAULT_URL;
|
||||
int width = DEFAULT_WIDTH;
|
||||
int height = DEFAULT_HEIGHT;
|
||||
bool tray = false;
|
||||
bool fullScreen = false;
|
||||
bool fixSize = false;
|
||||
bool hideButtons = false;
|
||||
QString szIcon = DEFAULT_ICON;
|
||||
QString szDesc = DEFAULT_DESC;
|
||||
QString szRootPath = DEFAULT_ROOT;
|
||||
quint16 u16Port = DEFAULT_PORT;
|
||||
bool toUseGPU = DEFAULT_GPU;
|
||||
#if SSL_SERVER
|
||||
quint16 u16sslPort = 0;
|
||||
#endif
|
||||
QString szDefaultDesc = QObject::tr("Presented By Spark developers # HadesStudio");
|
||||
|
||||
// 解析可能存在的配置文件
|
||||
QString szCfgFile = DEFAULT_CFG;
|
||||
if (parser.isSet(optCfgFile))
|
||||
{
|
||||
if (parser.isSet(optCfgFile)) {
|
||||
szCfgFile = parser.value(optCfgFile);
|
||||
if (!szCfgFile.isEmpty())
|
||||
{
|
||||
QFileInfo fi(szCfgFile);
|
||||
if (fi.exists())
|
||||
{
|
||||
if (!szCfgFile.isEmpty()) {
|
||||
if (QFileInfo(szCfgFile).exists()) {
|
||||
QSettings settings(szCfgFile, QSettings::IniFormat);
|
||||
szTitle = settings.value("SparkWebAppRuntime/Title", DEFAULT_TITLE).toString();
|
||||
szUrl = settings.value("SparkWebAppRuntime/URL", DEFAULT_TITLE).toString();
|
||||
width = settings.value("SparkWebAppRuntime/Width", DEFAULT_WIDTH).toUInt();
|
||||
height = settings.value("SparkWebAppRuntime/Height", DEFAULT_HEIGHT).toUInt();
|
||||
fixSize = settings.value("SparkWebAppRunTime/FixSize", false).toBool();
|
||||
hideButtons = settings.value("SparkWebAppRunTime/HideButtons", false).toBool();
|
||||
width = settings.value("SparkWebAppRuntime/Width", DEFAULT_WIDTH).toInt();
|
||||
height = settings.value("SparkWebAppRuntime/Height", DEFAULT_HEIGHT).toInt();
|
||||
tray = settings.value("SparkWebAppRuntime/Tray", false).toBool();
|
||||
fullScreen = settings.value("SparkWebAppRuntime/FullScreen", false).toBool();
|
||||
fixSize = settings.value("SparkWebAppRuntime/FixSize", false).toBool();
|
||||
hideButtons = settings.value("SparkWebAppRuntime/HideButtons", false).toBool();
|
||||
szIcon = settings.value("SparkWebAppRuntime/Ico", DEFAULT_ICON).toString();
|
||||
szDesc = QString("%1<br/><br/>%2")
|
||||
.arg(settings.value("SparkWebAppRuntime/Desc", QString()).toString())
|
||||
.arg(szDefaultDesc);
|
||||
.arg(settings.value("SparkWebAppRuntime/Desc", QString()).toString())
|
||||
.arg(szDefaultDesc);
|
||||
szRootPath = settings.value("SparkWebAppRuntime/RootPath", QString()).toString();
|
||||
u16Port = settings.value("SparkWebAppRuntime/Port", 0).toUInt();
|
||||
u16Port = static_cast<quint16>(settings.value("SparkWebAppRuntime/Port", 0).toUInt());
|
||||
#if SSL_SERVER
|
||||
u16sslPort = settings.value("SparkWebAppRuntime/SSLPort", 0).toUInt();
|
||||
#endif
|
||||
@ -179,142 +193,157 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// 命令行级别优先, 覆盖配置文件的设置
|
||||
if (parser.isSet(optTitle))
|
||||
{
|
||||
if (parser.isSet(optTitle)) {
|
||||
szTitle = parser.value(optTitle);
|
||||
}
|
||||
if (parser.isSet(optUrl))
|
||||
{
|
||||
if (parser.isSet(optUrl)) {
|
||||
szUrl = parser.value(optUrl);
|
||||
}
|
||||
if (parser.isSet(optWidth))
|
||||
{
|
||||
if (parser.isSet(optWidth)) {
|
||||
width = parser.value(optWidth).toInt();
|
||||
}
|
||||
if (parser.isSet(optHeight))
|
||||
{
|
||||
if (parser.isSet(optHeight)) {
|
||||
height = parser.value(optHeight).toInt();
|
||||
}
|
||||
|
||||
if (parser.isSet(optFixSize))
|
||||
{
|
||||
if (parser.isSet(optTray)) {
|
||||
tray = true;
|
||||
}
|
||||
if (parser.isSet(optFullScreen)) {
|
||||
fullScreen = true;
|
||||
}
|
||||
if (parser.isSet(optFixSize)) {
|
||||
fixSize = true;
|
||||
}
|
||||
if (parser.isSet(optHideButtons))
|
||||
{
|
||||
if (parser.isSet(optHideButtons)) {
|
||||
hideButtons = true;
|
||||
}
|
||||
|
||||
if (parser.isSet(optDesc))
|
||||
{
|
||||
szDesc = QString("%1<br/><br/>%2").arg(parser.value(optDesc))
|
||||
.arg(szDefaultDesc);
|
||||
if (parser.isSet(optIcon)) {
|
||||
szIcon = parser.value(optIcon);
|
||||
}
|
||||
if (parser.isSet(optDesc)) {
|
||||
szDesc = QString("%1<br/><br/>%2").arg(parser.value(optDesc)).arg(szDefaultDesc);
|
||||
}
|
||||
|
||||
if (parser.isSet(optRootPath))
|
||||
{
|
||||
if (parser.isSet(optRootPath)) {
|
||||
szRootPath = parser.value(optRootPath);
|
||||
}
|
||||
|
||||
if (parser.isSet(optPort))
|
||||
{
|
||||
u16Port = parser.value(optPort).toUInt();
|
||||
if (parser.isSet(optPort)) {
|
||||
u16Port = static_cast<quint16>(parser.value(optPort).toUInt());
|
||||
}
|
||||
|
||||
if (parser.isSet(useGPU)) {
|
||||
toUseGPU = parser.value(useGPU).toUInt();
|
||||
}
|
||||
|
||||
QStringList chromium_flags = {"--disable-web-security"};
|
||||
#if defined __sw_64__ || __loongarch__
|
||||
chromium_flags << "--no-sandbox";
|
||||
#endif
|
||||
if (toUseGPU == true) {
|
||||
chromium_flags << "--ignore-gpu-blocklist"
|
||||
<< "--enable-gpu-rasterization"
|
||||
<< "--enable-native-gpu-memory-buffers"
|
||||
<< "--enable-accelerated-video-decode";
|
||||
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", chromium_flags.join(" ").toUtf8());
|
||||
qDebug() << "Setting GPU to True.";
|
||||
}
|
||||
// 初始化 QtWebEngine 深色模式环境变量
|
||||
WebEngineView::handleChromiumFlags();
|
||||
|
||||
#if SSL_SERVER
|
||||
if (parser.isSet(optSSLPort))
|
||||
{
|
||||
if (parser.isSet(optSSLPort)) {
|
||||
u16sslPort = parser.value(optSSLPort).toUInt();
|
||||
}
|
||||
#endif
|
||||
|
||||
// 没设置 -p 并且参数个数>1 并且第一个参数不是-开始的
|
||||
if (!parser.isSet(optParser) && argc > 1 && !QString(argv[1]).startsWith("-"))
|
||||
{
|
||||
// 没设置 -p 并且参数个数 > 1 并且第一个参数不是 - 开始的
|
||||
if (!parser.isSet(optParser) && argc > 1 && !QString(argv[1]).startsWith("-")) {
|
||||
// 按照固定顺序级别最优先
|
||||
if (argc > 1)
|
||||
{
|
||||
if (argc > 1) {
|
||||
szTitle = argv[1];
|
||||
}
|
||||
if (argc > 2)
|
||||
{
|
||||
if (argc > 2) {
|
||||
szUrl = argv[2];
|
||||
}
|
||||
if (argc > 3)
|
||||
{
|
||||
if (argc > 3) {
|
||||
width = QString(argv[3]).toInt();
|
||||
}
|
||||
if (argc > 4)
|
||||
{
|
||||
if (argc > 4) {
|
||||
height = QString(argv[4]).toInt();
|
||||
}
|
||||
|
||||
if (argc > 5)
|
||||
{
|
||||
if (argc > 5) {
|
||||
tray = true;
|
||||
}
|
||||
if (argc > 6) {
|
||||
fullScreen = true;
|
||||
}
|
||||
if (argc > 7) {
|
||||
fixSize = true;
|
||||
}
|
||||
if (argc > 6)
|
||||
{
|
||||
if (argc > 8) {
|
||||
hideButtons = true;
|
||||
}
|
||||
|
||||
if (argc > 7)
|
||||
{
|
||||
szIcon = QString(argv[7]);
|
||||
if (argc > 9) {
|
||||
szIcon = QString(argv[9]);
|
||||
}
|
||||
if (argc > 8)
|
||||
{
|
||||
szDesc = QString("%1<br/><br/>%2").arg(QString(argv[8])).arg(szDefaultDesc);
|
||||
if (argc > 10) {
|
||||
szDesc = QString("%1<br/><br/>%2").arg(QString(argv[10])).arg(szDefaultDesc);
|
||||
}
|
||||
if (argc > 9)
|
||||
{
|
||||
szRootPath = QString(argv[9]);
|
||||
if (argc > 11) {
|
||||
szRootPath = QString(argv[11]);
|
||||
}
|
||||
if (argc > 10)
|
||||
{
|
||||
u16Port = QString(argv[10]).toUInt();
|
||||
if (argc > 12) {
|
||||
u16Port = static_cast<quint16>(QString(argv[12]).toUInt());
|
||||
}
|
||||
#if SSL_SERVER
|
||||
if (argc > 11)
|
||||
{
|
||||
u16sslPort = QString(argv[11]).toUInt();
|
||||
if (argc > 13) {
|
||||
u16sslPort = QString(argv[13]).toUInt();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
MainWindow w(szTitle, szUrl, width, height, fixSize, hideButtons, dialog);
|
||||
if (fixSize) {
|
||||
fullScreen = false; // 固定窗口大小时禁用全屏模式,避免标题栏按钮 BUG
|
||||
}
|
||||
|
||||
// DApplication 单例运行(标题名称_当前登录用户 id)
|
||||
if (!a.setSingleInstance(szTitle + "_" + QString::number(getuid()))) {
|
||||
qInfo() << "Another instance has already started, now exit...";
|
||||
exit(0);
|
||||
}
|
||||
a.setQuitOnLastWindowClosed(!tray); // 启用托盘时,退出程序后服务不终止
|
||||
|
||||
#if SSL_SERVER
|
||||
if (!szRootPath.isEmpty() && u16Port > 0 && u16sslPort > 0)
|
||||
{
|
||||
if (!szRootPath.isEmpty() && u16Port > 0 && u16sslPort > 0) {
|
||||
HttpD httpd(szRootPath, u16Port, u16sslPort);
|
||||
httpd.start();
|
||||
}
|
||||
#else
|
||||
if (!szRootPath.isEmpty() && u16Port > 0)
|
||||
{
|
||||
if (!szRootPath.isEmpty() && u16Port > 0) {
|
||||
static HttpD httpd(szRootPath, u16Port);
|
||||
QObject::connect(&w, &MainWindow::sigQuit, &httpd, &HttpD::stop);
|
||||
QObject::connect(&a, &Application::sigQuit, &httpd, &HttpD::stop);
|
||||
httpd.start();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (parser.isSet(optIcon))
|
||||
{
|
||||
szIcon = parser.value(optIcon);
|
||||
}
|
||||
MainWindow w(szTitle, szUrl, width, height, tray, fullScreen, fixSize, hideButtons);
|
||||
a.setMainWindow(&w);
|
||||
QObject::connect(&a, &Application::newInstanceStarted, &w, &MainWindow::slotNewInstanceStarted);
|
||||
QObject::connect(&w, &MainWindow::sigClose, &a, &Application::slotMainWindowClose);
|
||||
|
||||
if (!szIcon.isEmpty())
|
||||
{
|
||||
dialog->setWindowIcon(QIcon(szIcon));
|
||||
dialog->setProductIcon(QIcon(szIcon));
|
||||
if (!szIcon.isEmpty()) {
|
||||
w.setIcon(szIcon);
|
||||
}
|
||||
if (!szDesc.isEmpty())
|
||||
{
|
||||
dialog->setDescription(szDesc);
|
||||
if (!szDesc.isEmpty()) {
|
||||
w.setDescription(szDesc);
|
||||
}
|
||||
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
@ -1,34 +1,170 @@
|
||||
#include "mainwindow.h"
|
||||
#include "application.h"
|
||||
|
||||
#include <DMainWindow>
|
||||
#include <DLog>
|
||||
#include <DWidgetUtil>
|
||||
#include <DTitlebar>
|
||||
#include <DMessageManager>
|
||||
#include <DDesktopServices>
|
||||
|
||||
#include <QLayout>
|
||||
#include <QKeyEvent>
|
||||
#include <QWebEngineProfile>
|
||||
#include <QFileInfo>
|
||||
#include <QCloseEvent>
|
||||
#include <QDebug>
|
||||
#include <QFileDialog>
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
DCORE_USE_NAMESPACE
|
||||
|
||||
MainWindow::MainWindow(QString szTitle,
|
||||
QString szUrl,
|
||||
int nWidth,
|
||||
int nHeight,
|
||||
bool nTray,
|
||||
bool nFullScreen,
|
||||
bool nFixSize,
|
||||
bool nHideButtons,
|
||||
DAboutDialog *dialog,
|
||||
QWidget *parent)
|
||||
: DMainWindow(parent)
|
||||
, m_widget(new Widget(szUrl))
|
||||
, m_dialog(dialog)
|
||||
, m_title(szTitle)
|
||||
, m_url(szUrl)
|
||||
, m_width(nWidth)
|
||||
, m_height(nHeight)
|
||||
, m_isTrayEnabled(nTray)
|
||||
, m_isFullScreen(nFullScreen)
|
||||
, m_isFixedSize(nFixSize)
|
||||
, m_isHideButton(nHideButtons)
|
||||
, m_widget(new Widget(m_url, this, m_title))
|
||||
, m_tray(new QSystemTrayIcon(this))
|
||||
, btnBack(new DToolButton(titlebar()))
|
||||
, btnForward(new DToolButton(titlebar()))
|
||||
, btnRefresh(new DToolButton(titlebar()))
|
||||
, m_menu(new QMenu)
|
||||
, m_fixSize(new QAction(tr("Fix Size")))
|
||||
, m_hideButtons(new QAction(tr("Hide Buttons")))
|
||||
, m_width(nWidth)
|
||||
, m_height(nHeight)
|
||||
, m_menu(new QMenu(titlebar()))
|
||||
, m_fullScreen(new QAction(QObject::tr("Full Screen"), this))
|
||||
, m_fixSize(new QAction(QObject::tr("Fix Size"), this))
|
||||
, m_hideButtons(new QAction(QObject::tr("Hide Buttons"), this))
|
||||
, m_clearCache(new QAction(QObject::tr("Clear Cache"), this))
|
||||
, t_menu(new QMenu(this))
|
||||
, t_show(new QAction(QObject::tr("Show MainWindow"), this))
|
||||
, t_about(new QAction(qApp->translate("TitleBarMenu", QString("About").toUtf8().data()), this))
|
||||
, t_exit(new QAction(qApp->translate("TitleBarMenu", QString("Exit").toUtf8().data()), this))
|
||||
, downloadMessage(new DFloatingMessage(DFloatingMessage::ResidentType, this))
|
||||
, downloadProgressWidget(new QWidget(downloadMessage))
|
||||
, progressBarLayout(new QHBoxLayout(downloadProgressWidget))
|
||||
, downloadProgressBar(new DProgressBar(downloadProgressWidget))
|
||||
, btnPause(new DPushButton(QObject::tr("Pause"), downloadProgressWidget))
|
||||
, btnResume(new DPushButton(QObject::tr("Resume"), downloadProgressWidget))
|
||||
, btnCancel(new DPushButton(QObject::tr("Cancel"), downloadProgressWidget))
|
||||
, isCanceled(false)
|
||||
{
|
||||
initTmpDir();
|
||||
initLog();
|
||||
|
||||
initUI();
|
||||
initTrayIcon();
|
||||
initConnections();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void MainWindow::setIcon(QString szIconPath)
|
||||
{
|
||||
if (!QFile::exists(szIconPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
titlebar()->setIcon(QIcon(szIconPath));
|
||||
setWindowIcon(QIcon(szIconPath));
|
||||
m_tray->setIcon(QIcon(szIconPath));
|
||||
|
||||
qApp->setWindowIcon(QIcon::fromTheme(szIconPath));
|
||||
qApp->setProductIcon(QIcon::fromTheme(szIconPath));
|
||||
}
|
||||
|
||||
void MainWindow::setDescription(const QString &desc)
|
||||
{
|
||||
qApp->setApplicationDescription(desc);
|
||||
}
|
||||
|
||||
QString MainWindow::title() const
|
||||
{
|
||||
return m_title;
|
||||
}
|
||||
|
||||
QString MainWindow::tmpDir() const
|
||||
{
|
||||
QString orgName = qobject_cast<DApplication *>(qApp)->organizationName();
|
||||
QString appName = qobject_cast<DApplication *>(qApp)->applicationName();
|
||||
return QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/" + orgName + "/" + appName + "/" + m_title + "/" + QString::number(getuid());
|
||||
}
|
||||
|
||||
void MainWindow::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (!m_fixSize->isChecked()) // 固定窗口大小时禁止全屏
|
||||
{
|
||||
if (event->key() == Qt::Key_F11) // 绑定键盘快捷键 F11
|
||||
{
|
||||
m_fullScreen->trigger();
|
||||
m_menu->update();
|
||||
}
|
||||
}
|
||||
|
||||
DMainWindow::keyPressEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
if (this->isFullScreen()) {
|
||||
m_fullScreen->setChecked(true);
|
||||
} else {
|
||||
m_fullScreen->setChecked(false);
|
||||
if (!m_isFixedSize) {
|
||||
m_fixSize->setEnabled(true); // 命令行参数没有固定窗口大小时,窗口模式下允许手动选择固定窗口大小
|
||||
}
|
||||
}
|
||||
|
||||
DMainWindow::resizeEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (!m_isTrayEnabled) {
|
||||
emit sigClose(); // 不启用托盘时,关闭主窗口则关闭关于窗口
|
||||
}
|
||||
|
||||
DMainWindow::closeEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::initLog()
|
||||
{
|
||||
if (!QDir(tmpDir()).exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
DLogManager::setlogFilePath(tmpDir() + "/" + "log");
|
||||
DLogManager::registerFileAppender();
|
||||
DLogManager::registerConsoleAppender();
|
||||
}
|
||||
|
||||
void MainWindow::initTmpDir()
|
||||
{
|
||||
QDir dir(tmpDir());
|
||||
dir.removeRecursively();
|
||||
dir.mkpath(dir.path());
|
||||
if (!dir.exists()) {
|
||||
qCritical() << Q_FUNC_INFO << dir.path() << "not exists";
|
||||
return;
|
||||
}
|
||||
qDebug() << Q_FUNC_INFO << dir.path() << "created";
|
||||
}
|
||||
|
||||
void MainWindow::initUI()
|
||||
{
|
||||
// 初始化 MainWindow
|
||||
setCentralWidget(m_widget);
|
||||
centralWidget()->layout()->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
@ -38,7 +174,17 @@ MainWindow::MainWindow(QString szTitle,
|
||||
|
||||
setWindowIcon(QIcon(":/images/spark-webapp-runtime.svg"));
|
||||
|
||||
titlebar()->setTitle(szTitle);
|
||||
initTitleBar();
|
||||
initDownloadProgressBar();
|
||||
|
||||
fixSize();
|
||||
fullScreen();
|
||||
hideButtons(); // 修复指定hidebuttons之后没有生效
|
||||
}
|
||||
|
||||
void MainWindow::initTitleBar()
|
||||
{
|
||||
titlebar()->setTitle(m_title);
|
||||
titlebar()->setIcon(QIcon(":/images/spark-webapp-runtime.svg"));
|
||||
|
||||
btnBack->setIcon(QIcon(":/images/go-previous-24.svg"));
|
||||
@ -52,95 +198,321 @@ MainWindow::MainWindow(QString szTitle,
|
||||
titlebar()->addWidget(btnForward, Qt::AlignLeft);
|
||||
titlebar()->addWidget(btnRefresh, Qt::AlignLeft);
|
||||
|
||||
m_fullScreen->setCheckable(true);
|
||||
m_fullScreen->setChecked(m_isFullScreen);
|
||||
m_fullScreen->setDisabled(m_isFixedSize); // NOTE: 固定窗口大小时禁用全屏模式,避免标题栏按钮显示问题
|
||||
m_fixSize->setCheckable(true);
|
||||
m_fixSize->setChecked(nFixSize);
|
||||
m_fixSize->setDisabled(nFixSize); // 建议使用命令行参数 --fix-size 或者 --hide-buttons 时直接禁止在 GUI 修改选项,主要因为最大化按钮无法刷新存在状态,干脆都禁用了......
|
||||
m_fixSize->setChecked(m_isFixedSize);
|
||||
m_fixSize->setDisabled(m_isFixedSize);
|
||||
m_hideButtons->setCheckable(true);
|
||||
m_hideButtons->setChecked(nHideButtons);
|
||||
m_hideButtons->setDisabled(nHideButtons);
|
||||
m_menu->addAction(m_fixSize);
|
||||
m_menu->addAction(m_hideButtons);
|
||||
m_hideButtons->setChecked(m_isHideButton);
|
||||
m_hideButtons->setDisabled(m_isHideButton);
|
||||
|
||||
// 命令行设置参数后 GUI 中隐藏对应选项
|
||||
if (!m_isFixedSize) {
|
||||
m_menu->addAction(m_fullScreen);
|
||||
m_menu->addAction(m_fixSize);
|
||||
}
|
||||
|
||||
if (!m_isHideButton) {
|
||||
m_menu->addAction(m_hideButtons);
|
||||
}
|
||||
|
||||
if (m_menu->actions().size() > 0) {
|
||||
m_menu->addSeparator();
|
||||
m_menu->addAction(m_clearCache);
|
||||
}
|
||||
|
||||
titlebar()->setMenu(m_menu);
|
||||
titlebar()->setAutoHideOnFullscreen(true);
|
||||
}
|
||||
|
||||
fixSize();
|
||||
hideButtons();
|
||||
void MainWindow::initDownloadProgressBar()
|
||||
{
|
||||
// 初始化 DownloadProgressBar
|
||||
downloadProgressBar->setFixedSize(250, 8);
|
||||
btnPause->setFixedSize(80, 32);
|
||||
btnResume->setFixedSize(80, 32);
|
||||
btnCancel->setFixedSize(80, 32);
|
||||
|
||||
connect(btnBack, &DToolButton::clicked, this, [&]()
|
||||
{
|
||||
progressBarLayout->setMargin(0);
|
||||
progressBarLayout->setSpacing(0);
|
||||
progressBarLayout->setAlignment(Qt::AlignCenter);
|
||||
progressBarLayout->addWidget(downloadProgressBar);
|
||||
progressBarLayout->addSpacing(10);
|
||||
progressBarLayout->addWidget(btnPause);
|
||||
progressBarLayout->addWidget(btnResume);
|
||||
progressBarLayout->addWidget(btnCancel);
|
||||
|
||||
downloadMessage->setIcon(QIcon::fromTheme("deepin-download").pixmap(64, 64));
|
||||
downloadMessage->setWidget(downloadProgressWidget);
|
||||
downloadMessage->hide();
|
||||
}
|
||||
|
||||
void MainWindow::initTrayIcon()
|
||||
{
|
||||
// 初始化 TrayIcon
|
||||
t_menu->addAction(t_show);
|
||||
t_menu->addAction(t_about);
|
||||
t_menu->addAction(t_exit);
|
||||
m_tray->setContextMenu(t_menu);
|
||||
m_tray->setToolTip(m_title);
|
||||
m_tray->setIcon(QIcon(":/images/spark-webapp-runtime.svg"));
|
||||
|
||||
if (m_isTrayEnabled) {
|
||||
m_tray->show(); // 启用托盘时显示
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::initConnections()
|
||||
{
|
||||
connect(btnBack, &DToolButton::clicked, this, [&]() {
|
||||
m_widget->goBack();
|
||||
});
|
||||
connect(btnForward, &DToolButton::clicked, this, [&]()
|
||||
{
|
||||
connect(btnForward, &DToolButton::clicked, this, [&]() {
|
||||
m_widget->goForward();
|
||||
});
|
||||
connect(btnRefresh, &DToolButton::clicked, this, [&]()
|
||||
{
|
||||
connect(btnRefresh, &DToolButton::clicked, this, [&]() {
|
||||
m_widget->refresh();
|
||||
});
|
||||
|
||||
connect(m_fixSize, &QAction::triggered, this, [=]()
|
||||
{
|
||||
connect(m_fullScreen, &QAction::triggered, this, [=]() {
|
||||
fullScreen();
|
||||
});
|
||||
connect(m_fixSize, &QAction::triggered, this, [=]() {
|
||||
fixSize();
|
||||
});
|
||||
connect(m_hideButtons, &QAction::triggered, this, [=]()
|
||||
{
|
||||
connect(m_hideButtons, &QAction::triggered, this, [=]() {
|
||||
hideButtons();
|
||||
});
|
||||
connect(m_clearCache, &QAction::triggered, this, [=]() {
|
||||
clearCache();
|
||||
});
|
||||
|
||||
connect(t_show, &QAction::triggered, this, [=]() {
|
||||
this->activateWindow();
|
||||
fixSize();
|
||||
});
|
||||
connect(t_about, &QAction::triggered, this, [=]() {
|
||||
qobject_cast<Application *>(qApp)->triggerAboutAction();
|
||||
});
|
||||
connect(t_exit, &QAction::triggered, this, [=]() {
|
||||
exit(0);
|
||||
});
|
||||
connect(m_tray, &QSystemTrayIcon::activated, this, &MainWindow::on_trayIconActivated);
|
||||
|
||||
connect(m_widget, &Widget::sigLoadErrorOccurred, this, &MainWindow::slotLoadErrorOccurred);
|
||||
connect(m_widget->getPage()->profile(), &QWebEngineProfile::downloadRequested, this, &MainWindow::on_downloadStart);
|
||||
connect(m_widget->getPage(), &QWebEnginePage::windowCloseRequested, this, [=]() {
|
||||
this->close();
|
||||
});
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
void MainWindow::fullScreen()
|
||||
{
|
||||
emit sigQuit();
|
||||
delete m_widget;
|
||||
delete m_dialog;
|
||||
}
|
||||
|
||||
void MainWindow::setIcon(QString szIconPath)
|
||||
{
|
||||
QFileInfo fi(szIconPath);
|
||||
if (fi.exists())
|
||||
{
|
||||
titlebar()->setIcon(QIcon(szIconPath));
|
||||
setWindowIcon(QIcon(szIconPath));
|
||||
qDebug() << szIconPath << "is Set!";
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << szIconPath << "is Not Exists!";
|
||||
if (m_fullScreen->isChecked()) {
|
||||
m_fixSize->setChecked(false);
|
||||
m_fixSize->setDisabled(true);
|
||||
m_menu->update();
|
||||
showFullScreen();
|
||||
// DMessageManager::instance()->sendMessage(this, QIcon::fromTheme("dialog-information").pixmap(64, 64), QString(QObject::tr("%1Fullscreen Mode")).arg(" "));
|
||||
} else {
|
||||
if (!m_isFixedSize) {
|
||||
m_fixSize->setDisabled(false); // 命令行参数没有固定窗口大小时,窗口模式下允许手动选择固定窗口大小
|
||||
}
|
||||
m_menu->update();
|
||||
showNormal();
|
||||
// DMessageManager::instance()->sendMessage(this, QIcon::fromTheme("dialog-information").pixmap(64, 64), QString(QObject::tr("%1Windowed Mode")).arg(" "));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::fixSize()
|
||||
{
|
||||
if(m_fixSize->isChecked())
|
||||
{
|
||||
setFixedSize(this->width(), this->height());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_fixSize->isChecked()) {
|
||||
m_fullScreen->setChecked(false);
|
||||
m_fullScreen->setDisabled(true);
|
||||
m_menu->update();
|
||||
setFixedSize(this->size());
|
||||
// BUG: 启用托盘图标后,若手动选择固定窗口大小,并且关闭窗口,再次打开时会丢失最大化按钮,且无法恢复。
|
||||
} else {
|
||||
m_fullScreen->setDisabled(false);
|
||||
m_menu->update();
|
||||
setMinimumSize(m_width, m_height);
|
||||
setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
|
||||
}
|
||||
|
||||
fullScreen();
|
||||
}
|
||||
|
||||
void MainWindow::hideButtons()
|
||||
{
|
||||
if(m_hideButtons->isChecked())
|
||||
{
|
||||
if (m_hideButtons->isChecked()) {
|
||||
btnBack->hide();
|
||||
btnForward->hide();
|
||||
btnRefresh->hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
btnBack->show();
|
||||
btnForward->show();
|
||||
btnRefresh->show();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
void MainWindow::clearCache()
|
||||
{
|
||||
m_dialog->close();
|
||||
event->accept();
|
||||
// 清除缓存文件夹并刷新页面
|
||||
QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation));
|
||||
if (dir.exists()) {
|
||||
dir.removeRecursively();
|
||||
}
|
||||
|
||||
emit btnRefresh->clicked();
|
||||
}
|
||||
|
||||
QString MainWindow::saveAs(QString fileName)
|
||||
{
|
||||
QString saveFile = QFileDialog::getSaveFileName(this,
|
||||
QObject::tr("Save As"),
|
||||
QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/" + fileName);
|
||||
if (!saveFile.isEmpty()) {
|
||||
// 判断上层目录是否可写入
|
||||
if (QFileInfo(QFileInfo(saveFile).absoluteDir().canonicalPath()).isWritable()) {
|
||||
return saveFile;
|
||||
} else {
|
||||
return saveAs(fileName);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MainWindow::slotNewInstanceStarted()
|
||||
{
|
||||
this->setWindowState(Qt::WindowActive);
|
||||
this->activateWindow();
|
||||
this->show();
|
||||
}
|
||||
|
||||
void MainWindow::on_trayIconActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
{
|
||||
switch (reason) {
|
||||
/* 响应托盘点击事件 */
|
||||
case QSystemTrayIcon::Trigger:
|
||||
this->setWindowState(Qt::WindowActive);
|
||||
this->activateWindow();
|
||||
fixSize();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_downloadStart(QWebEngineDownloadItem *item)
|
||||
{
|
||||
// 尝试加锁互斥量,禁止同时下载多个文件
|
||||
if (mutex.tryLock()) {
|
||||
QString fileName = item->downloadFileName();
|
||||
QString filePath = saveAs(fileName);
|
||||
if (filePath.isEmpty()) {
|
||||
mutex.unlock();
|
||||
return;
|
||||
}
|
||||
item->setDownloadDirectory(QFileInfo(filePath).absoluteDir().canonicalPath());
|
||||
|
||||
connect(item, &QWebEngineDownloadItem::downloadProgress, this, &MainWindow::on_downloadProgress);
|
||||
connect(item, &QWebEngineDownloadItem::finished, this, [=]() {
|
||||
on_downloadFinish(filePath);
|
||||
});
|
||||
|
||||
connect(btnPause, &DPushButton::clicked, this, [=]() {
|
||||
on_downloadPause(item);
|
||||
});
|
||||
connect(btnResume, &DPushButton::clicked, this, [=]() {
|
||||
on_downloadResume(item);
|
||||
});
|
||||
connect(btnCancel, &DPushButton::clicked, this, [=]() {
|
||||
on_downloadCancel(item);
|
||||
});
|
||||
|
||||
DFloatingMessage *message = new DFloatingMessage(DFloatingMessage::TransientType);
|
||||
message->setIcon(QIcon::fromTheme("dialog-information").pixmap(64, 64));
|
||||
message->setMessage(QString(QObject::tr("%1Start downloading %2")).arg(" ").arg(fileName));
|
||||
DMessageManager::instance()->sendMessage(this, message);
|
||||
|
||||
item->accept();
|
||||
|
||||
// 重置 DownloadProgressBar 状态
|
||||
isCanceled = false;
|
||||
btnResume->hide();
|
||||
btnPause->show();
|
||||
this->downloadMessage->show(); // 上一次下载完成后隐藏了进度条,这里要重新显示
|
||||
} else {
|
||||
DMessageManager::instance()->sendMessage(this, QIcon::fromTheme("dialog-cancel").pixmap(64, 64), QString(QObject::tr("%1Wait for previous download to complete!")).arg(" "));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
|
||||
{
|
||||
int value = int(double(bytesReceived) / double(bytesTotal) * 100.0);
|
||||
downloadProgressBar->setValue(value);
|
||||
|
||||
downloadMessage->setMessage(" " + QString::number(value) + "%");
|
||||
|
||||
DMessageManager::instance()->sendMessage(this, downloadMessage);
|
||||
}
|
||||
|
||||
void MainWindow::on_downloadFinish(QString filePath)
|
||||
{
|
||||
mutex.unlock(); // 解锁互斥量,允许下载新文件
|
||||
|
||||
downloadMessage->hide();
|
||||
|
||||
// 下载完成显示提示信息
|
||||
if (!isCanceled) {
|
||||
DPushButton *button = new DPushButton(QObject::tr("Open"));
|
||||
|
||||
DFloatingMessage *message = new DFloatingMessage(DFloatingMessage::ResidentType);
|
||||
message->setIcon(QIcon::fromTheme("dialog-ok").pixmap(64, 64));
|
||||
message->setMessage(QString(" %1 %2 %3").arg(QFileInfo(filePath).fileName()).arg(QObject::tr("download finished.")).arg(QObject::tr("Show in file manager?")));
|
||||
message->setWidget(button);
|
||||
DMessageManager::instance()->sendMessage(this, message);
|
||||
|
||||
connect(button, &DPushButton::clicked, this, [=]() {
|
||||
DDesktopServices::showFileItem(filePath);
|
||||
message->hide();
|
||||
message->deleteLater();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_downloadPause(QWebEngineDownloadItem *item)
|
||||
{
|
||||
item->pause();
|
||||
|
||||
downloadMessage->setIcon(QIcon::fromTheme("package-download-failed").pixmap(64, 64));
|
||||
btnResume->show();
|
||||
btnPause->hide();
|
||||
}
|
||||
|
||||
void MainWindow::on_downloadResume(QWebEngineDownloadItem *item)
|
||||
{
|
||||
item->resume();
|
||||
|
||||
downloadMessage->setIcon(QIcon::fromTheme("deepin-download").pixmap(64, 64));
|
||||
btnResume->hide();
|
||||
btnPause->show();
|
||||
}
|
||||
|
||||
void MainWindow::on_downloadCancel(QWebEngineDownloadItem *item)
|
||||
{
|
||||
isCanceled = true; // 取消下载
|
||||
item->cancel();
|
||||
|
||||
mutex.unlock();
|
||||
|
||||
downloadMessage->hide();
|
||||
DMessageManager::instance()->sendMessage(this, QIcon::fromTheme("dialog-error").pixmap(64, 64), QString(QObject::tr("%1Download canceled!")).arg(" "));
|
||||
}
|
||||
|
||||
void MainWindow::slotLoadErrorOccurred()
|
||||
{
|
||||
DMessageManager::instance()->sendMessage(this, QIcon::fromTheme("dialog-warning").pixmap(64, 64), QString(QObject::tr("%1Load error occurred!")).arg(" "));
|
||||
}
|
||||
|
@ -4,6 +4,13 @@
|
||||
#include <DMainWindow>
|
||||
#include <DAboutDialog>
|
||||
#include <DToolButton>
|
||||
#include <DProgressBar>
|
||||
#include <DPushButton>
|
||||
#include <DFloatingMessage>
|
||||
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QProcess>
|
||||
#include <QMutex>
|
||||
|
||||
#include "widget.h"
|
||||
#include "globaldefine.h"
|
||||
@ -19,36 +26,92 @@ public:
|
||||
QString szUrl = DEFAULT_URL,
|
||||
int nWidth = DEFAULT_WIDTH,
|
||||
int nHeight = DEFAULT_HEIGHT,
|
||||
bool nTray = false,
|
||||
bool nFullScreen = false,
|
||||
bool nFixSize = false,
|
||||
bool nHideButtons = false,
|
||||
DAboutDialog *dialog = nullptr,
|
||||
QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
void setIcon(QString szIconPath);
|
||||
void setDescription(const QString &desc);
|
||||
|
||||
QString title() const;
|
||||
QString tmpDir() const;
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
||||
private:
|
||||
void initLog();
|
||||
void initTmpDir();
|
||||
|
||||
void initUI();
|
||||
void initTitleBar();
|
||||
void initDownloadProgressBar();
|
||||
void initTrayIcon();
|
||||
void initConnections();
|
||||
|
||||
void fullScreen();
|
||||
void fixSize();
|
||||
void hideButtons();
|
||||
void clearCache();
|
||||
|
||||
QString saveAs(QString fileName);
|
||||
|
||||
signals:
|
||||
void sigClose();
|
||||
|
||||
public slots:
|
||||
void slotNewInstanceStarted();
|
||||
|
||||
private slots:
|
||||
void on_trayIconActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
|
||||
void on_downloadStart(QWebEngineDownloadItem *item);
|
||||
void on_downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
||||
void on_downloadFinish(QString filePath);
|
||||
void on_downloadPause(QWebEngineDownloadItem *item);
|
||||
void on_downloadResume(QWebEngineDownloadItem *item);
|
||||
void on_downloadCancel(QWebEngineDownloadItem *item);
|
||||
|
||||
void slotLoadErrorOccurred();
|
||||
|
||||
private:
|
||||
QString m_title, m_url;
|
||||
int m_width, m_height;
|
||||
bool m_isTrayEnabled, m_isFullScreen, m_isFixedSize, m_isHideButton;
|
||||
|
||||
Widget *m_widget;
|
||||
DAboutDialog *m_dialog;
|
||||
QSystemTrayIcon *m_tray;
|
||||
|
||||
DToolButton *btnBack;
|
||||
DToolButton *btnForward;
|
||||
DToolButton *btnRefresh;
|
||||
|
||||
QMenu *m_menu;
|
||||
QAction *m_fullScreen;
|
||||
QAction *m_fixSize;
|
||||
QAction *m_hideButtons;
|
||||
QAction *m_clearCache;
|
||||
|
||||
int m_width, m_height;
|
||||
QMenu *t_menu;
|
||||
QAction *t_show;
|
||||
QAction *t_about;
|
||||
QAction *t_exit;
|
||||
|
||||
void fixSize();
|
||||
void hideButtons();
|
||||
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
||||
signals:
|
||||
void sigQuit();
|
||||
DFloatingMessage *downloadMessage;
|
||||
QWidget *downloadProgressWidget;
|
||||
QHBoxLayout *progressBarLayout;
|
||||
DProgressBar *downloadProgressBar;
|
||||
DPushButton *btnPause;
|
||||
DPushButton *btnResume;
|
||||
DPushButton *btnCancel;
|
||||
|
||||
QMutex mutex; // 通过 Mutex 互斥量禁止同时下载多个文件(使用简单的 bool 变量应该也可以实现该功能?)
|
||||
bool isCanceled; // 判断是否为取消下载
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
26
spark-webapp-runtime/resources/css/webkit-scrollbar.css
Normal file
26
spark-webapp-runtime/resources/css/webkit-scrollbar.css
Normal file
@ -0,0 +1,26 @@
|
||||
::-webkit-scrollbar {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
background-color: transparent
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
border: 2px solid transparent;
|
||||
border-radius: 99px;
|
||||
background-clip: padding-box;
|
||||
background-color: rgba(80, 80, 80, 0.3);
|
||||
-webkit-transition: background 0.2s cubic-bezier(0.34, 0.69, 0.1, 1);
|
||||
transition: background 0.2s cubic-bezier(0.34, 0.69, 0.1, 1)
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-button {
|
||||
display: none
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-corner {
|
||||
display: none
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background-color: rgba(80, 80, 80, 0.6)!important
|
||||
}
|
@ -28,6 +28,8 @@
|
||||
-u, --url <url> 设置要打开的目标 URL。默认为空。
|
||||
-w, --width <width> 设置应用的窗口宽度。默认为 1024。
|
||||
-H, --height <height> 设置应用的窗口高度。默认为 768。
|
||||
-T, --tray 启用托盘图标。默认不启用。
|
||||
--full-screen 以全屏模式运行。默认关闭该功能。
|
||||
--fix-size 固定窗口大小。默认关闭该功能。
|
||||
--hide-buttons 隐藏控制按钮。默认关闭该功能。
|
||||
-i, --ico <ico> 设置应用的图标。
|
||||
@ -35,6 +37,7 @@
|
||||
-c, --cfg <cfg> 设置应用的配置文件。
|
||||
-r, --root <root> 设置内置 WebServer 的根路径。
|
||||
-P, --port <port> 设置内置 WebServer 的监听端口号。
|
||||
-G, --GPU <0/1> 设置启用 GPU 渲染加速,默认开启。
|
||||
</xmp>
|
||||
<br/>
|
||||
<span style="color: red">需要注意的是, 命令行会覆盖配置文件信息。</span>
|
||||
@ -63,6 +66,8 @@
|
||||
-u, --url <url> The target URL. Default is Blank.
|
||||
-w, --width <width> The Width of Application. Default is 1024.
|
||||
-H, --height <height> The Height of Application. Default is 768.
|
||||
-T, --tray Enable Tray Icon. Default is false.
|
||||
--full-screen Run in Fullscreen Mode. Default is false.
|
||||
--fix-size Fix Window Size. Default is false.
|
||||
--hide-buttons Hide Control Buttons. Default is false.
|
||||
-i, --ico <ico> The ICON of Application.
|
||||
@ -70,6 +75,7 @@
|
||||
-c, --cfg <cfg> The Configuration file of Application.
|
||||
-r, --root <root> The root path of the program web service.
|
||||
-P, --port <port> The port number of the program web service.
|
||||
-G, --GPU <0/1> To use GPU instead of CPU to decoding. Default True.
|
||||
</xmp>
|
||||
<br/>
|
||||
<span style="color: red">It should be noticed that the command line parsers will overwrite the configuration from the config file.</span>
|
Before ![]() (image error) Size: 17 KiB After ![]() (image error) Size: 17 KiB ![]() ![]() |
Before (image error) Size: 373 B After (image error) Size: 373 B |
Before (image error) Size: 366 B After (image error) Size: 366 B |
Before (image error) Size: 5.9 KiB After (image error) Size: 5.9 KiB |
Before (image error) Size: 635 B After (image error) Size: 635 B |
@ -1,5 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>css/webkit-scrollbar.css</file>
|
||||
<file>images/spark-webapp-runtime.svg</file>
|
||||
<file>images/Logo-Spark.png</file>
|
||||
<file>images/go-previous-24.svg</file>
|
@ -1,4 +1,4 @@
|
||||
QT += core gui webengine webenginewidgets svg concurrent
|
||||
QT += core gui webenginewidgets concurrent dbus
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 5): QT += widgets
|
||||
|
||||
@ -6,26 +6,50 @@ TEMPLATE = app
|
||||
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
CONFIG += c++11 link_pkgconfig
|
||||
PKGCONFIG += dtkwidget
|
||||
DEFINES += PROJECT_NAME=\\\"'$${TARGET}'\\\"
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
globaldefine.h \
|
||||
httpd.h \
|
||||
httplib.h \
|
||||
webenginepage.h \
|
||||
widget.h
|
||||
# Get build version from qmake
|
||||
VERSION = $$BUILD_VERSION
|
||||
isEmpty(VERSION): VERSION = 1.0
|
||||
DEFINES += APP_VERSION=\\\"'$${VERSION}'\\\"
|
||||
|
||||
CONFIG += c++11 link_pkgconfig
|
||||
PKGCONFIG += dtkcore dtkgui dtkwidget
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
globaldefine.h \
|
||||
httpd.h \
|
||||
httplib.h \
|
||||
widget.h \
|
||||
webengineview.h \
|
||||
webenginepage.h \
|
||||
application.h \
|
||||
webengineurlrequestinterceptor.h
|
||||
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
httpd.cpp \
|
||||
mainwindow.cpp \
|
||||
widget.cpp \
|
||||
webengineview.cpp \
|
||||
webenginepage.cpp \
|
||||
widget.cpp
|
||||
application.cpp \
|
||||
webengineurlrequestinterceptor.cpp
|
||||
|
||||
RESOURCES += \
|
||||
imgs.qrc
|
||||
resources/resources.qrc
|
||||
|
||||
TRANSLATIONS += \
|
||||
translations/spark-webapp-runtime_zh_CN.ts
|
||||
translations/$${TARGET}_zh_CN.ts
|
||||
|
||||
# Default rules for deployment.
|
||||
qnx: target.path = /tmp/$${TARGET}/bin
|
||||
else: unix:!android: target.path = /opt/durapps/$${TARGET}/bin
|
||||
!isEmpty(target.path): INSTALLS += target
|
||||
|
||||
# Rules for deployment
|
||||
qm.files += translations/*.qm
|
||||
qm.path = /opt/durapps/$${TARGET}/share/$${TARGET}/translations
|
||||
|
||||
INSTALLS += qm
|
||||
|
Binary file not shown.
@ -1,73 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="zh_CN">
|
||||
<context>
|
||||
<name>MainWindow</name>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="27"/>
|
||||
<source>Fix Size</source>
|
||||
<translation>固定大小</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="28"/>
|
||||
<source>Hide Buttons</source>
|
||||
<translation>隐藏按钮</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>QObject</name>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="46"/>
|
||||
<location filename="../application.cpp" line="33"/>
|
||||
<location filename="../main.cpp" line="165"/>
|
||||
<source>Presented By Spark developers # HadesStudio</source>
|
||||
<translation>由 星火开发者联盟 @ 花心胡萝卜 提供</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="53"/>
|
||||
<source>This program is open source under GPLv3</source>
|
||||
<translation>本程序按GPL第三版开源</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="39"/>
|
||||
<source>Version:</source>
|
||||
<translation>版本:</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="57"/>
|
||||
<location filename="../main.cpp" line="42"/>
|
||||
<source>Description: %1</source>
|
||||
<translation>描述:%1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="62"/>
|
||||
<location filename="../main.cpp" line="48"/>
|
||||
<source>Enable CommandLineParser. Default is false.</source>
|
||||
<translation>启用参数解析方式。默认顺序解析方式。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="66"/>
|
||||
<location filename="../main.cpp" line="53"/>
|
||||
<source>The Title of Application. Default is %1.</source>
|
||||
<translation>设置程序的运行标题。默认是 %1。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="72"/>
|
||||
<location filename="../main.cpp" line="60"/>
|
||||
<source>The target URL. Default is Blank.</source>
|
||||
<translation>设置要打开的目标 URL。默认是空。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="78"/>
|
||||
<location filename="../main.cpp" line="67"/>
|
||||
<source>The Width of Application. Default is %1.</source>
|
||||
<translation>设置应用的窗口宽度。默认是 %1。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="84"/>
|
||||
<location filename="../main.cpp" line="74"/>
|
||||
<source>The Height of Application. Default is %1.</source>
|
||||
<translation>设置应用的窗口高度。默认是 %1。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="90"/>
|
||||
<location filename="../main.cpp" line="81"/>
|
||||
<source>Enable Tray Icon. Default is false.</source>
|
||||
<translation>启用托盘图标。默认不启用。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="85"/>
|
||||
<source>Run in Fullscreen Mode. Default is false.</source>
|
||||
<translation>以全屏模式运行。默认关闭该功能。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="89"/>
|
||||
<source>Fix Window Size. Default is false.</source>
|
||||
<translation>固定窗口大小。默认关闭该功能。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="94"/>
|
||||
<location filename="../main.cpp" line="93"/>
|
||||
<source>Hide Control Buttons. Default is false.</source>
|
||||
<translation>隐藏控制按钮。默认关闭该此功能。</translation>
|
||||
</message>
|
||||
@ -77,27 +65,32 @@
|
||||
<translation>设置应用的图标。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="104"/>
|
||||
<location filename="../main.cpp" line="105"/>
|
||||
<source>The Description of Application.</source>
|
||||
<translation>设置应用的描述信息。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="110"/>
|
||||
<location filename="../main.cpp" line="112"/>
|
||||
<source>The Configuration file of Application.</source>
|
||||
<translation>设置应用的配置文件。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="116"/>
|
||||
<location filename="../main.cpp" line="119"/>
|
||||
<source>The root path of the program web service.</source>
|
||||
<translation>设置内置 WebServer 的根路径。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="123"/>
|
||||
<location filename="../main.cpp" line="126"/>
|
||||
<source>The port number of the program web service.</source>
|
||||
<translation>设置内置 WebServer 的监听端口号。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="130"/>
|
||||
<location filename="../main.cpp" line="133"/>
|
||||
<source>To use GPU instead of CPU to decoding. Default True.</source>
|
||||
<translation>启用GPU渲染,默认开启。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../main.cpp" line="141"/>
|
||||
<source>The ssl port number of the program web service.</source>
|
||||
<translation>设置内置 WebServer 的 SSL 协议的监听端口号。</translation>
|
||||
</message>
|
||||
@ -106,18 +99,90 @@
|
||||
<source>SparkWebAppRuntime</source>
|
||||
<translation>星火网页应用运行环境</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>WebEnginePage</name>
|
||||
<message>
|
||||
<location filename="../webenginepage.cpp" line="38"/>
|
||||
<source>Start downloading...</source>
|
||||
<translation>开始下载...</translation>
|
||||
<location filename="../mainwindow.cpp" line="45"/>
|
||||
<source>Full Screen</source>
|
||||
<translation>全屏显示</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../webenginepage.cpp" line="48"/>
|
||||
<source>Download finished!</source>
|
||||
<translation>下载完成!</translation>
|
||||
<location filename="../mainwindow.cpp" line="46"/>
|
||||
<source>Fix Size</source>
|
||||
<translation>固定大小</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="47"/>
|
||||
<source>Hide Buttons</source>
|
||||
<translation>隐藏按钮</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="48"/>
|
||||
<source>Clear Cache</source>
|
||||
<translation>清理缓存</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="50"/>
|
||||
<source>Show MainWindow</source>
|
||||
<translation>显示主界面</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="57"/>
|
||||
<source>Pause</source>
|
||||
<translation>暂停</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="58"/>
|
||||
<source>Resume</source>
|
||||
<translation>继续</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="59"/>
|
||||
<source>Cancel</source>
|
||||
<translation>取消</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="374"/>
|
||||
<source>Save As</source>
|
||||
<translation>另存为</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="437"/>
|
||||
<source>%1Start downloading %2</source>
|
||||
<translation>%1开始下载 %2</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="448"/>
|
||||
<source>%1Wait for previous download to complete!</source>
|
||||
<translation>%1请等待上一个下载任务完成!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="470"/>
|
||||
<source>Open</source>
|
||||
<translation>打开</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="474"/>
|
||||
<source>download finished.</source>
|
||||
<translation>下载完成。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="474"/>
|
||||
<source>Show in file manager?</source>
|
||||
<translation>是否在文件管理器中显示?</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="512"/>
|
||||
<source>%1Download canceled!</source>
|
||||
<translation>%1下载取消!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../mainwindow.cpp" line="517"/>
|
||||
<source>%1Load error occurred!</source>
|
||||
<translation>%1加载存在错误!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../webengineview.cpp" line="82"/>
|
||||
<source>View</source>
|
||||
<translation>查看</translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
@ -1,49 +1,80 @@
|
||||
#include "webenginepage.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QWebEngineScript>
|
||||
#include <QWebEngineScriptCollection>
|
||||
#include <QDesktopServices>
|
||||
|
||||
WebEnginePage::WebEnginePage(QObject *parent)
|
||||
: QWebEnginePage(parent)
|
||||
, m_profile(this->profile())
|
||||
, process(new QProcess)
|
||||
{
|
||||
connect(m_profile, &QWebEngineProfile::downloadRequested, this, &WebEnginePage::on_download);
|
||||
initScrollBarStyle();
|
||||
|
||||
connect(this, &QWebEnginePage::featurePermissionRequested, [&](const QUrl &origin, QWebEnginePage::Feature feature) {
|
||||
if (feature != QWebEnginePage::Notifications) {
|
||||
return;
|
||||
}
|
||||
|
||||
setFeaturePermission(origin, feature, QWebEnginePage::PermissionGrantedByUser);
|
||||
});
|
||||
}
|
||||
|
||||
WebEnginePage::~WebEnginePage()
|
||||
{
|
||||
}
|
||||
|
||||
void WebEnginePage::setUrl(const QUrl &url)
|
||||
{
|
||||
if (m_currentUrl == url) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_currentUrl = url;
|
||||
QWebEnginePage::setUrl(url);
|
||||
}
|
||||
|
||||
QWebEnginePage *WebEnginePage::createWindow(QWebEnginePage::WebWindowType type)
|
||||
{
|
||||
Q_UNUSED(type)
|
||||
WebEnginePage *page = new WebEnginePage();
|
||||
connect(page, &QWebEnginePage::urlChanged, this, &WebEnginePage::on_urlChanged);
|
||||
qDebug() << Q_FUNC_INFO << type;
|
||||
|
||||
WebEnginePage *page = new WebEnginePage(parent());
|
||||
connect(page, &WebEnginePage::urlChanged, this, &WebEnginePage::slotUrlChanged);
|
||||
return page;
|
||||
}
|
||||
|
||||
void WebEnginePage::on_urlChanged(const QUrl url)
|
||||
void WebEnginePage::initScrollBarStyle()
|
||||
{
|
||||
setUrl(url);
|
||||
//自定义浏览器滚动条样式
|
||||
QFile file(":/css/webkit-scrollbar.css");
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
QString scrollbarStyleJS = QString("(function() {"
|
||||
" css = document.createElement('style');"
|
||||
" css.type = 'text/css';"
|
||||
" css.id = '%1';"
|
||||
" document.head.appendChild(css);"
|
||||
" css.innerText = '%2';"
|
||||
"})()\n")
|
||||
.arg("scrollbarStyle")
|
||||
.arg(QString::fromUtf8(file.readAll()).simplified());
|
||||
file.close();
|
||||
|
||||
QWebEngineScript script;
|
||||
script.setWorldId(QWebEngineScript::MainWorld);
|
||||
script.setSourceCode(scrollbarStyleJS);
|
||||
scripts().insert(script);
|
||||
runJavaScript(scrollbarStyleJS, QWebEngineScript::ApplicationWorld);
|
||||
}
|
||||
}
|
||||
|
||||
void WebEnginePage::slotUrlChanged(const QUrl &url)
|
||||
{
|
||||
if (m_currentUrl == url) {
|
||||
sender()->deleteLater();
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << Q_FUNC_INFO << m_currentUrl << url;
|
||||
|
||||
QDesktopServices::openUrl(url);
|
||||
sender()->deleteLater();
|
||||
}
|
||||
|
||||
void WebEnginePage::on_download(QWebEngineDownloadItem *item)
|
||||
|
||||
{
|
||||
connect(item, &QWebEngineDownloadItem::downloadProgress, this, &WebEnginePage::on_downloadProgress);
|
||||
connect(item, &QWebEngineDownloadItem::finished, this, &WebEnginePage::on_downloadFinished);
|
||||
|
||||
// 无法指定下载位置,原因未知;默认位置为 ~/Downloads
|
||||
// item->setPath(QDir::homePath() + "/Downloads/");
|
||||
item->accept();
|
||||
|
||||
process->start(QString("notify-send -a spark-webapp-runtime -t 5000 \"%1\"").arg(tr("Start downloading...")));
|
||||
}
|
||||
|
||||
void WebEnginePage::on_downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
|
||||
{
|
||||
qDebug() << "Download Progress:\tbytesReceived: " << bytesReceived << "\tbytesTotal: " << bytesTotal;
|
||||
}
|
||||
|
||||
void WebEnginePage::on_downloadFinished()
|
||||
{
|
||||
process->start(QString("notify-send -a spark-webapp-runtime -t 5000 \"%1\"").arg(tr("Download finished!")));
|
||||
}
|
||||
|
@ -2,29 +2,28 @@
|
||||
#define WEBENGINEPAGE_H
|
||||
|
||||
#include <QWebEnginePage>
|
||||
#include <QWebEngineProfile>
|
||||
#include <QObject>
|
||||
#include <QProcess>
|
||||
|
||||
class WebEnginePage : public QWebEnginePage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
WebEnginePage(QObject *parent = nullptr);
|
||||
explicit WebEnginePage(QObject *parent = nullptr);
|
||||
~WebEnginePage() override;
|
||||
|
||||
void setUrl(const QUrl &url);
|
||||
|
||||
protected:
|
||||
QWebEnginePage *createWindow(WebWindowType type) override;
|
||||
|
||||
private:
|
||||
QWebEngineProfile *m_profile;
|
||||
|
||||
QProcess *process;
|
||||
void initScrollBarStyle();
|
||||
|
||||
private slots:
|
||||
void on_urlChanged(const QUrl url);
|
||||
void on_download(QWebEngineDownloadItem *item);
|
||||
void on_downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
||||
void on_downloadFinished();
|
||||
void slotUrlChanged(const QUrl &url);
|
||||
|
||||
private:
|
||||
QUrl m_currentUrl;
|
||||
};
|
||||
|
||||
#endif // WEBENGINEPAGE_H
|
||||
|
13
spark-webapp-runtime/webengineurlrequestinterceptor.cpp
Normal file
13
spark-webapp-runtime/webengineurlrequestinterceptor.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "webengineurlrequestinterceptor.h"
|
||||
|
||||
#include <QLocale>
|
||||
|
||||
WebEngineUrlRequestInterceptor::WebEngineUrlRequestInterceptor(QObject *parent)
|
||||
: QWebEngineUrlRequestInterceptor(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void WebEngineUrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
|
||||
{
|
||||
info.setHttpHeader("Accept-Language", QLocale::system().name().toUtf8());
|
||||
}
|
15
spark-webapp-runtime/webengineurlrequestinterceptor.h
Normal file
15
spark-webapp-runtime/webengineurlrequestinterceptor.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef WEBENGINEURLREQUESTINTERCEPTOR_H
|
||||
#define WEBENGINEURLREQUESTINTERCEPTOR_H
|
||||
|
||||
#include <QWebEngineUrlRequestInterceptor>
|
||||
|
||||
class WebEngineUrlRequestInterceptor : public QWebEngineUrlRequestInterceptor
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WebEngineUrlRequestInterceptor(QObject *parent = nullptr);
|
||||
void interceptRequest(QWebEngineUrlRequestInfo &info) override;
|
||||
};
|
||||
|
||||
#endif // WEBENGINEURLREQUESTINTERCEPTOR_H
|
99
spark-webapp-runtime/webengineview.cpp
Normal file
99
spark-webapp-runtime/webengineview.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
#include "webengineview.h"
|
||||
//#include "webengineurlrequestinterceptor.h"
|
||||
#include "application.h"
|
||||
|
||||
#include <DGuiApplicationHelper>
|
||||
#include <DNotifySender>
|
||||
|
||||
#include <QWebEngineSettings>
|
||||
#include <QWebEngineProfile>
|
||||
#include <QLocale>
|
||||
#include <QFileInfo>
|
||||
|
||||
DGUI_USE_NAMESPACE
|
||||
DCORE_USE_NAMESPACE
|
||||
|
||||
WebEngineView::WebEngineView(QWidget *parent)
|
||||
: QWebEngineView(parent)
|
||||
// , interceptor(new WebEngineUrlRequestInterceptor(this))
|
||||
{
|
||||
connect(this, &WebEngineView::urlChanged, this, [=]() {
|
||||
// page()->setUrlRequestInterceptor(interceptor);
|
||||
// page()->settings()->setAttribute(QWebEngineSettings::WebAttribute::LocalContentCanAccessRemoteUrls, true);
|
||||
page()->profile()->setHttpAcceptLanguage(QLocale::system().name());
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
|
||||
page()->profile()->setNotificationPresenter([&](std::unique_ptr<QWebEngineNotification> notification) {
|
||||
WebEngineView::present(notification);
|
||||
});
|
||||
#endif
|
||||
});
|
||||
}
|
||||
|
||||
void WebEngineView::handleChromiumFlags()
|
||||
{
|
||||
DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType();
|
||||
|
||||
QString env = qgetenv("QTWEBENGINE_CHROMIUM_FLAGS");
|
||||
QStringList flags = env.split(" ", Qt::SkipEmptyParts);
|
||||
|
||||
/**
|
||||
* --blink-settings=preferredColorScheme=0 强制 prefers-color-scheme=dark (>= 5.14)
|
||||
* --blink-settings=darkModeEnabled=true,darkModeInversionAlgorithm=4 强制反转网页颜色 (>= 5.14 && < 5.15)
|
||||
* --blink-settings=forceDarkModeEnabled=true,darkModeInversionAlgorithm=4 强制反转网页颜色 (>= 5.15)
|
||||
* --force-dark-mode 强制 prefers-color-scheme=dark (>= 5.14)
|
||||
*/
|
||||
foreach (const QString &flag, flags) {
|
||||
if (flag == "--force-dark-mode") {
|
||||
flags.removeAll(flag);
|
||||
}
|
||||
if (flag.startsWith("--blink-settings")) {
|
||||
flags.removeAll(flag);
|
||||
}
|
||||
}
|
||||
|
||||
if (themeType == DGuiApplicationHelper::DarkType) {
|
||||
flags.append("--blink-settings=preferredColorScheme=0");
|
||||
} else {
|
||||
flags.append("--blink-settings=preferredColorScheme=1");
|
||||
}
|
||||
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", flags.join(" ").toUtf8());
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "QTWEBENGINE_CHROMIUM_FLAGS=" + qgetenv("QTWEBENGINE_CHROMIUM_FLAGS");
|
||||
}
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
|
||||
void WebEngineView::present(std::unique_ptr<QWebEngineNotification> &newNotification)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "New notification received:" << newNotification->title() << newNotification->message();
|
||||
|
||||
QImage image = newNotification->icon();
|
||||
QString tmpDir = qobject_cast<Application *>(qApp)->mainWindow()->tmpDir();
|
||||
QString appIcon = tmpDir + "/" + "icon.png";
|
||||
if (QFileInfo::exists(appIcon)) {
|
||||
QFile::remove(appIcon);
|
||||
}
|
||||
image.save(appIcon, "PNG");
|
||||
|
||||
QString summary = newNotification->title();
|
||||
QString appName = qobject_cast<Application *>(qApp)->mainWindow()->title();
|
||||
QString appBody = newNotification->message();
|
||||
quint32 replaceId = 0;
|
||||
int timeOut = 3000;
|
||||
QStringList actions = QStringList() << "view" << QObject::tr("View");
|
||||
|
||||
QString launchCmd = qobject_cast<Application *>(qApp)->launchParams().join(",");
|
||||
qDebug() << launchCmd;
|
||||
QVariantMap hints;
|
||||
hints.insert("x-deepin-action-view", launchCmd);
|
||||
|
||||
DUtil::DNotifySender(summary)
|
||||
.appName(appName)
|
||||
.appIcon(appIcon)
|
||||
.appBody(appBody)
|
||||
.replaceId(replaceId)
|
||||
.timeOut(timeOut)
|
||||
.actions(actions)
|
||||
.hints(hints)
|
||||
.call();
|
||||
}
|
||||
#endif
|
26
spark-webapp-runtime/webengineview.h
Normal file
26
spark-webapp-runtime/webengineview.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef WEBENGINEVIEW_H
|
||||
#define WEBENGINEVIEW_H
|
||||
|
||||
#include <QWebEngineView>
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
|
||||
#include <QWebEngineNotification>
|
||||
#endif
|
||||
|
||||
// class WebEngineUrlRequestInterceptor;
|
||||
class WebEngineView : public QWebEngineView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WebEngineView(QWidget *parent = nullptr);
|
||||
|
||||
static void handleChromiumFlags();
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
|
||||
static void present(std::unique_ptr<QWebEngineNotification> &newNotification);
|
||||
#endif
|
||||
|
||||
private:
|
||||
// WebEngineUrlRequestInterceptor *interceptor = nullptr;
|
||||
};
|
||||
|
||||
#endif // WEBENGINEVIEW_H
|
@ -1,37 +1,34 @@
|
||||
#include "widget.h"
|
||||
#include "webengineview.h"
|
||||
#include "webenginepage.h"
|
||||
|
||||
Widget::Widget(QString szUrl, QWidget *parent)
|
||||
#include <QDir>
|
||||
#include <QWebEngineProfile>
|
||||
#include <DApplication>
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
Widget::Widget(QString szUrl, QWidget *parent, QString szTitle)
|
||||
: QWidget(parent)
|
||||
, m_webEngineView(new QWebEngineView)
|
||||
, m_page(new WebEnginePage)
|
||||
, m_webEngineView(new WebEngineView(this))
|
||||
, m_spinner(new DSpinner(this))
|
||||
, mainLayout(new QStackedLayout(this))
|
||||
, m_szUrl(szUrl)
|
||||
, m_spinner(new DSpinner)
|
||||
, main(new QHBoxLayout)
|
||||
, m_szTitle(szTitle)
|
||||
{
|
||||
m_spinner->setFixedSize(96, 96);
|
||||
|
||||
setLayout(main);
|
||||
|
||||
m_webEngineView->setObjectName(QStringLiteral("webEngineView"));
|
||||
m_webEngineView->setEnabled(true);
|
||||
m_webEngineView->setAutoFillBackground(false);
|
||||
m_webEngineView->setZoomFactor(1);
|
||||
m_webEngineView->setPage(m_page);
|
||||
|
||||
m_webEngineView->setUrl(QUrl(nullptr));
|
||||
if (!m_szUrl.isEmpty())
|
||||
{
|
||||
m_webEngineView->setUrl(QUrl(m_szUrl));
|
||||
}
|
||||
|
||||
connect(m_webEngineView, &QWebEngineView::loadStarted, this, &Widget::on_loadStarted);
|
||||
connect(m_webEngineView, &QWebEngineView::loadFinished, this, &Widget::on_loadFinished);
|
||||
initUI();
|
||||
initConnections();
|
||||
}
|
||||
|
||||
Widget::~Widget()
|
||||
{
|
||||
}
|
||||
|
||||
QWebEnginePage *Widget::getPage()
|
||||
{
|
||||
return this->m_webEngineView->page();
|
||||
}
|
||||
|
||||
void Widget::goBack()
|
||||
{
|
||||
m_webEngineView->back();
|
||||
@ -47,30 +44,108 @@ void Widget::refresh()
|
||||
m_webEngineView->reload();
|
||||
}
|
||||
|
||||
void Widget::clearLayout(QLayout *layout)
|
||||
void Widget::initUI()
|
||||
{
|
||||
QLayoutItem *item;
|
||||
while ((item = layout->takeAt(0)) != nullptr)
|
||||
{
|
||||
delete item;
|
||||
m_spinner->setFixedSize(96, 96);
|
||||
|
||||
DApplication *dApp = qobject_cast<DApplication *>(qApp);
|
||||
m_webEngineView->setZoomFactor(dApp->devicePixelRatio());
|
||||
|
||||
WebEnginePage *page = new WebEnginePage(m_webEngineView);
|
||||
m_webEngineView->setPage(page);
|
||||
|
||||
page->setUrl(QUrl());
|
||||
if (!m_szUrl.isEmpty()) {
|
||||
page->setUrl(QUrl(m_szUrl));
|
||||
// 设置新的 cookie 路径以防止冲突(https://gitee.com/spark-store-project/spark-web-app-runtime/issues/IA759Q)
|
||||
QString cookiePath = QDir::homePath() +
|
||||
"/.config/spark-webapp-runtime/" +
|
||||
QUrl::toPercentEncoding(m_szTitle); // 使用 url 转移以便正确将标题做为文件名
|
||||
QWebEngineProfile *profile = page->profile();
|
||||
if (!QDir(cookiePath).exists()) {
|
||||
QDir().mkpath(cookiePath);
|
||||
}
|
||||
profile->setPersistentStoragePath(cookiePath);
|
||||
}
|
||||
|
||||
QWidget *spinnerWidget = new QWidget(this);
|
||||
QHBoxLayout *spinnerLayout = new QHBoxLayout(spinnerWidget);
|
||||
spinnerLayout->setMargin(0);
|
||||
spinnerLayout->setSpacing(0);
|
||||
spinnerLayout->setAlignment(Qt::AlignCenter);
|
||||
spinnerLayout->addStretch();
|
||||
spinnerLayout->addWidget(m_spinner);
|
||||
spinnerLayout->addStretch();
|
||||
|
||||
mainLayout->addWidget(spinnerWidget);
|
||||
mainLayout->addWidget(m_webEngineView);
|
||||
}
|
||||
|
||||
void Widget::on_loadStarted()
|
||||
void Widget::initConnections()
|
||||
{
|
||||
clearLayout(main);
|
||||
connect(m_webEngineView, &QWebEngineView::loadStarted, this, &Widget::slotLoadStarted, Qt::UniqueConnection);
|
||||
connect(m_webEngineView, &QWebEngineView::loadProgress, this, &Widget::slotLoadProgress, Qt::UniqueConnection);
|
||||
connect(m_webEngineView, &QWebEngineView::loadFinished, this, &Widget::slotLoadFinished, Qt::UniqueConnection);
|
||||
|
||||
main->addStretch();
|
||||
main->addWidget(m_spinner);
|
||||
main->addStretch();
|
||||
// FIXME: DTK 主题切换时,动态修改 QtWebEngine prefers-color-scheme
|
||||
// connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::paletteTypeChanged, this, &Widget::slotPaletteTypeChanged, Qt::UniqueConnection);
|
||||
}
|
||||
|
||||
void Widget::updateLayout()
|
||||
{
|
||||
slotLoadStarted();
|
||||
|
||||
mainLayout->removeWidget(m_webEngineView);
|
||||
QUrl url = m_webEngineView->url();
|
||||
m_webEngineView->deleteLater();
|
||||
|
||||
m_webEngineView = new WebEngineView(this);
|
||||
mainLayout->addWidget(m_webEngineView);
|
||||
initConnections();
|
||||
|
||||
DApplication *dApp = qobject_cast<DApplication *>(qApp);
|
||||
m_webEngineView->setZoomFactor(dApp->devicePixelRatio());
|
||||
|
||||
WebEnginePage *page = new WebEnginePage(m_webEngineView);
|
||||
m_webEngineView->setPage(page);
|
||||
page->setUrl(url);
|
||||
}
|
||||
|
||||
void Widget::slotLoadStarted()
|
||||
{
|
||||
mainLayout->setCurrentIndex(0);
|
||||
m_spinner->start();
|
||||
}
|
||||
|
||||
void Widget::on_loadFinished()
|
||||
void Widget::slotLoadProgress(int value)
|
||||
{
|
||||
if (value == 100) {
|
||||
slotLoadFinished(-1);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::slotLoadFinished(int status)
|
||||
{
|
||||
m_spinner->stop();
|
||||
clearLayout(main);
|
||||
mainLayout->setCurrentIndex(1);
|
||||
|
||||
main->addWidget(m_webEngineView);
|
||||
if (status < 0) {
|
||||
qDebug() << Q_FUNC_INFO << "Load progress: 100%";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!status) {
|
||||
qWarning() << Q_FUNC_INFO << "Load finished, error occurred!";
|
||||
emit sigLoadErrorOccurred();
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::slotPaletteTypeChanged(DGuiApplicationHelper::ColorType paletteType)
|
||||
{
|
||||
Q_UNUSED(paletteType)
|
||||
|
||||
WebEngineView::handleChromiumFlags();
|
||||
if (m_webEngineView) {
|
||||
updateLayout();
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +1,52 @@
|
||||
#ifndef WIDGET_H
|
||||
#define WIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QWebEngineView>
|
||||
#include <QWebEnginePage>
|
||||
#include <QWebEngineProfile>
|
||||
#include <QLayout>
|
||||
|
||||
#include <DSpinner>
|
||||
#include <DGuiApplicationHelper>
|
||||
|
||||
#include "webenginepage.h"
|
||||
#include <QWidget>
|
||||
#include <QWebEnginePage>
|
||||
#include <QStackedLayout>
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
DGUI_USE_NAMESPACE
|
||||
|
||||
class WebEngineView;
|
||||
class Widget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Widget(QString szUrl = nullptr, QWidget *parent = nullptr);
|
||||
explicit Widget(QString szUrl = nullptr, QWidget *parent = nullptr, QString szTitle = nullptr);
|
||||
~Widget();
|
||||
|
||||
QWebEnginePage *getPage();
|
||||
void goBack();
|
||||
void goForward();
|
||||
void refresh();
|
||||
|
||||
private:
|
||||
QWebEngineView *m_webEngineView;
|
||||
WebEnginePage *m_page;
|
||||
QString m_szUrl;
|
||||
DSpinner *m_spinner;
|
||||
void initUI();
|
||||
void initConnections();
|
||||
void updateLayout();
|
||||
|
||||
QHBoxLayout *main;
|
||||
|
||||
void clearLayout(QLayout *layout);
|
||||
signals:
|
||||
void sigLoadErrorOccurred();
|
||||
|
||||
private slots:
|
||||
void on_loadStarted();
|
||||
void on_loadFinished();
|
||||
void slotLoadStarted();
|
||||
void slotLoadProgress(int value);
|
||||
void slotLoadFinished(int status);
|
||||
|
||||
void slotPaletteTypeChanged(DGuiApplicationHelper::ColorType paletteType);
|
||||
|
||||
private:
|
||||
WebEngineView *m_webEngineView = nullptr;
|
||||
DSpinner *m_spinner = nullptr;
|
||||
QStackedLayout *mainLayout = nullptr;
|
||||
|
||||
QString m_szUrl;
|
||||
QString m_szTitle;
|
||||
};
|
||||
|
||||
#endif // WIDGET_H
|
||||
|
6
translate_generation.sh
Executable file
6
translate_generation.sh
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
# this file is used to auto-generate .qm file from .ts file.
|
||||
|
||||
cd $(dirname $0)
|
||||
|
||||
lrelease ./spark-webapp-runtime/spark-webapp-runtime.pro
|
6
translate_update.sh
Executable file
6
translate_update.sh
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
# this file is used to auto-update .ts file.
|
||||
|
||||
cd $(dirname $0)
|
||||
|
||||
lupdate ./spark-webapp-runtime/spark-webapp-runtime.pro -no-obsolete
|
Loading…
x
Reference in New Issue
Block a user