Compare commits
132 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5666a23e00 | ||
|
|
69fae4dd21 | ||
|
|
2986f80f89 | ||
|
|
e423e56152 | ||
|
|
9c00dc8a54 | ||
|
|
558721fa79 | ||
|
|
0c198c23fc | ||
|
|
99aa0fc1f5 | ||
|
|
1aac166c43 | ||
|
|
28a6067033 | ||
|
|
9c3b822311 | ||
|
|
ba44649ce1 | ||
|
|
e7b1773e5c | ||
|
|
3feef3936c | ||
|
|
7837fa4339 | ||
|
|
82a201d3dc | ||
|
|
c479d18714 | ||
|
|
469b9fe8cd | ||
|
|
c47e24ac5b | ||
|
|
1063916474 | ||
|
|
a63e240ce0 | ||
|
|
1a8d572fbd | ||
|
|
21ac323ed1 | ||
|
|
2faea10d61 | ||
|
|
04cf5b65ce | ||
|
|
4d741ac82a | ||
|
|
068089d207 | ||
|
|
5ebb4e6b3e | ||
|
|
19e0b283ae | ||
|
|
7e8600ab6d | ||
|
|
7c0e01d0d5 | ||
|
|
f3c670d82c | ||
|
|
49f9b0b179 | ||
|
|
47861b1e0b | ||
|
|
923667d57c | ||
|
|
e6458a1d7f | ||
|
|
f109aca484 | ||
|
|
a518dca0ca | ||
|
|
be1a162632 | ||
|
|
0e8a8056f8 | ||
|
|
587e0a4640 | ||
|
|
9608c9139c | ||
|
|
913ce312de | ||
|
|
b6ab4b7fde | ||
|
|
7c6649f941 | ||
|
|
7c84957230 | ||
|
|
092c3f522a | ||
|
|
877b93ae3a | ||
|
|
565bc8012a | ||
|
|
96034f9487 | ||
|
|
0522cfef1c | ||
|
|
0ecc321115 | ||
|
|
9c8f9c3b9f | ||
|
|
b2e2d4c603 | ||
|
|
599bd2cfd3 | ||
|
|
6bda94bd7b | ||
|
|
cfd28c3009 | ||
|
|
7e01c4cbb3 | ||
|
|
78b46998d1 | ||
|
|
d43d251d92 | ||
|
|
1c29b76455 | ||
|
|
611518f790 | ||
|
|
62a1122174 | ||
|
|
ca17af30cf | ||
|
|
3998f549e4 | ||
|
|
9541c0c7ab | ||
|
|
475bb8c4b0 | ||
|
|
a0b68862fc | ||
|
|
bfd31e561c | ||
|
|
5b8468effa | ||
|
|
bd04fd3f1a | ||
|
|
398c49bb99 | ||
|
|
c036b78708 | ||
|
|
7f1bd06422 | ||
|
|
06302d7162 | ||
|
|
57ecdddc76 | ||
|
|
04db5a82b9 | ||
|
|
bb1bf9219c | ||
|
|
3ed476275f | ||
|
|
9cbd29d3c1 | ||
|
|
8cbe76d9ff | ||
|
|
1bd673a164 | ||
|
|
4148aac31b | ||
|
|
64196a7ba6 | ||
|
|
cb5aed8e79 | ||
|
|
f60b09abe4 | ||
|
|
d4368f5084 | ||
|
|
330ff9a621 | ||
|
|
0fdc1b784b | ||
|
|
228f228d44 | ||
|
|
b4d42eecf3 | ||
|
|
0533766c1c | ||
|
|
36d7dc7bb2 | ||
|
|
282443a548 | ||
|
|
bfe7140a44 | ||
|
|
7e8e0e2efc | ||
|
|
49f70fe41a | ||
|
|
50762d585c | ||
|
|
6f30976ef7 | ||
|
|
b0c3cd3834 | ||
|
|
d224ad8cf8 | ||
|
|
b824e06736 | ||
|
|
74a933eb6e | ||
|
|
29e3ee0156 | ||
|
|
f9aa3b1728 | ||
|
|
521ff998af | ||
|
|
b0165c3313 | ||
|
|
2a0cc5ca30 | ||
|
|
52b82af52c | ||
|
|
5c59833233 | ||
|
|
9e2d49773f | ||
|
|
fd1b2fc7b0 | ||
|
|
a06ea82f2c | ||
|
|
9b7d33369a | ||
|
|
9663e4174d | ||
|
|
c524db9f59 | ||
|
|
4274e8bed1 | ||
|
|
fa73c4feee | ||
|
|
00cfd0f88d | ||
|
|
f8201f9542 | ||
|
|
f0081e0587 | ||
|
|
e6e08dc407 | ||
|
|
7a5516792c | ||
|
|
241002c3ea | ||
|
|
34e6b99297 | ||
|
|
b800bd91fd | ||
|
|
07fbf78853 | ||
|
|
bb80f093e0 | ||
|
|
fa8ffdc656 | ||
|
|
f07d33a1d6 | ||
|
|
282e61afac | ||
|
|
feb3b10f1f |
2
.gitignore
vendored
@@ -47,3 +47,5 @@ app.*.map.json
|
||||
|
||||
/android/app/fjy.androidstudio.key
|
||||
/release
|
||||
test.dart
|
||||
.fvm
|
||||
24
.metadata
@@ -1,10 +1,30 @@
|
||||
# This file tracks properties of this Flutter project.
|
||||
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||
#
|
||||
# This file should be version controlled and should not be manually edited.
|
||||
# This file should be version controlled.
|
||||
|
||||
version:
|
||||
revision: 4cc385b4b84ac2f816d939a49ea1f328c4e0b48e
|
||||
revision: 9944297138845a94256f1cf37beb88ff9a8e811a
|
||||
channel: stable
|
||||
|
||||
project_type: app
|
||||
|
||||
# Tracks metadata for the flutter migrate command
|
||||
migration:
|
||||
platforms:
|
||||
- platform: root
|
||||
create_revision: 9944297138845a94256f1cf37beb88ff9a8e811a
|
||||
base_revision: 9944297138845a94256f1cf37beb88ff9a8e811a
|
||||
- platform: macos
|
||||
create_revision: 9944297138845a94256f1cf37beb88ff9a8e811a
|
||||
base_revision: 9944297138845a94256f1cf37beb88ff9a8e811a
|
||||
|
||||
# User provided section
|
||||
|
||||
# List of Local paths (relative to this file) that should be
|
||||
# ignored by the migrate tool.
|
||||
#
|
||||
# Files that are not part of the templates will be ignored by default.
|
||||
unmanaged_files:
|
||||
- 'lib/main.dart'
|
||||
- 'ios/Runner.xcodeproj/project.pbxproj'
|
||||
|
||||
12
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"dart.flutterSdkPath": ".fvm",
|
||||
"files.watcherExclude": {
|
||||
"**/.fvm": true
|
||||
},
|
||||
"git.ignoredRepositories": [
|
||||
".fvm"
|
||||
],
|
||||
"search.exclude": {
|
||||
"**/.fvm": true
|
||||
}
|
||||
}
|
||||
674
LICENCE
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://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 <http://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:
|
||||
|
||||
{project} Copyright (C) {year} {fullname}
|
||||
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
|
||||
<http://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>.
|
||||
149
README.md
@@ -1,71 +1,92 @@
|
||||
# Server Monitor & Toolbox
|
||||
<!-- Title-->
|
||||
<p align="center">
|
||||
<h1 align="center">Server Box</h1>
|
||||
</p>
|
||||
|
||||
A new Flutter project which provide a chart view to display server status data and a manager toolbox.
|
||||
<!-- Badges-->
|
||||
<p align="center">
|
||||
<a href="https://apps.apple.com/app/id1586449703">
|
||||
<img style="height: 37px" src="screenshots/appstore.svg">
|
||||
</a>
|
||||
<a href="https://github.com/lollipopkit/flutter_server_box/releases/latest">
|
||||
<img style="height: 37px" src="screenshots/dl-android.svg">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
## ScreenShots
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/server.jpg">
|
||||
</td>
|
||||
<td>
|
||||
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/server_detail.jpg">
|
||||
</td>
|
||||
<td>
|
||||
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/server_edit.jpg">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/convert.jpg">
|
||||
</td>
|
||||
<td>
|
||||
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/ping.jpg">
|
||||
</td>
|
||||
<td>
|
||||
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/setting.jpg">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<img width="200px" src="https://raw.githubusercontent.com/LollipopKit/flutter_server_monitor_toolbox/main/screenshots/drawer.jpg">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p align="center">
|
||||
<a href="https://count.ly/f/badge" rel="nofollow">
|
||||
<img style="height: 37px" src="https://count.ly/badges/light.svg">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
# Support
|
||||
Status|Platform
|
||||
--|--|
|
||||
Full Support|Android/iOS/macOS
|
||||
Support, but not tested|Windows/Linux
|
||||
<p align="center">
|
||||
A Flutter project which provide charts to display server status and tools to manage server.
|
||||
<br>
|
||||
Especially thanks to <a href="https://github.com/TerminalStudio/dartssh2">dartssh2</a> & <a href="https://github.com/TerminalStudio/xterm.dart">xterm.dart</a>.
|
||||
</p>
|
||||
|
||||
## Milestone
|
||||
- [x] SSH connect
|
||||
- [x] Server info store
|
||||
- [x] Status chart view
|
||||
- [x] Base64/Url En/Decode
|
||||
- [x] Server status detail page
|
||||
- [x] Theme switch
|
||||
- [x] Migrate from `ssh2` to `dartssh2`
|
||||
|
||||
## 🔖 Feature
|
||||
- [x] Functions
|
||||
- [x] `SSH` Terminal
|
||||
- [x] `Docker & Pkg` Manager
|
||||
- [x] `SFTP`
|
||||
- [x] `Snippet`
|
||||
- [x] `Ping`
|
||||
- [x] Status charts
|
||||
- [x] etc.
|
||||
- [x] i18n (English, Chinese)
|
||||
- **Welcome contribution** :)
|
||||
- [How to contribute?](#i18n-guide)
|
||||
- [x] Desktop support
|
||||
- [ ] Apt manager
|
||||
- [ ] SFTP
|
||||
- [ ] Snippet market
|
||||
- [ ] Docker manager
|
||||
- [ ] SSH terminal
|
||||
|
||||
## Build
|
||||
Please use `make.dart` to build.
|
||||
```shell
|
||||
# build android apk
|
||||
./make.dart build android
|
||||
# Run in release mode
|
||||
./make.dart run release
|
||||
```
|
||||
## 📱 ScreenShots
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<img width="200px" src="screenshots/server.jpg">
|
||||
</td>
|
||||
<td>
|
||||
<img width="200px" src="screenshots/detail.jpg">
|
||||
</td>
|
||||
<td>
|
||||
<img width="200px" src="screenshots/ssh.jpg">
|
||||
</td>
|
||||
<td>
|
||||
<img width="200px" src="screenshots/apt.png">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<img width="200px" src="screenshots/ping.png">
|
||||
</td>
|
||||
<td>
|
||||
<img width="200px" src="screenshots/sftp.jpg">
|
||||
</td>
|
||||
<td>
|
||||
<img width="200px" src="screenshots/docker.jpg">
|
||||
</td>
|
||||
<td>
|
||||
<img width="200px" src="screenshots/convert.png">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## License
|
||||
`LGPL License. LollipopKit 2021`
|
||||
## 🖥 Platform
|
||||
Status|Platform
|
||||
--- | ---
|
||||
Full Support|Android/iOS
|
||||
Support, but not tested|macOS/Windows/Linux
|
||||
|
||||
## i18n guide
|
||||
1. Fork this repo and clone it to your local machine.
|
||||
2. Create `arb` file in `lib/l10n/` directory
|
||||
- File name should be `intl_XX.arb`, where `XX` is the language code. Such as `intl_en.arb` for English and `intl_zh.arb` for Chinese.
|
||||
3. Add content to the file. You can refer to `intl_en.arb` and `intl_zh.arb` for the format.
|
||||
4. Pull commit to your forked repo.
|
||||
5. Request a pull request on my repo.
|
||||
|
||||
## 📝 License
|
||||
`GPL v3. lollipopkit 2023`
|
||||
|
||||
@@ -22,6 +22,8 @@ linter:
|
||||
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
|
||||
# producing the lint.
|
||||
rules:
|
||||
library_private_types_in_public_api: false
|
||||
use_build_context_synchronously: false
|
||||
# avoid_print: false # Uncomment to disable the `avoid_print` rule
|
||||
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ apply plugin: 'kotlin-android'
|
||||
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
|
||||
|
||||
android {
|
||||
compileSdkVersion 31
|
||||
compileSdkVersion 33
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
@@ -48,7 +48,6 @@ android {
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||
applicationId "tech.lolli.toolbox"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 30
|
||||
@@ -67,12 +66,18 @@ android {
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
// TODO: Add your own signing config for the release build.
|
||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
||||
signingConfig signingConfigs.release
|
||||
minifyEnabled true
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
|
||||
debug {
|
||||
applicationIdSuffix '.debug'
|
||||
}
|
||||
|
||||
profile {
|
||||
applicationIdSuffix '.debug'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BIN
android/app/src/main/res/drawable-night-hdpi/splash.png
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
android/app/src/main/res/drawable-night-mdpi/splash.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
android/app/src/main/res/drawable-night-v21/background.png
Normal file
|
After Width: | Height: | Size: 70 B |
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<bitmap android:gravity="fill" android:src="@drawable/background"/>
|
||||
</item>
|
||||
<item>
|
||||
<bitmap android:gravity="center" android:src="@drawable/splash"/>
|
||||
</item>
|
||||
</layer-list>
|
||||
BIN
android/app/src/main/res/drawable-night-xhdpi/splash.png
Normal file
|
After Width: | Height: | Size: 55 KiB |
BIN
android/app/src/main/res/drawable-night-xxhdpi/splash.png
Normal file
|
After Width: | Height: | Size: 102 KiB |
BIN
android/app/src/main/res/drawable-night-xxxhdpi/splash.png
Normal file
|
After Width: | Height: | Size: 144 KiB |
BIN
android/app/src/main/res/drawable-night/background.png
Normal file
|
After Width: | Height: | Size: 70 B |
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<bitmap android:gravity="fill" android:src="@drawable/background"/>
|
||||
</item>
|
||||
<item>
|
||||
<bitmap android:gravity="center" android:src="@drawable/splash"/>
|
||||
</item>
|
||||
</layer-list>
|
||||
18
android/app/src/main/res/values-night-v31/styles.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
|
||||
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
||||
<item name="android:forceDarkAllowed">false</item>
|
||||
<item name="android:windowFullscreen">false</item>
|
||||
<item name="android:windowSplashScreenBackground">#121212</item>
|
||||
</style>
|
||||
<!-- Theme applied to the Android Window as soon as the process has started.
|
||||
This theme determines the color of the Android Window while your
|
||||
Flutter UI initializes, as well as behind your Flutter UI while its
|
||||
running.
|
||||
|
||||
This Theme is only used starting with V2 of Flutter's Android embedding. -->
|
||||
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
||||
<item name="android:windowBackground">?android:colorBackground</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -5,7 +5,8 @@
|
||||
<!-- Show a splash screen on the activity. Automatically removed when
|
||||
Flutter draws its first frame -->
|
||||
<item name="android:windowBackground">@drawable/launch_background</item>
|
||||
<item name="android:windowFullscreen">true</item>
|
||||
<item name="android:forceDarkAllowed">false</item>
|
||||
<item name="android:windowFullscreen">false</item>
|
||||
</style>
|
||||
<!-- Theme applied to the Android Window as soon as the process has started.
|
||||
This theme determines the color of the Android Window while your
|
||||
|
||||
18
android/app/src/main/res/values-v31/styles.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
|
||||
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
|
||||
<item name="android:forceDarkAllowed">false</item>
|
||||
<item name="android:windowFullscreen">false</item>
|
||||
<item name="android:windowSplashScreenBackground">#ffffff</item>
|
||||
</style>
|
||||
<!-- Theme applied to the Android Window as soon as the process has started.
|
||||
This theme determines the color of the Android Window while your
|
||||
Flutter UI initializes, as well as behind your Flutter UI while its
|
||||
running.
|
||||
|
||||
This Theme is only used starting with V2 of Flutter's Android embedding. -->
|
||||
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
|
||||
<item name="android:windowBackground">?android:colorBackground</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -5,7 +5,8 @@
|
||||
<!-- Show a splash screen on the activity. Automatically removed when
|
||||
Flutter draws its first frame -->
|
||||
<item name="android:windowBackground">@drawable/launch_background</item>
|
||||
<item name="android:windowFullscreen">true</item>
|
||||
<item name="android:forceDarkAllowed">false</item>
|
||||
<item name="android:windowFullscreen">false</item>
|
||||
</style>
|
||||
<!-- Theme applied to the Android Window as soon as the process has started.
|
||||
This theme determines the color of the Android Window while your
|
||||
|
||||
1
apk.sksl.json
Normal file
BIN
assets/linux/armbian.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
assets/linux/rocky.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
assets/linux/wrt.png
Normal file
|
After Width: | Height: | Size: 80 KiB |
@@ -21,6 +21,6 @@
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>MinimumOSVersion</key>
|
||||
<string>9.0</string>
|
||||
<string>11.0</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Uncomment this line to define a global platform for your project
|
||||
# platform :ios, '9.0'
|
||||
# platform :ios, '11.0'
|
||||
|
||||
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
|
||||
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
|
||||
@@ -27,6 +27,10 @@ require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelpe
|
||||
|
||||
flutter_ios_podfile_setup
|
||||
|
||||
# Used for flutter lib "file_picker"
|
||||
Pod::PICKER_MEDIA = false
|
||||
Pod::PICKER_AUDIO = false
|
||||
|
||||
target 'Runner' do
|
||||
use_frameworks!
|
||||
use_modular_headers!
|
||||
|
||||
@@ -1,46 +1,59 @@
|
||||
PODS:
|
||||
- countly_flutter (20.11.4):
|
||||
- countly_flutter (22.09.0):
|
||||
- Flutter
|
||||
- file_picker (0.0.1):
|
||||
- Flutter
|
||||
- Flutter (1.0.0)
|
||||
- flutter_icmp_ping (0.0.1):
|
||||
- flutter_native_splash (0.0.1):
|
||||
- Flutter
|
||||
- path_provider_ios (0.0.1):
|
||||
- path_provider_foundation (0.0.1):
|
||||
- Flutter
|
||||
- FlutterMacOS
|
||||
- r_upgrade (0.0.1):
|
||||
- Flutter
|
||||
- share_plus (0.0.1):
|
||||
- Flutter
|
||||
- url_launcher_ios (0.0.1):
|
||||
- Flutter
|
||||
|
||||
DEPENDENCIES:
|
||||
- countly_flutter (from `.symlinks/plugins/countly_flutter/ios`)
|
||||
- file_picker (from `.symlinks/plugins/file_picker/ios`)
|
||||
- Flutter (from `Flutter`)
|
||||
- flutter_icmp_ping (from `.symlinks/plugins/flutter_icmp_ping/ios`)
|
||||
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
|
||||
- flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`)
|
||||
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/ios`)
|
||||
- r_upgrade (from `.symlinks/plugins/r_upgrade/ios`)
|
||||
- share_plus (from `.symlinks/plugins/share_plus/ios`)
|
||||
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
countly_flutter:
|
||||
:path: ".symlinks/plugins/countly_flutter/ios"
|
||||
file_picker:
|
||||
:path: ".symlinks/plugins/file_picker/ios"
|
||||
Flutter:
|
||||
:path: Flutter
|
||||
flutter_icmp_ping:
|
||||
:path: ".symlinks/plugins/flutter_icmp_ping/ios"
|
||||
path_provider_ios:
|
||||
:path: ".symlinks/plugins/path_provider_ios/ios"
|
||||
flutter_native_splash:
|
||||
:path: ".symlinks/plugins/flutter_native_splash/ios"
|
||||
path_provider_foundation:
|
||||
:path: ".symlinks/plugins/path_provider_foundation/ios"
|
||||
r_upgrade:
|
||||
:path: ".symlinks/plugins/r_upgrade/ios"
|
||||
share_plus:
|
||||
:path: ".symlinks/plugins/share_plus/ios"
|
||||
url_launcher_ios:
|
||||
:path: ".symlinks/plugins/url_launcher_ios/ios"
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
countly_flutter: 38419412e193a1faa5babeb5d28a63fda260687d
|
||||
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
|
||||
flutter_icmp_ping: 07e508847df7fa9262d050bb0b203de074bbe517
|
||||
path_provider_ios: 7d7ce634493af4477d156294792024ec3485acd5
|
||||
countly_flutter: 135f1a4930f8e26ba223a14201d3f265ea7b4c83
|
||||
file_picker: 1d63c4949e05e386da864365f8c13e1e64787675
|
||||
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
|
||||
flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef
|
||||
path_provider_foundation: c68054786f1b4f3343858c1e1d0caaded73f0be9
|
||||
r_upgrade: 44d715c61914cce3d01ea225abffe894fd51c114
|
||||
url_launcher_ios: 02f1989d4e14e998335b02b67a7590fa34f971af
|
||||
share_plus: 056a1e8ac890df3e33cb503afffaf1e9b4fbae68
|
||||
url_launcher_ios: 08a3dfac5fb39e8759aeb0abbd5d9480f30fc8b4
|
||||
|
||||
PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
|
||||
PODFILE CHECKSUM: 7fb15c416f8685fca4966867a8da218ec592ec2e
|
||||
|
||||
COCOAPODS: 1.11.2
|
||||
COCOAPODS: 1.11.3
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 51;
|
||||
objectVersion = 54;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
@@ -199,6 +199,7 @@
|
||||
/* Begin PBXShellScriptBuildPhase section */
|
||||
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
alwaysOutOfDate = 1;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
@@ -213,6 +214,7 @@
|
||||
};
|
||||
9740EEB61CF901F6004384FC /* Run Script */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
alwaysOutOfDate = 1;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
@@ -339,7 +341,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = iphoneos;
|
||||
SUPPORTED_PLATFORMS = iphoneos;
|
||||
@@ -354,7 +356,7 @@
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CURRENT_PROJECT_VERSION = 88;
|
||||
CURRENT_PROJECT_VERSION = 227;
|
||||
DEVELOPMENT_TEAM = BA88US33G6;
|
||||
ENABLE_BITCODE = NO;
|
||||
INFOPLIST_FILE = Runner/Info.plist;
|
||||
@@ -362,7 +364,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0.88;
|
||||
MARKETING_VERSION = 1.0.227;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
@@ -418,7 +420,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = iphoneos;
|
||||
@@ -467,7 +469,7 @@
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = iphoneos;
|
||||
SUPPORTED_PLATFORMS = iphoneos;
|
||||
@@ -484,7 +486,7 @@
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CURRENT_PROJECT_VERSION = 88;
|
||||
CURRENT_PROJECT_VERSION = 227;
|
||||
DEVELOPMENT_TEAM = BA88US33G6;
|
||||
ENABLE_BITCODE = NO;
|
||||
INFOPLIST_FILE = Runner/Info.plist;
|
||||
@@ -492,7 +494,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0.88;
|
||||
MARKETING_VERSION = 1.0.227;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
@@ -508,7 +510,7 @@
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CURRENT_PROJECT_VERSION = 88;
|
||||
CURRENT_PROJECT_VERSION = 227;
|
||||
DEVELOPMENT_TEAM = BA88US33G6;
|
||||
ENABLE_BITCODE = NO;
|
||||
INFOPLIST_FILE = Runner/Info.plist;
|
||||
@@ -516,7 +518,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0.88;
|
||||
MARKETING_VERSION = 1.0.227;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
|
||||
@@ -5,11 +5,42 @@
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"filename" : "darkbackground.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
|
||||
BIN
ios/Runner/Assets.xcassets/LaunchBackground.imageset/darkbackground.png
vendored
Normal file
|
After Width: | Height: | Size: 70 B |
@@ -1,45 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>ServerBox</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>UIStatusBarHidden</key>
|
||||
<false/>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>ServerBox</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>UIStatusBarHidden</key>
|
||||
<false/>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
<key>CFBundleLocalizations</key>
|
||||
<array>
|
||||
<string>en</string>
|
||||
<string>zh</string>
|
||||
</array>
|
||||
<key>CADisableMinimumFrameDurationOnPhone</key>
|
||||
<true/>
|
||||
<key>UIApplicationSupportsIndirectInputEvents</key>
|
||||
<true/>
|
||||
<key>UIBackgroundModes</key>
|
||||
<array>
|
||||
<string>fetch</string>
|
||||
</array>
|
||||
<key>LSSupportsOpeningDocumentsInPlace</key>
|
||||
<true/>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
1
ipa.sksl.json
Normal file
4
l10n.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
arb-dir: lib/l10n
|
||||
template-arb-file: app_en.arb
|
||||
output-localization-file: l10n.dart
|
||||
output-class: S
|
||||
150
lib/app.dart
@@ -1,78 +1,92 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/data/res/build_data.dart';
|
||||
import 'package:toolbox/data/store/setting.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
import 'package:toolbox/view/page/home.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import '/core/extension/colorx.dart';
|
||||
import 'core/utils/ui.dart';
|
||||
import 'data/res/build_data.dart';
|
||||
import 'data/res/color.dart';
|
||||
import 'data/store/setting.dart';
|
||||
import 'locator.dart';
|
||||
import 'view/page/home.dart';
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
MyApp({Key? key}) : super(key: key);
|
||||
|
||||
MaterialStateProperty<Color?> getMaterialStateColor(Color primaryColor) {
|
||||
return MaterialStateProperty.resolveWith((states) {
|
||||
const Set<MaterialState> interactiveStates = <MaterialState>{
|
||||
MaterialState.pressed,
|
||||
MaterialState.hovered,
|
||||
MaterialState.focused,
|
||||
MaterialState.selected
|
||||
};
|
||||
if (states.any(interactiveStates.contains)) {
|
||||
return primaryColor;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
final _setting = locator<SettingStore>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
setTransparentNavigationBar(context);
|
||||
return ValueListenableBuilder<int>(
|
||||
valueListenable: locator<SettingStore>().primaryColor.listenable(),
|
||||
builder: (_, value, __) {
|
||||
final primaryColor = Color(value);
|
||||
final textStyle = TextStyle(color: primaryColor);
|
||||
return MaterialApp(
|
||||
title: BuildData.name,
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(
|
||||
primaryColor: primaryColor,
|
||||
appBarTheme: AppBarTheme(backgroundColor: primaryColor),
|
||||
floatingActionButtonTheme:
|
||||
FloatingActionButtonThemeData(backgroundColor: primaryColor),
|
||||
iconTheme: IconThemeData(color: primaryColor),
|
||||
primaryIconTheme: IconThemeData(color: primaryColor),
|
||||
switchTheme: SwitchThemeData(
|
||||
thumbColor: getMaterialStateColor(primaryColor),
|
||||
trackColor:
|
||||
getMaterialStateColor(primaryColor.withOpacity(0.7)),
|
||||
),
|
||||
buttonTheme: ButtonThemeData(splashColor: primaryColor),
|
||||
inputDecorationTheme: InputDecorationTheme(
|
||||
labelStyle: textStyle,
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor))),
|
||||
radioTheme: RadioThemeData(
|
||||
fillColor: getMaterialStateColor(primaryColor),
|
||||
),
|
||||
),
|
||||
darkTheme: ThemeData.dark().copyWith(
|
||||
primaryColor: primaryColor,
|
||||
floatingActionButtonTheme: FloatingActionButtonThemeData(
|
||||
backgroundColor: primaryColor),
|
||||
iconTheme: IconThemeData(color: primaryColor),
|
||||
primaryIconTheme: IconThemeData(color: primaryColor),
|
||||
switchTheme: SwitchThemeData(
|
||||
thumbColor: getMaterialStateColor(primaryColor),
|
||||
trackColor:
|
||||
getMaterialStateColor(primaryColor.withOpacity(0.7)),
|
||||
),
|
||||
buttonTheme: ButtonThemeData(splashColor: primaryColor),
|
||||
inputDecorationTheme: InputDecorationTheme(
|
||||
labelStyle: textStyle,
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor))),
|
||||
radioTheme: RadioThemeData(
|
||||
fillColor: getMaterialStateColor(primaryColor))),
|
||||
home: MyHomePage(primaryColor: primaryColor),
|
||||
);
|
||||
});
|
||||
valueListenable: _setting.primaryColor.listenable(),
|
||||
builder: (_, colorValue, __) {
|
||||
primaryColor = Color(colorValue);
|
||||
return ValueListenableBuilder<int>(
|
||||
valueListenable: _setting.nightMode.listenable(),
|
||||
builder: (_, mode, __) => _buildApp(mode),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildApp(int nightMode) {
|
||||
final textStyle = TextStyle(color: primaryColor);
|
||||
final materialColor = primaryColor.materialStateColor;
|
||||
final materialColorAlpha = primaryColor.withOpacity(0.7).materialStateColor;
|
||||
final fabTheme =
|
||||
FloatingActionButtonThemeData(backgroundColor: primaryColor);
|
||||
final switchTheme = SwitchThemeData(
|
||||
thumbColor: materialColor,
|
||||
trackColor: materialColorAlpha,
|
||||
);
|
||||
final appBarTheme = AppBarTheme(backgroundColor: primaryColor);
|
||||
final iconTheme = IconThemeData(color: primaryColor);
|
||||
final inputDecorationTheme = InputDecorationTheme(
|
||||
labelStyle: textStyle,
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor),
|
||||
),
|
||||
);
|
||||
final radioTheme = RadioThemeData(
|
||||
fillColor: materialColor,
|
||||
);
|
||||
final ok = nightMode >= 0 && nightMode <= ThemeMode.values.length - 1;
|
||||
final themeMode = ok ? ThemeMode.values[nightMode] : ThemeMode.system;
|
||||
|
||||
return MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
localizationsDelegates: S.localizationsDelegates,
|
||||
supportedLocales: S.supportedLocales,
|
||||
title: BuildData.name,
|
||||
themeMode: themeMode,
|
||||
theme: ThemeData(
|
||||
useMaterial3: false,
|
||||
primaryColor: primaryColor,
|
||||
primarySwatch: primaryColor.materialColor,
|
||||
appBarTheme: appBarTheme,
|
||||
floatingActionButtonTheme: fabTheme,
|
||||
iconTheme: iconTheme,
|
||||
primaryIconTheme: iconTheme,
|
||||
switchTheme: switchTheme,
|
||||
inputDecorationTheme: inputDecorationTheme,
|
||||
radioTheme: radioTheme,
|
||||
),
|
||||
darkTheme: ThemeData.dark().copyWith(
|
||||
useMaterial3: false,
|
||||
floatingActionButtonTheme: fabTheme,
|
||||
iconTheme: iconTheme,
|
||||
primaryIconTheme: iconTheme,
|
||||
switchTheme: switchTheme,
|
||||
inputDecorationTheme: inputDecorationTheme,
|
||||
radioTheme: radioTheme,
|
||||
colorScheme: ColorScheme.fromSwatch(
|
||||
primarySwatch: primaryColor.materialColor,
|
||||
brightness: Brightness.dark,
|
||||
accentColor: primaryColor,
|
||||
),
|
||||
),
|
||||
themeAnimationDuration: const Duration(milliseconds: 237),
|
||||
home: const MyHomePage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:countly_flutter/countly_config.dart';
|
||||
import 'package:countly_flutter/countly_flutter.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:toolbox/core/build_mode.dart';
|
||||
|
||||
class Analysis {
|
||||
static const _url = 'https://countly.xuty.cc';
|
||||
@@ -8,13 +12,22 @@ class Analysis {
|
||||
|
||||
static bool _enabled = false;
|
||||
|
||||
static Future<void> init(bool debug) async {
|
||||
_enabled = true;
|
||||
await Countly.setLoggingEnabled(debug);
|
||||
await Countly.init(_url, _key);
|
||||
await Countly.start();
|
||||
await Countly.enableCrashReporting();
|
||||
await Countly.giveAllConsent();
|
||||
static Future<void> init() async {
|
||||
if (!BuildMode.isRelease) {
|
||||
return;
|
||||
}
|
||||
if (Platform.isAndroid || Platform.isIOS) {
|
||||
_enabled = true;
|
||||
final config = CountlyConfig(_url, _key)
|
||||
.setLoggingEnabled(false)
|
||||
.enableCrashReporting();
|
||||
await Countly.initWithConfig(config);
|
||||
await Countly.start();
|
||||
await Countly.giveAllConsent();
|
||||
} else {
|
||||
Logger('COUNTLY')
|
||||
.info('Unsupported platform ${Platform.operatingSystem}');
|
||||
}
|
||||
}
|
||||
|
||||
static void recordView(String view) {
|
||||
|
||||
@@ -6,7 +6,7 @@ enum _BuildMode {
|
||||
profile,
|
||||
}
|
||||
|
||||
_BuildMode _buildMode = (() {
|
||||
final _buildMode = (() {
|
||||
if (const bool.fromEnvironment('dart.vm.product')) {
|
||||
return _BuildMode.release;
|
||||
}
|
||||
|
||||
40
lib/core/extension/colorx.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
const Set<MaterialState> interactiveStates = <MaterialState>{
|
||||
MaterialState.pressed,
|
||||
MaterialState.hovered,
|
||||
MaterialState.focused,
|
||||
MaterialState.selected
|
||||
};
|
||||
|
||||
extension ColorX on Color {
|
||||
bool get isBrightColor {
|
||||
return getBrightnessFromColor == Brightness.light;
|
||||
}
|
||||
|
||||
Brightness get getBrightnessFromColor {
|
||||
return ThemeData.estimateBrightnessForColor(this);
|
||||
}
|
||||
|
||||
MaterialStateProperty<Color?> get materialStateColor {
|
||||
return MaterialStateProperty.resolveWith((states) {
|
||||
if (states.any(interactiveStates.contains)) {
|
||||
return this;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
MaterialColor get materialColor => MaterialColor(value, {
|
||||
50: withOpacity(0.05),
|
||||
100: withOpacity(0.1),
|
||||
200: withOpacity(0.2),
|
||||
300: withOpacity(0.3),
|
||||
400: withOpacity(0.4),
|
||||
500: withOpacity(0.5),
|
||||
600: withOpacity(0.6),
|
||||
700: withOpacity(0.7),
|
||||
800: withOpacity(0.8),
|
||||
900: withOpacity(0.9),
|
||||
});
|
||||
}
|
||||
15
lib/core/extension/numx.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
extension NumX on num {
|
||||
String get convertBytes {
|
||||
const suffix = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
double value = toDouble();
|
||||
int squareTimes = 0;
|
||||
for (; value / 1024 > 1 && squareTimes < suffix.length - 1; squareTimes++) {
|
||||
value /= 1024;
|
||||
}
|
||||
var finalValue = value.toStringAsFixed(1);
|
||||
if (finalValue.endsWith('.0')) {
|
||||
finalValue = finalValue.replaceFirst('.0', '');
|
||||
}
|
||||
return '$finalValue ${suffix[squareTimes]}';
|
||||
}
|
||||
}
|
||||
49
lib/core/extension/ssh_client.dart
Normal file
@@ -0,0 +1,49 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:toolbox/core/extension/uint8list.dart';
|
||||
|
||||
typedef OnStd = void Function(String data, StreamSink<Uint8List> sink);
|
||||
typedef OnStdin = void Function(StreamSink<Uint8List> sink);
|
||||
|
||||
typedef PwdRequestFunc = Future<String> Function();
|
||||
final pwdRequestWithUserReg = RegExp(r'\[sudo\] password for (.+):');
|
||||
|
||||
extension SSHClientX on SSHClient {
|
||||
Future<int?> exec(String cmd,
|
||||
{OnStd? onStderr, OnStd? onStdout, OnStdin? stdin}) async {
|
||||
final session = await execute(cmd);
|
||||
|
||||
final stdoutDone = Completer<void>();
|
||||
final stderrDone = Completer<void>();
|
||||
|
||||
if (onStdout != null) {
|
||||
session.stdout.listen(
|
||||
(e) => onStdout(e.string, session.stdin),
|
||||
onDone: stdoutDone.complete,
|
||||
);
|
||||
} else {
|
||||
stdoutDone.complete();
|
||||
}
|
||||
|
||||
if (onStderr != null) {
|
||||
session.stderr.listen(
|
||||
(e) => onStderr(e.string, session.stdin),
|
||||
onDone: stderrDone.complete,
|
||||
);
|
||||
} else {
|
||||
stderrDone.complete();
|
||||
}
|
||||
|
||||
if (stdin != null) {
|
||||
stdin(session.stdin);
|
||||
}
|
||||
|
||||
await stdoutDone.future;
|
||||
await stderrDone.future;
|
||||
|
||||
session.close();
|
||||
return session.exitCode;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,52 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
extension StringX on String {
|
||||
int get i => int.parse(this);
|
||||
|
||||
Uri get uri {
|
||||
return Uri.parse(this);
|
||||
}
|
||||
|
||||
Widget omitStartStr(
|
||||
{TextStyle? style, TextOverflow? overflow, int? maxLines}) {
|
||||
return LayoutBuilder(builder: (context, size) {
|
||||
bool exceeded = false;
|
||||
int len = 0;
|
||||
for (; !exceeded && len < length; len++) {
|
||||
// Build the textspan
|
||||
var span = TextSpan(
|
||||
text: 'A' * 7 + substring(length - len),
|
||||
style: style ?? Theme.of(context).textTheme.bodyMedium,
|
||||
);
|
||||
|
||||
// Use a textpainter to determine if it will exceed max lines
|
||||
var tp = TextPainter(
|
||||
maxLines: maxLines ?? 1,
|
||||
textDirection: TextDirection.ltr,
|
||||
text: span,
|
||||
);
|
||||
|
||||
// trigger it to layout
|
||||
tp.layout(maxWidth: size.maxWidth);
|
||||
|
||||
// whether the text overflowed or not
|
||||
exceeded = tp.didExceedMaxLines;
|
||||
}
|
||||
|
||||
return Text(
|
||||
(exceeded ? '...' : '') + substring(length - len),
|
||||
overflow: overflow ?? TextOverflow.fade,
|
||||
softWrap: false,
|
||||
maxLines: maxLines ?? 1,
|
||||
style: style,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
String get withLangExport => 'export LANG=en_US.UTF-8 && $this';
|
||||
|
||||
Uint8List get uint8List => Uint8List.fromList(utf8.encode(this));
|
||||
}
|
||||
|
||||
10
lib/core/extension/uint8list.dart
Normal file
@@ -0,0 +1,10 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
extension FutureUint8ListX on Future<Uint8List> {
|
||||
Future<String> get string async => utf8.decode(await this);
|
||||
}
|
||||
|
||||
extension Uint8ListX on Uint8List {
|
||||
String get string => utf8.decode(this);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
|
||||
class PersistentStore<E> {
|
||||
late Box<E> box;
|
||||
|
||||
@@ -9,11 +9,6 @@ class ProviderBase with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
enum ProviderState {
|
||||
idle,
|
||||
busy,
|
||||
}
|
||||
|
||||
class BusyProvider extends ProviderBase {
|
||||
bool _isBusy = false;
|
||||
bool get isBusy => _isBusy;
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
// ignore_for_file: avoid_print
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:r_upgrade/r_upgrade.dart';
|
||||
import 'package:toolbox/core/utils.dart';
|
||||
import 'package:toolbox/data/provider/app.dart';
|
||||
import 'package:toolbox/data/res/build_data.dart';
|
||||
import 'package:toolbox/data/service/app.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
|
||||
import '../data/model/app/update.dart';
|
||||
import '../data/provider/app.dart';
|
||||
import '../data/res/build_data.dart';
|
||||
import '../data/service/app.dart';
|
||||
import '../locator.dart';
|
||||
import 'utils/ui.dart';
|
||||
|
||||
final _logger = Logger('UPDATE');
|
||||
|
||||
Future<bool> isFileAvailable(String url) async {
|
||||
try {
|
||||
final resp = await Dio().head(url);
|
||||
return resp.statusCode == 200;
|
||||
} catch (e) {
|
||||
print('update file not available: $e');
|
||||
_logger.warning('update file not available: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -26,30 +30,69 @@ Future<void> doUpdate(BuildContext context, {bool force = false}) async {
|
||||
|
||||
locator<AppProvider>().setNewestBuild(update.newest);
|
||||
|
||||
if (!force && update.newest <= BuildData.build) {
|
||||
print('Update ignored due to current: ${BuildData.build}, '
|
||||
'update: ${update.newest}');
|
||||
final newest = () {
|
||||
if (Platform.isAndroid) {
|
||||
return update.androidbuild;
|
||||
} else if (Platform.isIOS) {
|
||||
return update.iosbuild;
|
||||
} else if (Platform.isMacOS) {
|
||||
return update.macbuild;
|
||||
}
|
||||
return update.newest;
|
||||
}();
|
||||
|
||||
if (!force && newest <= BuildData.build) {
|
||||
_logger.info('Update ignored due to current: ${BuildData.build}, '
|
||||
'update: $newest');
|
||||
return;
|
||||
}
|
||||
print('Update available: ${update.newest}');
|
||||
_logger.info('Update available: $newest');
|
||||
|
||||
if (Platform.isAndroid && !await isFileAvailable(update.android)) {
|
||||
_logger.warning('Android update file not available');
|
||||
return;
|
||||
}
|
||||
|
||||
final s = S.of(context)!;
|
||||
|
||||
if (update.min > BuildData.build) {
|
||||
showRoundDialog(
|
||||
context,
|
||||
s.attention,
|
||||
Text(s.updateTipTooLow(newest)),
|
||||
[
|
||||
TextButton(
|
||||
onPressed: () => _doUpdate(update, context, s),
|
||||
child: Text(s.ok),
|
||||
)
|
||||
],
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
showSnackBarWithAction(
|
||||
context,
|
||||
update.min > BuildData.build
|
||||
? 'Your version is too old. \nPlease update to v1.0.${update.newest}.'
|
||||
: 'Update: v1.0.${update.newest} available. \n${update.changelog}',
|
||||
'Update', () async {
|
||||
if (Platform.isAndroid) {
|
||||
await RUpgrade.upgrade(update.android,
|
||||
fileName: update.android.split('/').last, isAutoRequestInstall: true);
|
||||
} else if (Platform.isIOS) {
|
||||
await RUpgrade.upgradeFromAppStore('1586449703');
|
||||
} else if (Platform.isMacOS) {
|
||||
await RUpgrade.upgradeFromUrl(update.mac);
|
||||
}
|
||||
});
|
||||
context,
|
||||
'${s.updateTip(newest)} \n${update.changelog}',
|
||||
s.update,
|
||||
() => _doUpdate(update, context, s),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _doUpdate(AppUpdate update, BuildContext context, S s) async {
|
||||
if (Platform.isAndroid) {
|
||||
await RUpgrade.upgrade(
|
||||
update.android,
|
||||
fileName: update.android.split('/').last,
|
||||
isAutoRequestInstall: true,
|
||||
);
|
||||
} else if (Platform.isIOS) {
|
||||
await RUpgrade.upgradeFromAppStore('1586449703');
|
||||
} else {
|
||||
showRoundDialog(context, s.attention, Text(s.platformNotSupportUpdate), [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: Text(s.ok),
|
||||
)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
33
lib/core/utils/misc.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
Future<bool> shareFiles(BuildContext context, List<String> filePaths) async {
|
||||
for (final filePath in filePaths) {
|
||||
if (!await File(filePath).exists()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
var text = '';
|
||||
if (filePaths.length == 1) {
|
||||
text = filePaths.first.split('/').last;
|
||||
} else {
|
||||
text = '${filePaths.length} ${S.of(context)!.files}';
|
||||
}
|
||||
final xfiles = filePaths.map((e) => XFile(e)).toList();
|
||||
await Share.shareXFiles(xfiles, text: 'ServerBox -> $text');
|
||||
return filePaths.isNotEmpty;
|
||||
}
|
||||
|
||||
void copy(String text) {
|
||||
Clipboard.setData(ClipboardData(text: text));
|
||||
}
|
||||
|
||||
Future<String?> pickOneFile() async {
|
||||
final result = await FilePicker.platform.pickFiles(type: FileType.any);
|
||||
return result?.files.single.path;
|
||||
}
|
||||
46
lib/core/utils/server.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../data/model/server/server_private_info.dart';
|
||||
import '../../data/store/private_key.dart';
|
||||
import '../../locator.dart';
|
||||
|
||||
/// Must put this func out of any Class.
|
||||
///
|
||||
/// Because of this function is called by [compute] in [ServerProvider.genClient].
|
||||
///
|
||||
/// https://stackoverflow.com/questions/51998995/invalid-arguments-illegal-argument-in-isolate-message-object-is-a-closure
|
||||
List<SSHKeyPair> loadIndentity(String key) {
|
||||
return SSHKeyPair.fromPem(key);
|
||||
}
|
||||
|
||||
/// [args] : [key, pwd]
|
||||
String decyptPem(List<String> args) {
|
||||
/// skip when the key is not encrypted, or will throw exception
|
||||
if (!SSHKeyPair.isEncryptedPem(args[0])) return args[0];
|
||||
final sshKey = SSHKeyPair.fromPem(args[0], args[1]);
|
||||
return sshKey.first.toPem();
|
||||
}
|
||||
|
||||
Future<SSHClient> genClient(ServerPrivateInfo spi) async {
|
||||
final socket = await SSHSocket.connect(
|
||||
spi.ip,
|
||||
spi.port,
|
||||
timeout: const Duration(seconds: 5),
|
||||
);
|
||||
if (spi.pubKeyId == null) {
|
||||
return SSHClient(
|
||||
socket,
|
||||
username: spi.user,
|
||||
onPasswordRequest: () => spi.pwd,
|
||||
);
|
||||
}
|
||||
final key = locator<PrivateKeyStore>().get(spi.pubKeyId!);
|
||||
return SSHClient(
|
||||
socket,
|
||||
username: spi.user,
|
||||
identities: await compute(loadIndentity, key.privateKey),
|
||||
);
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:toolbox/core/persistant_store.dart';
|
||||
import 'package:toolbox/view/widget/card_dialog.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:toolbox/core/extension/stringx.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
void unawaited(Future<void> future) {}
|
||||
import '../../view/widget/card_dialog.dart';
|
||||
import '../persistant_store.dart';
|
||||
|
||||
bool isDarkMode(BuildContext context) =>
|
||||
Theme.of(context).brightness == Brightness.dark;
|
||||
@@ -27,14 +27,7 @@ void showSnackBarWithAction(BuildContext context, String content, String action,
|
||||
}
|
||||
|
||||
Future<bool> openUrl(String url) async {
|
||||
if (!await canLaunch(url)) {
|
||||
return false;
|
||||
}
|
||||
final ok = await launch(url, forceSafariVC: false);
|
||||
if (ok == true) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return await launchUrl(url.uri, mode: LaunchMode.externalApplication);
|
||||
}
|
||||
|
||||
Future<T?>? showRoundDialog<T>(
|
||||
@@ -71,12 +64,40 @@ Widget buildSwitch(BuildContext context, StoreProperty<bool> prop,
|
||||
void setTransparentNavigationBar(BuildContext context) {
|
||||
if (Platform.isAndroid) {
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
||||
statusBarColor: Colors.transparent,
|
||||
systemNavigationBarColor: Colors.transparent,
|
||||
systemNavigationBarContrastEnforced: true,
|
||||
systemNavigationBarIconBrightness:
|
||||
isDarkMode(context) ? Brightness.light : Brightness.dark,
|
||||
));
|
||||
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
|
||||
systemNavigationBarColor: Colors.transparent,
|
||||
systemNavigationBarContrastEnforced: true));
|
||||
}
|
||||
}
|
||||
|
||||
Widget buildPopuopMenu(
|
||||
{required List<PopupMenuEntry> items,
|
||||
required Function(dynamic) onSelected}) {
|
||||
return PopupMenuButton(
|
||||
itemBuilder: (_) => items,
|
||||
onSelected: onSelected,
|
||||
padding: EdgeInsets.zero,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.only(left: 7),
|
||||
child: Icon(
|
||||
Icons.more_vert,
|
||||
size: 21,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String tabTitleName(BuildContext context, int i) {
|
||||
final s = S.of(context)!;
|
||||
switch (i) {
|
||||
case 0:
|
||||
return s.server;
|
||||
case 1:
|
||||
return s.convert;
|
||||
case 2:
|
||||
return s.ping;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
52
lib/data/model/app/backup.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
import 'package:toolbox/data/model/server/private_key_info.dart';
|
||||
import 'package:toolbox/data/model/server/server_private_info.dart';
|
||||
import 'package:toolbox/data/model/server/snippet.dart';
|
||||
|
||||
class Backup {
|
||||
// backup format version
|
||||
final int version;
|
||||
final String date;
|
||||
final List<ServerPrivateInfo> spis;
|
||||
final List<Snippet> snippets;
|
||||
final List<PrivateKeyInfo> keys;
|
||||
final int primaryColor;
|
||||
final int serverStatusUpdateInterval;
|
||||
final int launchPage;
|
||||
|
||||
Backup(
|
||||
this.version,
|
||||
this.date,
|
||||
this.spis,
|
||||
this.snippets,
|
||||
this.keys,
|
||||
this.primaryColor,
|
||||
this.serverStatusUpdateInterval,
|
||||
this.launchPage,
|
||||
);
|
||||
|
||||
Backup.fromJson(Map<String, dynamic> json)
|
||||
: version = json['version'] as int,
|
||||
date = json['date'],
|
||||
spis = (json['spis'] as List)
|
||||
.map((e) => ServerPrivateInfo.fromJson(e))
|
||||
.toList(),
|
||||
snippets =
|
||||
(json['snippets'] as List).map((e) => Snippet.fromJson(e)).toList(),
|
||||
keys = (json['keys'] as List)
|
||||
.map((e) => PrivateKeyInfo.fromJson(e))
|
||||
.toList(),
|
||||
primaryColor = json['primaryColor'],
|
||||
serverStatusUpdateInterval = json['serverStatusUpdateInterval'],
|
||||
launchPage = json['launchPage'];
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'version': version,
|
||||
'date': date,
|
||||
'spis': spis,
|
||||
'snippets': snippets,
|
||||
'keys': keys,
|
||||
'primaryColor': primaryColor,
|
||||
'serverStatusUpdateInterval': serverStatusUpdateInterval,
|
||||
'launchPage': launchPage,
|
||||
};
|
||||
}
|
||||
15
lib/data/model/app/dynamic_color.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../../core/utils/ui.dart';
|
||||
|
||||
class DynamicColor {
|
||||
/// 白天模式显示的颜色
|
||||
Color light;
|
||||
|
||||
/// 暗黑模式显示的颜色
|
||||
Color dark;
|
||||
|
||||
DynamicColor(this.light, this.dark);
|
||||
|
||||
Color resolve(BuildContext context) => isDarkMode(context) ? dark : light;
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MenuItem {
|
||||
final String text;
|
||||
final IconData icon;
|
||||
|
||||
const MenuItem({
|
||||
required this.text,
|
||||
required this.icon,
|
||||
});
|
||||
}
|
||||
|
||||
class MenuItems {
|
||||
static const List<MenuItem> firstItems = [sftp, snippet, apt];
|
||||
static const List<MenuItem> secondItems = [edit];
|
||||
|
||||
static const sftp = MenuItem(text: 'SFTP', icon: Icons.file_present);
|
||||
static const snippet = MenuItem(text: 'Snippet', icon: Icons.label);
|
||||
static const apt = MenuItem(text: 'Apt', icon: Icons.system_security_update);
|
||||
static const edit = MenuItem(text: 'Edit', icon: Icons.settings);
|
||||
|
||||
static Widget buildItem(MenuItem item) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(item.icon),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Text(
|
||||
item.text,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
38
lib/data/model/app/path_with_prefix.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
class PathWithPrefix {
|
||||
late String _prefixPath;
|
||||
String _path = '/';
|
||||
String? _prePath;
|
||||
String get path => _prefixPath + _path;
|
||||
|
||||
PathWithPrefix(String prefixPath) {
|
||||
if (prefixPath.endsWith('/')) {
|
||||
_prefixPath = prefixPath.substring(0, prefixPath.length - 1);
|
||||
} else {
|
||||
_prefixPath = prefixPath;
|
||||
}
|
||||
}
|
||||
|
||||
void update(String newPath) {
|
||||
_prePath = _path;
|
||||
if (newPath == '..') {
|
||||
_path = _path.substring(0, _path.lastIndexOf('/'));
|
||||
if (_path == '') {
|
||||
_path = '/';
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (newPath == '/') {
|
||||
_path = '/';
|
||||
return;
|
||||
}
|
||||
_path = _path + (_path.endsWith('/') ? '' : '/') + newPath;
|
||||
}
|
||||
|
||||
bool undo() {
|
||||
if (_prePath == null || _path == _prePath) {
|
||||
return false;
|
||||
}
|
||||
_path = _prePath!;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -31,9 +31,9 @@ class AppUpdate {
|
||||
});
|
||||
AppUpdate.fromJson(Map<String, dynamic> json) {
|
||||
newest = json["newest"]?.toInt();
|
||||
newest = json["macbuild"]?.toInt();
|
||||
newest = json["iosbuild"]?.toInt();
|
||||
newest = json["androidbuild"]?.toInt();
|
||||
macbuild = json["macbuild"]?.toInt();
|
||||
iosbuild = json["iosbuild"]?.toInt();
|
||||
androidbuild = json["androidbuild"]?.toInt();
|
||||
android = json["android"].toString();
|
||||
ios = json["ios"].toString();
|
||||
min = json["min"].toInt();
|
||||
|
||||
47
lib/data/model/docker/image.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
final _dockerImageReg = RegExp(r'(\S+) +(\S+) +(\S+) +(.+) +(\S+)');
|
||||
|
||||
class DockerImage {
|
||||
final String repo;
|
||||
final String tag;
|
||||
final String id;
|
||||
final String created;
|
||||
final String size;
|
||||
|
||||
static final Map<String, DockerImage> _cache = <String, DockerImage>{};
|
||||
|
||||
DockerImage({
|
||||
required this.repo,
|
||||
required this.tag,
|
||||
required this.id,
|
||||
required this.created,
|
||||
required this.size,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'repo': repo,
|
||||
'tag': tag,
|
||||
'id': id,
|
||||
'created': created,
|
||||
'size': size,
|
||||
};
|
||||
}
|
||||
|
||||
factory DockerImage.fromRawStr(String raw) {
|
||||
return _cache.putIfAbsent(raw, () => _parse(raw));
|
||||
}
|
||||
|
||||
static DockerImage _parse(String raw) {
|
||||
final match = _dockerImageReg.firstMatch(raw);
|
||||
if (match == null) {
|
||||
throw Exception('Invalid docker image: $raw');
|
||||
}
|
||||
return DockerImage(
|
||||
repo: match.group(1)!,
|
||||
tag: match.group(2)!,
|
||||
id: match.group(3)!,
|
||||
created: match.group(4)!,
|
||||
size: match.group(5)!,
|
||||
);
|
||||
}
|
||||
}
|
||||
37
lib/data/model/docker/ps.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
class DockerPsItem {
|
||||
late String containerId;
|
||||
late String image;
|
||||
late String command;
|
||||
late String created;
|
||||
late String status;
|
||||
late String ports;
|
||||
late String name;
|
||||
|
||||
DockerPsItem(this.containerId, this.image, this.command, this.created,
|
||||
this.status, this.ports, this.name);
|
||||
|
||||
DockerPsItem.fromRawString(String rawString) {
|
||||
List<String> parts = rawString.split(RegExp(' +'));
|
||||
parts = parts.map((e) => e.trim()).toList();
|
||||
|
||||
containerId = parts[0];
|
||||
image = parts[1];
|
||||
command = parts[2].trim();
|
||||
created = parts[3];
|
||||
status = parts[4];
|
||||
if (running && parts.length > 6) {
|
||||
ports = parts[5];
|
||||
name = parts[6];
|
||||
} else {
|
||||
ports = '';
|
||||
name = parts[5];
|
||||
}
|
||||
}
|
||||
|
||||
bool get running => status.contains('Up ');
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'DockerPsItem<$containerId@$name>';
|
||||
}
|
||||
}
|
||||
1
lib/data/model/pkg/manager.dart
Normal file
@@ -0,0 +1 @@
|
||||
enum PkgManager { apt, yum, zypper, pacman, opkg }
|
||||
75
lib/data/model/pkg/upgrade_info.dart
Normal file
@@ -0,0 +1,75 @@
|
||||
import 'package:toolbox/data/model/pkg/manager.dart';
|
||||
|
||||
class UpgradePkgInfo {
|
||||
final PkgManager? _mgr;
|
||||
|
||||
late String package;
|
||||
late String nowVersion;
|
||||
late String newVersion;
|
||||
late String arch;
|
||||
|
||||
UpgradePkgInfo(String raw, this._mgr) {
|
||||
switch (_mgr) {
|
||||
case PkgManager.apt:
|
||||
_parseApt(raw);
|
||||
break;
|
||||
case PkgManager.yum:
|
||||
_parseYum(raw);
|
||||
break;
|
||||
case PkgManager.zypper:
|
||||
_parseZypper(raw);
|
||||
break;
|
||||
case PkgManager.pacman:
|
||||
_parsePacman(raw);
|
||||
break;
|
||||
case PkgManager.opkg:
|
||||
_parseOpkg(raw);
|
||||
break;
|
||||
default:
|
||||
throw Exception('Unsupported pkg type: $_mgr');
|
||||
}
|
||||
}
|
||||
|
||||
void _parseApt(String raw) {
|
||||
final split1 = raw.split("/");
|
||||
package = split1[0];
|
||||
final split2 = split1[1].split(" ");
|
||||
newVersion = split2[1];
|
||||
arch = split2[2];
|
||||
nowVersion = split2[5].replaceFirst(']', '');
|
||||
}
|
||||
|
||||
void _parseYum(String raw) {
|
||||
final result = RegExp(r'\S+').allMatches(raw);
|
||||
final pkgAndArch = result.elementAt(0).group(0) ?? '.';
|
||||
final split1 = pkgAndArch.split('.');
|
||||
package = split1[0];
|
||||
arch = split1[1];
|
||||
newVersion = result.elementAt(1).group(0) ?? 'Unknown';
|
||||
nowVersion = '';
|
||||
}
|
||||
|
||||
void _parseZypper(String raw) {
|
||||
final cols = raw.split("|");
|
||||
package = cols[2].trim();
|
||||
nowVersion = cols[3].trim();
|
||||
newVersion = cols[4].trim();
|
||||
arch = cols[5].trim();
|
||||
}
|
||||
|
||||
void _parsePacman(String raw) {
|
||||
final parts = raw.split(' ');
|
||||
package = parts[0];
|
||||
nowVersion = parts[1];
|
||||
newVersion = parts[3];
|
||||
arch = '';
|
||||
}
|
||||
|
||||
void _parseOpkg(String raw) {
|
||||
final parts = raw.split(' - ');
|
||||
package = parts[0];
|
||||
nowVersion = parts[1];
|
||||
newVersion = parts[2];
|
||||
arch = '';
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
import 'package:toolbox/data/model/server/cpu_status.dart';
|
||||
|
||||
class Cpu2Status {
|
||||
List<CpuStatus> pre;
|
||||
List<CpuStatus> now;
|
||||
String temp;
|
||||
Cpu2Status(this.pre, this.now, this.temp);
|
||||
|
||||
double usedPercent({int coreIdx = 0}) {
|
||||
if (now.length != pre.length) return 0;
|
||||
final idleDelta = now[coreIdx].idle - pre[coreIdx].idle;
|
||||
final totalDelta = now[coreIdx].total - pre[coreIdx].total;
|
||||
final used = idleDelta / totalDelta;
|
||||
return used.isNaN ? 0 : 100 - used * 100;
|
||||
}
|
||||
|
||||
Cpu2Status update(List<CpuStatus> newStatus, String newTemp) {
|
||||
return Cpu2Status(now, newStatus, newTemp);
|
||||
}
|
||||
|
||||
int get coresCount => now.length;
|
||||
|
||||
int get totalDelta => now[0].total - pre[0].total;
|
||||
|
||||
double get user {
|
||||
if (now.length != pre.length) return 0;
|
||||
final delta = now[0].user - pre[0].user;
|
||||
final used = delta / totalDelta;
|
||||
return used.isNaN ? 0 : used * 100;
|
||||
}
|
||||
|
||||
double get sys {
|
||||
if (now.length != pre.length) return 0;
|
||||
final delta = now[0].sys - pre[0].sys;
|
||||
final used = delta / totalDelta;
|
||||
return used.isNaN ? 0 : used * 100;
|
||||
}
|
||||
|
||||
double get nice {
|
||||
if (now.length != pre.length) return 0;
|
||||
final delta = now[0].nice - pre[0].nice;
|
||||
final used = delta / totalDelta;
|
||||
return used.isNaN ? 0 : used * 100;
|
||||
}
|
||||
|
||||
double get idle => 100 - usedPercent();
|
||||
}
|
||||
@@ -1,7 +1,62 @@
|
||||
class CpuStatus {
|
||||
List<OneTimeCpuStatus> _pre;
|
||||
List<OneTimeCpuStatus> _now;
|
||||
String temp;
|
||||
CpuStatus(this._pre, this._now, this.temp);
|
||||
|
||||
double usedPercent({int coreIdx = 0}) {
|
||||
if (_now.length != _pre.length) return 0;
|
||||
final idleDelta = _now[coreIdx].idle - _pre[coreIdx].idle;
|
||||
final totalDelta = _now[coreIdx].total - _pre[coreIdx].total;
|
||||
final used = idleDelta / totalDelta;
|
||||
return used.isNaN ? 0 : 100 - used * 100;
|
||||
}
|
||||
|
||||
void update(List<OneTimeCpuStatus> newStatus, String newTemp) {
|
||||
_pre = _now;
|
||||
_now = newStatus;
|
||||
temp = newTemp;
|
||||
}
|
||||
|
||||
int get coresCount => _now.length;
|
||||
|
||||
int get totalDelta => _now[0].total - _pre[0].total;
|
||||
|
||||
double get user {
|
||||
if (_now.length != _pre.length) return 0;
|
||||
final delta = _now[0].user - _pre[0].user;
|
||||
final used = delta / totalDelta;
|
||||
return used.isNaN ? 0 : used * 100;
|
||||
}
|
||||
|
||||
double get sys {
|
||||
if (_now.length != _pre.length) return 0;
|
||||
final delta = _now[0].sys - _pre[0].sys;
|
||||
final used = delta / totalDelta;
|
||||
return used.isNaN ? 0 : used * 100;
|
||||
}
|
||||
|
||||
double get nice {
|
||||
if (_now.length != _pre.length) return 0;
|
||||
final delta = _now[0].nice - _pre[0].nice;
|
||||
final used = delta / totalDelta;
|
||||
return used.isNaN ? 0 : used * 100;
|
||||
}
|
||||
|
||||
double get iowait {
|
||||
if (_now.length != _pre.length) return 0;
|
||||
final delta = _now[0].iowait - _pre[0].iowait;
|
||||
final used = delta / totalDelta;
|
||||
return used.isNaN ? 0 : used * 100;
|
||||
}
|
||||
|
||||
double get idle => 100 - usedPercent();
|
||||
}
|
||||
|
||||
///
|
||||
/// Code generated by jsonToDartModel https://ashamp.github.io/jsonToDartModel/
|
||||
///
|
||||
class CpuStatus {
|
||||
class OneTimeCpuStatus {
|
||||
/*
|
||||
{
|
||||
"user": 0,
|
||||
@@ -23,7 +78,7 @@ class CpuStatus {
|
||||
late int irq;
|
||||
late int softirq;
|
||||
|
||||
CpuStatus(
|
||||
OneTimeCpuStatus(
|
||||
this.id,
|
||||
this.user,
|
||||
this.sys,
|
||||
@@ -36,3 +91,51 @@ class CpuStatus {
|
||||
|
||||
int get total => user + sys + nice + idle + iowait + irq + softirq;
|
||||
}
|
||||
|
||||
List<OneTimeCpuStatus> parseCPU(String raw) {
|
||||
final List<OneTimeCpuStatus> cpus = [];
|
||||
|
||||
for (var item in raw.split('\n')) {
|
||||
if (item == '') break;
|
||||
final id = item.split(' ').first;
|
||||
final matches = item.replaceFirst(id, '').trim().split(' ');
|
||||
cpus.add(OneTimeCpuStatus(
|
||||
id,
|
||||
int.parse(matches[0]),
|
||||
int.parse(matches[1]),
|
||||
int.parse(matches[2]),
|
||||
int.parse(matches[3]),
|
||||
int.parse(matches[4]),
|
||||
int.parse(matches[5]),
|
||||
int.parse(matches[6])));
|
||||
}
|
||||
return cpus;
|
||||
}
|
||||
|
||||
final cpuTempReg = RegExp(r'(x86_pkg_temp|cpu_thermal)');
|
||||
|
||||
String parseCPUTemp(List<String> segments) {
|
||||
const noMatch = "/sys/class/thermal/thermal_zone*/type";
|
||||
final type = segments[0];
|
||||
final value = segments[1];
|
||||
// Not support to get CPU temperature
|
||||
if (value.contains(noMatch) ||
|
||||
type.contains(noMatch) ||
|
||||
value.isEmpty ||
|
||||
type.isEmpty) {
|
||||
return '';
|
||||
}
|
||||
final split = type.split('\n');
|
||||
int idx = 0;
|
||||
for (var item in split) {
|
||||
if (item.contains(cpuTempReg)) {
|
||||
break;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
final valueSplited = value.split('\n');
|
||||
if (idx >= valueSplited.length) return '';
|
||||
final temp = int.tryParse(valueSplited[idx].trim());
|
||||
if (temp == null) return '';
|
||||
return '${(temp / 1000).toStringAsFixed(1)}°C';
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import '../../res/misc.dart';
|
||||
|
||||
class DiskInfo {
|
||||
/*
|
||||
{
|
||||
@@ -10,19 +12,40 @@ class DiskInfo {
|
||||
}
|
||||
*/
|
||||
|
||||
late String mountPath;
|
||||
late String mountLocation;
|
||||
late String path;
|
||||
late String loc;
|
||||
late int usedPercent;
|
||||
late String used;
|
||||
late String size;
|
||||
late String avail;
|
||||
|
||||
DiskInfo(
|
||||
this.mountPath,
|
||||
this.mountLocation,
|
||||
this.path,
|
||||
this.loc,
|
||||
this.usedPercent,
|
||||
this.used,
|
||||
this.size,
|
||||
this.avail,
|
||||
);
|
||||
}
|
||||
|
||||
List<DiskInfo> parseDisk(String raw) {
|
||||
final list = <DiskInfo>[];
|
||||
final items = raw.split('\n');
|
||||
items.removeAt(0);
|
||||
for (var item in items) {
|
||||
if (item.isEmpty) {
|
||||
continue;
|
||||
}
|
||||
final vals = item.split(numReg);
|
||||
list.add(DiskInfo(
|
||||
vals[0],
|
||||
vals[5],
|
||||
int.parse(vals[4].replaceFirst('%', '')),
|
||||
vals[2],
|
||||
vals[1],
|
||||
vals[3],
|
||||
));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
28
lib/data/model/server/dist.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
enum Dist {
|
||||
debian,
|
||||
ubuntu,
|
||||
centos,
|
||||
fedora,
|
||||
opensuse,
|
||||
kali,
|
||||
wrt,
|
||||
armbian,
|
||||
arch,
|
||||
rocky;
|
||||
|
||||
String? get iconPath {
|
||||
return 'assets/linux/$name.png';
|
||||
}
|
||||
}
|
||||
|
||||
extension StringX on String {
|
||||
Dist? get dist {
|
||||
final lower = toLowerCase();
|
||||
for (final dist in Dist.values) {
|
||||
if (lower.contains(dist.name)) {
|
||||
return dist;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
class LinuxIcons {
|
||||
List<String> db;
|
||||
|
||||
LinuxIcons(this.db);
|
||||
|
||||
String? search(String sysVer) {
|
||||
for (var item in db) {
|
||||
if (sysVer.toLowerCase().contains(item)) {
|
||||
return 'assets/linux/$item.png';
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,79 @@ class Memory {
|
||||
int total;
|
||||
int used;
|
||||
int free;
|
||||
int shared;
|
||||
int cache;
|
||||
int avail;
|
||||
Memory(
|
||||
{required this.total,
|
||||
required this.used,
|
||||
required this.free,
|
||||
required this.shared,
|
||||
required this.cache,
|
||||
required this.avail});
|
||||
}
|
||||
|
||||
final memItemReg = RegExp(r'([A-Z].+:)\s+([0-9]+) kB');
|
||||
|
||||
Memory parseMem(String raw) {
|
||||
final items = raw.split('\n').map((e) => memItemReg.firstMatch(e)).toList();
|
||||
|
||||
final total = int.parse(
|
||||
items.firstWhere((e) => e?.group(1) == 'MemTotal:')?.group(2) ?? '1',
|
||||
);
|
||||
final free = int.parse(
|
||||
items.firstWhere((e) => e?.group(1) == 'MemFree:')?.group(2) ?? '0',
|
||||
);
|
||||
final cached = int.parse(
|
||||
items.firstWhere((e) => e?.group(1) == 'Cached:')?.group(2) ?? '0',
|
||||
);
|
||||
final available = int.parse(
|
||||
items.firstWhere((e) => e?.group(1) == 'MemAvailable:')?.group(2) ?? '0',
|
||||
);
|
||||
|
||||
return Memory(
|
||||
total: total,
|
||||
used: total - available,
|
||||
free: free,
|
||||
cache: cached,
|
||||
avail: available,
|
||||
);
|
||||
}
|
||||
|
||||
class Swap {
|
||||
final int total;
|
||||
final int used;
|
||||
final int free;
|
||||
final int cached;
|
||||
|
||||
Swap({
|
||||
required this.total,
|
||||
required this.used,
|
||||
required this.free,
|
||||
required this.cached,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Swap{total: $total, used: $used, free: $free, cached: $cached}';
|
||||
}
|
||||
}
|
||||
|
||||
Swap parseSwap(String raw) {
|
||||
final items = raw.split('\n').map((e) => memItemReg.firstMatch(e)).toList();
|
||||
|
||||
final total = int.parse(
|
||||
items.firstWhere((e) => e?.group(1) == 'SwapTotal:')?.group(2) ?? '1',
|
||||
);
|
||||
final free = int.parse(
|
||||
items.firstWhere((e) => e?.group(1) == 'SwapFree:')?.group(2) ?? '0',
|
||||
);
|
||||
final cached = int.parse(
|
||||
items.firstWhere((e) => e?.group(1) == 'SwapCached:')?.group(2) ?? '0',
|
||||
);
|
||||
|
||||
return Swap(
|
||||
total: total,
|
||||
used: total - free,
|
||||
free: free,
|
||||
cached: cached,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,71 +1,99 @@
|
||||
import 'dart:math';
|
||||
import 'package:toolbox/core/extension/numx.dart';
|
||||
|
||||
class NetSpeedPart {
|
||||
String device;
|
||||
int bytesIn;
|
||||
int bytesOut;
|
||||
int time;
|
||||
BigInt bytesIn;
|
||||
BigInt bytesOut;
|
||||
BigInt time;
|
||||
NetSpeedPart(this.device, this.bytesIn, this.bytesOut, this.time);
|
||||
}
|
||||
|
||||
class NetSpeed {
|
||||
List<NetSpeedPart> old;
|
||||
List<NetSpeedPart> now;
|
||||
NetSpeed(this.old, this.now);
|
||||
List<NetSpeedPart> _old;
|
||||
List<NetSpeedPart> _now;
|
||||
NetSpeed(this._old, this._now);
|
||||
|
||||
List<String> get devices {
|
||||
final devices = <String>[];
|
||||
for (var item in now) {
|
||||
for (var item in _now) {
|
||||
devices.add(item.device);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
NetSpeed update(List<NetSpeedPart> newOne) => NetSpeed(now, newOne);
|
||||
void update(List<NetSpeedPart> newOne) {
|
||||
_old = _now;
|
||||
_now = newOne;
|
||||
}
|
||||
|
||||
int get timeDiff => now[0].time - old[0].time;
|
||||
BigInt get timeDiff => _now[0].time - _old[0].time;
|
||||
|
||||
String speedIn({String? device}) {
|
||||
if (old[0].device == '' || now[0].device == '') return '0kb/s';
|
||||
int idx = 0;
|
||||
if (device != null) {
|
||||
for (var item in now) {
|
||||
if (item.device == device) {
|
||||
idx = now.indexOf(item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_old[0].device == '' || _now[0].device == '') return '0kb/s';
|
||||
final idx = deviceIdx(device);
|
||||
final speedInBytesPerSecond =
|
||||
(now[idx].bytesIn - old[idx].bytesIn) / timeDiff;
|
||||
int squareTimes = 0;
|
||||
for (; speedInBytesPerSecond / pow(1024, squareTimes) > 1024;) {
|
||||
if (squareTimes >= suffixs.length - 1) break;
|
||||
squareTimes++;
|
||||
}
|
||||
return '${(speedInBytesPerSecond / pow(1024, squareTimes)).toStringAsFixed(1)} ${suffixs[squareTimes]}';
|
||||
(_now[idx].bytesIn - _old[idx].bytesIn) / timeDiff;
|
||||
return buildStandardOutput(speedInBytesPerSecond);
|
||||
}
|
||||
|
||||
String totalIn({String? device}) {
|
||||
if (_old[0].device == '' || _now[0].device == '') return '0kb';
|
||||
final idx = deviceIdx(device);
|
||||
final totalInBytes = _now[idx].bytesIn;
|
||||
return totalInBytes.toInt().convertBytes;
|
||||
}
|
||||
|
||||
String speedOut({String? device}) {
|
||||
if (old[0].device == '' || now[0].device == '') return '0kb/s';
|
||||
int idx = 0;
|
||||
if (_old[0].device == '' || _now[0].device == '') return '0kb/s';
|
||||
final idx = deviceIdx(device);
|
||||
final speedOutBytesPerSecond =
|
||||
(_now[idx].bytesOut - _old[idx].bytesOut) / timeDiff;
|
||||
return buildStandardOutput(speedOutBytesPerSecond);
|
||||
}
|
||||
|
||||
String totalOut({String? device}) {
|
||||
if (_old[0].device == '' || _now[0].device == '') return '0kb';
|
||||
final idx = deviceIdx(device);
|
||||
final totalOutBytes = _now[idx].bytesOut;
|
||||
return totalOutBytes.toInt().convertBytes;
|
||||
}
|
||||
|
||||
int deviceIdx(String? device) {
|
||||
if (device != null) {
|
||||
for (var item in now) {
|
||||
for (var item in _now) {
|
||||
if (item.device == device) {
|
||||
idx = now.indexOf(item);
|
||||
break;
|
||||
return _now.indexOf(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
final speedInBytesPerSecond =
|
||||
(now[idx].bytesOut - old[idx].bytesOut) / timeDiff;
|
||||
int squareTimes = 0;
|
||||
for (; speedInBytesPerSecond / pow(1024, squareTimes) > 1024;) {
|
||||
if (squareTimes >= suffixs.length - 1) break;
|
||||
squareTimes++;
|
||||
}
|
||||
return '${(speedInBytesPerSecond / pow(1024, squareTimes)).toStringAsFixed(1)} ${suffixs[squareTimes]}';
|
||||
return 0;
|
||||
}
|
||||
|
||||
String buildStandardOutput(double speed) => '${speed.convertBytes}/s';
|
||||
}
|
||||
|
||||
const suffixs = ['b/s', 'kb/s', 'mb/s', 'gb/s'];
|
||||
/// [raw] example:
|
||||
/// Inter-| Receive | Transmit
|
||||
/// face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
|
||||
/// lo: 45929941 269112 0 0 0 0 0 0 45929941 269112 0 0 0 0 0 0
|
||||
/// eth0: 48481023 505772 0 0 0 0 0 0 36002262 202307 0 0 0 0 0 0
|
||||
/// 1635752901
|
||||
List<NetSpeedPart> parseNetSpeed(String raw) {
|
||||
final split = raw.split('\n');
|
||||
if (split.length < 4) {
|
||||
return [];
|
||||
}
|
||||
|
||||
final time = BigInt.parse(split[split.length - 1]);
|
||||
final results = <NetSpeedPart>[];
|
||||
for (final item in split.sublist(2, split.length - 1)) {
|
||||
final data = item.trim().split(':');
|
||||
final device = data.first;
|
||||
final bytes = data.last.trim().split(' ');
|
||||
bytes.removeWhere((element) => element == '');
|
||||
final bytesIn = BigInt.parse(bytes.first);
|
||||
final bytesOut = BigInt.parse(bytes[8]);
|
||||
results.add(NetSpeedPart(device, bytesIn, bytesOut, time));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
79
lib/data/model/server/ping_result.dart
Normal file
@@ -0,0 +1,79 @@
|
||||
final parseFailed = Exception('Parse failed');
|
||||
final seqReg = RegExp(r'icmp_seq=(.+) ttl=(.+) time=(.+) ms');
|
||||
final packetReg =
|
||||
RegExp(r'(.+) packets transmitted, (.+) received, (.+)% packet loss');
|
||||
final timeReg = RegExp(r'min/avg/max/mdev = (.+)/(.+)/(.+)/(.+) ms');
|
||||
final ipReg = RegExp(r' \((\S+)\) ');
|
||||
|
||||
class PingResult {
|
||||
String serverName;
|
||||
String? ip;
|
||||
List<PingSeqResult>? results;
|
||||
PingStatistics? statistic;
|
||||
|
||||
PingResult.parse(this.serverName, String raw) {
|
||||
final lines = raw.split('\n');
|
||||
lines.removeWhere((element) => element.isEmpty);
|
||||
final statisticIndex =
|
||||
lines.indexWhere((element) => element.startsWith('---'));
|
||||
if (statisticIndex == -1) {
|
||||
throw parseFailed;
|
||||
}
|
||||
final statisticRaw = lines.sublist(statisticIndex + 1);
|
||||
statistic = PingStatistics.parse(statisticRaw);
|
||||
results = lines
|
||||
.sublist(1, statisticIndex)
|
||||
.map((e) => PingSeqResult.parse(e))
|
||||
.toList();
|
||||
ip = ipReg.firstMatch(lines[0])?.group(1);
|
||||
}
|
||||
}
|
||||
|
||||
class PingSeqResult {
|
||||
int? seq;
|
||||
int? ttl;
|
||||
double? time;
|
||||
|
||||
PingSeqResult.parse(String raw) {
|
||||
final seqMatched = seqReg.firstMatch(raw);
|
||||
if (seqMatched == null) {
|
||||
throw parseFailed;
|
||||
}
|
||||
seq = int.tryParse(seqMatched.group(1)!);
|
||||
ttl = int.tryParse(seqMatched.group(2)!);
|
||||
time = double.tryParse(seqMatched.group(3)!);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'seq: $seq, ttl: $ttl, time: $time';
|
||||
}
|
||||
}
|
||||
|
||||
class PingStatistics {
|
||||
int? total;
|
||||
int? received;
|
||||
double? loss;
|
||||
double? min;
|
||||
double? max;
|
||||
double? avg;
|
||||
double? stddev;
|
||||
|
||||
PingStatistics.parse(List<String> lines) {
|
||||
if (lines.isEmpty || lines.length != 2) {
|
||||
return;
|
||||
}
|
||||
final packetMatched = packetReg.firstMatch(lines[0]);
|
||||
final timeMatched = timeReg.firstMatch(lines[1]);
|
||||
if (packetMatched == null || timeMatched == null) {
|
||||
return;
|
||||
}
|
||||
total = int.tryParse(packetMatched.group(1)!);
|
||||
received = int.tryParse(packetMatched.group(2)!);
|
||||
loss = double.tryParse(packetMatched.group(3)!);
|
||||
min = double.tryParse(timeMatched.group(1)!);
|
||||
avg = double.tryParse(timeMatched.group(2)!);
|
||||
max = double.tryParse(timeMatched.group(3)!);
|
||||
stddev = double.tryParse(timeMatched.group(4)!);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
|
||||
part 'private_key_info.g.dart';
|
||||
|
||||
///
|
||||
/// Code generated by jsonToDartModel https://ashamp.github.io/jsonToDartModel/
|
||||
///
|
||||
@HiveType(typeId: 1)
|
||||
class PrivateKeyInfo {
|
||||
/*
|
||||
{
|
||||
@@ -12,8 +17,11 @@ class PrivateKeyInfo {
|
||||
}
|
||||
*/
|
||||
|
||||
@HiveField(0)
|
||||
late String id;
|
||||
@HiveField(1)
|
||||
late String privateKey;
|
||||
@HiveField(2)
|
||||
late String password;
|
||||
|
||||
PrivateKeyInfo(
|
||||
|
||||
47
lib/data/model/server/private_key_info.g.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'private_key_info.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class PrivateKeyInfoAdapter extends TypeAdapter<PrivateKeyInfo> {
|
||||
@override
|
||||
final int typeId = 1;
|
||||
|
||||
@override
|
||||
PrivateKeyInfo read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return PrivateKeyInfo(
|
||||
fields[0] as String,
|
||||
fields[1] as String,
|
||||
fields[2] as String,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, PrivateKeyInfo obj) {
|
||||
writer
|
||||
..writeByte(3)
|
||||
..writeByte(0)
|
||||
..write(obj.id)
|
||||
..writeByte(1)
|
||||
..write(obj.privateKey)
|
||||
..writeByte(2)
|
||||
..write(obj.password);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is PrivateKeyInfoAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
@@ -1,13 +1,22 @@
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
import 'package:toolbox/data/model/server/server_connection_state.dart';
|
||||
import 'package:toolbox/data/model/server/server_private_info.dart';
|
||||
import 'package:toolbox/data/model/server/server_status.dart';
|
||||
|
||||
class ServerInfo {
|
||||
ServerPrivateInfo info;
|
||||
class Server {
|
||||
ServerPrivateInfo spi;
|
||||
ServerStatus status;
|
||||
SSHClient? client;
|
||||
ServerConnectionState connectionState;
|
||||
ServerState cs;
|
||||
|
||||
ServerInfo(this.info, this.status, this.client, this.connectionState);
|
||||
Server(this.spi, this.status, this.client, this.cs);
|
||||
}
|
||||
|
||||
enum ServerState {
|
||||
disconnected,
|
||||
connecting,
|
||||
connected,
|
||||
failed;
|
||||
|
||||
bool get shouldConnect =>
|
||||
this == ServerState.disconnected || this == ServerState.failed;
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
enum ServerConnectionState { disconnected, connecting, connected, failed }
|
||||
@@ -1,8 +1,13 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
|
||||
part 'server_private_info.g.dart';
|
||||
|
||||
///
|
||||
/// Code generated by jsonToDartModel https://ashamp.github.io/jsonToDartModel/
|
||||
///
|
||||
@HiveType(typeId: 3)
|
||||
class ServerPrivateInfo {
|
||||
/*
|
||||
{
|
||||
@@ -13,35 +18,47 @@ class ServerPrivateInfo {
|
||||
}
|
||||
*/
|
||||
|
||||
@HiveField(0)
|
||||
late String name;
|
||||
@HiveField(1)
|
||||
late String ip;
|
||||
@HiveField(2)
|
||||
late int port;
|
||||
@HiveField(3)
|
||||
late String user;
|
||||
late Object authorization;
|
||||
@HiveField(4)
|
||||
late String pwd;
|
||||
@HiveField(5)
|
||||
String? pubKeyId;
|
||||
|
||||
ServerPrivateInfo(
|
||||
{required this.name,
|
||||
required this.ip,
|
||||
required this.port,
|
||||
required this.user,
|
||||
required this.authorization,
|
||||
this.pubKeyId});
|
||||
late String id;
|
||||
|
||||
ServerPrivateInfo({
|
||||
required this.name,
|
||||
required this.ip,
|
||||
required this.port,
|
||||
required this.user,
|
||||
required this.pwd,
|
||||
this.pubKeyId,
|
||||
}) : id = '$user@$ip:$port';
|
||||
|
||||
ServerPrivateInfo.fromJson(Map<String, dynamic> json) {
|
||||
name = json["name"].toString();
|
||||
ip = json["ip"].toString();
|
||||
port = json["port"].toInt();
|
||||
user = json["user"].toString();
|
||||
authorization = json["authorization"];
|
||||
pwd = json["authorization"].toString();
|
||||
pubKeyId = json["pubKeyId"]?.toString();
|
||||
id = '$user@$ip:$port';
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data["name"] = name;
|
||||
data["ip"] = ip;
|
||||
data["port"] = port;
|
||||
data["user"] = user;
|
||||
data["authorization"] = authorization;
|
||||
data["authorization"] = pwd;
|
||||
data["pubKeyId"] = pubKeyId;
|
||||
return data;
|
||||
}
|
||||
|
||||
56
lib/data/model/server/server_private_info.g.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'server_private_info.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class ServerPrivateInfoAdapter extends TypeAdapter<ServerPrivateInfo> {
|
||||
@override
|
||||
final int typeId = 3;
|
||||
|
||||
@override
|
||||
ServerPrivateInfo read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return ServerPrivateInfo(
|
||||
name: fields[0] as String,
|
||||
ip: fields[1] as String,
|
||||
port: fields[2] as int,
|
||||
user: fields[3] as String,
|
||||
pwd: fields[4] as String,
|
||||
pubKeyId: fields[5] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, ServerPrivateInfo obj) {
|
||||
writer
|
||||
..writeByte(6)
|
||||
..writeByte(0)
|
||||
..write(obj.name)
|
||||
..writeByte(1)
|
||||
..write(obj.ip)
|
||||
..writeByte(2)
|
||||
..write(obj.port)
|
||||
..writeByte(3)
|
||||
..write(obj.user)
|
||||
..writeByte(4)
|
||||
..write(obj.pwd)
|
||||
..writeByte(5)
|
||||
..write(obj.pubKeyId);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is ServerPrivateInfoAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'package:toolbox/data/model/server/cpu_2_status.dart';
|
||||
import 'package:toolbox/data/model/server/cpu_status.dart';
|
||||
import 'package:toolbox/data/model/server/disk_info.dart';
|
||||
import 'package:toolbox/data/model/server/memory.dart';
|
||||
import 'package:toolbox/data/model/server/net_speed.dart';
|
||||
@@ -30,8 +30,9 @@ class ServerStatus {
|
||||
}
|
||||
*/
|
||||
|
||||
Cpu2Status cpu2Status;
|
||||
Memory memory;
|
||||
CpuStatus cpu;
|
||||
Memory mem;
|
||||
Swap swap;
|
||||
String sysVer;
|
||||
String uptime;
|
||||
List<DiskInfo> disk;
|
||||
@@ -39,7 +40,15 @@ class ServerStatus {
|
||||
NetSpeed netSpeed;
|
||||
String? failedInfo;
|
||||
|
||||
ServerStatus(this.cpu2Status, this.memory, this.sysVer, this.uptime,
|
||||
this.disk, this.tcp, this.netSpeed,
|
||||
{this.failedInfo});
|
||||
ServerStatus({
|
||||
required this.cpu,
|
||||
required this.mem,
|
||||
required this.sysVer,
|
||||
required this.uptime,
|
||||
required this.disk,
|
||||
required this.tcp,
|
||||
required this.netSpeed,
|
||||
required this.swap,
|
||||
this.failedInfo,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
|
||||
part 'snippet.g.dart';
|
||||
|
||||
@HiveType(typeId: 2)
|
||||
class Snippet {
|
||||
@HiveField(0)
|
||||
late String name;
|
||||
@HiveField(1)
|
||||
late String script;
|
||||
Snippet(this.name, this.script);
|
||||
|
||||
|
||||
44
lib/data/model/server/snippet.g.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'snippet.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class SnippetAdapter extends TypeAdapter<Snippet> {
|
||||
@override
|
||||
final int typeId = 2;
|
||||
|
||||
@override
|
||||
Snippet read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return Snippet(
|
||||
fields[0] as String,
|
||||
fields[1] as String,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, Snippet obj) {
|
||||
writer
|
||||
..writeByte(2)
|
||||
..writeByte(0)
|
||||
..write(obj.name)
|
||||
..writeByte(1)
|
||||
..write(obj.script);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is SnippetAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
import '../../../core/extension/stringx.dart';
|
||||
import '../../res/misc.dart';
|
||||
|
||||
///
|
||||
/// Code generated by jsonToDartModel https://ashamp.github.io/jsonToDartModel/
|
||||
///
|
||||
@@ -39,3 +42,14 @@ class TcpStatus {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
TcpStatus? parseTcp(String raw) {
|
||||
final lines = raw.split('\n');
|
||||
final idx = lines.lastWhere((element) => element.startsWith('Tcp:'),
|
||||
orElse: () => '');
|
||||
if (idx != '') {
|
||||
final vals = idx.split(numReg);
|
||||
return TcpStatus(vals[5].i, vals[6].i, vals[7].i, vals[8].i);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
35
lib/data/model/sftp/absolute_path.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
class AbsolutePath {
|
||||
String _path;
|
||||
String get path => _path;
|
||||
final List<String> _prePath;
|
||||
|
||||
AbsolutePath(this._path) : _prePath = ['/'];
|
||||
|
||||
void update(String newPath) {
|
||||
_prePath.add(_path);
|
||||
if (newPath == '..') {
|
||||
_path = _path.substring(0, _path.lastIndexOf('/'));
|
||||
if (_path == '') {
|
||||
_path = '/';
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (newPath == '/') {
|
||||
_path = '/';
|
||||
return;
|
||||
}
|
||||
if (newPath.startsWith('/')) {
|
||||
_path = newPath;
|
||||
return;
|
||||
}
|
||||
_path = _path + (_path.endsWith('/') ? '' : '/') + newPath;
|
||||
}
|
||||
|
||||
bool undo() {
|
||||
if (_prePath.isEmpty) {
|
||||
return false;
|
||||
}
|
||||
_path = _prePath.removeLast();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
11
lib/data/model/sftp/browser_status.dart
Normal file
@@ -0,0 +1,11 @@
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
import 'package:toolbox/data/model/sftp/absolute_path.dart';
|
||||
|
||||
class SftpBrowserStatus {
|
||||
List<SftpName>? files;
|
||||
AbsolutePath? path;
|
||||
SftpClient? client;
|
||||
bool isBusy = false;
|
||||
|
||||
SftpBrowserStatus();
|
||||
}
|
||||
16
lib/data/model/sftp/download_item.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
import '../server/server_private_info.dart';
|
||||
|
||||
class DownloadItem {
|
||||
DownloadItem(this.spi, this.remotePath, this.localPath);
|
||||
|
||||
final ServerPrivateInfo spi;
|
||||
final String remotePath;
|
||||
final String localPath;
|
||||
}
|
||||
|
||||
class DownloadItemEvent {
|
||||
DownloadItemEvent(this.item, this.privateKey);
|
||||
|
||||
final DownloadItem item;
|
||||
final String? privateKey;
|
||||
}
|
||||
60
lib/data/model/sftp/download_status.dart
Normal file
@@ -0,0 +1,60 @@
|
||||
import 'package:toolbox/data/model/sftp/download_worker.dart';
|
||||
|
||||
import 'download_item.dart';
|
||||
|
||||
class SftpDownloadStatus {
|
||||
final int id;
|
||||
final DownloadItem item;
|
||||
final void Function() notifyListeners;
|
||||
late SftpDownloadWorker worker;
|
||||
|
||||
String get fileName => item.localPath.split('/').last;
|
||||
|
||||
// status of the download
|
||||
double? progress;
|
||||
SftpWorkerStatus? status;
|
||||
int? size;
|
||||
Exception? error;
|
||||
Duration? spentTime;
|
||||
|
||||
SftpDownloadStatus(this.item, this.notifyListeners, {String? key})
|
||||
: id = DateTime.now().microsecondsSinceEpoch {
|
||||
worker =
|
||||
SftpDownloadWorker(onNotify: onNotify, item: item, privateKey: key);
|
||||
worker.init();
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
other is SftpDownloadStatus && id == other.id;
|
||||
|
||||
@override
|
||||
int get hashCode => id ^ super.hashCode;
|
||||
|
||||
void onNotify(dynamic event) {
|
||||
switch (event.runtimeType) {
|
||||
case SftpWorkerStatus:
|
||||
status = event;
|
||||
if (status == SftpWorkerStatus.finished) {
|
||||
worker.dispose();
|
||||
}
|
||||
break;
|
||||
case double:
|
||||
progress = event;
|
||||
break;
|
||||
case int:
|
||||
size = event;
|
||||
break;
|
||||
case Exception:
|
||||
error = event;
|
||||
break;
|
||||
case Duration:
|
||||
spentTime = event;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
enum SftpWorkerStatus { preparing, sshConnectted, downloading, finished }
|
||||
96
lib/data/model/sftp/download_worker.dart
Normal file
@@ -0,0 +1,96 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
import 'package:easy_isolate/easy_isolate.dart';
|
||||
|
||||
import 'download_item.dart';
|
||||
import 'download_status.dart';
|
||||
|
||||
class SftpDownloadWorker {
|
||||
SftpDownloadWorker(
|
||||
{required this.onNotify, required this.item, this.privateKey});
|
||||
|
||||
final Function(Object event) onNotify;
|
||||
final DownloadItem item;
|
||||
final worker = Worker();
|
||||
final String? privateKey;
|
||||
|
||||
void dispose() {
|
||||
worker.dispose();
|
||||
}
|
||||
|
||||
/// Initiate the worker (new thread) and start listen from messages between
|
||||
/// the threads
|
||||
Future<void> init() async {
|
||||
if (worker.isInitialized) worker.dispose();
|
||||
await worker.init(
|
||||
mainMessageHandler,
|
||||
isolateMessageHandler,
|
||||
errorHandler: print,
|
||||
);
|
||||
worker.sendMessage(DownloadItemEvent(item, privateKey));
|
||||
}
|
||||
|
||||
/// Handle the messages coming from the isolate
|
||||
void mainMessageHandler(dynamic data, SendPort isolateSendPort) {
|
||||
onNotify(data);
|
||||
}
|
||||
|
||||
/// Handle the messages coming from the main
|
||||
static isolateMessageHandler(
|
||||
dynamic data, SendPort mainSendPort, SendErrorFunction sendError) async {
|
||||
if (data is DownloadItemEvent) {
|
||||
try {
|
||||
mainSendPort.send(SftpWorkerStatus.preparing);
|
||||
final watch = Stopwatch()..start();
|
||||
final item = data.item;
|
||||
final spi = item.spi;
|
||||
final socket = await SSHSocket.connect(spi.ip, spi.port);
|
||||
SSHClient client;
|
||||
if (spi.pubKeyId == null) {
|
||||
client = SSHClient(socket,
|
||||
username: spi.user, onPasswordRequest: () => spi.pwd);
|
||||
} else {
|
||||
client = SSHClient(socket,
|
||||
username: spi.user,
|
||||
identities: SSHKeyPair.fromPem(data.privateKey!));
|
||||
}
|
||||
mainSendPort.send(SftpWorkerStatus.sshConnectted);
|
||||
|
||||
final remotePath = item.remotePath;
|
||||
final localPath = item.localPath;
|
||||
await Directory(localPath.substring(0, item.localPath.lastIndexOf('/')))
|
||||
.create(recursive: true);
|
||||
final local = File(localPath);
|
||||
if (await local.exists()) {
|
||||
await local.delete();
|
||||
}
|
||||
final localFile = local.openWrite(mode: FileMode.append);
|
||||
final file = await (await client.sftp()).open(remotePath);
|
||||
final size = (await file.stat()).size;
|
||||
if (size == null) {
|
||||
mainSendPort.send(Exception('can not get file size'));
|
||||
return;
|
||||
}
|
||||
const defaultChunkSize = 1024 * 1024;
|
||||
final chunkSize = size > defaultChunkSize ? defaultChunkSize : size;
|
||||
mainSendPort.send(size);
|
||||
mainSendPort.send(SftpWorkerStatus.downloading);
|
||||
for (var i = 0; i < size; i += chunkSize) {
|
||||
final fileData = file.read(length: chunkSize);
|
||||
await for (var form in fileData) {
|
||||
localFile.add(form);
|
||||
mainSendPort.send((i + form.length) / size * 100);
|
||||
}
|
||||
}
|
||||
localFile.close();
|
||||
mainSendPort.send(watch.elapsed);
|
||||
mainSendPort.send(SftpWorkerStatus.finished);
|
||||
} catch (e) {
|
||||
mainSendPort.send(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
142
lib/data/model/ssh/terminal_color.dart
Normal file
@@ -0,0 +1,142 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:xterm/ui.dart';
|
||||
import '../../res/terminal_color.dart';
|
||||
|
||||
class TerminalUITheme {
|
||||
final Color cursor;
|
||||
final Color selection;
|
||||
final Color foreground;
|
||||
final Color background;
|
||||
final Color searchHitBackground;
|
||||
final Color searchHitBackgroundCurrent;
|
||||
final Color searchHitForeground;
|
||||
|
||||
const TerminalUITheme({
|
||||
required this.cursor,
|
||||
required this.selection,
|
||||
required this.foreground,
|
||||
required this.background,
|
||||
required this.searchHitBackground,
|
||||
required this.searchHitBackgroundCurrent,
|
||||
required this.searchHitForeground,
|
||||
});
|
||||
|
||||
TerminalTheme toTerminalTheme(TerminalColors termColor) {
|
||||
return TerminalTheme(
|
||||
cursor: cursor,
|
||||
selection: selection,
|
||||
foreground: foreground,
|
||||
background: background,
|
||||
black: termColor.black,
|
||||
red: termColor.red,
|
||||
green: termColor.green,
|
||||
yellow: termColor.yellow,
|
||||
blue: termColor.blue,
|
||||
magenta: termColor.magenta,
|
||||
cyan: termColor.cyan,
|
||||
white: termColor.white,
|
||||
brightBlack: termColor.brightBlack,
|
||||
brightRed: termColor.brightRed,
|
||||
brightGreen: termColor.brightGreen,
|
||||
brightYellow: termColor.brightYellow,
|
||||
brightBlue: termColor.brightBlue,
|
||||
brightMagenta: termColor.brightMagenta,
|
||||
brightCyan: termColor.brightCyan,
|
||||
brightWhite: termColor.brightWhite,
|
||||
searchHitBackground: searchHitBackground,
|
||||
searchHitBackgroundCurrent: searchHitBackgroundCurrent,
|
||||
searchHitForeground: searchHitForeground,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class TerminalColors {
|
||||
final TerminalColorsPlatform platform;
|
||||
final Color black = Colors.black;
|
||||
final Color red;
|
||||
final Color green;
|
||||
final Color yellow;
|
||||
final Color blue;
|
||||
// 品红
|
||||
final Color magenta;
|
||||
// 青
|
||||
final Color cyan;
|
||||
final Color white;
|
||||
|
||||
/// Also called grey
|
||||
final Color brightBlack;
|
||||
final Color brightRed;
|
||||
final Color brightGreen;
|
||||
final Color brightYellow;
|
||||
final Color brightBlue;
|
||||
final Color brightMagenta;
|
||||
final Color brightCyan;
|
||||
final Color brightWhite;
|
||||
|
||||
TerminalColors(
|
||||
this.platform,
|
||||
this.red,
|
||||
this.green,
|
||||
this.yellow,
|
||||
this.blue,
|
||||
this.magenta,
|
||||
this.cyan,
|
||||
this.white,
|
||||
this.brightBlack,
|
||||
this.brightRed,
|
||||
this.brightGreen,
|
||||
this.brightYellow,
|
||||
this.brightBlue,
|
||||
this.brightMagenta,
|
||||
this.brightCyan, {
|
||||
this.brightWhite = Colors.white,
|
||||
});
|
||||
}
|
||||
|
||||
enum TerminalColorsPlatform {
|
||||
macOS,
|
||||
vga,
|
||||
cmd,
|
||||
putty,
|
||||
xterm,
|
||||
ubuntu,
|
||||
;
|
||||
|
||||
String get name {
|
||||
switch (this) {
|
||||
case TerminalColorsPlatform.vga:
|
||||
return 'VGA';
|
||||
case TerminalColorsPlatform.cmd:
|
||||
return 'CMD';
|
||||
case TerminalColorsPlatform.macOS:
|
||||
return 'macOS';
|
||||
case TerminalColorsPlatform.putty:
|
||||
return 'PuTTY';
|
||||
case TerminalColorsPlatform.xterm:
|
||||
return 'XTerm';
|
||||
case TerminalColorsPlatform.ubuntu:
|
||||
return 'Ubuntu';
|
||||
default:
|
||||
return 'Unknown';
|
||||
}
|
||||
}
|
||||
|
||||
TerminalColors get colors {
|
||||
switch (this) {
|
||||
case TerminalColorsPlatform.vga:
|
||||
return VGATerminalColor();
|
||||
case TerminalColorsPlatform.cmd:
|
||||
return CMDTerminalColor();
|
||||
case TerminalColorsPlatform.macOS:
|
||||
return MacOSTerminalColor();
|
||||
case TerminalColorsPlatform.putty:
|
||||
return PuttyTerminalColor();
|
||||
case TerminalColorsPlatform.xterm:
|
||||
return XTermTerminalColor();
|
||||
case TerminalColorsPlatform.ubuntu:
|
||||
return UbuntuTerminalColor();
|
||||
default:
|
||||
return MacOSTerminalColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
15
lib/data/model/ssh/virtual_key.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:xterm/core.dart';
|
||||
|
||||
class VirtualKey {
|
||||
final String text;
|
||||
final bool toggleable;
|
||||
final TerminalKey? key;
|
||||
final IconData? icon;
|
||||
final VirtualKeyFunc? func;
|
||||
|
||||
VirtualKey(this.text,
|
||||
{this.key, this.toggleable = false, this.icon, this.func});
|
||||
}
|
||||
|
||||
enum VirtualKeyFunc { toggleIME, backspace, copy, paste }
|
||||
@@ -1,20 +1,9 @@
|
||||
import 'package:toolbox/core/provider_base.dart';
|
||||
import 'package:toolbox/data/service/app.dart';
|
||||
|
||||
class AppProvider extends BusyProvider {
|
||||
Map? _notify;
|
||||
Map? get notify => _notify;
|
||||
int? _newestBuild;
|
||||
int? get newestBuild => _newestBuild;
|
||||
|
||||
Future<void> loadData() async {
|
||||
setBusyState(true);
|
||||
final service = AppService();
|
||||
_notify = await service.getNotify();
|
||||
setBusyState(false);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setNewestBuild(int build) {
|
||||
_newestBuild = build;
|
||||
notifyListeners();
|
||||
|
||||
@@ -1,32 +1,42 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../data/res/misc.dart';
|
||||
|
||||
/// format: [NAME][LEVEL]: MESSAGE
|
||||
final _headReg = RegExp(r'(\[[A-Za-z]+\])(\[[A-Z]+\]): (.*)');
|
||||
const _level2Color = {
|
||||
'[INFO]': Colors.blue,
|
||||
'[WARNING]': Colors.yellow,
|
||||
};
|
||||
|
||||
class DebugProvider extends ChangeNotifier {
|
||||
final widgets = <Widget>[];
|
||||
|
||||
void addText(String text) {
|
||||
_addText(text);
|
||||
notifyListeners();
|
||||
}
|
||||
final match = _headReg.allMatches(text);
|
||||
|
||||
void _addText(String text) {
|
||||
_addWidget(Text(text));
|
||||
}
|
||||
|
||||
void addError(Object error) {
|
||||
_addError(error);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _addError(Object error) {
|
||||
_addMultiline(error, Colors.red);
|
||||
if (match.isNotEmpty) {
|
||||
_addWidget(Text.rich(TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: match.first.group(1),
|
||||
style: const TextStyle(color: Colors.cyan),
|
||||
),
|
||||
TextSpan(
|
||||
text: match.first.group(2),
|
||||
style: TextStyle(color: _level2Color[match.first.group(2)]),
|
||||
),
|
||||
TextSpan(
|
||||
text: '\n${match.first.group(3)}',
|
||||
)
|
||||
],
|
||||
)));
|
||||
} else {
|
||||
_addWidget(Text(text));
|
||||
}
|
||||
}
|
||||
|
||||
void addMultiline(Object data, [Color color = Colors.blue]) {
|
||||
_addMultiline(data, color);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _addMultiline(Object data, [Color color = Colors.blue]) {
|
||||
final widget = Text(
|
||||
'$data',
|
||||
style: TextStyle(
|
||||
@@ -34,28 +44,18 @@ class DebugProvider extends ChangeNotifier {
|
||||
),
|
||||
);
|
||||
_addWidget(SingleChildScrollView(
|
||||
child: widget,
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: widget,
|
||||
));
|
||||
}
|
||||
|
||||
void addWidget(Widget widget) {
|
||||
_addWidget(widget);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _addWidget(Widget widget) {
|
||||
final outlined = Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: Colors.green,
|
||||
),
|
||||
),
|
||||
child: widget,
|
||||
);
|
||||
|
||||
widgets.add(outlined);
|
||||
widgets.add(widget);
|
||||
widgets.add(const SizedBox(height: 13));
|
||||
if (widgets.length > maxDebugLogLines) {
|
||||
widgets.removeRange(0, widgets.length - maxDebugLogLines);
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void clear() {
|
||||
|
||||
169
lib/data/provider/docker.dart
Normal file
@@ -0,0 +1,169 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:toolbox/core/extension/ssh_client.dart';
|
||||
import 'package:toolbox/core/extension/stringx.dart';
|
||||
import 'package:toolbox/core/extension/uint8list.dart';
|
||||
import 'package:toolbox/core/provider_base.dart';
|
||||
import 'package:toolbox/data/model/docker/image.dart';
|
||||
import 'package:toolbox/data/model/docker/ps.dart';
|
||||
import 'package:toolbox/data/res/error.dart';
|
||||
import 'package:toolbox/data/store/docker.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
|
||||
final _dockerNotFound = RegExp(r'command not found|Unknown command');
|
||||
final _versionReg = RegExp(r'(Version:)\s+([0-9]+\.[0-9]+\.[0-9]+)');
|
||||
final _editionReg = RegExp(r'(Client:)\s+(.+-.+)');
|
||||
final _dockerPrefixReg = RegExp(r'(sudo )?docker ');
|
||||
|
||||
const _dockerPS = 'docker ps -a';
|
||||
const _dockerImgs = 'docker images';
|
||||
|
||||
final _logger = Logger('DOCKER');
|
||||
|
||||
class DockerProvider extends BusyProvider {
|
||||
final dockerStore = locator<DockerStore>();
|
||||
|
||||
SSHClient? client;
|
||||
String? userName;
|
||||
List<DockerPsItem>? items;
|
||||
List<DockerImage>? images;
|
||||
String? version;
|
||||
String? edition;
|
||||
DockerErr? error;
|
||||
PwdRequestFunc? onPwdReq;
|
||||
String? hostId;
|
||||
String? runLog;
|
||||
bool isRequestingPwd = false;
|
||||
|
||||
void init(SSHClient client, String userName, PwdRequestFunc onPwdReq,
|
||||
String hostId) {
|
||||
this.client = client;
|
||||
this.userName = userName;
|
||||
this.onPwdReq = onPwdReq;
|
||||
this.hostId = hostId;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
client = userName = error = items = version = edition = onPwdReq = null;
|
||||
isRequestingPwd = false;
|
||||
hostId = runLog = images = null;
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
if (isBusy) return;
|
||||
final verRaw = await client!.run('docker version'.withLangExport).string;
|
||||
if (verRaw.contains(_dockerNotFound)) {
|
||||
error = DockerErr(type: DockerErrType.notInstalled);
|
||||
setBusyState(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
version = _versionReg.firstMatch(verRaw)?.group(2);
|
||||
edition = _editionReg.firstMatch(verRaw)?.group(2);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
|
||||
try {
|
||||
setBusyState();
|
||||
final cmd = _wrap(_dockerPS);
|
||||
|
||||
// run docker ps
|
||||
var raw = '';
|
||||
await client!.exec(
|
||||
cmd,
|
||||
onStderr: _onPwd,
|
||||
onStdout: (data, _) => raw = '$raw$data',
|
||||
);
|
||||
|
||||
// parse result
|
||||
final lines = raw.split('\n');
|
||||
lines.removeAt(0);
|
||||
lines.removeWhere((element) => element.isEmpty);
|
||||
items = lines.map((e) => DockerPsItem.fromRawString(e)).toList();
|
||||
|
||||
final imageCmd = _wrap(_dockerImgs);
|
||||
raw = '';
|
||||
await client!.exec(
|
||||
imageCmd,
|
||||
onStderr: _onPwd,
|
||||
onStdout: (data, _) => raw = '$raw$data',
|
||||
);
|
||||
|
||||
final imageLines = raw.split('\n');
|
||||
imageLines.removeAt(0);
|
||||
imageLines.removeWhere((element) => element.isEmpty);
|
||||
images = imageLines.map((e) => DockerImage.fromRawStr(e)).toList();
|
||||
} catch (e) {
|
||||
error = DockerErr(type: DockerErrType.unknown, message: e.toString());
|
||||
rethrow;
|
||||
} finally {
|
||||
setBusyState(false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onPwd(String event, StreamSink<Uint8List> stdin) async {
|
||||
if (isRequestingPwd) return;
|
||||
isRequestingPwd = true;
|
||||
if (event.contains('[sudo] password for ')) {
|
||||
_logger.info('sudo password request for $userName');
|
||||
final pwd = await onPwdReq!();
|
||||
if (pwd.isEmpty) {
|
||||
_logger.info('sudo password request cancelled');
|
||||
return;
|
||||
}
|
||||
stdin.add('$pwd\n'.uint8List);
|
||||
}
|
||||
isRequestingPwd = false;
|
||||
}
|
||||
|
||||
Future<DockerErr?> stop(String id) async => await run('docker stop $id');
|
||||
|
||||
Future<DockerErr?> start(String id) async => await run('docker start $id');
|
||||
|
||||
Future<DockerErr?> delete(String id) async => await run('docker rm $id');
|
||||
|
||||
Future<DockerErr?> run(String cmd) async {
|
||||
if (!cmd.startsWith(_dockerPrefixReg)) {
|
||||
return DockerErr(type: DockerErrType.cmdNoPrefix);
|
||||
}
|
||||
setBusyState();
|
||||
|
||||
runLog = '';
|
||||
final errs = <String>[];
|
||||
final code = await client!.exec(
|
||||
_wrap(cmd),
|
||||
onStderr: (data, sink) {
|
||||
_onPwd(data, sink);
|
||||
errs.add(data);
|
||||
},
|
||||
onStdout: (data, _) {
|
||||
runLog = '$runLog$data';
|
||||
notifyListeners();
|
||||
},
|
||||
);
|
||||
runLog = null;
|
||||
|
||||
if (code != 0) {
|
||||
setBusyState(false);
|
||||
return DockerErr(
|
||||
type: DockerErrType.unknown, message: errs.join('\n').trim());
|
||||
}
|
||||
await refresh();
|
||||
setBusyState(false);
|
||||
return null;
|
||||
}
|
||||
|
||||
// judge whether to use DOCKER_HOST / sudo
|
||||
String _wrap(String cmd) {
|
||||
final dockerHost = dockerStore.getDockerHost(hostId!);
|
||||
if (dockerHost == null || dockerHost.isEmpty) {
|
||||
return 'sudo $cmd'.withLangExport;
|
||||
}
|
||||
return 'export DOCKER_HOST=$dockerHost && $cmd'.withLangExport;
|
||||
}
|
||||
}
|
||||
216
lib/data/provider/pkg.dart
Normal file
@@ -0,0 +1,216 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:toolbox/core/extension/ssh_client.dart';
|
||||
import 'package:toolbox/core/extension/stringx.dart';
|
||||
import 'package:toolbox/core/extension/uint8list.dart';
|
||||
import 'package:toolbox/core/provider_base.dart';
|
||||
import 'package:toolbox/data/model/pkg/manager.dart';
|
||||
import 'package:toolbox/data/model/pkg/upgrade_info.dart';
|
||||
import 'package:toolbox/data/model/server/dist.dart';
|
||||
|
||||
class PkgProvider extends BusyProvider {
|
||||
final logger = Logger('PKG');
|
||||
|
||||
SSHClient? client;
|
||||
Dist? dist;
|
||||
PkgManager? type;
|
||||
Function()? onUpgrade;
|
||||
Function()? onUpdate;
|
||||
PwdRequestFunc? onPasswordRequest;
|
||||
|
||||
String? whoami;
|
||||
List<UpgradePkgInfo>? upgradeable;
|
||||
String? error;
|
||||
String? upgradeLog;
|
||||
String? updateLog;
|
||||
String lastLog = '';
|
||||
bool isRequestingPwd = false;
|
||||
|
||||
PkgProvider();
|
||||
|
||||
Future<void> init(
|
||||
SSHClient client,
|
||||
Dist? dist,
|
||||
Function() onUpgrade,
|
||||
Function() onUpdate,
|
||||
PwdRequestFunc onPasswordRequest,
|
||||
String user) async {
|
||||
this.client = client;
|
||||
this.dist = dist;
|
||||
this.onUpgrade = onUpgrade;
|
||||
this.onPasswordRequest = onPasswordRequest;
|
||||
whoami = user;
|
||||
|
||||
switch (dist) {
|
||||
case Dist.centos:
|
||||
case Dist.rocky:
|
||||
case Dist.fedora:
|
||||
type = PkgManager.yum;
|
||||
break;
|
||||
case Dist.debian:
|
||||
case Dist.ubuntu:
|
||||
case Dist.kali:
|
||||
case Dist.armbian:
|
||||
type = PkgManager.apt;
|
||||
break;
|
||||
case Dist.opensuse:
|
||||
type = PkgManager.zypper;
|
||||
break;
|
||||
case Dist.wrt:
|
||||
type = PkgManager.opkg;
|
||||
break;
|
||||
case Dist.arch:
|
||||
type = PkgManager.pacman;
|
||||
break;
|
||||
case null:
|
||||
error = 'Unsupported dist: $dist';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool get isSU => whoami == 'root';
|
||||
|
||||
void clear() {
|
||||
client = dist = updateLog = upgradeLog = upgradeable =
|
||||
error = whoami = onUpdate = onUpgrade = onPasswordRequest = null;
|
||||
isRequestingPwd = false;
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
final result = await _update();
|
||||
try {
|
||||
_parse(result);
|
||||
} catch (e) {
|
||||
error = '[Server Raw]:\n$result\n[App Error]:\n$e';
|
||||
} finally {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void _parse(String? raw) {
|
||||
if (raw == null) return;
|
||||
var list = raw.split('\n');
|
||||
switch (type) {
|
||||
case PkgManager.yum:
|
||||
list = list.sublist(2);
|
||||
list.removeWhere((element) => element.isEmpty);
|
||||
final endLine = list.lastIndexWhere(
|
||||
(element) => element.contains('Obsoleting Packages'));
|
||||
list = list.sublist(0, endLine);
|
||||
break;
|
||||
case PkgManager.apt:
|
||||
// avoid other outputs
|
||||
// such as: [Could not chdir to home directory /home/test: No such file or directory, , WARNING: apt does not have a stable CLI interface. Use with caution in scripts., , Listing...]
|
||||
final idx =
|
||||
list.indexWhere((element) => element.contains('[upgradable from:'));
|
||||
if (idx == -1) {
|
||||
upgradeable = [];
|
||||
return;
|
||||
}
|
||||
list = list.sublist(idx);
|
||||
list.removeWhere((element) => element.isEmpty);
|
||||
break;
|
||||
case PkgManager.zypper:
|
||||
list = list.sublist(4);
|
||||
break;
|
||||
case PkgManager.pacman:
|
||||
case PkgManager.opkg:
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
upgradeable = list.map((e) => UpgradePkgInfo(e, type)).toList();
|
||||
}
|
||||
|
||||
Future<String?> _update() async {
|
||||
switch (type) {
|
||||
case PkgManager.yum:
|
||||
return await client?.run(_wrap('yum check-update')).string;
|
||||
case PkgManager.apt:
|
||||
await client!.exec(
|
||||
_wrap('apt update'),
|
||||
onStderr: _onPwd,
|
||||
onStdout: (data, sink) {
|
||||
updateLog = (updateLog ?? '') + data;
|
||||
notifyListeners();
|
||||
if (onUpdate != null) onUpdate!();
|
||||
},
|
||||
);
|
||||
return await client
|
||||
?.run('apt list --upgradeable'.withLangExport)
|
||||
.string;
|
||||
case PkgManager.zypper:
|
||||
return await client?.run(_wrap('zypper lu')).string;
|
||||
case PkgManager.pacman:
|
||||
await client?.run('pacman -Sy');
|
||||
return await client?.run(_wrap('pacman -Qu')).string;
|
||||
case PkgManager.opkg:
|
||||
await client?.run('opkg update');
|
||||
return await client?.run(_wrap('opkg list-upgradable')).string;
|
||||
default:
|
||||
error = 'Unsupported dist: $dist';
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> upgrade() async {
|
||||
final upgradeCmd = () {
|
||||
switch (type) {
|
||||
case PkgManager.yum:
|
||||
return 'yum upgrade -y';
|
||||
case PkgManager.apt:
|
||||
return 'apt upgrade -y';
|
||||
case PkgManager.zypper:
|
||||
return 'zypper up -y';
|
||||
case PkgManager.pacman:
|
||||
return 'pacman -Syu --noconfirm';
|
||||
case PkgManager.opkg:
|
||||
return 'opkg upgrade ${upgradeable?.map((e) => e.package).join(" ")}';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}();
|
||||
|
||||
if (upgradeCmd == null) {
|
||||
error = 'Unsupported dist: $dist';
|
||||
return;
|
||||
}
|
||||
|
||||
await client!.exec(
|
||||
_wrap(upgradeCmd),
|
||||
onStderr: _onPwd,
|
||||
onStdout: (log, sink) {
|
||||
if (lastLog == log.trim()) return;
|
||||
upgradeLog = (upgradeLog ?? '') + log;
|
||||
lastLog = log.trim();
|
||||
notifyListeners();
|
||||
if (onUpgrade != null) onUpgrade!();
|
||||
},
|
||||
);
|
||||
|
||||
upgradeLog = null;
|
||||
refresh();
|
||||
}
|
||||
|
||||
Future<void> _onPwd(String event, StreamSink<Uint8List> stdin) async {
|
||||
if (isRequestingPwd) return;
|
||||
isRequestingPwd = true;
|
||||
if (event.contains('[sudo] password for ')) {
|
||||
final user = pwdRequestWithUserReg.firstMatch(event)?.group(1);
|
||||
logger.info('sudo password request for $user');
|
||||
final pwd = await onPasswordRequest!();
|
||||
if (pwd.isEmpty) {
|
||||
logger.info('sudo password request cancelled');
|
||||
return;
|
||||
}
|
||||
stdin.add('$pwd\n'.uint8List);
|
||||
}
|
||||
isRequestingPwd = false;
|
||||
}
|
||||
|
||||
String _wrap(String cmd) =>
|
||||
'export LANG=en_US.utf-8 && ${isSU ? "" : "sudo -S "}$cmd';
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class PrivateKeyProvider extends BusyProvider {
|
||||
void updateInfo(PrivateKeyInfo old, PrivateKeyInfo newInfo) {
|
||||
final idx = _infos.indexWhere((e) => e.id == old.id);
|
||||
_infos[idx] = newInfo;
|
||||
locator<PrivateKeyStore>().update(old, newInfo);
|
||||
locator<PrivateKeyStore>().put(newInfo);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,104 +1,59 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dartssh2/dartssh2.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:toolbox/core/extension/stringx.dart';
|
||||
import 'package:toolbox/core/provider_base.dart';
|
||||
import 'package:toolbox/data/model/server/cpu_2_status.dart';
|
||||
import 'package:toolbox/data/model/server/cpu_status.dart';
|
||||
import 'package:toolbox/data/model/server/memory.dart';
|
||||
import 'package:toolbox/data/model/server/net_speed.dart';
|
||||
import 'package:toolbox/data/model/server/server_connection_state.dart';
|
||||
import 'package:toolbox/data/model/server/disk_info.dart';
|
||||
import 'package:toolbox/data/model/server/server.dart';
|
||||
import 'package:toolbox/data/model/server/server_private_info.dart';
|
||||
import 'package:toolbox/data/model/server/server_status.dart';
|
||||
import 'package:toolbox/data/model/server/snippet.dart';
|
||||
import 'package:toolbox/data/model/server/tcp_status.dart';
|
||||
import 'package:toolbox/data/store/private_key.dart';
|
||||
import 'package:toolbox/data/store/server.dart';
|
||||
import 'package:toolbox/data/store/setting.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
|
||||
/// Must put this func out of any Class.
|
||||
/// Because of this function is called by [compute] in [ServerProvider.genClient].
|
||||
/// https://stackoverflow.com/questions/51998995/invalid-arguments-illegal-argument-in-isolate-message-object-is-a-closure
|
||||
List<SSHKeyPair> loadIndentity(String key) {
|
||||
return SSHKeyPair.fromPem(key);
|
||||
}
|
||||
import '../../core/extension/uint8list.dart';
|
||||
import '../../core/provider_base.dart';
|
||||
import '../../core/utils/server.dart';
|
||||
import '../../locator.dart';
|
||||
import '../model/server/cpu_status.dart';
|
||||
import '../model/server/disk_info.dart';
|
||||
import '../model/server/memory.dart';
|
||||
import '../model/server/net_speed.dart';
|
||||
import '../model/server/server.dart';
|
||||
import '../model/server/server_private_info.dart';
|
||||
import '../model/server/snippet.dart';
|
||||
import '../model/server/tcp_status.dart';
|
||||
import '../res/server_cmd.dart';
|
||||
import '../res/status.dart';
|
||||
import '../store/server.dart';
|
||||
import '../store/setting.dart';
|
||||
|
||||
class ServerProvider extends BusyProvider {
|
||||
List<ServerInfo> _servers = [];
|
||||
List<ServerInfo> get servers => _servers;
|
||||
List<Server> _servers = [];
|
||||
List<Server> get servers => _servers;
|
||||
final _TryLimiter _limiter = _TryLimiter();
|
||||
|
||||
Timer? _timer;
|
||||
|
||||
final logger = Logger('ServerProvider');
|
||||
|
||||
Memory get emptyMemory =>
|
||||
Memory(total: 1, used: 0, free: 1, shared: 0, cache: 0, avail: 1);
|
||||
|
||||
NetSpeedPart get emptyNetSpeedPart => NetSpeedPart('', 0, 0, 0);
|
||||
|
||||
NetSpeed get emptyNetSpeed =>
|
||||
NetSpeed([emptyNetSpeedPart], [emptyNetSpeedPart]);
|
||||
|
||||
CpuStatus get emptyCpuStatus => CpuStatus('cpu', 0, 0, 0, 0, 0, 0, 0);
|
||||
|
||||
Cpu2Status get emptyCpu2Status =>
|
||||
Cpu2Status([emptyCpuStatus], [emptyCpuStatus], '');
|
||||
|
||||
ServerStatus get emptyStatus => ServerStatus(
|
||||
emptyCpu2Status,
|
||||
emptyMemory,
|
||||
'Loading...',
|
||||
'',
|
||||
[DiskInfo('/', '/', 0, '0', '0', '0')],
|
||||
TcpStatus(0, 0, 0, 0),
|
||||
emptyNetSpeed);
|
||||
final _logger = Logger('SERVER');
|
||||
|
||||
Future<void> loadLocalData() async {
|
||||
setBusyState(true);
|
||||
final infos = locator<ServerStore>().fetch();
|
||||
_servers = List.generate(infos.length, (index) => genInfo(infos[index]));
|
||||
_servers = List.generate(infos.length, (index) => genServer(infos[index]));
|
||||
setBusyState(false);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
ServerInfo genInfo(ServerPrivateInfo spi) {
|
||||
return ServerInfo(
|
||||
spi, emptyStatus, null, ServerConnectionState.disconnected);
|
||||
Server genServer(ServerPrivateInfo spi) {
|
||||
return Server(spi, initStatus, null, ServerState.disconnected);
|
||||
}
|
||||
|
||||
Future<SSHClient> genClient(ServerPrivateInfo spi) async {
|
||||
final socket = await SSHSocket.connect(spi.ip, spi.port);
|
||||
if (spi.pubKeyId == null) {
|
||||
return SSHClient(socket,
|
||||
username: spi.user,
|
||||
onPasswordRequest: () => spi.authorization as String);
|
||||
}
|
||||
final key = locator<PrivateKeyStore>().get(spi.pubKeyId!);
|
||||
return SSHClient(socket,
|
||||
username: spi.user,
|
||||
identities: await compute(loadIndentity, key.privateKey));
|
||||
}
|
||||
|
||||
Future<void> refreshData({ServerPrivateInfo? spi}) async {
|
||||
Future<void> refreshData(
|
||||
{ServerPrivateInfo? spi, bool onlyFailed = false}) async {
|
||||
if (spi != null) {
|
||||
_getData(spi);
|
||||
await _getData(spi);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await Future.wait(_servers.map((s) async {
|
||||
await _getData(s.info);
|
||||
}));
|
||||
} catch (e) {
|
||||
if (e is! RangeError) {
|
||||
rethrow;
|
||||
await Future.wait(_servers.map((s) async {
|
||||
if (onlyFailed) {
|
||||
if (s.cs != ServerState.failed) return;
|
||||
_limiter.resetTryTimes(s.spi.id);
|
||||
}
|
||||
}
|
||||
await _getData(s.spi);
|
||||
}));
|
||||
}
|
||||
|
||||
Future<void> startAutoRefresh() async {
|
||||
@@ -120,212 +75,213 @@ class ServerProvider extends BusyProvider {
|
||||
|
||||
void setDisconnected() {
|
||||
for (var i = 0; i < _servers.length; i++) {
|
||||
_servers[i].connectionState = ServerConnectionState.disconnected;
|
||||
_servers[i].cs = ServerState.disconnected;
|
||||
}
|
||||
_limiter.clear();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void closeServer({ServerPrivateInfo? spi}) {
|
||||
if (spi == null) {
|
||||
for (var i = 0; i < _servers.length; i++) {
|
||||
_servers[i].client?.close();
|
||||
_servers[i].client = null;
|
||||
}
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
final idx = getServerIdx(spi.id);
|
||||
_servers[idx].client?.close();
|
||||
_servers[idx].client = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void addServer(ServerPrivateInfo spi) {
|
||||
_servers.add(genInfo(spi));
|
||||
locator<ServerStore>().put(spi);
|
||||
_servers.add(genServer(spi));
|
||||
notifyListeners();
|
||||
locator<ServerStore>().put(spi);
|
||||
refreshData(spi: spi);
|
||||
}
|
||||
|
||||
void delServer(ServerPrivateInfo info) {
|
||||
final idx = _servers.indexWhere((s) => s.info == info);
|
||||
void delServer(String id) {
|
||||
final idx = getServerIdx(id);
|
||||
_servers[idx].client?.close();
|
||||
_servers.removeAt(idx);
|
||||
notifyListeners();
|
||||
locator<ServerStore>().delete(info);
|
||||
locator<ServerStore>().delete(id);
|
||||
}
|
||||
|
||||
Future<void> updateServer(
|
||||
ServerPrivateInfo old, ServerPrivateInfo newSpi) async {
|
||||
final idx = _servers.indexWhere((e) => e.info == old);
|
||||
final idx = _servers.indexWhere((e) => e.spi.id == old.id);
|
||||
if (idx < 0) {
|
||||
throw RangeError.index(idx, _servers);
|
||||
}
|
||||
_servers[idx].info = newSpi;
|
||||
_servers[idx].client = await genClient(newSpi);
|
||||
_servers[idx].spi = newSpi;
|
||||
locator<ServerStore>().update(old, newSpi);
|
||||
_servers[idx].client = await genClient(newSpi);
|
||||
notifyListeners();
|
||||
refreshData(spi: newSpi);
|
||||
}
|
||||
|
||||
int getServerIdx(String id) {
|
||||
final idx = _servers.indexWhere((s) => s.spi.id == id);
|
||||
if (idx < 0) {
|
||||
throw Exception('Server not found: $id');
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
Server getServer(String id) => _servers[getServerIdx(id)];
|
||||
|
||||
Future<void> _getData(ServerPrivateInfo spi) async {
|
||||
final idx = _servers.indexWhere((element) => element.info == spi);
|
||||
final state = _servers[idx].connectionState;
|
||||
if (_servers[idx].client == null ||
|
||||
state == ServerConnectionState.failed ||
|
||||
state == ServerConnectionState.disconnected) {
|
||||
_servers[idx].connectionState = ServerConnectionState.connecting;
|
||||
final sid = spi.id;
|
||||
final s = getServer(sid);
|
||||
final state = s.cs;
|
||||
if (state.shouldConnect) {
|
||||
if (!_limiter.shouldTry(sid)) {
|
||||
s.cs = ServerState.failed;
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
s.cs = ServerState.connecting;
|
||||
notifyListeners();
|
||||
final time1 = DateTime.now();
|
||||
|
||||
try {
|
||||
_servers[idx].client = await genClient(spi);
|
||||
// try to connect
|
||||
final time1 = DateTime.now();
|
||||
s.client = await genClient(spi);
|
||||
final time2 = DateTime.now();
|
||||
logger.info(
|
||||
'Connected to [${spi.name}] in [${time2.difference(time1).toString()}].');
|
||||
_servers[idx].connectionState = ServerConnectionState.connected;
|
||||
notifyListeners();
|
||||
final spentTime = time2.difference(time1).inMilliseconds;
|
||||
_logger.info('Connected to [$sid] in $spentTime ms.');
|
||||
|
||||
// after connected
|
||||
s.cs = ServerState.connected;
|
||||
final writeResult = await s.client!
|
||||
.run("echo '$shellCmd' > $shellPath && chmod +x $shellPath")
|
||||
.string;
|
||||
|
||||
// if write failed
|
||||
if (writeResult.isNotEmpty) {
|
||||
throw Exception(writeResult);
|
||||
}
|
||||
_limiter.resetTryTimes(sid);
|
||||
} catch (e) {
|
||||
_servers[idx].connectionState = ServerConnectionState.failed;
|
||||
_servers[idx].status.failedInfo = e.toString() + ' ## ';
|
||||
s.cs = ServerState.failed;
|
||||
s.status.failedInfo = '$e';
|
||||
_logger.warning(e);
|
||||
} finally {
|
||||
notifyListeners();
|
||||
logger.warning(e);
|
||||
}
|
||||
}
|
||||
final si = _servers[idx];
|
||||
try {
|
||||
if (si.client == null) return;
|
||||
final raw = utf8.decode(await si.client!.run(
|
||||
r"cat /proc/net/dev && date +%s && echo 'A====A' && cat /etc/os-release | grep PRETTY_NAME && echo 'A====A' && cat /proc/stat | grep cpu && echo 'A====A' && paste <(cat /sys/class/thermal/thermal_zone*/type) <(cat /sys/class/thermal/thermal_zone*/temp) | column -s $'\t' -t | sed 's/\(.\)..$/.\1°C/' && echo 'A====A' && uptime && echo 'A====A' && cat /proc/net/snmp && echo 'A====A' && df -h && echo 'A====A' && free -m"));
|
||||
final lines = raw.split('A====A').map((e) => e.trim()).toList();
|
||||
_getCPU(spi, lines[2], lines[3]);
|
||||
_getMem(spi, lines[7]);
|
||||
_getSysVer(spi, lines[1]);
|
||||
_getUpTime(spi, lines[4]);
|
||||
_getDisk(spi, lines[6]);
|
||||
_getTcp(spi, lines[5]);
|
||||
_getNetSpeed(spi, lines[0]);
|
||||
} catch (e) {
|
||||
_servers[idx].connectionState = ServerConnectionState.failed;
|
||||
servers[idx].status.failedInfo = e.toString();
|
||||
|
||||
if (s.client == null) return;
|
||||
// run script to get server status
|
||||
final raw = await s.client!.run("sh $shellPath").string;
|
||||
final segments = raw.split(seperator).map((e) => e.trim()).toList();
|
||||
if (raw.isEmpty || segments.length == 1) {
|
||||
s.cs = ServerState.failed;
|
||||
if (s.status.failedInfo == null || s.status.failedInfo!.isEmpty) {
|
||||
s.status.failedInfo = 'Seperate segments failed, raw:\n$raw';
|
||||
}
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
// remove first empty segment
|
||||
segments.removeAt(0);
|
||||
|
||||
try {
|
||||
_getCPU(sid, segments[2], segments[7], segments[8]);
|
||||
_getMem(sid, segments[6]);
|
||||
_getSysVer(sid, segments[1]);
|
||||
_getUpTime(sid, segments[3]);
|
||||
_getDisk(sid, segments[5]);
|
||||
_getTcp(sid, segments[4]);
|
||||
_getNetSpeed(sid, segments[0]);
|
||||
} catch (e) {
|
||||
s.cs = ServerState.failed;
|
||||
s.status.failedInfo = e.toString();
|
||||
_logger.warning(e);
|
||||
rethrow;
|
||||
} finally {
|
||||
notifyListeners();
|
||||
logger.warning(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// [raw] example:
|
||||
/// Inter-| Receive | Transmit
|
||||
/// face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
|
||||
/// lo: 45929941 269112 0 0 0 0 0 0 45929941 269112 0 0 0 0 0 0
|
||||
/// eth0: 48481023 505772 0 0 0 0 0 0 36002262 202307 0 0 0 0 0 0
|
||||
/// 1635752901
|
||||
void _getNetSpeed(ServerPrivateInfo spi, String raw) {
|
||||
final info = _servers.firstWhere((e) => e.info == spi);
|
||||
final split = raw.split('\n');
|
||||
final deviceCount = split.length - 3;
|
||||
if (deviceCount < 1) return;
|
||||
final time = int.parse(split[split.length - 1]);
|
||||
final results = <NetSpeedPart>[];
|
||||
for (int idx = 2; idx < deviceCount; idx++) {
|
||||
final data = split[idx].trim().split(':');
|
||||
final device = data.first;
|
||||
final bytes = data.last.trim().split(' ');
|
||||
bytes.removeWhere((element) => element == '');
|
||||
final bytesIn = int.parse(bytes.first);
|
||||
final bytesOut = int.parse(bytes[8]);
|
||||
results.add(NetSpeedPart(device, bytesIn, bytesOut, time));
|
||||
}
|
||||
info.status.netSpeed = info.status.netSpeed.update(results);
|
||||
notifyListeners();
|
||||
Future<void> _getNetSpeed(String id, String raw) async {
|
||||
final net = await compute(parseNetSpeed, raw);
|
||||
getServer(id).status.netSpeed.update(net);
|
||||
}
|
||||
|
||||
void _getSysVer(ServerPrivateInfo spi, String raw) {
|
||||
final info = _servers.firstWhere((e) => e.info == spi);
|
||||
void _getSysVer(String id, String raw) {
|
||||
final s = raw.split('=');
|
||||
if (s.length == 2) {
|
||||
info.status.sysVer = s[1].replaceAll('"', '').replaceFirst('\n', '');
|
||||
final ver = s[1].replaceAll('"', '').replaceFirst('\n', '');
|
||||
getServer(id).status.sysVer = ver;
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
String _getCPUTemp(String raw) {
|
||||
final split = raw.split('\n');
|
||||
for (var item in split) {
|
||||
if (item.contains('x86_pkg_temp') || item.contains('cpu_thermal')) {
|
||||
return item.split(' ').last;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
Future<void> _getCPU(
|
||||
String id, String raw, String tempType, String tempValue) async {
|
||||
final cpus = await compute(parseCPU, raw);
|
||||
final temp = await compute(parseCPUTemp, [tempType, tempValue]);
|
||||
|
||||
void _getCPU(ServerPrivateInfo spi, String raw, String temp) {
|
||||
final info = _servers.firstWhere((e) => e.info == spi);
|
||||
final List<CpuStatus> cpus = [];
|
||||
|
||||
for (var item in raw.split('\n')) {
|
||||
if (item == '') break;
|
||||
final id = item.split(' ').first;
|
||||
final matches = item.replaceFirst(id, '').trim().split(' ');
|
||||
cpus.add(CpuStatus(
|
||||
id,
|
||||
int.parse(matches[0]),
|
||||
int.parse(matches[1]),
|
||||
int.parse(matches[2]),
|
||||
int.parse(matches[3]),
|
||||
int.parse(matches[4]),
|
||||
int.parse(matches[5]),
|
||||
int.parse(matches[6])));
|
||||
}
|
||||
if (cpus.isNotEmpty) {
|
||||
info.status.cpu2Status =
|
||||
info.status.cpu2Status.update(cpus, _getCPUTemp(temp));
|
||||
getServer(id).status.cpu.update(cpus, temp);
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _getUpTime(ServerPrivateInfo spi, String raw) {
|
||||
_servers.firstWhere((e) => e.info == spi).status.uptime =
|
||||
raw.split('up ')[1].split(', ')[0];
|
||||
notifyListeners();
|
||||
void _getUpTime(String id, String raw) {
|
||||
getServer(id).status.uptime = raw.split('up ')[1].split(', ')[0];
|
||||
}
|
||||
|
||||
void _getTcp(ServerPrivateInfo spi, String raw) {
|
||||
final info = _servers.firstWhere((e) => e.info == spi);
|
||||
final lines = raw.split('\n');
|
||||
final idx = lines.lastWhere((element) => element.startsWith('Tcp:'),
|
||||
orElse: () => '');
|
||||
if (idx != '') {
|
||||
final vals = idx.split(RegExp(r'\s{1,}'));
|
||||
info.status.tcp = TcpStatus(vals[5].i, vals[6].i, vals[7].i, vals[8].i);
|
||||
Future<void> _getTcp(String id, String raw) async {
|
||||
final status = await compute(parseTcp, raw);
|
||||
if (status != null) {
|
||||
getServer(id).status.tcp = status;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _getDisk(ServerPrivateInfo spi, String raw) {
|
||||
final info = _servers.firstWhere((e) => e.info == spi);
|
||||
final list = <DiskInfo>[];
|
||||
final items = raw.split('\n');
|
||||
for (var item in items) {
|
||||
if (items.indexOf(item) == 0 || item.isEmpty) {
|
||||
continue;
|
||||
}
|
||||
final vals = item.split(RegExp(r'\s{1,}'));
|
||||
list.add(DiskInfo(vals[0], vals[5],
|
||||
int.parse(vals[4].replaceFirst('%', '')), vals[2], vals[1], vals[3]));
|
||||
Future<void> _getDisk(String id, String raw) async {
|
||||
getServer(id).status.disk = await compute(parseDisk, raw);
|
||||
}
|
||||
|
||||
Future<void> _getMem(String id, String raw) async {
|
||||
final s = getServer(id);
|
||||
s.status.mem = await compute(parseMem, raw);
|
||||
s.status.swap = await compute(parseSwap, raw);
|
||||
}
|
||||
|
||||
Future<String?> runSnippet(String id, Snippet snippet) async {
|
||||
final client = getServer(id).client;
|
||||
if (client == null) {
|
||||
return null;
|
||||
}
|
||||
info.status.disk = list;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void _getMem(ServerPrivateInfo spi, String raw) {
|
||||
final info = _servers.firstWhere((e) => e.info == spi);
|
||||
for (var item in raw.split('\n')) {
|
||||
if (item.contains('Mem:')) {
|
||||
final split = item.replaceFirst('Mem:', '').split(' ');
|
||||
split.removeWhere((e) => e == '');
|
||||
final memList = split.map((e) => int.parse(e)).toList();
|
||||
info.status.memory = Memory(
|
||||
total: memList[0],
|
||||
used: memList[1],
|
||||
free: memList[2],
|
||||
shared: memList[3],
|
||||
cache: memList[4],
|
||||
avail: memList[5]);
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<String?> runSnippet(ServerPrivateInfo spi, Snippet snippet) async {
|
||||
final result = await _servers
|
||||
.firstWhere((element) => element.info == spi)
|
||||
.client!
|
||||
.run(snippet.script);
|
||||
return utf8.decode(result);
|
||||
return await client.run(snippet.script).string;
|
||||
}
|
||||
}
|
||||
|
||||
class _TryLimiter {
|
||||
final Map<String, int> _triedTimes = {};
|
||||
|
||||
bool shouldTry(String id) {
|
||||
final maxCount = locator<SettingStore>().maxRetryCount.fetch()!;
|
||||
if (maxCount <= 0) {
|
||||
return true;
|
||||
}
|
||||
final times = _triedTimes[id] ?? 0;
|
||||
if (times >= maxCount) {
|
||||
return false;
|
||||
}
|
||||
_triedTimes[id] = times + 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
void resetTryTimes(String id) {
|
||||
_triedTimes[id] = 0;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_triedTimes.clear();
|
||||
}
|
||||
}
|
||||
|
||||
32
lib/data/provider/sftp_download.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
import 'package:toolbox/core/provider_base.dart';
|
||||
|
||||
import '../model/sftp/download_item.dart';
|
||||
import '../model/sftp/download_status.dart';
|
||||
|
||||
class SftpDownloadProvider extends ProviderBase {
|
||||
final List<SftpDownloadStatus> _status = [];
|
||||
List<SftpDownloadStatus> get status => _status;
|
||||
|
||||
List<SftpDownloadStatus> gets({int? id, String? fileName}) {
|
||||
var found = <SftpDownloadStatus>[];
|
||||
if (id != null) {
|
||||
found = _status.where((e) => e.id == id).toList();
|
||||
}
|
||||
if (fileName != null) {
|
||||
found = found
|
||||
.where((e) => e.item.localPath.split('/').last == fileName)
|
||||
.toList();
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
SftpDownloadStatus? get({int? id, String? name}) {
|
||||
final found = gets(id: id, fileName: name);
|
||||
if (found.isEmpty) return null;
|
||||
return found.first;
|
||||
}
|
||||
|
||||
void add(DownloadItem item, {String? key}) {
|
||||
_status.add(SftpDownloadStatus(item, notifyListeners, key: key));
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:toolbox/core/provider_base.dart';
|
||||
import 'package:toolbox/data/model/server/snippet.dart';
|
||||
import 'package:toolbox/data/store/snippet.dart';
|
||||
@@ -11,22 +13,34 @@ class SnippetProvider extends BusyProvider {
|
||||
_snippets = locator<SnippetStore>().fetch();
|
||||
}
|
||||
|
||||
void addInfo(Snippet snippet) {
|
||||
void add(Snippet snippet) {
|
||||
if (have(snippet)) return;
|
||||
_snippets.add(snippet);
|
||||
locator<SnippetStore>().put(snippet);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void delInfo(Snippet snippet) {
|
||||
_snippets.removeWhere((e) => e.name == snippet.name);
|
||||
void del(Snippet snippet) {
|
||||
if (!have(snippet)) return;
|
||||
_snippets.removeAt(index(snippet));
|
||||
locator<SnippetStore>().delete(snippet);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void updateInfo(Snippet old, Snippet newOne) {
|
||||
final idx = _snippets.indexWhere((e) => e.name == old.name);
|
||||
_snippets[idx] = newOne;
|
||||
locator<SnippetStore>().update(old, newOne);
|
||||
int index(Snippet snippet) {
|
||||
return _snippets.indexWhere((e) => e.name == snippet.name);
|
||||
}
|
||||
|
||||
bool have(Snippet snippet) {
|
||||
return index(snippet) != -1;
|
||||
}
|
||||
|
||||
void update(Snippet old, Snippet newOne) {
|
||||
if (!have(old)) return;
|
||||
_snippets[index(old)] = newOne;
|
||||
locator<SnippetStore>().put(newOne);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
String get export => json.encode(snippets);
|
||||
}
|
||||
|
||||
29
lib/data/provider/virtual_keyboard.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:xterm/core.dart';
|
||||
|
||||
class VirtualKeyboard extends TerminalInputHandler with ChangeNotifier {
|
||||
VirtualKeyboard();
|
||||
|
||||
bool ctrl = false;
|
||||
bool alt = false;
|
||||
|
||||
void reset(TerminalKeyboardEvent e) {
|
||||
if (e.ctrl) {
|
||||
ctrl = false;
|
||||
}
|
||||
if (e.alt) {
|
||||
alt = false;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
String? call(TerminalKeyboardEvent event) {
|
||||
final e = event.copyWith(
|
||||
ctrl: event.ctrl || ctrl,
|
||||
alt: event.alt || alt,
|
||||
);
|
||||
reset(e);
|
||||
return defaultInputHandler.call(e);
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ServerBox";
|
||||
static const int build = 95;
|
||||
static const int build = 227;
|
||||
static const String engine =
|
||||
"Flutter 2.10.0 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 5f105a6ca7 (7 days ago) • 2022-02-01 14:15:42 -0800\nEngine • revision 776efd2034\nTools • Dart 2.16.0 • DevTools 2.9.2\n";
|
||||
static const String buildAt = "2022-02-08 21:30:51.218738";
|
||||
static const int modifications = 3;
|
||||
"Flutter 3.7.3 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 9944297138 (2 weeks ago) • 2023-02-08 15:46:04 -0800\nEngine • revision 248290d6d5\nTools • Dart 2.19.2 • DevTools 2.20.1\n";
|
||||
static const String buildAt = "2023-02-25 18:23:00.718232";
|
||||
static const int modifications = 13;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toolbox/core/utils.dart';
|
||||
import 'package:toolbox/data/store/setting.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
|
||||
Color get primaryColor => Color(locator<SettingStore>().primaryColor.fetch()!);
|
||||
import '../model/app/dynamic_color.dart';
|
||||
|
||||
class DynamicColor {
|
||||
/// 白天模式显示的颜色
|
||||
Color light;
|
||||
Color primaryColor = Color(locator<SettingStore>().primaryColor.fetch()!);
|
||||
|
||||
/// 暗黑模式显示的颜色
|
||||
Color dark;
|
||||
|
||||
DynamicColor(this.light, this.dark);
|
||||
|
||||
resolve(BuildContext context) => isDarkMode(context) ? dark : light;
|
||||
}
|
||||
|
||||
final mainColor = DynamicColor(Colors.black87, Colors.white70);
|
||||
final progressColor = DynamicColor(Colors.grey.shade100, Colors.grey);
|
||||
final contentColor = DynamicColor(Colors.black87, Colors.white70);
|
||||
final bgColor = DynamicColor(Colors.white, Colors.black);
|
||||
final progressColor = DynamicColor(Colors.grey.shade100, Colors.white10);
|
||||
|
||||
28
lib/data/res/error.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
enum ErrFrom {
|
||||
unknown,
|
||||
apt,
|
||||
docker,
|
||||
sftp,
|
||||
ssh,
|
||||
}
|
||||
|
||||
abstract class Err<T> {
|
||||
final ErrFrom from;
|
||||
final T type;
|
||||
final String? message;
|
||||
|
||||
Err({required this.from, required this.type, this.message});
|
||||
}
|
||||
|
||||
enum DockerErrType {
|
||||
unknown,
|
||||
noClient,
|
||||
notInstalled,
|
||||
invalidVersion,
|
||||
cmdNoPrefix
|
||||
}
|
||||
|
||||
class DockerErr extends Err<DockerErrType> {
|
||||
DockerErr({required DockerErrType type, String? message})
|
||||
: super(from: ErrFrom.docker, type: type, message: message);
|
||||
}
|
||||
9
lib/data/res/font_style.dart
Normal file
@@ -0,0 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
const textSize18 = TextStyle(fontSize: 18);
|
||||
const textSize11 = TextStyle(fontSize: 11);
|
||||
const textSize13 = TextStyle(fontSize: 13);
|
||||
const textSize13Grey = TextStyle(color: Colors.grey, fontSize: 13);
|
||||
const textSize27 = TextStyle(fontSize: 27);
|
||||
|
||||
const grey = TextStyle(color: Colors.grey);
|
||||
@@ -1,4 +0,0 @@
|
||||
import 'package:toolbox/data/model/server/linux_icon.dart';
|
||||
|
||||
final linuxIcons = LinuxIcons(
|
||||
['ubuntu', 'arch', 'centos', 'debian', 'fedora', 'opensuse', 'kali']);
|
||||
43
lib/data/res/menu.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import '../../view/widget/dropdown_menu.dart';
|
||||
|
||||
class ServerTabMenuItems {
|
||||
static const List<DropdownBtnItem> firstItems = [sftp, snippet, pkg, docker];
|
||||
static const List<DropdownBtnItem> secondItems = [edit];
|
||||
|
||||
static const sftp =
|
||||
DropdownBtnItem(text: 'SFTP', icon: Icons.insert_drive_file);
|
||||
static const snippet = DropdownBtnItem(text: 'Snippet', icon: Icons.code);
|
||||
static const pkg =
|
||||
DropdownBtnItem(text: 'Pkg', icon: Icons.system_security_update);
|
||||
static const docker =
|
||||
DropdownBtnItem(text: 'Docker', icon: Icons.view_agenda);
|
||||
static const edit = DropdownBtnItem(text: 'Edit', icon: Icons.edit);
|
||||
}
|
||||
|
||||
class DockerMenuItems {
|
||||
static const rm = DropdownBtnItem(text: 'Remove', icon: Icons.delete);
|
||||
static const start = DropdownBtnItem(text: 'Start', icon: Icons.play_arrow);
|
||||
static const stop = DropdownBtnItem(text: 'Stop', icon: Icons.stop);
|
||||
}
|
||||
|
||||
String getDropdownBtnText(S s, String text) {
|
||||
switch (text) {
|
||||
case 'Snippet':
|
||||
return s.snippet;
|
||||
case 'Pkg':
|
||||
return s.pkg;
|
||||
case 'Remove':
|
||||
return s.delete;
|
||||
case 'Start':
|
||||
return s.start;
|
||||
case 'Stop':
|
||||
return s.stop;
|
||||
case 'Edit':
|
||||
return s.edit;
|
||||
default:
|
||||
return text;
|
||||
}
|
||||
}
|
||||
7
lib/data/res/misc.dart
Normal file
@@ -0,0 +1,7 @@
|
||||
final numReg = RegExp(r'\s{1,}');
|
||||
|
||||
/// Private Key max allowed size is 20kb
|
||||
const privateKeyMaxSize = 20 * 1024;
|
||||
|
||||
/// Max debug log lines
|
||||
const maxDebugLogLines = 100;
|
||||
@@ -1,3 +1,3 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
const roundRectCardPadding = EdgeInsets.symmetric(horizontal: 17);
|
||||
const roundRectCardPadding = EdgeInsets.symmetric(horizontal: 17, vertical: 13);
|
||||
|
||||
10
lib/data/res/path.dart
Normal file
@@ -0,0 +1,10 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
Future<Directory> get docDir async => await getApplicationDocumentsDirectory();
|
||||
|
||||
Future<Directory> get sftpDownloadDir async {
|
||||
final dir = Directory('${(await docDir).path}/sftp');
|
||||
return dir.create(recursive: true);
|
||||
}
|
||||