mirror of
https://github.com/venera-app/venera.git
synced 2025-12-16 15:11:14 +00:00
Compare commits
224 Commits
v1.3.3
...
version-1.
| Author | SHA1 | Date | |
|---|---|---|---|
| e87fb535b8 | |||
| 09a1d2821c | |||
|
|
7842b5a1ac | ||
|
|
079f574e2f | ||
|
|
b08f11f6ac | ||
|
|
cd925df125 | ||
|
|
8c87c4a906 | ||
|
|
c234a53518 | ||
| 49fd64358c | |||
| 3426d707fe | |||
| ebc106d45b | |||
| 0cda9a2921 | |||
| 0eb5d76687 | |||
| 29d25f7fcd | |||
| 7d60e78f27 | |||
|
|
e93b56a008 | ||
|
|
d10873a903 | ||
|
|
2d27f7d650 | ||
| e1fbdfbd50 | |||
| 0a5b70b161 | |||
|
|
5a76a10fb2 | ||
| 9173665afe | |||
|
|
f09e766a8a | ||
| e0ea449c17 | |||
| c438a84537 | |||
| 8c625e212a | |||
| ab786ed2ab | |||
| d9303aab2e | |||
|
|
b7f79476c8 | ||
|
|
44bcce4385 | ||
|
|
6ce6066de2 | ||
|
|
7fa48cec29 | ||
| e549a18dbf | |||
| c17c4abb5b | |||
| af57bc31b1 | |||
| 16449a1440 | |||
| a7c1983f35 | |||
| 4c257d7178 | |||
| 3a9d634edf | |||
|
|
e179c8f67f | ||
|
|
c4b85471c1 | ||
|
|
a898b57d96 | ||
| 50c6bec4cd | |||
|
|
8c44f83d6c | ||
|
|
103b6b2832 | ||
| 4129349c70 | |||
| 77a9aa5457 | |||
| 97940b9492 | |||
| 7945c0e54f | |||
| dfee65c3af | |||
| fa2dbd79f6 | |||
| 9a9f539906 | |||
| d7331f36e9 | |||
|
|
d0b76de465 | ||
| 894a922b8f | |||
| a91d7fff2d | |||
|
|
926a3a530e | ||
| d308c2ac60 | |||
| ac13807ef4 | |||
| 38a5b2b8cf | |||
| 3a7c8d5e38 | |||
|
|
ce0d10aeb2 | ||
|
|
0ac857ef9a | ||
| 3928f5afe7 | |||
| 8a61a4750b | |||
|
|
1bc3fef47b | ||
|
|
4dac132bee | ||
|
|
7c60c00962 | ||
| 9d8ade6fe0 | |||
| 6245399810 | |||
| c074e7f9d1 | |||
| f822e198ea | |||
| 7035f11eb5 | |||
| f2f5a4f573 | |||
| 2acf234f7d | |||
| 9ed8f351c7 | |||
| 7c35dc7cf7 | |||
|
|
17b8b9ea8f | ||
| ccb03343f4 | |||
|
|
951bcae603 | ||
|
|
0b9de68c86 | ||
|
|
81b27fd941 | ||
|
|
b9817ec030 | ||
|
|
5ebb554e54 | ||
|
|
d5d72911ed | ||
|
|
838d5c9c3e | ||
| 23ee79fe9d | |||
|
|
85baac657a | ||
|
|
cceca6b96f | ||
|
|
b5b0dc85e3 | ||
|
|
50044c4372 | ||
|
|
5fd7f1b880 | ||
|
|
058fde3f5a | ||
|
|
a2d46123dd | ||
|
|
01acc4f9de | ||
|
|
856aae0769 | ||
|
|
8eda8adcc8 | ||
| defd4b8624 | |||
| b2a164e066 | |||
| a46ceebf19 | |||
| cc08445f13 | |||
| 93f7f72d07 | |||
| 20f7ab4866 | |||
| 54363919cd | |||
| 182a821fc5 | |||
| 8868c6edb3 | |||
|
|
fffbb4ed23 | ||
|
|
b057be0311 | ||
|
|
fc5fed1707 | ||
|
|
8525f5318f | ||
|
|
d58cafc4a0 | ||
| 23afafd1d6 | |||
|
|
3b6e0adbbb | ||
| 20a57c7a36 | |||
| 665f50ed2a | |||
| 55733ef505 | |||
| 0c46214619 | |||
| 749a1a47fb | |||
| 76e9ef87d4 | |||
| dcd6466547 | |||
| ed70fdba93 | |||
| ded0068ea6 | |||
|
|
7dc6be622a | ||
|
|
88f093f7e5 | ||
| 8f357b3e6c | |||
| 9ee82975e8 | |||
|
|
9f048685e4 | ||
|
|
bc1f5e11b5 | ||
| 1f2147ef72 | |||
| fba365fd93 | |||
| a5e3fbaee5 | |||
| 190e645a12 | |||
|
|
8a83ff5367 | ||
| 6e14942dab | |||
| 146fc70143 | |||
| b37ea01aca | |||
| bf7b90313a | |||
| 929c1a9d91 | |||
| 9ff68d0701 | |||
| dfd15ed34a | |||
|
|
dfe2a0db6a | ||
| c6714f79b6 | |||
| 552a42fb27 | |||
| af456c52f1 | |||
| f38129133a | |||
| 17e2696ca4 | |||
| 9d6999af33 | |||
| ae5548918c | |||
| 92d22c977c | |||
| 8cc3702e1a | |||
| 3131ce52a7 | |||
| 62e4056f4a | |||
| a29a7cbaf3 | |||
| 7bdab7ade7 | |||
| ea99e87afb | |||
| 0d3fde9457 | |||
| aa9f4dae82 | |||
| 6877aa120f | |||
| d25d72a5f7 | |||
|
|
97768b4945 | ||
| 2481780ab3 | |||
|
|
49481bfa6a | ||
| 211850d73e | |||
| fcf0334d55 | |||
| aa8eec5792 | |||
| 6eb0060dd6 | |||
| c096f5a2d8 | |||
| 554b9f2a77 | |||
| f87afbe397 | |||
| 6ff30f8ac3 | |||
| 118941f239 | |||
| d91bca6913 | |||
| 463ad5b5bc | |||
| 971fc1da92 | |||
| 37af7e266a | |||
| 276e23354d | |||
| 3da00595b7 | |||
|
|
d3c115ee0c | ||
| dcc94c5b3d | |||
| a116b5b615 | |||
| 05fcb23a4d | |||
| daa6e8ce18 | |||
| 8665994572 | |||
| 90441af989 | |||
| 7631fab86b | |||
| cd9b07bb3e | |||
| 6c179ceb95 | |||
| ec48dbef57 | |||
| cd1cc1229e | |||
|
|
bda299e1f8 | ||
|
|
78ea129564 | ||
|
|
f3b4598bb6 | ||
|
|
7bc4c69a32 | ||
|
|
a8e55e0151 | ||
|
|
fddd959545 | ||
|
|
ebf6846bf1 | ||
| 0f2d0bb9f9 | |||
| 48338e4ef7 | |||
| 8d8e345d82 | |||
|
|
fcbf6a6277 | ||
| d83d679eb9 | |||
| d6087e5f59 | |||
| 37371bee6c | |||
| 45fe5f503a | |||
| d440ed6424 | |||
| d812332613 | |||
| dee8d17b1e | |||
|
|
c0d461ebd9 | ||
|
|
45e2a1142a | ||
|
|
533c2b2507 | ||
|
|
29b7e0d646 | ||
| b1870b65d6 | |||
| 1103076009 | |||
| 51739355c8 | |||
| 1b4f67b314 | |||
| d9b23dadf0 | |||
| ba8831caa6 | |||
| 2b1684b0fc | |||
| cd3f09efae | |||
| d05eaf8c7e | |||
| 03628f2afa | |||
|
|
9dae28e366 | ||
|
|
11e66328c4 | ||
|
|
73d4e28ed0 |
4
.github/workflows/fastlane.yml
vendored
4
.github/workflows/fastlane.yml
vendored
@@ -4,8 +4,12 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches: [ "master" ]
|
branches: [ "master" ]
|
||||||
|
paths:
|
||||||
|
- 'fastlane/**'
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "master" ]
|
branches: [ "master" ]
|
||||||
|
paths:
|
||||||
|
- 'fastlane/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
go:
|
go:
|
||||||
|
|||||||
29
.github/workflows/issue_check.yml
vendored
Normal file
29
.github/workflows/issue_check.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
name: Check Issue
|
||||||
|
|
||||||
|
on:
|
||||||
|
issues:
|
||||||
|
types: [opened]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
issues: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check:
|
||||||
|
name: Check Issue
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
id: checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Check Issue
|
||||||
|
id: check
|
||||||
|
uses: wgh136/gpt_issue_checker@v1.0.2
|
||||||
|
with:
|
||||||
|
api-url: ${{ secrets.API_URL }}
|
||||||
|
api-key: ${{ secrets.API_KEY }}
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
prompt: "You are a repository issue checker. The project is a comic app that supports view local or network comics using config files. To view a comic source, user must add a config file. User should not report any issue related to config file to the project repository because there is another repository for managing config files. You are given an issue content and you need to decide whether to close the issue. If you decide to close the issue, you should also provide a comment explaining why you are closing the issue. If you decide not to close the issue, you should provide a comment which is a summary of the issue. You should response with a JSON object with the following keys: should_close, should_comment, comment."
|
||||||
|
model: "gpt-4o"
|
||||||
104
.github/workflows/main.yml
vendored
104
.github/workflows/main.yml
vendored
@@ -15,7 +15,7 @@ jobs:
|
|||||||
channel: "stable"
|
channel: "stable"
|
||||||
flutter-version-file: pubspec.yaml
|
flutter-version-file: pubspec.yaml
|
||||||
architecture: x64
|
architecture: x64
|
||||||
- run: sudo xcode-select --switch /Applications/Xcode_16.0.app
|
- run: sudo xcode-select --switch /Applications/Xcode_16.4.app
|
||||||
- run: flutter pub get
|
- run: flutter pub get
|
||||||
# Step 1: Decode and install the certificate
|
# Step 1: Decode and install the certificate
|
||||||
- name: Decode and install certificate
|
- name: Decode and install certificate
|
||||||
@@ -26,6 +26,9 @@ jobs:
|
|||||||
echo "$CERTIFICATE" | base64 --decode > signing_certificate.p12
|
echo "$CERTIFICATE" | base64 --decode > signing_certificate.p12
|
||||||
security import signing_certificate.p12 -k ~/Library/Keychains/login.keychain -P "$CERTIFICATE_PASSWORD" -T /usr/bin/codesign
|
security import signing_certificate.p12 -k ~/Library/Keychains/login.keychain -P "$CERTIFICATE_PASSWORD" -T /usr/bin/codesign
|
||||||
|
|
||||||
|
- name: Check rust-toolchain.toml
|
||||||
|
run: rustup show
|
||||||
|
|
||||||
# Step 2: Build the Flutter macOS app
|
# Step 2: Build the Flutter macOS app
|
||||||
- name: Build Flutter macOS App
|
- name: Build Flutter macOS App
|
||||||
run: flutter build macos --release
|
run: flutter build macos --release
|
||||||
@@ -60,7 +63,7 @@ jobs:
|
|||||||
channel: "stable"
|
channel: "stable"
|
||||||
flutter-version-file: pubspec.yaml
|
flutter-version-file: pubspec.yaml
|
||||||
architecture: x64
|
architecture: x64
|
||||||
- run: sudo xcode-select --switch /Applications/Xcode_16.0.app
|
- run: sudo xcode-select --switch /Applications/Xcode_16.4.app
|
||||||
- run: flutter pub get
|
- run: flutter pub get
|
||||||
- run: flutter build ios --release --no-codesign
|
- run: flutter build ios --release --no-codesign
|
||||||
- run: |
|
- run: |
|
||||||
@@ -97,10 +100,8 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
distribution: 'oracle'
|
distribution: 'oracle'
|
||||||
java-version: '17'
|
java-version: '17'
|
||||||
- name: Setup Rust
|
- name: Check rust-toolchain.toml
|
||||||
run: |
|
run: rustup show
|
||||||
rustup update
|
|
||||||
rustup default stable
|
|
||||||
- run: flutter pub get
|
- run: flutter pub get
|
||||||
- run: flutter build apk --release
|
- run: flutter build apk --release
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v4
|
||||||
@@ -115,6 +116,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
choco install yq -y
|
choco install yq -y
|
||||||
pip install httpx
|
pip install httpx
|
||||||
|
- name: Install Inno Setup
|
||||||
|
run: choco install innosetup --no-progress
|
||||||
- uses: subosito/flutter-action@v2
|
- uses: subosito/flutter-action@v2
|
||||||
with:
|
with:
|
||||||
channel: "stable"
|
channel: "stable"
|
||||||
@@ -148,45 +151,6 @@ jobs:
|
|||||||
sudo rm -rf build/linux/arch/pkg
|
sudo rm -rf build/linux/arch/pkg
|
||||||
sudo rm -rf build/linux/arch/src
|
sudo rm -rf build/linux/arch/src
|
||||||
sudo rm -rf build/linux/arch/PKGBUILD
|
sudo rm -rf build/linux/arch/PKGBUILD
|
||||||
- name: Build AppImage
|
|
||||||
run: |
|
|
||||||
sudo apt-get install -y libfuse2
|
|
||||||
wget -O appimagetool "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage"
|
|
||||||
chmod +x appimagetool
|
|
||||||
|
|
||||||
mkdir -p Venera.AppDir
|
|
||||||
cp -r build/linux/x64/release/bundle/* Venera.AppDir/
|
|
||||||
|
|
||||||
cat > Venera.AppDir/venera.desktop << EOF
|
|
||||||
[Desktop Entry]
|
|
||||||
Name=Venera
|
|
||||||
Exec=venera
|
|
||||||
Icon=venera
|
|
||||||
Type=Application
|
|
||||||
Categories=Utility;
|
|
||||||
EOF
|
|
||||||
|
|
||||||
cp assets/app_icon.png Venera.AppDir/venera.png
|
|
||||||
|
|
||||||
cat > Venera.AppDir/AppRun << EOF
|
|
||||||
#!/bin/sh
|
|
||||||
HERE=\$(dirname \$(readlink -f "\${0}"))
|
|
||||||
export PATH="\${HERE}"/usr/bin/:"\${HERE}"/usr/sbin/:"\${HERE}"/usr/games/:"\${HERE}"/bin/:"\${HERE}"/sbin/:\${PATH}
|
|
||||||
export LD_LIBRARY_PATH="\${HERE}"/usr/lib/:\${LD_LIBRARY_PATH}
|
|
||||||
export XDG_DATA_DIRS="\${HERE}"/usr/share/:\${XDG_DATA_DIRS}
|
|
||||||
exec "\${HERE}"/venera "\$@"
|
|
||||||
EOF
|
|
||||||
chmod +x Venera.AppDir/AppRun
|
|
||||||
|
|
||||||
APP_VERSION=$(grep "version:" pubspec.yaml | cut -d':' -f2 | tr -d ' ')
|
|
||||||
./appimagetool Venera.AppDir Venera-${APP_VERSION}-x86_64.AppImage
|
|
||||||
|
|
||||||
mkdir -p build/linux/appimage
|
|
||||||
mv Venera-${APP_VERSION}-x86_64.AppImage build/linux/appimage/
|
|
||||||
- uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: appimage_build
|
|
||||||
path: build/linux/appimage
|
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: deb_build
|
name: deb_build
|
||||||
@@ -208,46 +172,10 @@ jobs:
|
|||||||
sudo apt-get update -y
|
sudo apt-get update -y
|
||||||
sudo apt-get install -y ninja-build libgtk-3-dev webkit2gtk-4.1
|
sudo apt-get install -y ninja-build libgtk-3-dev webkit2gtk-4.1
|
||||||
dart pub global activate flutter_to_debian
|
dart pub global activate flutter_to_debian
|
||||||
- run: python3 debian/build.py arm64
|
- name: "Patch font"
|
||||||
- name: Build AppImage
|
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get install -y libfuse2
|
dart run patch/font.dart
|
||||||
wget -O appimagetool "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-aarch64.AppImage"
|
- run: python3 debian/build.py arm64
|
||||||
chmod +x appimagetool
|
|
||||||
|
|
||||||
mkdir -p Venera.AppDir
|
|
||||||
cp -r build/linux/arm64/release/bundle/* Venera.AppDir/
|
|
||||||
|
|
||||||
cat > Venera.AppDir/venera.desktop << EOF
|
|
||||||
[Desktop Entry]
|
|
||||||
Name=Venera
|
|
||||||
Exec=venera
|
|
||||||
Icon=venera
|
|
||||||
Type=Application
|
|
||||||
Categories=Utility;
|
|
||||||
EOF
|
|
||||||
|
|
||||||
cp assets/app_icon.png Venera.AppDir/venera.png
|
|
||||||
|
|
||||||
cat > Venera.AppDir/AppRun << EOF
|
|
||||||
#!/bin/sh
|
|
||||||
HERE=\$(dirname \$(readlink -f "\${0}"))
|
|
||||||
export PATH="\${HERE}"/usr/bin/:"\${HERE}"/usr/sbin/:"\${HERE}"/usr/games/:"\${HERE}"/bin/:"\${HERE}"/sbin/:\${PATH}
|
|
||||||
export LD_LIBRARY_PATH="\${HERE}"/usr/lib/:\${LD_LIBRARY_PATH}
|
|
||||||
export XDG_DATA_DIRS="\${HERE}"/usr/share/:\${XDG_DATA_DIRS}
|
|
||||||
exec "\${HERE}"/venera "\$@"
|
|
||||||
EOF
|
|
||||||
chmod +x Venera.AppDir/AppRun
|
|
||||||
|
|
||||||
APP_VERSION=$(grep "version:" pubspec.yaml | cut -d':' -f2 | tr -d ' ')
|
|
||||||
./appimagetool Venera.AppDir Venera-${APP_VERSION}-aarch64.AppImage
|
|
||||||
|
|
||||||
mkdir -p build/linux/appimage
|
|
||||||
mv Venera-${APP_VERSION}-aarch64.AppImage build/linux/appimage/
|
|
||||||
- uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: appimage_arm64_build
|
|
||||||
path: build/linux/appimage
|
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: deb_arm64_build
|
name: deb_arm64_build
|
||||||
@@ -286,14 +214,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
name: deb_arm64_build
|
name: deb_arm64_build
|
||||||
path: outputs
|
path: outputs
|
||||||
- uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: appimage_build
|
|
||||||
path: outputs
|
|
||||||
- uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: appimage_arm64_build
|
|
||||||
path: outputs
|
|
||||||
- uses: softprops/action-gh-release@v2
|
- uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ github.ref_name }}
|
tag_name: ${{ github.ref_name }}
|
||||||
|
|||||||
87
.github/workflows/update_alt_store.yml
vendored
Normal file
87
.github/workflows/update_alt_store.yml
vendored
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
name: Update AltStore Source
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_run:
|
||||||
|
workflows: ["Build ALL"]
|
||||||
|
types: [completed]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
update-source:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success'
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install requests
|
||||||
|
|
||||||
|
- name: Record job start time
|
||||||
|
id: job_start_time
|
||||||
|
run: echo "start_time=$(date +%s)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Update AltStore source
|
||||||
|
id: update_source
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
python update_alt_store.py
|
||||||
|
git config --global user.name 'GitHub Action'
|
||||||
|
git config --global user.email 'action@github.com'
|
||||||
|
git add alt_store.json
|
||||||
|
if git diff --staged --quiet; then
|
||||||
|
echo "changes=false" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
# Create a new branch for the PR
|
||||||
|
branch_name="update-altstore-$(date +%Y%m%d-%H%M%S)"
|
||||||
|
git checkout -b "$branch_name"
|
||||||
|
git commit -m "Updated source with latest release"
|
||||||
|
git push -u origin "$branch_name"
|
||||||
|
|
||||||
|
# Create PR using GitHub CLI
|
||||||
|
gh pr create \
|
||||||
|
--title "Update AltStore source with latest release" \
|
||||||
|
--body "This PR updates the alt_store.json file with the latest release information." \
|
||||||
|
--head "$branch_name" \
|
||||||
|
--base master
|
||||||
|
|
||||||
|
echo "changes=true" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Calculate job duration
|
||||||
|
id: duration
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
end_time=$(date +%s)
|
||||||
|
duration=$((end_time - ${{ steps.job_start_time.outputs.start_time }}))
|
||||||
|
echo "duration=$duration seconds" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Create job summary
|
||||||
|
run: |
|
||||||
|
if [[ "${{ steps.update_source.outputs.changes }}" == "true" ]]; then
|
||||||
|
echo "## Update Altstore Source Summary 🚀" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "✅ Changes Detected and Applied" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "The alt_store.json file has been updated with the latest release information." >> $GITHUB_STEP_SUMMARY
|
||||||
|
else
|
||||||
|
echo "## Update Altstore Source Summary 🚀" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "🔍 No Changes Detected" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "The alt_store.json file is up to date. No changes were necessary." >> $GITHUB_STEP_SUMMARY
|
||||||
|
fi
|
||||||
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "🕐 Execution Time" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "This job took ${{ steps.duration.outputs.duration }} to complete." >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "📆 Next Scheduled Run" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "" >> $GITHUB_STEP_SUMMARY
|
||||||
|
echo "The next scheduled run will be tomorrow at midnight UTC." >> $GITHUB_STEP_SUMMARY
|
||||||
14
README.md
14
README.md
@@ -1,16 +1,15 @@
|
|||||||
# venera
|
# venera
|
||||||
[](https://flutter.dev/)
|
[](https://flutter.dev/)
|
||||||
[](https://github.com/venera-app/venera/blob/master/LICENSE)
|
[](https://github.com/venera-app/venera/blob/master/LICENSE)
|
||||||
[](https://github.com/venera-app/venera/releases)
|
|
||||||
[](https://github.com/venera-app/venera/stargazers)
|
[](https://github.com/venera-app/venera/stargazers)
|
||||||
[](https://t.me/+Ws-IpmUutzkxMjhl)
|
[](https://t.me/venera_release)
|
||||||
|
|
||||||
|
[](https://github.com/venera-app/venera/releases)
|
||||||
|
[](https://aur.archlinux.org/packages/venera-bin)
|
||||||
|
[](https://f-droid.org/packages/com.github.wgh136.venera/)
|
||||||
|
|
||||||
A comic reader that support reading local and network comics.
|
A comic reader that support reading local and network comics.
|
||||||
|
|
||||||
[<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png"
|
|
||||||
alt="Get it on F-Droid"
|
|
||||||
height="75">](https://f-droid.org/packages/com.github.wgh136.venera/)
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
- Read local comics
|
- Read local comics
|
||||||
- Use javascript to create comic sources
|
- Use javascript to create comic sources
|
||||||
@@ -34,4 +33,7 @@ See [Comic Source](doc/comic_source.md)
|
|||||||
### Tags Translation
|
### Tags Translation
|
||||||
[](https://github.com/EhTagTranslation/Database)
|
[](https://github.com/EhTagTranslation/Database)
|
||||||
|
|
||||||
|
## Headless Mode
|
||||||
|
See [Headless Doc](doc/headless_doc.md)
|
||||||
|
|
||||||
The Chinese translation of the manga tags is from this project.
|
The Chinese translation of the manga tags is from this project.
|
||||||
|
|||||||
81
alt_store.json
Normal file
81
alt_store.json
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
{
|
||||||
|
"name": "Venera",
|
||||||
|
"identifier": "com.github.wgh136.venera.source",
|
||||||
|
"website": "https://github.com/venera-app/venera",
|
||||||
|
"subtitle": "Venera official AltStore Source.",
|
||||||
|
"description": "This is the official AltStore Source for Venera.\n\n A comic reader that supports reading local and network comics",
|
||||||
|
"tintColor": "#0784FC",
|
||||||
|
"iconURL": "https://raw.githubusercontent.com/venera-app/venera/master/assets/app_icon.png",
|
||||||
|
"apps": [
|
||||||
|
{
|
||||||
|
"beta": false,
|
||||||
|
"name": "Venera",
|
||||||
|
"bundleIdentifier": "com.github.wgh136.venera",
|
||||||
|
"developerName": "wgh136",
|
||||||
|
"subtitle": "A comic reader that supports reading local and network comics",
|
||||||
|
"version": "1.5.3",
|
||||||
|
"versionDate": "2025-10-13",
|
||||||
|
"versionDescription": "1. Fix an issue where the app freezes after swiping back on Android. 544\r\n2. Enable minification when building for Android. 547\r\n3. Prevent the app from creating an archive download task when the archive URL is an empty string.",
|
||||||
|
"downloadURL": "https://github.com/venera-app/venera/releases/download/v1.5.3/venera-ios-1.5.3%2B153.ipa",
|
||||||
|
"localizedDescription": "A comic reader that supports reading local and network comics",
|
||||||
|
"iconURL": "https://raw.githubusercontent.com/venera-app/venera/master/assets/app_icon.png",
|
||||||
|
"tintColor": "#0784FC",
|
||||||
|
"category": "utilities",
|
||||||
|
"size": 15047841,
|
||||||
|
"appPermissions": {
|
||||||
|
"entitlements": [
|
||||||
|
"application-identifier",
|
||||||
|
"com.apple.security.application-groups",
|
||||||
|
"get-task-allow",
|
||||||
|
"keychain-access-groups",
|
||||||
|
"com.apple.developer.kernel.extended-virtual-addressing",
|
||||||
|
"com.apple.developer.kernel.increased-memory-limit",
|
||||||
|
"com.apple.developer.healthkit.background-delivery"
|
||||||
|
],
|
||||||
|
"privacy": {
|
||||||
|
"NSFaceIDUsageDescription": "Face ID or Touch ID is used to protect your privacy when opening the app, ensuring secure access to your reading content.",
|
||||||
|
"NSPhotoLibraryAddUsageDescription": "Used to save comic images you've favorited or downloaded to your photo library for easy access and sharing.",
|
||||||
|
"NSPhotoLibraryUsageDescription": "Used to select images from your photo library when needed, and to save comic images you've collected to your device."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"versions": [
|
||||||
|
{
|
||||||
|
"version": "1.5.3",
|
||||||
|
"date": "2025-10-13",
|
||||||
|
"localizedDescription": "1. Fix an issue where the app freezes after swiping back on Android. 544\r\n2. Enable minification when building for Android. 547\r\n3. Prevent the app from creating an archive download task when the archive URL is an empty string.",
|
||||||
|
"downloadURL": "https://github.com/venera-app/venera/releases/download/v1.5.3/venera-ios-1.5.3%2B153.ipa",
|
||||||
|
"size": 15047841
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "1.4.5",
|
||||||
|
"date": "2025-06-18",
|
||||||
|
"localizedDescription": "1. Fixed an abnormal single image height issue when \"imagesPerPage > 1\". 379 \r\n2. Fixed an invalid page calculation issue when \"showSingleImageOnFirstPage\" is enabled. \r\n3. Fixed an issue with incorrect reading history when displaying a single image on the first page. \r\n4. Fixed abnormal history recording when pages are not flipped. 392 \r\n5. Fixed an issue where the download task would stop after exiting the reader. 387 \r\n6. Fixed a \"RangeError\" when translating tags. 356 \r\n7. Reset the current folder to null on the favorites page if the folder is invalid. 389 \r\n8. Fixed various issues when using a custom download path on Android. 400 \r\n9. Set the initial chapter to the first downloaded chapter if no history exists when starting to read a local comic. 405 \r\n10. Removed the config file repository URL from the app.",
|
||||||
|
"downloadURL": "https://github.com/venera-app/venera/releases/download/v1.4.5/venera-ios-1.4.5%2B145.ipa",
|
||||||
|
"size": 14960268
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"news": [
|
||||||
|
{
|
||||||
|
"appID": "com.github.wgh136.venera",
|
||||||
|
"caption": "Update of Venera just got released!",
|
||||||
|
"date": "2025-06-18T09:02:01Z",
|
||||||
|
"identifier": "release-v1.4.5",
|
||||||
|
"notify": true,
|
||||||
|
"tintColor": "#0784FC",
|
||||||
|
"title": "v1.4.5 - Venera 18/06/25",
|
||||||
|
"url": "https://github.com/venera-app/venera/releases/tag/v1.4.5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"appID": "com.github.wgh136.venera",
|
||||||
|
"caption": "Update of Venera just got released!",
|
||||||
|
"date": "2025-10-13T12:47:27Z",
|
||||||
|
"identifier": "release-v1.5.3",
|
||||||
|
"notify": true,
|
||||||
|
"tintColor": "#0784FC",
|
||||||
|
"title": "v1.5.3 - Venera 13/10/25",
|
||||||
|
"url": "https://github.com/venera-app/venera/releases/tag/v1.5.3"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ linter:
|
|||||||
rules:
|
rules:
|
||||||
collection_methods_unrelated_type: false
|
collection_methods_unrelated_type: false
|
||||||
use_build_context_synchronously: false
|
use_build_context_synchronously: false
|
||||||
# avoid_print: false # Uncomment to disable the `avoid_print` rule
|
avoid_print: false
|
||||||
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
|
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
|
||||||
|
|
||||||
# Additional information about this file can be found at
|
# Additional information about this file can be found at
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ android {
|
|||||||
compileSdk = flutter.compileSdkVersion
|
compileSdk = flutter.compileSdkVersion
|
||||||
ndkVersion "28.0.13004108"
|
ndkVersion "28.0.13004108"
|
||||||
|
|
||||||
|
packaging {
|
||||||
|
jniLibs {
|
||||||
|
useLegacyPackaging true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
splits{
|
splits{
|
||||||
abi {
|
abi {
|
||||||
reset()
|
reset()
|
||||||
@@ -67,7 +73,6 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
|
||||||
applicationId = "com.github.wgh136.venera"
|
applicationId = "com.github.wgh136.venera"
|
||||||
// You can update the following values to match your application needs.
|
// You can update the following values to match your application needs.
|
||||||
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||||||
@@ -79,6 +84,8 @@ android {
|
|||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
minifyEnabled true
|
||||||
|
shrinkResources true
|
||||||
ndk {
|
ndk {
|
||||||
abiFilters "armeabi-v7a", "arm64-v8a", "x86_64"
|
abiFilters "armeabi-v7a", "arm64-v8a", "x86_64"
|
||||||
}
|
}
|
||||||
@@ -125,6 +132,6 @@ flutter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "androidx.activity:activity-ktx:1.9.2"
|
implementation "androidx.activity:activity-ktx:1.10.1"
|
||||||
implementation 'androidx.documentfile:documentfile:1.0.1'
|
implementation 'androidx.documentfile:documentfile:1.0.1'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
android:theme="@style/LaunchTheme"
|
android:theme="@style/LaunchTheme"
|
||||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="true"
|
||||||
|
android:enableOnBackInvokedCallback="true"
|
||||||
android:windowSoftInputMode="adjustResize">
|
android:windowSoftInputMode="adjustResize">
|
||||||
<!-- Specifies an Android theme to apply to this Activity as soon as
|
<!-- Specifies an Android theme to apply to this Activity as soon as
|
||||||
the Android process has started. This theme is visible to the user
|
the Android process has started. This theme is visible to the user
|
||||||
@@ -58,8 +59,6 @@
|
|||||||
<meta-data
|
<meta-data
|
||||||
android:name="flutterEmbedding"
|
android:name="flutterEmbedding"
|
||||||
android:value="2" />
|
android:value="2" />
|
||||||
<!-- [flutter 3.27.1] Impeller is still worse than skia, disable it -->
|
|
||||||
<meta-data android:name="io.flutter.embedding.android.EnableImpeller" android:value="false"/>
|
|
||||||
</application>
|
</application>
|
||||||
<!-- Required to query activities that can process text, see:
|
<!-- Required to query activities that can process text, see:
|
||||||
https://developer.android.com/training/package-visibility and
|
https://developer.android.com/training/package-visibility and
|
||||||
|
|||||||
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ pluginManagement {
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
|
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
|
||||||
id "com.android.application" version '8.3.2' apply false
|
id "com.android.application" version '8.9.0' apply false
|
||||||
id "org.jetbrains.kotlin.android" version "1.8.10" apply false
|
id "org.jetbrains.kotlin.android" version "2.1.0" apply false
|
||||||
}
|
}
|
||||||
|
|
||||||
include ":app"
|
include ":app"
|
||||||
|
|||||||
@@ -4,6 +4,18 @@ Venera JavaScript Library
|
|||||||
This library provides a set of APIs for interacting with the Venera app.
|
This library provides a set of APIs for interacting with the Venera app.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @function sendMessage
|
||||||
|
* @global
|
||||||
|
* @param {Object} message
|
||||||
|
* @returns {any}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a timeout to execute a callback function after a specified delay.
|
||||||
|
* @param callback {Function}
|
||||||
|
* @param delay {number} - delay in milliseconds
|
||||||
|
*/
|
||||||
function setTimeout(callback, delay) {
|
function setTimeout(callback, delay) {
|
||||||
sendMessage({
|
sendMessage({
|
||||||
method: 'delay',
|
method: 'delay',
|
||||||
@@ -39,6 +51,32 @@ let Convert = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param str {string}
|
||||||
|
* @returns {ArrayBuffer}
|
||||||
|
*/
|
||||||
|
encodeGbk: (str) => {
|
||||||
|
return sendMessage({
|
||||||
|
method: "convert",
|
||||||
|
type: "gbk",
|
||||||
|
value: str,
|
||||||
|
isEncode: true
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param value {ArrayBuffer}
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
decodeGbk: (value) => {
|
||||||
|
return sendMessage({
|
||||||
|
method: "convert",
|
||||||
|
type: "gbk",
|
||||||
|
value: value,
|
||||||
|
isEncode: false
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ArrayBuffer} value
|
* @param {ArrayBuffer} value
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
@@ -176,7 +214,7 @@ let Convert = {
|
|||||||
decryptAesCbc: (value, key, iv) => {
|
decryptAesCbc: (value, key, iv) => {
|
||||||
return sendMessage({
|
return sendMessage({
|
||||||
method: "convert",
|
method: "convert",
|
||||||
type: "aes-ecb",
|
type: "aes-cbc",
|
||||||
value: value,
|
value: value,
|
||||||
key: key,
|
key: key,
|
||||||
iv: iv,
|
iv: iv,
|
||||||
@@ -1296,13 +1334,15 @@ let UI = {
|
|||||||
* Show an input dialog
|
* Show an input dialog
|
||||||
* @param title {string}
|
* @param title {string}
|
||||||
* @param validator {(string) => string | null | undefined} - A function that validates the input. If the function returns a string, the dialog will show the error message.
|
* @param validator {(string) => string | null | undefined} - A function that validates the input. If the function returns a string, the dialog will show the error message.
|
||||||
|
* @param image {string?} - Available since 1.4.6. An optional image to show in the dialog. You can use this to show a captcha.
|
||||||
* @returns {Promise<string | null>} - The input value. If the dialog is canceled, return null.
|
* @returns {Promise<string | null>} - The input value. If the dialog is canceled, return null.
|
||||||
*/
|
*/
|
||||||
showInputDialog: (title, validator) => {
|
showInputDialog: (title, validator, image) => {
|
||||||
return sendMessage({
|
return sendMessage({
|
||||||
method: 'UI',
|
method: 'UI',
|
||||||
function: 'showInputDialog',
|
function: 'showInputDialog',
|
||||||
title: title,
|
title: title,
|
||||||
|
image: image,
|
||||||
validator: validator
|
validator: validator
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -1357,4 +1397,45 @@ let APP = {
|
|||||||
method: 'getPlatform'
|
method: 'getPlatform'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set clipboard text
|
||||||
|
* @param text {string}
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*
|
||||||
|
* @since 1.3.4
|
||||||
|
*/
|
||||||
|
function setClipboard(text) {
|
||||||
|
return sendMessage({
|
||||||
|
method: 'setClipboard',
|
||||||
|
text: text
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get clipboard text
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
*
|
||||||
|
* @since 1.3.4
|
||||||
|
*/
|
||||||
|
function getClipboard() {
|
||||||
|
return sendMessage({
|
||||||
|
method: 'getClipboard'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute a function with arguments. The function will be executed in the engine pool which is not in the main thread.
|
||||||
|
* @param func {string} - A js code string which can be evaluated to a function. The function will receive the args as its only argument.
|
||||||
|
* @param args {any[]} - The arguments to pass to the function.
|
||||||
|
* @returns {Promise<any>} - The result of the function.
|
||||||
|
* @since 1.5.0
|
||||||
|
*/
|
||||||
|
function compute(func, ...args) {
|
||||||
|
return sendMessage({
|
||||||
|
method: 'compute',
|
||||||
|
function: func,
|
||||||
|
args: args
|
||||||
|
})
|
||||||
}
|
}
|
||||||
3982
assets/opencc.txt
Normal file
3982
assets/opencc.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -83,7 +83,10 @@
|
|||||||
"New Folder": "新建文件夹",
|
"New Folder": "新建文件夹",
|
||||||
"Reading": "阅读中",
|
"Reading": "阅读中",
|
||||||
"Appearance": "外观",
|
"Appearance": "外观",
|
||||||
|
"Network Favorites": "网络收藏",
|
||||||
"Local Favorites": "本地收藏",
|
"Local Favorites": "本地收藏",
|
||||||
|
"Show local favorites before network favorites": "在网络收藏之前显示本地收藏",
|
||||||
|
"Auto close favorite panel after operation": "自动关闭收藏面板",
|
||||||
"APP": "应用",
|
"APP": "应用",
|
||||||
"About": "关于",
|
"About": "关于",
|
||||||
"Display mode of comic tile": "漫画缩略图的显示模式",
|
"Display mode of comic tile": "漫画缩略图的显示模式",
|
||||||
@@ -140,18 +143,18 @@
|
|||||||
"Block": "屏蔽",
|
"Block": "屏蔽",
|
||||||
"Add new favorite to": "添加新收藏到",
|
"Add new favorite to": "添加新收藏到",
|
||||||
"Move favorite after reading": "阅读后移动收藏",
|
"Move favorite after reading": "阅读后移动收藏",
|
||||||
"Delete folder?" : "删除文件夹?",
|
"Delete folder?": "删除文件夹?",
|
||||||
"Delete folder '@f' ?" : "删除文件夹 '@f' ?",
|
"Delete folder '@f' ?": "删除文件夹 '@f' ?",
|
||||||
"Import from file": "从文件导入",
|
"Import from file": "从文件导入",
|
||||||
"Failed to import": "导入失败",
|
"Failed to import": "导入失败",
|
||||||
"Cache Limit": "缓存限制",
|
"Cache Limit": "缓存限制",
|
||||||
"Set Cache Limit": "设置缓存限制",
|
"Set Cache Limit": "设置缓存限制",
|
||||||
"Size in MB": "大小(MB)",
|
"Size in MB": "大小(MB)",
|
||||||
"Select a directory which contains the comic directories." : "选择一个包含漫画文件夹的目录",
|
"Select a directory which contains the comic directories.": "选择一个包含漫画文件夹的目录",
|
||||||
"Help": "帮助",
|
"Help": "帮助",
|
||||||
"Export as cbz": "导出为cbz",
|
"Export as cbz": "导出为cbz",
|
||||||
"Select an archive file (cbz, zip, 7z, cb7)" : "选择一个归档文件 (cbz, zip, 7z, cb7)",
|
"Select an archive file (cbz, zip, 7z, cb7)": "选择一个归档文件 (cbz, zip, 7z, cb7)",
|
||||||
"An archive file" : "一个归档文件",
|
"An archive file": "一个归档文件",
|
||||||
"Fullscreen": "全屏",
|
"Fullscreen": "全屏",
|
||||||
"Exit": "退出",
|
"Exit": "退出",
|
||||||
"View more": "查看更多",
|
"View more": "查看更多",
|
||||||
@@ -198,9 +201,9 @@
|
|||||||
"Long press on the favorite button to quickly add to this folder": "长按收藏按钮快速添加到这个文件夹",
|
"Long press on the favorite button to quickly add to this folder": "长按收藏按钮快速添加到这个文件夹",
|
||||||
"Added": "已添加",
|
"Added": "已添加",
|
||||||
"Turn page by volume keys": "使用音量键翻页",
|
"Turn page by volume keys": "使用音量键翻页",
|
||||||
"Display time & battery info in reader":"在阅读器中显示时间和电量信息",
|
"Display time & battery info in reader": "在阅读器中显示时间和电量信息",
|
||||||
"EhViewer downloads":"EhViewer下载",
|
"EhViewer downloads": "EhViewer下载",
|
||||||
"Select an EhViewer database and a download folder.":"选择EhViewer的下载数据(导出的db文件)与存放下载内容的目录",
|
"Select an EhViewer database and a download folder.": "选择EhViewer的下载数据(导出的db文件)与存放下载内容的目录",
|
||||||
"(EhViewer)Default": "(EhViewer)默认",
|
"(EhViewer)Default": "(EhViewer)默认",
|
||||||
"If you import an EhViewer's database, program will automatically create folders according to the download label in that database.": "若通过EhViewer数据库导入漫画,程序将会按其中的下载标签自动创建收藏文件夹。",
|
"If you import an EhViewer's database, program will automatically create folders according to the download label in that database.": "若通过EhViewer数据库导入漫画,程序将会按其中的下载标签自动创建收藏文件夹。",
|
||||||
"Multi-Select": "进入多选模式",
|
"Multi-Select": "进入多选模式",
|
||||||
@@ -234,14 +237,16 @@
|
|||||||
"Please add some sources": "请添加一些源",
|
"Please add some sources": "请添加一些源",
|
||||||
"Please check your settings": "请检查您的设置",
|
"Please check your settings": "请检查您的设置",
|
||||||
"No Category Pages": "没有分类页面",
|
"No Category Pages": "没有分类页面",
|
||||||
|
"Group @group": "第 @group 组",
|
||||||
"Chapter @ep": "第 @ep 章",
|
"Chapter @ep": "第 @ep 章",
|
||||||
"Page @page": "第 @page 页",
|
"Page @page": "第 @page 页",
|
||||||
|
"Remove local favorite and history": "删除本地收藏和历史记录",
|
||||||
"Also remove files on disk": "同时删除磁盘上的文件",
|
"Also remove files on disk": "同时删除磁盘上的文件",
|
||||||
"Copy to app local path": "将漫画复制到本地存储目录中",
|
"Copy to app local path": "将漫画复制到本地存储目录中",
|
||||||
"Delete all unavailable local favorite items": "删除所有无效的本地收藏",
|
"Delete all unavailable local favorite items": "删除所有无效的本地收藏",
|
||||||
"Deleted @a favorite items.": "已删除 @a 条无效收藏",
|
"Deleted @a favorite items.": "已删除 @a 条无效收藏",
|
||||||
"New version available": "有新版本可用",
|
"New version available": "有新版本可用",
|
||||||
"A new version is available. Do you want to update now?" : "有新版本可用。您要现在更新吗?",
|
"A new version is available. Do you want to update now?": "有新版本可用。您要现在更新吗?",
|
||||||
"No new version available": "没有新版本可用",
|
"No new version available": "没有新版本可用",
|
||||||
"Export as pdf": "导出为pdf",
|
"Export as pdf": "导出为pdf",
|
||||||
"Export as epub": "导出为epub",
|
"Export as epub": "导出为epub",
|
||||||
@@ -288,15 +293,15 @@
|
|||||||
"Copy the title successfully": "复制标题成功",
|
"Copy the title successfully": "复制标题成功",
|
||||||
"The comic is invalid, please long press to delete, you can double click the title to copy": "该漫画已失效, 请长按删除, 可以双击标题进行复制",
|
"The comic is invalid, please long press to delete, you can double click the title to copy": "该漫画已失效, 请长按删除, 可以双击标题进行复制",
|
||||||
"No search results found": "未找到搜索结果",
|
"No search results found": "未找到搜索结果",
|
||||||
"Added @c comics to download queue." : "已添加 @c 本漫画到下载队列",
|
"Added @c comics to download queue.": "已添加 @c 本漫画到下载队列",
|
||||||
"Download started": "下载已开始",
|
"Download started": "下载已开始",
|
||||||
"Click favorite": "点击收藏",
|
"Click favorite": "点击收藏",
|
||||||
"End": "末尾",
|
"End": "末尾",
|
||||||
"None": "无",
|
"None": "无",
|
||||||
"View Detail": "查看详情",
|
"View Detail": "查看详情",
|
||||||
"Select a directory which contains multiple archive files." : "选择一个包含多个归档文件的目录",
|
"Select a directory which contains multiple archive files.": "选择一个包含多个归档文件的目录",
|
||||||
"Multiple archive files" : "多个归档文件",
|
"Multiple archive files": "多个归档文件",
|
||||||
"No valid comics found" : "未找到有效的漫画",
|
"No valid comics found": "未找到有效的漫画",
|
||||||
"Enable DNS Overrides": "启用DNS覆写",
|
"Enable DNS Overrides": "启用DNS覆写",
|
||||||
"DNS Overrides": "DNS覆写",
|
"DNS Overrides": "DNS覆写",
|
||||||
"Custom Image Processing": "自定义图片处理",
|
"Custom Image Processing": "自定义图片处理",
|
||||||
@@ -342,12 +347,12 @@
|
|||||||
"Replies": "回复",
|
"Replies": "回复",
|
||||||
"Follow Updates": "追更",
|
"Follow Updates": "追更",
|
||||||
"Not Configured": "未配置",
|
"Not Configured": "未配置",
|
||||||
"Choose a folder to follow updates." : "选择一个文件夹以追更",
|
"Choose a folder to follow updates.": "选择一个文件夹以追更",
|
||||||
"Choose Folder": "选择文件夹",
|
"Choose Folder": "选择文件夹",
|
||||||
"No folders available": "没有可用的文件夹",
|
"No folders available": "没有可用的文件夹",
|
||||||
"Updating comics...": "更新漫画中...",
|
"Updating comics...": "更新漫画中...",
|
||||||
"Automatic update checking enabled." : "已启用自动更新检查",
|
"Automatic update checking enabled.": "已启用自动更新检查",
|
||||||
"The app will check for updates at most once a day." : "APP将每天最多检查一次更新",
|
"The app will check for updates at most once a day.": "APP将每天最多检查一次更新",
|
||||||
"Change Folder": "更改文件夹",
|
"Change Folder": "更改文件夹",
|
||||||
"Check Now": "立即检查",
|
"Check Now": "立即检查",
|
||||||
"Updates": "更新",
|
"Updates": "更新",
|
||||||
@@ -358,9 +363,9 @@
|
|||||||
"Once the operation is successful, app will automatically sync data with the server.": "操作成功后, APP将自动与服务器同步数据",
|
"Once the operation is successful, app will automatically sync data with the server.": "操作成功后, APP将自动与服务器同步数据",
|
||||||
"Cache cleared": "缓存已清除",
|
"Cache cleared": "缓存已清除",
|
||||||
"Disabled": "已禁用",
|
"Disabled": "已禁用",
|
||||||
"WebDAV Auto Sync": "WebDAV 自动同步",
|
"Auto Sync Data": "自动同步数据",
|
||||||
"Mark all as read": "全部标记为已读",
|
"Mark all as read": "全部标记为已读",
|
||||||
"Do you want to mark all as read?" : "您要全部标记为已读吗?",
|
"Do you want to mark all as read?": "您要全部标记为已读吗?",
|
||||||
"Swipe down for previous chapter": "向下滑动查看上一章",
|
"Swipe down for previous chapter": "向下滑动查看上一章",
|
||||||
"Swipe up for next chapter": "向上滑动查看下一章",
|
"Swipe up for next chapter": "向上滑动查看下一章",
|
||||||
"Initial Page": "初始页面",
|
"Initial Page": "初始页面",
|
||||||
@@ -372,7 +377,44 @@
|
|||||||
"Refresh": "刷新",
|
"Refresh": "刷新",
|
||||||
"Paging": "分页",
|
"Paging": "分页",
|
||||||
"Continuous": "连续",
|
"Continuous": "连续",
|
||||||
"Display mode of comic list": "漫画列表的显示模式"
|
"Display mode of comic list": "漫画列表的显示模式",
|
||||||
|
"Show Page Number": "显示页码",
|
||||||
|
"Jump to page": "跳转到页面",
|
||||||
|
"Page": "页面",
|
||||||
|
"Jump": "跳转",
|
||||||
|
"Copy Image": "复制图片",
|
||||||
|
"A valid WebDav directory URL": "有效的WebDav目录URL",
|
||||||
|
"Shut Down": "关闭",
|
||||||
|
"Uploading data...": "正在上传数据...",
|
||||||
|
"Pages": "页数",
|
||||||
|
"Long press zoom position": "长按缩放位置",
|
||||||
|
"Press position": "按压位置",
|
||||||
|
"Screen center": "屏幕中心",
|
||||||
|
"Suggestions": "建议",
|
||||||
|
"Do not report any issues related to sources to App repo.": "请不要向App仓库报告任何与源相关的问题",
|
||||||
|
"Show single image on first page": "在首页显示单张图片",
|
||||||
|
"Show system status bar": "显示系统状态栏",
|
||||||
|
"Click to select an image": "点击选择一张图片",
|
||||||
|
"Repo URL": "仓库地址",
|
||||||
|
"The URL should point to a 'index.json' file": "该URL应指向一个'index.json'文件",
|
||||||
|
"Double tap to zoom": "双击缩放",
|
||||||
|
"Clear Unfavorited": "清除未收藏",
|
||||||
|
"Reverse": "反转",
|
||||||
|
"Delete Chapters": "删除章节",
|
||||||
|
"Open Folder": "打开文件夹",
|
||||||
|
"Path copied to clipboard": "路径已复制到剪贴板",
|
||||||
|
"Reverse default chapter order": "反转默认章节顺序",
|
||||||
|
"Reload Configs": "重新加载配置文件",
|
||||||
|
"Reload": "重载",
|
||||||
|
"Disable Length Limitation": "禁用长度限制",
|
||||||
|
"Only valid for this run": "仅对本次运行有效",
|
||||||
|
"Logs": "日志",
|
||||||
|
"Export logs": "导出日志",
|
||||||
|
"Clear specific reader settings for all comics": "清除所有漫画的特殊阅读设置",
|
||||||
|
"Clear specific reader settings for this comic": "清除该漫画的特殊阅读设置",
|
||||||
|
"Enable comic specific settings": "启用此漫画特定设置",
|
||||||
|
"Ignore Certificate Errors": "忽略证书错误",
|
||||||
|
"Mouse scroll speed": "鼠标滚动速度"
|
||||||
},
|
},
|
||||||
"zh_TW": {
|
"zh_TW": {
|
||||||
"Home": "首頁",
|
"Home": "首頁",
|
||||||
@@ -458,7 +500,10 @@
|
|||||||
"New Folder": "建立資料夾",
|
"New Folder": "建立資料夾",
|
||||||
"Reading": "閱讀中",
|
"Reading": "閱讀中",
|
||||||
"Appearance": "外觀",
|
"Appearance": "外觀",
|
||||||
|
"Network Favorites": "網路收藏",
|
||||||
"Local Favorites": "本機收藏",
|
"Local Favorites": "本機收藏",
|
||||||
|
"Show local favorites before network favorites": "在網路收藏之前顯示本機收藏",
|
||||||
|
"Auto close favorite panel after operation": "自動關閉收藏面板",
|
||||||
"APP": "應用",
|
"APP": "應用",
|
||||||
"About": "關於",
|
"About": "關於",
|
||||||
"Display mode of comic tile": "漫畫縮圖的顯示模式",
|
"Display mode of comic tile": "漫畫縮圖的顯示模式",
|
||||||
@@ -514,18 +559,18 @@
|
|||||||
"Block": "封鎖",
|
"Block": "封鎖",
|
||||||
"Add new favorite to": "添加新收藏到",
|
"Add new favorite to": "添加新收藏到",
|
||||||
"Move favorite after reading": "閱讀後移動收藏",
|
"Move favorite after reading": "閱讀後移動收藏",
|
||||||
"Delete folder?" : "刪除資料夾?",
|
"Delete folder?": "刪除資料夾?",
|
||||||
"Delete folder '@f' ?" : "刪除資料夾 '@f' ?",
|
"Delete folder '@f' ?": "刪除資料夾 '@f' ?",
|
||||||
"Import from file": "從文件匯入",
|
"Import from file": "從文件匯入",
|
||||||
"Failed to import": "匯入失敗",
|
"Failed to import": "匯入失敗",
|
||||||
"Cache Limit": "快取限制",
|
"Cache Limit": "快取限制",
|
||||||
"Set Cache Limit": "設定快取限制",
|
"Set Cache Limit": "設定快取限制",
|
||||||
"Size in MB": "大小(MB)",
|
"Size in MB": "大小(MB)",
|
||||||
"Select a directory which contains the comic directories." : "選擇一個包含漫畫資料夾的目錄",
|
"Select a directory which contains the comic directories.": "選擇一個包含漫畫資料夾的目錄",
|
||||||
"Help": "幫助",
|
"Help": "幫助",
|
||||||
"Export as cbz": "匯出為cbz",
|
"Export as cbz": "匯出為cbz",
|
||||||
"Select an archive file (cbz, zip, 7z, cb7)" : "選擇一個歸檔文件 (cbz, zip, 7z, cb7)",
|
"Select an archive file (cbz, zip, 7z, cb7)": "選擇一個歸檔文件 (cbz, zip, 7z, cb7)",
|
||||||
"An archive file" : "一個歸檔文件",
|
"An archive file": "一個歸檔文件",
|
||||||
"Fullscreen": "全螢幕",
|
"Fullscreen": "全螢幕",
|
||||||
"Exit": "退出",
|
"Exit": "退出",
|
||||||
"View more": "查看更多",
|
"View more": "查看更多",
|
||||||
@@ -609,20 +654,22 @@
|
|||||||
"Please add some sources": "請添加一些源",
|
"Please add some sources": "請添加一些源",
|
||||||
"Please check your settings": "請檢查您的設定",
|
"Please check your settings": "請檢查您的設定",
|
||||||
"No Category Pages": "沒有分類頁面",
|
"No Category Pages": "沒有分類頁面",
|
||||||
|
"Group @group": "第 @group 組",
|
||||||
"Chapter @ep": "第 @ep 章",
|
"Chapter @ep": "第 @ep 章",
|
||||||
"Page @page": "第 @page 頁",
|
"Page @page": "第 @page 頁",
|
||||||
|
"Remove local favorite and history": "刪除本機收藏和歷史記錄",
|
||||||
"Also remove files on disk": "同時刪除磁碟上的文件",
|
"Also remove files on disk": "同時刪除磁碟上的文件",
|
||||||
"Copy to app local path": "將漫畫複製到本機儲存目錄中",
|
"Copy to app local path": "將漫畫複製到本機儲存目錄中",
|
||||||
"Delete all unavailable local favorite items": "刪除所有無效的本機收藏",
|
"Delete all unavailable local favorite items": "刪除所有無效的本機收藏",
|
||||||
"Deleted @a favorite items.": "已刪除 @a 條無效收藏",
|
"Deleted @a favorite items.": "已刪除 @a 條無效收藏",
|
||||||
"New version available": "有新版本可用",
|
"New version available": "有新版本可用",
|
||||||
"A new version is available. Do you want to update now?" : "有新版本可用。您要現在更新嗎?",
|
"A new version is available. Do you want to update now?": "有新版本可用。您要現在更新嗎?",
|
||||||
"No new version available": "沒有新版本可用",
|
"No new version available": "沒有新版本可用",
|
||||||
"Export as pdf": "匯出為pdf",
|
"Export as pdf": "匯出為pdf",
|
||||||
"Export as epub": "匯出為epub",
|
"Export as epub": "匯出為epub",
|
||||||
"Aggregated Search": "聚合搜尋",
|
"Aggregated Search": "聚合搜尋",
|
||||||
"No search results found": "未找到搜尋結果",
|
"No search results found": "未找到搜尋結果",
|
||||||
"Added @c comics to download queue." : "已添加 @c 本漫畫到下載佇列",
|
"Added @c comics to download queue.": "已添加 @c 本漫畫到下載佇列",
|
||||||
"Download started": "下載已開始",
|
"Download started": "下載已開始",
|
||||||
"Click favorite": "點擊收藏",
|
"Click favorite": "點擊收藏",
|
||||||
"Local comic collection is not supported at present": "本機收藏暫不支援",
|
"Local comic collection is not supported at present": "本機收藏暫不支援",
|
||||||
@@ -669,9 +716,9 @@
|
|||||||
"End": "末尾",
|
"End": "末尾",
|
||||||
"None": "無",
|
"None": "無",
|
||||||
"View Detail": "查看詳情",
|
"View Detail": "查看詳情",
|
||||||
"Select a directory which contains multiple archive files." : "選擇一個包含多個歸檔文件的目錄",
|
"Select a directory which contains multiple archive files.": "選擇一個包含多個歸檔文件的目錄",
|
||||||
"Multiple archive files" : "多個歸檔文件",
|
"Multiple archive files": "多個歸檔文件",
|
||||||
"No valid comics found" : "未找到有效的漫畫",
|
"No valid comics found": "未找到有效的漫畫",
|
||||||
"Enable DNS Overrides": "啟用DNS覆寫",
|
"Enable DNS Overrides": "啟用DNS覆寫",
|
||||||
"DNS Overrides": "DNS覆寫",
|
"DNS Overrides": "DNS覆寫",
|
||||||
"Custom Image Processing": "自訂圖片處理",
|
"Custom Image Processing": "自訂圖片處理",
|
||||||
@@ -717,12 +764,12 @@
|
|||||||
"Replies": "回覆",
|
"Replies": "回覆",
|
||||||
"Follow Updates": "追更",
|
"Follow Updates": "追更",
|
||||||
"Not Configured": "未配置",
|
"Not Configured": "未配置",
|
||||||
"Choose a folder to follow updates." : "選擇一個資料夾以追更",
|
"Choose a folder to follow updates.": "選擇一個資料夾以追更",
|
||||||
"Choose Folder": "選擇資料夾",
|
"Choose Folder": "選擇資料夾",
|
||||||
"No folders available": "沒有可用的資料夾",
|
"No folders available": "沒有可用的資料夾",
|
||||||
"Updating comics...": "更新漫畫中...",
|
"Updating comics...": "更新漫畫中...",
|
||||||
"Automatic update checking enabled." : "已啟用自動更新檢查",
|
"Automatic update checking enabled.": "已啟用自動更新檢查",
|
||||||
"The app will check for updates at most once a day." : "APP將每天最多檢查一次更新",
|
"The app will check for updates at most once a day.": "APP將每天最多檢查一次更新",
|
||||||
"Change Folder": "更改資料夾",
|
"Change Folder": "更改資料夾",
|
||||||
"Check Now": "立即檢查",
|
"Check Now": "立即檢查",
|
||||||
"Updates": "更新",
|
"Updates": "更新",
|
||||||
@@ -733,9 +780,9 @@
|
|||||||
"Once the operation is successful, app will automatically sync data with the server.": "操作成功後, APP將自動與伺服器同步資料",
|
"Once the operation is successful, app will automatically sync data with the server.": "操作成功後, APP將自動與伺服器同步資料",
|
||||||
"Cache cleared": "快取已清除",
|
"Cache cleared": "快取已清除",
|
||||||
"Disabled": "已停用",
|
"Disabled": "已停用",
|
||||||
"WebDAV Auto Sync": "WebDAV 自動同步",
|
"Auto Sync Data": "自動同步資料",
|
||||||
"Mark all as read": "全部標記為已讀",
|
"Mark all as read": "全部標記為已讀",
|
||||||
"Do you want to mark all as read?" : "您要全部標記為已讀嗎?",
|
"Do you want to mark all as read?": "您要全部標記為已讀嗎?",
|
||||||
"Swipe down for previous chapter": "向下滑動查看上一章",
|
"Swipe down for previous chapter": "向下滑動查看上一章",
|
||||||
"Swipe up for next chapter": "向上滑動查看下一章",
|
"Swipe up for next chapter": "向上滑動查看下一章",
|
||||||
"Initial Page": "初始頁面",
|
"Initial Page": "初始頁面",
|
||||||
@@ -747,6 +794,43 @@
|
|||||||
"Refresh": "刷新",
|
"Refresh": "刷新",
|
||||||
"Paging": "分頁",
|
"Paging": "分頁",
|
||||||
"Continuous": "連續",
|
"Continuous": "連續",
|
||||||
"Display mode of comic list": "漫畫列表的顯示模式"
|
"Display mode of comic list": "漫畫列表的顯示模式",
|
||||||
|
"Show Page Number": "顯示頁碼",
|
||||||
|
"Jump to page": "跳轉到頁面",
|
||||||
|
"Page": "頁面",
|
||||||
|
"Jump": "跳轉",
|
||||||
|
"Copy Image": "複製圖片",
|
||||||
|
"A valid WebDav directory URL": "有效的WebDav目錄URL",
|
||||||
|
"Shut Down": "關閉",
|
||||||
|
"Uploading data...": "正在上傳數據...",
|
||||||
|
"Pages": "頁數",
|
||||||
|
"Long press zoom position": "長按縮放位置",
|
||||||
|
"Press position": "按壓位置",
|
||||||
|
"Screen center": "螢幕中心",
|
||||||
|
"Suggestions": "建議",
|
||||||
|
"Do not report any issues related to sources to App repo.": "請不要向App倉庫報告任何與源相關的問題",
|
||||||
|
"Show single image on first page": "在首頁顯示單張圖片",
|
||||||
|
"Show system status bar": "顯示系統狀態欄",
|
||||||
|
"Click to select an image": "點擊選擇一張圖片",
|
||||||
|
"Repo URL": "倉庫地址",
|
||||||
|
"The URL should point to a 'index.json' file": "該URL應指向一個'index.json'文件",
|
||||||
|
"Double tap to zoom": "雙擊縮放",
|
||||||
|
"Clear Unfavorited": "清除未收藏",
|
||||||
|
"Reverse": "反轉",
|
||||||
|
"Delete Chapters": "刪除章節",
|
||||||
|
"Open Folder": "打開資料夾",
|
||||||
|
"Path copied to clipboard": "路徑已複製到剪貼簿",
|
||||||
|
"Reverse default chapter order": "反轉預設章節順序",
|
||||||
|
"Reload Configs": "重新載入設定檔",
|
||||||
|
"Reload": "重載",
|
||||||
|
"Disable Length Limitation": "禁用長度限制",
|
||||||
|
"Only valid for this run": "僅對本次運行有效",
|
||||||
|
"Logs": "日誌",
|
||||||
|
"Export logs": "匯出日誌",
|
||||||
|
"Clear specific reader settings for all comics": "清除所有漫畫的特殊閱讀設定",
|
||||||
|
"Clear specific reader settings for this comic": "清除該漫畫的特殊閱讀設定",
|
||||||
|
"Enable comic specific settings": "啟用此漫畫特定設定",
|
||||||
|
"Ignore Certificate Errors": "忽略證書錯誤",
|
||||||
|
"Mouse scroll speed": "滑鼠滾動速度"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BIN
debian/gui/venera.png
vendored
BIN
debian/gui/venera.png
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 64 KiB |
@@ -9,13 +9,47 @@ Venera uses [flutter_qjs](https://github.com/wgh136/flutter_qjs) as js engine wh
|
|||||||
|
|
||||||
This document will describe how to write a comic source for Venera.
|
This document will describe how to write a comic source for Venera.
|
||||||
|
|
||||||
## Preparation
|
## Comic Source List
|
||||||
|
|
||||||
|
Venera can display a list of comic sources in the app.
|
||||||
|
|
||||||
|
You can use the following repo url:
|
||||||
|
```
|
||||||
|
https://git.nyne.dev/nyne/venera-configs/raw/branch/main/index.json
|
||||||
|
```
|
||||||
|
The repo is maintained by the Venera team.
|
||||||
|
|
||||||
|
> The link is a mirror of the original repo. To contribute your comic source, please visit the [original repo](https://github.com/venera-app/venera-configs)
|
||||||
|
|
||||||
|
You should provide a repository url to let the app load the comic source list.
|
||||||
|
The url should point to a JSON file that contains the list of comic sources.
|
||||||
|
|
||||||
|
The JSON file should have the following format:
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "Source Name",
|
||||||
|
"url": "https://example.com/source.js",
|
||||||
|
"filename": "Relative path to the source file",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A brief description of the source"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
Only one of `url` and `filename` should be provided.
|
||||||
|
The description field is optional.
|
||||||
|
|
||||||
|
## Create a Comic Source
|
||||||
|
|
||||||
|
### Preparation
|
||||||
|
|
||||||
- Install Venera. Using flutter to run the project is recommended since it's easier to debug.
|
- Install Venera. Using flutter to run the project is recommended since it's easier to debug.
|
||||||
- An editor that supports javascript.
|
- An editor that supports javascript.
|
||||||
- Download template and venera javascript api from [here](https://github.com/venera-app/venera-configs).
|
- Download template and venera javascript api from [here](https://github.com/venera-app/venera-configs).
|
||||||
|
|
||||||
## Start Writing
|
### Start Writing
|
||||||
|
|
||||||
The template contains detailed comments and examples. You can refer to it when writing your own comic source.
|
The template contains detailed comments and examples. You can refer to it when writing your own comic source.
|
||||||
|
|
||||||
@@ -23,7 +57,7 @@ Here is a brief introduction to the template:
|
|||||||
|
|
||||||
> Note: Javascript api document is [here](js_api.md).
|
> Note: Javascript api document is [here](js_api.md).
|
||||||
|
|
||||||
### Write basic information
|
#### Write basic information
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
class NewComicSource extends ComicSource {
|
class NewComicSource extends ComicSource {
|
||||||
@@ -49,7 +83,7 @@ In this part, you need to do the following:
|
|||||||
- Change the class name to your source name.
|
- Change the class name to your source name.
|
||||||
- Fill in the name, key, version, minAppVersion, and url fields.
|
- Fill in the name, key, version, minAppVersion, and url fields.
|
||||||
|
|
||||||
### init function
|
#### init function
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
/**
|
/**
|
||||||
@@ -64,7 +98,7 @@ The function will be called when the source is initialized. You can do some init
|
|||||||
|
|
||||||
Remove this function if not used.
|
Remove this function if not used.
|
||||||
|
|
||||||
### Account
|
#### Account
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// [Optional] account related
|
// [Optional] account related
|
||||||
@@ -140,7 +174,7 @@ In this part, you can implement login, logout, and register functions.
|
|||||||
|
|
||||||
Remove this part if not used.
|
Remove this part if not used.
|
||||||
|
|
||||||
### Explore page
|
#### Explore page
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// explore page list
|
// explore page list
|
||||||
@@ -185,7 +219,7 @@ There are three types of explore pages:
|
|||||||
- multiPageComicList: An explore page contains multiple comics, the comics are loaded page by page.
|
- multiPageComicList: An explore page contains multiple comics, the comics are loaded page by page.
|
||||||
- mixed: An explore page contains multiple parts, each part can be a list of comics or a block of comics which have a title and a view more button.
|
- mixed: An explore page contains multiple parts, each part can be a list of comics or a block of comics which have a title and a view more button.
|
||||||
|
|
||||||
### Category Page
|
#### Category Page
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// categories
|
// categories
|
||||||
@@ -227,7 +261,7 @@ Category page is a static page that contains multiple parts, each part contains
|
|||||||
|
|
||||||
A comic source can only have one category page.
|
A comic source can only have one category page.
|
||||||
|
|
||||||
### Category Comics Page
|
#### Category Comics Page
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
/// category comic loading related
|
/// category comic loading related
|
||||||
@@ -280,7 +314,7 @@ When user clicks on a category, the category comics page will be displayed.
|
|||||||
|
|
||||||
This part is used to load comics of a category.
|
This part is used to load comics of a category.
|
||||||
|
|
||||||
### Search
|
#### Search
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
/// search related
|
/// search related
|
||||||
@@ -331,6 +365,11 @@ This part is used to load comics of a category.
|
|||||||
|
|
||||||
// enable tags suggestions
|
// enable tags suggestions
|
||||||
enableTagsSuggestions: false,
|
enableTagsSuggestions: false,
|
||||||
|
// [Optional] handle tag suggestion click
|
||||||
|
onTagSuggestionSelected: (namespace, tag) => {
|
||||||
|
// return the text to insert into search box
|
||||||
|
return `${namespace}:${tag}`
|
||||||
|
},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -339,7 +378,7 @@ This part is used to load search results.
|
|||||||
`load` and `loadNext` functions are used to load search results.
|
`load` and `loadNext` functions are used to load search results.
|
||||||
If `load` function is implemented, `loadNext` function will be ignored.
|
If `load` function is implemented, `loadNext` function will be ignored.
|
||||||
|
|
||||||
### Favorites
|
#### Favorites
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// favorite related
|
// favorite related
|
||||||
@@ -411,7 +450,7 @@ This part is used to manage network favorites of the source.
|
|||||||
`load` and `loadNext` functions are used to load search results.
|
`load` and `loadNext` functions are used to load search results.
|
||||||
If `load` function is implemented, `loadNext` function will be ignored.
|
If `load` function is implemented, `loadNext` function will be ignored.
|
||||||
|
|
||||||
### Comic Details
|
#### Comic Details
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
/// single comic related
|
/// single comic related
|
||||||
@@ -576,7 +615,7 @@ If `load` function is implemented, `loadNext` function will be ignored.
|
|||||||
|
|
||||||
This part is used to load comic details.
|
This part is used to load comic details.
|
||||||
|
|
||||||
### Settings
|
#### Settings
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
/*
|
/*
|
||||||
@@ -635,7 +674,7 @@ This part is used to load comic details.
|
|||||||
This part is used to provide settings for the source.
|
This part is used to provide settings for the source.
|
||||||
|
|
||||||
|
|
||||||
### Translations
|
#### Translations
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// [Optional] translations for the strings in this config
|
// [Optional] translations for the strings in this config
|
||||||
|
|||||||
180
doc/headless_doc.md
Normal file
180
doc/headless_doc.md
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
# Venera Headless Mode
|
||||||
|
|
||||||
|
Venera's headless mode allows you to run key features from the command line, making it easy to automate tasks and integrate with other tools. This document outlines the available commands and their usage.
|
||||||
|
|
||||||
|
## How to Use
|
||||||
|
|
||||||
|
To activate headless mode, use the `--headless` flag when running the Venera executable, followed by the desired command.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
venera --headless <command> [subcommand] [options]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Global Options
|
||||||
|
|
||||||
|
- **`--ignore-disheadless-log`**: Suppresses log output, providing a cleaner output for scripting.
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
### `webdav`
|
||||||
|
|
||||||
|
Manage WebDAV data synchronization.
|
||||||
|
|
||||||
|
- **`webdav up`**: Uploads your local configuration to the WebDAV server.
|
||||||
|
- **`webdav down`**: Downloads and applies the remote configuration from the WebDAV server.
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
venera --headless webdav up
|
||||||
|
```
|
||||||
|
|
||||||
|
### `updatescript`
|
||||||
|
|
||||||
|
Update comic source scripts.
|
||||||
|
|
||||||
|
- **`updatescript all`**: Checks for and applies all available updates for your comic source scripts.
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
venera --headless updatescript all
|
||||||
|
```
|
||||||
|
|
||||||
|
**Output Format:**
|
||||||
|
|
||||||
|
The `updatescript` command provides detailed progress and a final summary.
|
||||||
|
|
||||||
|
**Progress Logs:**
|
||||||
|
|
||||||
|
- **`Progress`**: Indicates a successful update for a single script.
|
||||||
|
- **`ProgressError`**: Indicates a failure during a script update.
|
||||||
|
|
||||||
|
**Example `Progress` Log:**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": "running",
|
||||||
|
"message": "Progress",
|
||||||
|
"data": {
|
||||||
|
"current": 1,
|
||||||
|
"total": 5,
|
||||||
|
"source": {
|
||||||
|
"key": "source-key",
|
||||||
|
"name": "Source Name",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"url": "https://example.com/source.js"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Final Summary:**
|
||||||
|
|
||||||
|
A summary is provided at the end, detailing the total number of scripts, how many were updated, and how many failed.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": "success",
|
||||||
|
"message": "All scripts updated.",
|
||||||
|
"data": {
|
||||||
|
"total": 5,
|
||||||
|
"updated": 4,
|
||||||
|
"errors": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### `updatesubscribe`
|
||||||
|
|
||||||
|
Update your subscribed comics and retrieve a list of updated comics.
|
||||||
|
|
||||||
|
- **`updatesubscribe`**: Checks all subscribed comics for updates.
|
||||||
|
- **`updatesubscribe --update-comic-by-id-type <id> <type>`**: Updates a single comic specified by its `id` and `type`.
|
||||||
|
|
||||||
|
**Example:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Update all subscriptions
|
||||||
|
venera --headless updatesubscribe
|
||||||
|
|
||||||
|
# Update a single comic
|
||||||
|
venera --headless updatesubscribe --update-comic-by-id-type "comic-id" "source-key"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Output Format
|
||||||
|
|
||||||
|
All headless commands output JSON objects prefixed with `[CLI PRINT]`. This structured format allows for easy parsing in automated scripts. The JSON object always contains a `status` and a `message`. For commands that return data, a `data` field will also be present.
|
||||||
|
|
||||||
|
### `updatesubscribe` Output
|
||||||
|
|
||||||
|
The `updatesubscribe` command provides detailed progress and final results in JSON format.
|
||||||
|
|
||||||
|
**Progress Logs:**
|
||||||
|
|
||||||
|
During an update, you will receive `Progress` or `ProgressError` messages.
|
||||||
|
|
||||||
|
- **`Progress`**: Indicates a successful step in the update process.
|
||||||
|
- **`ProgressError`**: Indicates an error occurred while updating a specific comic.
|
||||||
|
|
||||||
|
**Example `Progress` Log:**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": "running",
|
||||||
|
"message": "Progress",
|
||||||
|
"data": {
|
||||||
|
"current": 1,
|
||||||
|
"total": 10,
|
||||||
|
"comic": {
|
||||||
|
"id": "some-comic-id",
|
||||||
|
"name": "Some Comic Name",
|
||||||
|
"coverUrl": "https://example.com/cover.jpg",
|
||||||
|
"author": "Author Name",
|
||||||
|
"type": "source-key",
|
||||||
|
"updateTime": "2023-10-27T12:00:00Z",
|
||||||
|
"tags": ["tag1", "tag2"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Example `ProgressError` Log:**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": "running",
|
||||||
|
"message": "ProgressError",
|
||||||
|
"data": {
|
||||||
|
"current": 2,
|
||||||
|
"total": 10,
|
||||||
|
"comic": {
|
||||||
|
"id": "another-comic-id",
|
||||||
|
"name": "Another Comic Name",
|
||||||
|
...
|
||||||
|
},
|
||||||
|
"error": "Error message here"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Final Output:**
|
||||||
|
|
||||||
|
Once the update process is complete, a final JSON object is returned with a list of all comics that have been updated.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": "success",
|
||||||
|
"message": "Updated comics list.",
|
||||||
|
"data": [
|
||||||
|
{
|
||||||
|
"id": "some-comic-id",
|
||||||
|
"name": "Some Comic Name",
|
||||||
|
"coverUrl": "https://example.com/cover.jpg",
|
||||||
|
"author": "Author Name",
|
||||||
|
"type": "source-key",
|
||||||
|
"updateTime": "2023-10-27T12:00:00Z",
|
||||||
|
"tags": ["tag1", "tag2"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -46,12 +46,14 @@
|
|||||||
<key>UIApplicationSupportsIndirectInputEvents</key>
|
<key>UIApplicationSupportsIndirectInputEvents</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>NSPhotoLibraryUsageDescription</key>
|
<key>NSPhotoLibraryUsageDescription</key>
|
||||||
<string>Choose images</string>
|
<string>Choose images</string>
|
||||||
<key>UIFileSharingEnabled</key>
|
<key>UIFileSharingEnabled</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>LSSupportsOpeningDocumentsInPlace</key>
|
<key>LSSupportsOpeningDocumentsInPlace</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>NSFaceIDUsageDescription</key>
|
<key>NSFaceIDUsageDescription</key>
|
||||||
<string>Ensure that the operation is being performed by the user themselves.</string>
|
<string>Ensure that the operation is being performed by the user themselves.</string>
|
||||||
|
<key>LSApplicationCategoryType</key>
|
||||||
|
<string>public.app-category.books</string>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ class _AppbarState extends State<Appbar> {
|
|||||||
var content = Container(
|
var content = Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: widget.backgroundColor ??
|
color: widget.backgroundColor ??
|
||||||
context.colorScheme.surface.toOpacity(0.72),
|
context.colorScheme.surface.toOpacity(0.86),
|
||||||
),
|
),
|
||||||
height: _kAppBarHeight + context.padding.top,
|
height: _kAppBarHeight + context.padding.top,
|
||||||
child: Row(
|
child: Row(
|
||||||
@@ -231,7 +231,7 @@ class _MySliverAppBarDelegate extends SliverPersistentHeaderDelegate {
|
|||||||
child: BlurEffect(
|
child: BlurEffect(
|
||||||
blur: 15,
|
blur: 15,
|
||||||
child: Material(
|
child: Material(
|
||||||
color: context.colorScheme.surface.toOpacity(0.72),
|
color: context.colorScheme.surface.toOpacity(0.86),
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
borderRadius: BorderRadius.circular(radius),
|
borderRadius: BorderRadius.circular(radius),
|
||||||
child: body,
|
child: body,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ ImageProvider? _findImageProvider(Comic comic) {
|
|||||||
comic.cover,
|
comic.cover,
|
||||||
sourceKey: comic.sourceKey,
|
sourceKey: comic.sourceKey,
|
||||||
cid: comic.id,
|
cid: comic.id,
|
||||||
|
fallbackToLocalCover: comic is FavoriteItem,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
@@ -334,7 +335,12 @@ class ComicTile extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var children = <Widget>[];
|
var children = <Widget>[];
|
||||||
for (var line in text.split('\n')) {
|
var lines = text.split('\n');
|
||||||
|
lines.removeWhere((e) => e.trim().isEmpty);
|
||||||
|
if (lines.length > 3) {
|
||||||
|
lines = lines.sublist(0, 3);
|
||||||
|
}
|
||||||
|
for (var line in lines) {
|
||||||
children.add(Container(
|
children.add(Container(
|
||||||
margin: const EdgeInsets.fromLTRB(2, 0, 2, 2),
|
margin: const EdgeInsets.fromLTRB(2, 0, 2, 2),
|
||||||
padding: constraints.maxWidth < 80
|
padding: constraints.maxWidth < 80
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
|
import 'dart:convert';
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
@@ -21,11 +22,13 @@ import 'package:venera/foundation/image_provider/cached_image.dart';
|
|||||||
import 'package:venera/foundation/image_provider/history_image_provider.dart';
|
import 'package:venera/foundation/image_provider/history_image_provider.dart';
|
||||||
import 'package:venera/foundation/image_provider/local_comic_image.dart';
|
import 'package:venera/foundation/image_provider/local_comic_image.dart';
|
||||||
import 'package:venera/foundation/local.dart';
|
import 'package:venera/foundation/local.dart';
|
||||||
|
import 'package:venera/foundation/log.dart';
|
||||||
import 'package:venera/foundation/res.dart';
|
import 'package:venera/foundation/res.dart';
|
||||||
import 'package:venera/network/cloudflare.dart';
|
import 'package:venera/network/cloudflare.dart';
|
||||||
import 'package:venera/pages/comic_details_page/comic_page.dart';
|
import 'package:venera/pages/comic_details_page/comic_page.dart';
|
||||||
import 'package:venera/pages/favorites/favorites_page.dart';
|
import 'package:venera/pages/favorites/favorites_page.dart';
|
||||||
import 'package:venera/utils/ext.dart';
|
import 'package:venera/utils/ext.dart';
|
||||||
|
import 'package:venera/utils/io.dart';
|
||||||
import 'package:venera/utils/tags_translation.dart';
|
import 'package:venera/utils/tags_translation.dart';
|
||||||
import 'package:venera/utils/translations.dart';
|
import 'package:venera/utils/translations.dart';
|
||||||
|
|
||||||
|
|||||||
@@ -37,9 +37,11 @@ mixin class JsUiApi {
|
|||||||
case 'showInputDialog':
|
case 'showInputDialog':
|
||||||
var title = message['title'];
|
var title = message['title'];
|
||||||
var validator = message['validator'];
|
var validator = message['validator'];
|
||||||
|
var image = message['image'];
|
||||||
if (title is! String) return;
|
if (title is! String) return;
|
||||||
if (validator != null && validator is! JSInvokable) return;
|
if (validator != null && validator is! JSInvokable) return;
|
||||||
return _showInputDialog(title, validator);
|
if (image != null && image is! String) return;
|
||||||
|
return _showInputDialog(title, validator, image);
|
||||||
case 'showSelectDialog':
|
case 'showSelectDialog':
|
||||||
var title = message['title'];
|
var title = message['title'];
|
||||||
var options = message['options'];
|
var options = message['options'];
|
||||||
@@ -124,12 +126,13 @@ mixin class JsUiApi {
|
|||||||
controller?.close();
|
controller?.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> _showInputDialog(String title, JSInvokable? validator) async {
|
Future<String?> _showInputDialog(String title, JSInvokable? validator, String? image) async {
|
||||||
String? result;
|
String? result;
|
||||||
var func = validator == null ? null : JSAutoFreeFunction(validator);
|
var func = validator == null ? null : JSAutoFreeFunction(validator);
|
||||||
await showInputDialog(
|
await showInputDialog(
|
||||||
context: App.rootContext,
|
context: App.rootContext,
|
||||||
title: title,
|
title: title,
|
||||||
|
image: image,
|
||||||
onConfirm: (v) {
|
onConfirm: (v) {
|
||||||
if (func != null) {
|
if (func != null) {
|
||||||
var res = func.call([v]);
|
var res = func.call([v]);
|
||||||
|
|||||||
@@ -163,3 +163,29 @@ class SliverLazyToBoxAdapter extends StatelessWidget {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SliverAnimatedVisibility extends StatelessWidget {
|
||||||
|
const SliverAnimatedVisibility({
|
||||||
|
super.key,
|
||||||
|
required this.visible,
|
||||||
|
required this.child,
|
||||||
|
});
|
||||||
|
|
||||||
|
final bool visible;
|
||||||
|
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var child = visible ? this.child : const SizedBox.shrink();
|
||||||
|
|
||||||
|
return SliverToBoxAdapter(
|
||||||
|
child: AnimatedSize(
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
curve: Curves.easeInOut,
|
||||||
|
alignment: Alignment.topCenter,
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class NetworkError extends StatelessWidget {
|
|||||||
this.retry,
|
this.retry,
|
||||||
this.withAppbar = true,
|
this.withAppbar = true,
|
||||||
this.buttonText,
|
this.buttonText,
|
||||||
|
this.action,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String message;
|
final String message;
|
||||||
@@ -17,6 +18,8 @@ class NetworkError extends StatelessWidget {
|
|||||||
|
|
||||||
final String? buttonText;
|
final String? buttonText;
|
||||||
|
|
||||||
|
final Widget? action;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var cfe = CloudflareException.fromString(message);
|
var cfe = CloudflareException.fromString(message);
|
||||||
@@ -41,18 +44,22 @@ class NetworkError extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(height: 8),
|
||||||
height: 8,
|
|
||||||
),
|
|
||||||
Text(
|
Text(
|
||||||
cfe == null ? message : "Cloudflare verification required".tl,
|
cfe == null ? message : "Cloudflare verification required".tl,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
maxLines: 3,
|
maxLines: 3,
|
||||||
),
|
),
|
||||||
if (retry != null)
|
TextButton(
|
||||||
const SizedBox(
|
onPressed: () {
|
||||||
height: 12,
|
saveFile(
|
||||||
),
|
data: utf8.encode(Log().toString()),
|
||||||
|
filename: 'log.txt',
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: Text("Export logs".tl),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
if (retry != null)
|
if (retry != null)
|
||||||
if (cfe != null)
|
if (cfe != null)
|
||||||
FilledButton(
|
FilledButton(
|
||||||
@@ -63,9 +70,16 @@ class NetworkError extends StatelessWidget {
|
|||||||
child: Text('Verify'.tl),
|
child: Text('Verify'.tl),
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
FilledButton(
|
Row(
|
||||||
onPressed: retry,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
child: Text(buttonText ?? 'Retry'.tl),
|
children: [
|
||||||
|
if (action != null)
|
||||||
|
action!.paddingRight(8),
|
||||||
|
FilledButton(
|
||||||
|
onPressed: retry,
|
||||||
|
child: Text(buttonText ?? 'Retry'.tl),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -74,15 +88,11 @@ class NetworkError extends StatelessWidget {
|
|||||||
body = Column(
|
body = Column(
|
||||||
children: [
|
children: [
|
||||||
const Appbar(title: Text("")),
|
const Appbar(title: Text("")),
|
||||||
Expanded(
|
Expanded(child: body),
|
||||||
child: body,
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return Material(
|
return Material(child: body);
|
||||||
child: body,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,9 +104,7 @@ class ListLoadingIndicator extends StatelessWidget {
|
|||||||
return const SizedBox(
|
return const SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
height: 80,
|
height: 80,
|
||||||
child: Center(
|
child: Center(child: FiveDotLoadingAnimation()),
|
||||||
child: FiveDotLoadingAnimation(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,10 +116,9 @@ class SliverListLoadingIndicator extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// SliverToBoxAdapter can not been lazy loaded.
|
// SliverToBoxAdapter can not been lazy loaded.
|
||||||
// Use SliverList to make sure the animation can be lazy loaded.
|
// Use SliverList to make sure the animation can be lazy loaded.
|
||||||
return SliverList.list(children: const [
|
return SliverList.list(
|
||||||
SizedBox(),
|
children: const [SizedBox(), ListLoadingIndicator()],
|
||||||
ListLoadingIndicator(),
|
);
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,10 +185,7 @@ abstract class LoadingState<T extends StatefulWidget, S extends Object>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget buildError() {
|
Widget buildError() {
|
||||||
return NetworkError(
|
return NetworkError(message: error!, retry: retry);
|
||||||
message: error!,
|
|
||||||
retry: retry,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -323,11 +327,7 @@ abstract class MultiPageLoadingState<T extends StatefulWidget, S extends Object>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget buildError(BuildContext context, String error) {
|
Widget buildError(BuildContext context, String error) {
|
||||||
return NetworkError(
|
return NetworkError(withAppbar: false, message: error, retry: reset);
|
||||||
withAppbar: false,
|
|
||||||
message: error,
|
|
||||||
retry: reset,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -388,7 +388,7 @@ class _FiveDotLoadingAnimationState extends State<FiveDotLoadingAnimation>
|
|||||||
Colors.green,
|
Colors.green,
|
||||||
Colors.blue,
|
Colors.blue,
|
||||||
Colors.yellow,
|
Colors.yellow,
|
||||||
Colors.purple
|
Colors.purple,
|
||||||
];
|
];
|
||||||
|
|
||||||
static const _padding = 12.0;
|
static const _padding = 12.0;
|
||||||
@@ -400,16 +400,15 @@ class _FiveDotLoadingAnimationState extends State<FiveDotLoadingAnimation>
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return AnimatedBuilder(
|
return AnimatedBuilder(
|
||||||
animation: _controller,
|
animation: _controller,
|
||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
width: _dotSize * 5 + _padding * 6,
|
width: _dotSize * 5 + _padding * 6,
|
||||||
height: _height,
|
height: _height,
|
||||||
child: Stack(
|
child: Stack(children: List.generate(5, (index) => buildDot(index))),
|
||||||
children: List.generate(5, (index) => buildDot(index)),
|
);
|
||||||
),
|
},
|
||||||
);
|
);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildDot(int index) {
|
Widget buildDot(int index) {
|
||||||
@@ -417,7 +416,8 @@ class _FiveDotLoadingAnimationState extends State<FiveDotLoadingAnimation>
|
|||||||
var startValue = index * 0.8;
|
var startValue = index * 0.8;
|
||||||
return Positioned(
|
return Positioned(
|
||||||
left: index * _dotSize + (index + 1) * _padding,
|
left: index * _dotSize + (index + 1) * _padding,
|
||||||
bottom: (math.sin(math.pi / 2 * (value - startValue).clamp(0, 2))) *
|
bottom:
|
||||||
|
(math.sin(math.pi / 2 * (value - startValue).clamp(0, 2))) *
|
||||||
(_height - _dotSize),
|
(_height - _dotSize),
|
||||||
child: Container(
|
child: Container(
|
||||||
width: _dotSize,
|
width: _dotSize,
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class _MenuRoute<T> extends PopupRoute<T> {
|
|||||||
child: BlurEffect(
|
child: BlurEffect(
|
||||||
borderRadius: BorderRadius.circular(4),
|
borderRadius: BorderRadius.circular(4),
|
||||||
child: Material(
|
child: Material(
|
||||||
color: context.colorScheme.surface.toOpacity(0.78),
|
color: context.colorScheme.surface.toOpacity(0.92),
|
||||||
borderRadius: BorderRadius.circular(4),
|
borderRadius: BorderRadius.circular(4),
|
||||||
child: Container(
|
child: Container(
|
||||||
width: width,
|
width: width,
|
||||||
|
|||||||
@@ -290,28 +290,30 @@ class ContentDialog extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var content = Column(
|
var content = SingleChildScrollView(
|
||||||
mainAxisSize: MainAxisSize.min,
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
title != null
|
children: [
|
||||||
? Appbar(
|
title != null
|
||||||
leading: IconButton(
|
? Appbar(
|
||||||
icon: const Icon(Icons.close),
|
leading: IconButton(
|
||||||
onPressed: dismissible ? context.pop : null,
|
icon: const Icon(Icons.close),
|
||||||
),
|
onPressed: dismissible ? context.pop : null,
|
||||||
title: Text(title!),
|
),
|
||||||
backgroundColor: Colors.transparent,
|
title: Text(title!),
|
||||||
)
|
backgroundColor: Colors.transparent,
|
||||||
: const SizedBox.shrink(),
|
)
|
||||||
this.content,
|
: const SizedBox.shrink(),
|
||||||
const SizedBox(height: 16),
|
this.content,
|
||||||
Row(
|
const SizedBox(height: 16),
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
Row(
|
||||||
children: actions,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
).paddingRight(12),
|
children: actions,
|
||||||
const SizedBox(height: 16),
|
).paddingRight(12),
|
||||||
],
|
const SizedBox(height: 16),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
return Dialog(
|
return Dialog(
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
@@ -357,6 +359,7 @@ Future<void> showInputDialog({
|
|||||||
String confirmText = "Confirm",
|
String confirmText = "Confirm",
|
||||||
String cancelText = "Cancel",
|
String cancelText = "Cancel",
|
||||||
RegExp? inputValidator,
|
RegExp? inputValidator,
|
||||||
|
String? image,
|
||||||
}) {
|
}) {
|
||||||
var controller = TextEditingController(text: initialValue);
|
var controller = TextEditingController(text: initialValue);
|
||||||
bool isLoading = false;
|
bool isLoading = false;
|
||||||
@@ -369,14 +372,23 @@ Future<void> showInputDialog({
|
|||||||
builder: (context, setState) {
|
builder: (context, setState) {
|
||||||
return ContentDialog(
|
return ContentDialog(
|
||||||
title: title,
|
title: title,
|
||||||
content: TextField(
|
content: Column(
|
||||||
controller: controller,
|
children: [
|
||||||
decoration: InputDecoration(
|
if (image != null)
|
||||||
hintText: hintText,
|
SizedBox(
|
||||||
border: const OutlineInputBorder(),
|
height: 108,
|
||||||
errorText: error,
|
child: Image.network(image, fit: BoxFit.none),
|
||||||
),
|
).paddingBottom(8),
|
||||||
).paddingHorizontal(12),
|
TextField(
|
||||||
|
controller: controller,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: hintText,
|
||||||
|
border: const OutlineInputBorder(),
|
||||||
|
errorText: error,
|
||||||
|
),
|
||||||
|
).paddingHorizontal(12),
|
||||||
|
],
|
||||||
|
),
|
||||||
actions: [
|
actions: [
|
||||||
Button.filled(
|
Button.filled(
|
||||||
isLoading: isLoading,
|
isLoading: isLoading,
|
||||||
|
|||||||
@@ -7,8 +7,11 @@ class PaneItemEntry {
|
|||||||
|
|
||||||
IconData activeIcon;
|
IconData activeIcon;
|
||||||
|
|
||||||
PaneItemEntry(
|
PaneItemEntry({
|
||||||
{required this.label, required this.icon, required this.activeIcon});
|
required this.label,
|
||||||
|
required this.icon,
|
||||||
|
required this.activeIcon,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class PaneActionEntry {
|
class PaneActionEntry {
|
||||||
@@ -18,20 +21,24 @@ class PaneActionEntry {
|
|||||||
|
|
||||||
VoidCallback onTap;
|
VoidCallback onTap;
|
||||||
|
|
||||||
PaneActionEntry(
|
PaneActionEntry({
|
||||||
{required this.label, required this.icon, required this.onTap});
|
required this.label,
|
||||||
|
required this.icon,
|
||||||
|
required this.onTap,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class NaviPane extends StatefulWidget {
|
class NaviPane extends StatefulWidget {
|
||||||
const NaviPane(
|
const NaviPane({
|
||||||
{required this.paneItems,
|
required this.paneItems,
|
||||||
required this.paneActions,
|
required this.paneActions,
|
||||||
required this.pageBuilder,
|
required this.pageBuilder,
|
||||||
this.initialPage = 0,
|
this.initialPage = 0,
|
||||||
this.onPageChanged,
|
this.onPageChanged,
|
||||||
required this.observer,
|
required this.observer,
|
||||||
required this.navigatorKey,
|
required this.navigatorKey,
|
||||||
super.key});
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
final List<PaneItemEntry> paneItems;
|
final List<PaneItemEntry> paneItems;
|
||||||
|
|
||||||
@@ -187,7 +194,8 @@ class NaviPaneState extends State<NaviPane>
|
|||||||
child: buildLeft(),
|
child: buildLeft(),
|
||||||
),
|
),
|
||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
left: _kFoldedSideBarWidth * ((value - 1).clamp(0, 1)) +
|
left:
|
||||||
|
_kFoldedSideBarWidth * ((value - 1).clamp(0, 1)) +
|
||||||
(_kSideBarWidth - _kFoldedSideBarWidth) *
|
(_kSideBarWidth - _kFoldedSideBarWidth) *
|
||||||
((value - 2).clamp(0, 1)),
|
((value - 2).clamp(0, 1)),
|
||||||
child: buildMainView(),
|
child: buildMainView(),
|
||||||
@@ -202,14 +210,19 @@ class NaviPaneState extends State<NaviPane>
|
|||||||
Widget buildMainView() {
|
Widget buildMainView() {
|
||||||
return HeroControllerScope(
|
return HeroControllerScope(
|
||||||
controller: MaterialApp.createMaterialHeroController(),
|
controller: MaterialApp.createMaterialHeroController(),
|
||||||
child: Navigator(
|
child: NavigatorPopHandler(
|
||||||
observers: [widget.observer],
|
onPopWithResult: (result) {
|
||||||
key: widget.navigatorKey,
|
widget.navigatorKey.currentState?.maybePop(result);
|
||||||
onGenerateRoute: (settings) => AppPageRoute(
|
},
|
||||||
preventRebuild: false,
|
child: Navigator(
|
||||||
builder: (context) {
|
observers: [widget.observer],
|
||||||
return _NaviMainView(state: this);
|
key: widget.navigatorKey,
|
||||||
},
|
onGenerateRoute: (settings) => AppPageRoute(
|
||||||
|
preventRebuild: false,
|
||||||
|
builder: (context) {
|
||||||
|
return _NaviMainView(state: this);
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -239,7 +252,7 @@ class NaviPaneState extends State<NaviPane>
|
|||||||
icon: Icon(action.icon),
|
icon: Icon(action.icon),
|
||||||
onPressed: action.onTap,
|
onPressed: action.onTap,
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -261,21 +274,18 @@ class NaviPaneState extends State<NaviPane>
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: List<Widget>.generate(
|
children: List<Widget>.generate(widget.paneItems.length, (index) {
|
||||||
widget.paneItems.length,
|
return Expanded(
|
||||||
(index) {
|
child: _SingleBottomNaviWidget(
|
||||||
return Expanded(
|
enabled: currentPage == index,
|
||||||
child: _SingleBottomNaviWidget(
|
entry: widget.paneItems[index],
|
||||||
enabled: currentPage == index,
|
onTap: () {
|
||||||
entry: widget.paneItems[index],
|
updatePage(index);
|
||||||
onTap: () {
|
},
|
||||||
updatePage(index);
|
key: ValueKey(index),
|
||||||
},
|
),
|
||||||
key: ValueKey(index),
|
);
|
||||||
),
|
}),
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -286,7 +296,8 @@ class NaviPaneState extends State<NaviPane>
|
|||||||
const paddingHorizontal = 12.0;
|
const paddingHorizontal = 12.0;
|
||||||
return Material(
|
return Material(
|
||||||
child: Container(
|
child: Container(
|
||||||
width: _kFoldedSideBarWidth +
|
width:
|
||||||
|
_kFoldedSideBarWidth +
|
||||||
(_kSideBarWidth - _kFoldedSideBarWidth) * ((value - 2).clamp(0, 1)),
|
(_kSideBarWidth - _kFoldedSideBarWidth) * ((value - 2).clamp(0, 1)),
|
||||||
height: double.infinity,
|
height: double.infinity,
|
||||||
padding: const EdgeInsets.symmetric(horizontal: paddingHorizontal),
|
padding: const EdgeInsets.symmetric(horizontal: paddingHorizontal),
|
||||||
@@ -323,9 +334,7 @@ class NaviPaneState extends State<NaviPane>
|
|||||||
key: ValueKey(index + widget.paneItems.length),
|
key: ValueKey(index + widget.paneItems.length),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(height: 16),
|
||||||
height: 16,
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -334,12 +343,13 @@ class NaviPaneState extends State<NaviPane>
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _SideNaviWidget extends StatelessWidget {
|
class _SideNaviWidget extends StatelessWidget {
|
||||||
const _SideNaviWidget(
|
const _SideNaviWidget({
|
||||||
{required this.enabled,
|
required this.enabled,
|
||||||
required this.entry,
|
required this.entry,
|
||||||
required this.onTap,
|
required this.onTap,
|
||||||
required this.showTitle,
|
required this.showTitle,
|
||||||
super.key});
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
final bool enabled;
|
final bool enabled;
|
||||||
|
|
||||||
@@ -368,18 +378,18 @@ class _SideNaviWidget extends StatelessWidget {
|
|||||||
? Row(
|
? Row(
|
||||||
children: [icon, const SizedBox(width: 12), Text(entry.label)],
|
children: [icon, const SizedBox(width: 12), Text(entry.label)],
|
||||||
)
|
)
|
||||||
: Align(
|
: Align(alignment: Alignment.centerLeft, child: icon),
|
||||||
alignment: Alignment.centerLeft,
|
|
||||||
child: icon,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
).paddingVertical(4);
|
).paddingVertical(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PaneActionWidget extends StatelessWidget {
|
class _PaneActionWidget extends StatelessWidget {
|
||||||
const _PaneActionWidget(
|
const _PaneActionWidget({
|
||||||
{required this.entry, required this.showTitle, super.key});
|
required this.entry,
|
||||||
|
required this.showTitle,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
final PaneActionEntry entry;
|
final PaneActionEntry entry;
|
||||||
|
|
||||||
@@ -399,21 +409,19 @@ class _PaneActionWidget extends StatelessWidget {
|
|||||||
? Row(
|
? Row(
|
||||||
children: [icon, const SizedBox(width: 12), Text(entry.label)],
|
children: [icon, const SizedBox(width: 12), Text(entry.label)],
|
||||||
)
|
)
|
||||||
: Align(
|
: Align(alignment: Alignment.centerLeft, child: icon),
|
||||||
alignment: Alignment.centerLeft,
|
|
||||||
child: icon,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
).paddingVertical(4);
|
).paddingVertical(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SingleBottomNaviWidget extends StatefulWidget {
|
class _SingleBottomNaviWidget extends StatefulWidget {
|
||||||
const _SingleBottomNaviWidget(
|
const _SingleBottomNaviWidget({
|
||||||
{required this.enabled,
|
required this.enabled,
|
||||||
required this.entry,
|
required this.entry,
|
||||||
required this.onTap,
|
required this.onTap,
|
||||||
super.key});
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
final bool enabled;
|
final bool enabled;
|
||||||
|
|
||||||
@@ -482,8 +490,9 @@ class _SingleBottomNaviWidgetState extends State<_SingleBottomNaviWidget>
|
|||||||
Widget buildContent() {
|
Widget buildContent() {
|
||||||
final value = controller.value;
|
final value = controller.value;
|
||||||
final colorScheme = Theme.of(context).colorScheme;
|
final colorScheme = Theme.of(context).colorScheme;
|
||||||
final icon =
|
final icon = Icon(
|
||||||
Icon(widget.enabled ? widget.entry.activeIcon : widget.entry.icon);
|
widget.enabled ? widget.entry.activeIcon : widget.entry.icon,
|
||||||
|
);
|
||||||
return Center(
|
return Center(
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 64,
|
width: 64,
|
||||||
@@ -570,8 +579,11 @@ class NaviObserver extends NavigatorObserver implements Listenable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _NaviPopScope extends StatelessWidget {
|
class _NaviPopScope extends StatelessWidget {
|
||||||
const _NaviPopScope(
|
const _NaviPopScope({
|
||||||
{required this.child, this.popGesture = false, required this.action});
|
required this.child,
|
||||||
|
this.popGesture = false,
|
||||||
|
required this.action,
|
||||||
|
});
|
||||||
|
|
||||||
final Widget child;
|
final Widget child;
|
||||||
final bool popGesture;
|
final bool popGesture;
|
||||||
@@ -581,32 +593,25 @@ class _NaviPopScope extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Widget res = App.isIOS
|
Widget res = child;
|
||||||
? child
|
|
||||||
: PopScope(
|
|
||||||
canPop: App.isAndroid ? false : true,
|
|
||||||
onPopInvokedWithResult: (value, result) {
|
|
||||||
action();
|
|
||||||
},
|
|
||||||
child: child,
|
|
||||||
);
|
|
||||||
if (popGesture) {
|
if (popGesture) {
|
||||||
res = GestureDetector(
|
res = GestureDetector(
|
||||||
onPanStart: (details) {
|
onPanStart: (details) {
|
||||||
if (details.globalPosition.dx < 64) {
|
if (details.globalPosition.dx < 64) {
|
||||||
panStartAtEdge = true;
|
panStartAtEdge = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onPanEnd: (details) {
|
||||||
|
if (details.velocity.pixelsPerSecond.dx < 0 ||
|
||||||
|
details.velocity.pixelsPerSecond.dx > 0) {
|
||||||
|
if (panStartAtEdge) {
|
||||||
|
action();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
onPanEnd: (details) {
|
panStartAtEdge = false;
|
||||||
if (details.velocity.pixelsPerSecond.dx < 0 ||
|
},
|
||||||
details.velocity.pixelsPerSecond.dx > 0) {
|
child: res,
|
||||||
if (panStartAtEdge) {
|
);
|
||||||
action();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
panStartAtEdge = false;
|
|
||||||
},
|
|
||||||
child: res);
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,10 +51,32 @@ class _SmoothScrollProviderState extends State<SmoothScrollProvider> {
|
|||||||
|
|
||||||
static bool _isMouseScroll = App.isDesktop;
|
static bool _isMouseScroll = App.isDesktop;
|
||||||
|
|
||||||
|
late int id;
|
||||||
|
|
||||||
|
static int _id = 0;
|
||||||
|
|
||||||
|
var activeChildren = <int>{};
|
||||||
|
|
||||||
|
ScrollState? parent;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
_controller = widget.controller ?? ScrollController();
|
_controller = widget.controller ?? ScrollController();
|
||||||
super.initState();
|
super.initState();
|
||||||
|
id = _id;
|
||||||
|
_id++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
parent = ScrollState.maybeOf(context);
|
||||||
|
super.didChangeDependencies();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
parent?.onChildInactive(id);
|
||||||
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -66,8 +88,7 @@ class _SmoothScrollProviderState extends State<SmoothScrollProvider> {
|
|||||||
const BouncingScrollPhysics(),
|
const BouncingScrollPhysics(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return Listener(
|
var child = Listener(
|
||||||
behavior: HitTestBehavior.translucent,
|
|
||||||
onPointerDown: (event) {
|
onPointerDown: (event) {
|
||||||
_futurePosition = null;
|
_futurePosition = null;
|
||||||
if (_isMouseScroll) {
|
if (_isMouseScroll) {
|
||||||
@@ -77,6 +98,9 @@ class _SmoothScrollProviderState extends State<SmoothScrollProvider> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onPointerSignal: (pointerSignal) {
|
onPointerSignal: (pointerSignal) {
|
||||||
|
if (activeChildren.isNotEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (pointerSignal is PointerScrollEvent) {
|
if (pointerSignal is PointerScrollEvent) {
|
||||||
if (HardwareKeyboard.instance.isShiftPressed) {
|
if (HardwareKeyboard.instance.isShiftPressed) {
|
||||||
return;
|
return;
|
||||||
@@ -93,16 +117,25 @@ class _SmoothScrollProviderState extends State<SmoothScrollProvider> {
|
|||||||
_futurePosition ??= currentLocation;
|
_futurePosition ??= currentLocation;
|
||||||
double k = (_futurePosition! - currentLocation).abs() / 1600 + 1;
|
double k = (_futurePosition! - currentLocation).abs() / 1600 + 1;
|
||||||
_futurePosition = _futurePosition! + pointerSignal.scrollDelta.dy * k;
|
_futurePosition = _futurePosition! + pointerSignal.scrollDelta.dy * k;
|
||||||
|
var beforeOffset = (_futurePosition! - currentLocation).abs();
|
||||||
_futurePosition = _futurePosition!.clamp(
|
_futurePosition = _futurePosition!.clamp(
|
||||||
_controller.position.minScrollExtent,
|
_controller.position.minScrollExtent,
|
||||||
_controller.position.maxScrollExtent,
|
_controller.position.maxScrollExtent,
|
||||||
);
|
);
|
||||||
|
var afterOffset = (_futurePosition! - currentLocation).abs();
|
||||||
if (_futurePosition == old) return;
|
if (_futurePosition == old) return;
|
||||||
var target = _futurePosition!;
|
var target = _futurePosition!;
|
||||||
|
var duration = _fastAnimationDuration;
|
||||||
|
if (afterOffset < beforeOffset) {
|
||||||
|
duration = duration * (afterOffset / beforeOffset);
|
||||||
|
if (duration < Duration(milliseconds: 10)) {
|
||||||
|
duration = Duration(milliseconds: 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
_controller
|
_controller
|
||||||
.animateTo(
|
.animateTo(
|
||||||
_futurePosition!,
|
_futurePosition!,
|
||||||
duration: _fastAnimationDuration,
|
duration: duration,
|
||||||
curve: Curves.linear,
|
curve: Curves.linear,
|
||||||
)
|
)
|
||||||
.then((_) {
|
.then((_) {
|
||||||
@@ -113,8 +146,14 @@ class _SmoothScrollProviderState extends State<SmoothScrollProvider> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: ScrollControllerProvider._(
|
child: ScrollState._(
|
||||||
controller: _controller,
|
controller: _controller,
|
||||||
|
onChildActive: (id) {
|
||||||
|
activeChildren.add(id);
|
||||||
|
},
|
||||||
|
onChildInactive: (id) {
|
||||||
|
activeChildren.remove(id);
|
||||||
|
},
|
||||||
child: widget.builder(
|
child: widget.builder(
|
||||||
context,
|
context,
|
||||||
_controller,
|
_controller,
|
||||||
@@ -124,25 +163,49 @@ class _SmoothScrollProviderState extends State<SmoothScrollProvider> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (parent != null) {
|
||||||
|
return MouseRegion(
|
||||||
|
onEnter: (_) {
|
||||||
|
parent!.onChildActive(id);
|
||||||
|
},
|
||||||
|
onExit: (_) {
|
||||||
|
parent!.onChildInactive(id);
|
||||||
|
},
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ScrollControllerProvider extends InheritedWidget {
|
class ScrollState extends InheritedWidget {
|
||||||
const ScrollControllerProvider._({
|
const ScrollState._({
|
||||||
required this.controller,
|
required this.controller,
|
||||||
required super.child,
|
required super.child,
|
||||||
|
required this.onChildActive,
|
||||||
|
required this.onChildInactive,
|
||||||
});
|
});
|
||||||
|
|
||||||
final ScrollController controller;
|
final ScrollController controller;
|
||||||
|
|
||||||
static ScrollController of(BuildContext context) {
|
final void Function(int id) onChildActive;
|
||||||
final ScrollControllerProvider? provider =
|
|
||||||
context.dependOnInheritedWidgetOfExactType<ScrollControllerProvider>();
|
final void Function(int id) onChildInactive;
|
||||||
return provider!.controller;
|
|
||||||
|
static ScrollState of(BuildContext context) {
|
||||||
|
final ScrollState? provider =
|
||||||
|
context.dependOnInheritedWidgetOfExactType<ScrollState>();
|
||||||
|
return provider!;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ScrollState? maybeOf(BuildContext context) {
|
||||||
|
return context.dependOnInheritedWidgetOfExactType<ScrollState>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool updateShouldNotify(ScrollControllerProvider oldWidget) {
|
bool updateShouldNotify(ScrollState oldWidget) {
|
||||||
return oldWidget.controller != controller;
|
return oldWidget.controller != controller;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,7 +237,7 @@ class _AppScrollBarState extends State<AppScrollBar> {
|
|||||||
|
|
||||||
double viewHeight = 0;
|
double viewHeight = 0;
|
||||||
|
|
||||||
final _scrollIndicatorSize = App.isDesktop ? 42.0 : 64.0;
|
final _scrollIndicatorSize = App.isDesktop ? 36.0 : 54.0;
|
||||||
|
|
||||||
late final VerticalDragGestureRecognizer _dragGestureRecognizer;
|
late final VerticalDragGestureRecognizer _dragGestureRecognizer;
|
||||||
|
|
||||||
@@ -291,7 +354,7 @@ class _ScrollIndicatorPainter extends CustomPainter {
|
|||||||
Offset(size.width, 0),
|
Offset(size.width, 0),
|
||||||
radius: Radius.circular(size.width),
|
radius: Radius.circular(size.width),
|
||||||
);
|
);
|
||||||
canvas.drawShadow(path, shadowColor, 4, true);
|
canvas.drawShadow(path, shadowColor, 2, true);
|
||||||
var backgroundPaint = Paint()
|
var backgroundPaint = Paint()
|
||||||
..color = backgroundColor
|
..color = backgroundColor
|
||||||
..style = PaintingStyle.fill;
|
..style = PaintingStyle.fill;
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ class _WindowFrameState extends State<WindowFrame> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
windowManager.close();
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -147,9 +147,10 @@ class _WindowFrameState extends State<WindowFrame> {
|
|||||||
onPressed: debug,
|
onPressed: debug,
|
||||||
child: Text('Debug'),
|
child: Text('Debug'),
|
||||||
),
|
),
|
||||||
if (!App.isMacOS) _WindowButtons(
|
if (!App.isMacOS)
|
||||||
onClose: _onClose,
|
_WindowButtons(
|
||||||
)
|
onClose: _onClose,
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -559,22 +560,18 @@ class _VirtualWindowFrameState extends State<VirtualWindowFrame>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildVirtualWindowFrame(BuildContext context) {
|
Widget _buildVirtualWindowFrame(BuildContext context) {
|
||||||
return DecoratedBox(
|
return Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(_isMaximized ? 0 : 8),
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
border: Border.all(
|
|
||||||
color: Theme.of(context).dividerColor,
|
|
||||||
width: (_isMaximized || _isFullScreen) ? 0 : 1,
|
|
||||||
),
|
|
||||||
boxShadow: <BoxShadow>[
|
boxShadow: <BoxShadow>[
|
||||||
if (!_isMaximized && !_isFullScreen)
|
BoxShadow(
|
||||||
BoxShadow(
|
color: Colors.black.toOpacity(_isFocused ? 0.4 : 0.2),
|
||||||
color: Colors.black.toOpacity(0.1),
|
blurRadius: 4,
|
||||||
offset: Offset(0.0, _isFocused ? 4 : 2),
|
)
|
||||||
blurRadius: 6,
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
clipBehavior: Clip.antiAlias,
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -583,7 +580,10 @@ class _VirtualWindowFrameState extends State<VirtualWindowFrame>
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return DragToResizeArea(
|
return DragToResizeArea(
|
||||||
enableResizeEdges: (_isMaximized || _isFullScreen) ? [] : null,
|
enableResizeEdges: (_isMaximized || _isFullScreen) ? [] : null,
|
||||||
child: _buildVirtualWindowFrame(context),
|
child: Padding(
|
||||||
|
padding: EdgeInsets.all(_isMaximized ? 0 : 4),
|
||||||
|
child: _buildVirtualWindowFrame(context),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export "widget_utils.dart";
|
|||||||
export "context.dart";
|
export "context.dart";
|
||||||
|
|
||||||
class _App {
|
class _App {
|
||||||
final version = "1.3.3";
|
final version = "1.6.0";
|
||||||
|
|
||||||
bool get isAndroid => Platform.isAndroid;
|
bool get isAndroid => Platform.isAndroid;
|
||||||
|
|
||||||
@@ -30,6 +30,10 @@ class _App {
|
|||||||
|
|
||||||
bool get isMobile => Platform.isAndroid || Platform.isIOS;
|
bool get isMobile => Platform.isAndroid || Platform.isIOS;
|
||||||
|
|
||||||
|
// Whether the app has been initialized.
|
||||||
|
// If current Isolate is main Isolate, this value is always true.
|
||||||
|
bool isInitialized = false;
|
||||||
|
|
||||||
Locale get locale {
|
Locale get locale {
|
||||||
Locale deviceLocale = PlatformDispatcher.instance.locale;
|
Locale deviceLocale = PlatformDispatcher.instance.locale;
|
||||||
if (deviceLocale.languageCode == "zh" &&
|
if (deviceLocale.languageCode == "zh" &&
|
||||||
@@ -47,6 +51,7 @@ class _App {
|
|||||||
|
|
||||||
late String dataPath;
|
late String dataPath;
|
||||||
late String cachePath;
|
late String cachePath;
|
||||||
|
String? externalStoragePath;
|
||||||
|
|
||||||
final rootNavigatorKey = GlobalKey<NavigatorState>();
|
final rootNavigatorKey = GlobalKey<NavigatorState>();
|
||||||
|
|
||||||
@@ -77,6 +82,10 @@ class _App {
|
|||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
cachePath = (await getApplicationCacheDirectory()).path;
|
cachePath = (await getApplicationCacheDirectory()).path;
|
||||||
dataPath = (await getApplicationSupportDirectory()).path;
|
dataPath = (await getApplicationSupportDirectory()).path;
|
||||||
|
if (isAndroid) {
|
||||||
|
externalStoragePath = (await getExternalStorageDirectory())!.path;
|
||||||
|
}
|
||||||
|
isInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> initComponents() async {
|
Future<void> initComponents() async {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'dart:math';
|
|||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:venera/foundation/app.dart';
|
||||||
|
|
||||||
const double _kBackGestureWidth = 20.0;
|
const double _kBackGestureWidth = 20.0;
|
||||||
const int _kMaxDroppedSwipePageForwardAnimationTime = 800;
|
const int _kMaxDroppedSwipePageForwardAnimationTime = 800;
|
||||||
@@ -115,12 +116,19 @@ mixin _AppRouteTransitionMixin<T> on PageRoute<T> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
|
Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
|
||||||
return SlidePageTransitionBuilder().buildTransitions(
|
PageTransitionsBuilder builder;
|
||||||
|
if (App.isAndroid) {
|
||||||
|
builder = PredictiveBackPageTransitionsBuilder();
|
||||||
|
} else {
|
||||||
|
builder = SlidePageTransitionBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.buildTransitions(
|
||||||
this,
|
this,
|
||||||
context,
|
context,
|
||||||
animation,
|
animation,
|
||||||
secondaryAnimation,
|
secondaryAnimation,
|
||||||
enableIOSGesture
|
enableIOSGesture && App.isIOS
|
||||||
? IOSBackGestureDetector(
|
? IOSBackGestureDetector(
|
||||||
gestureWidth: _kBackGestureWidth,
|
gestureWidth: _kBackGestureWidth,
|
||||||
enabledCallback: () => _isPopGestureEnabled<T>(this),
|
enabledCallback: () => _isPopGestureEnabled<T>(this),
|
||||||
@@ -294,7 +302,7 @@ class _IOSBackGestureDetectorState extends State<IOSBackGestureDetector> {
|
|||||||
assert(mounted);
|
assert(mounted);
|
||||||
assert(_backGestureController != null);
|
assert(_backGestureController != null);
|
||||||
_backGestureController!.dragUpdate(
|
_backGestureController!.dragUpdate(
|
||||||
_convertToLogical(details.primaryDelta! / context.size!.width));
|
_convertToLogical(details.primaryDelta! / context.size!.width));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'dart:convert';
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:venera/foundation/app.dart';
|
import 'package:venera/foundation/app.dart';
|
||||||
|
import 'package:venera/foundation/log.dart';
|
||||||
import 'package:venera/utils/data_sync.dart';
|
import 'package:venera/utils/data_sync.dart';
|
||||||
import 'package:venera/utils/init.dart';
|
import 'package:venera/utils/init.dart';
|
||||||
import 'package:venera/utils/io.dart';
|
import 'package:venera/utils/io.dart';
|
||||||
@@ -17,17 +18,17 @@ class Appdata with Init {
|
|||||||
bool _isSavingData = false;
|
bool _isSavingData = false;
|
||||||
|
|
||||||
Future<void> saveData([bool sync = true]) async {
|
Future<void> saveData([bool sync = true]) async {
|
||||||
if (_isSavingData) {
|
while (_isSavingData) {
|
||||||
await Future.doWhile(() async {
|
await Future.delayed(const Duration(milliseconds: 20));
|
||||||
await Future.delayed(const Duration(milliseconds: 20));
|
|
||||||
return _isSavingData;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
_isSavingData = true;
|
_isSavingData = true;
|
||||||
var data = jsonEncode(toJson());
|
try {
|
||||||
var file = File(FilePath.join(App.dataPath, 'appdata.json'));
|
var data = jsonEncode(toJson());
|
||||||
await file.writeAsString(data);
|
var file = File(FilePath.join(App.dataPath, 'appdata.json'));
|
||||||
_isSavingData = false;
|
await file.writeAsString(data);
|
||||||
|
} finally {
|
||||||
|
_isSavingData = false;
|
||||||
|
}
|
||||||
if (sync) {
|
if (sync) {
|
||||||
DataSync().uploadData();
|
DataSync().uploadData();
|
||||||
}
|
}
|
||||||
@@ -55,10 +56,7 @@ class Appdata with Init {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
return {
|
return {'settings': settings._data, 'searchHistory': searchHistory};
|
||||||
'settings': settings._data,
|
|
||||||
'searchHistory': searchHistory,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Following fields are related to device-specific data and should not be synced.
|
/// Following fields are related to device-specific data and should not be synced.
|
||||||
@@ -85,31 +83,49 @@ class Appdata with Init {
|
|||||||
|
|
||||||
var implicitData = <String, dynamic>{};
|
var implicitData = <String, dynamic>{};
|
||||||
|
|
||||||
void writeImplicitData() {
|
void writeImplicitData() async {
|
||||||
var file = File(FilePath.join(App.dataPath, 'implicitData.json'));
|
while (_isSavingData) {
|
||||||
file.writeAsString(jsonEncode(implicitData));
|
await Future.delayed(const Duration(milliseconds: 20));
|
||||||
|
}
|
||||||
|
_isSavingData = true;
|
||||||
|
try {
|
||||||
|
var file = File(FilePath.join(App.dataPath, 'implicitData.json'));
|
||||||
|
await file.writeAsString(jsonEncode(implicitData));
|
||||||
|
} finally {
|
||||||
|
_isSavingData = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> doInit() async {
|
Future<void> doInit() async {
|
||||||
var dataPath = (await getApplicationSupportDirectory()).path;
|
var dataPath = (await getApplicationSupportDirectory()).path;
|
||||||
var file = File(FilePath.join(
|
var file = File(FilePath.join(dataPath, 'appdata.json'));
|
||||||
dataPath,
|
|
||||||
'appdata.json',
|
|
||||||
));
|
|
||||||
if (!await file.exists()) {
|
if (!await file.exists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var json = jsonDecode(await file.readAsString());
|
try {
|
||||||
for (var key in (json['settings'] as Map<String, dynamic>).keys) {
|
var json = jsonDecode(await file.readAsString());
|
||||||
if (json['settings'][key] != null) {
|
for (var key in (json['settings'] as Map<String, dynamic>).keys) {
|
||||||
settings[key] = json['settings'][key];
|
if (json['settings'][key] != null) {
|
||||||
|
settings[key] = json['settings'][key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
searchHistory = List.from(json['searchHistory']);
|
||||||
|
} catch (e) {
|
||||||
|
Log.error("Appdata", "Failed to load appdata", e);
|
||||||
|
Log.info("Appdata", "Resetting appdata");
|
||||||
|
file.deleteIgnoreError();
|
||||||
}
|
}
|
||||||
searchHistory = List.from(json['searchHistory']);
|
try {
|
||||||
var implicitDataFile = File(FilePath.join(dataPath, 'implicitData.json'));
|
var implicitDataFile = File(FilePath.join(dataPath, 'implicitData.json'));
|
||||||
if (await implicitDataFile.exists()) {
|
if (await implicitDataFile.exists()) {
|
||||||
implicitData = jsonDecode(await implicitDataFile.readAsString());
|
implicitData = jsonDecode(await implicitDataFile.readAsString());
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
Log.error("Appdata", "Failed to load implicit data", e);
|
||||||
|
Log.info("Appdata", "Resetting implicit data");
|
||||||
|
var implicitDataFile = File(FilePath.join(dataPath, 'implicitData.json'));
|
||||||
|
implicitDataFile.deleteIgnoreError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,6 +162,7 @@ class Settings with ChangeNotifier {
|
|||||||
'cacheSize': 2048, // in MB
|
'cacheSize': 2048, // in MB
|
||||||
'downloadThreads': 5,
|
'downloadThreads': 5,
|
||||||
'enableLongPressToZoom': true,
|
'enableLongPressToZoom': true,
|
||||||
|
'longPressZoomPosition': "press", // press, center
|
||||||
'checkUpdateOnStart': false,
|
'checkUpdateOnStart': false,
|
||||||
'limitImageWidth': true,
|
'limitImageWidth': true,
|
||||||
'webdav': [], // empty means not configured
|
'webdav': [], // empty means not configured
|
||||||
@@ -162,12 +179,21 @@ class Settings with ChangeNotifier {
|
|||||||
'customImageProcessing': defaultCustomImageProcessing,
|
'customImageProcessing': defaultCustomImageProcessing,
|
||||||
'sni': true,
|
'sni': true,
|
||||||
'autoAddLanguageFilter': 'none', // none, chinese, english, japanese
|
'autoAddLanguageFilter': 'none', // none, chinese, english, japanese
|
||||||
'comicSourceListUrl':
|
'comicSourceListUrl': _defaultSourceListUrl,
|
||||||
"https://cdn.jsdelivr.net/gh/venera-app/venera-configs@latest/index.json",
|
|
||||||
'preloadImageCount': 4,
|
'preloadImageCount': 4,
|
||||||
'followUpdatesFolder': null,
|
'followUpdatesFolder': null,
|
||||||
'initialPage': '0',
|
'initialPage': '0',
|
||||||
'comicListDisplayMode': 'paging', // paging, continuous
|
'comicListDisplayMode': 'paging', // paging, continuous
|
||||||
|
'showPageNumberInReader': true,
|
||||||
|
'showSingleImageOnFirstPage': false,
|
||||||
|
'enableDoubleTapToZoom': true,
|
||||||
|
'reverseChapterOrder': false,
|
||||||
|
'showSystemStatusBar': false,
|
||||||
|
'comicSpecificSettings': <String, Map<String, dynamic>>{},
|
||||||
|
'ignoreBadCertificate': false,
|
||||||
|
'readerScrollSpeed': 1.0, // 0.5 - 3.0
|
||||||
|
'localFavoritesFirst': true,
|
||||||
|
'autoCloseFavoritePanel': false,
|
||||||
};
|
};
|
||||||
|
|
||||||
operator [](String key) {
|
operator [](String key) {
|
||||||
@@ -176,6 +202,45 @@ class Settings with ChangeNotifier {
|
|||||||
|
|
||||||
operator []=(String key, dynamic value) {
|
operator []=(String key, dynamic value) {
|
||||||
_data[key] = value;
|
_data[key] = value;
|
||||||
|
if (key != "dataVersion") {
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setEnabledComicSpecificSettings(String comicId, String sourceKey, bool enabled) {
|
||||||
|
setReaderSetting(comicId, sourceKey, "enabled", enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isComicSpecificSettingsEnabled(String? comicId, String? sourceKey) {
|
||||||
|
if (comicId == null || sourceKey == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return _data['comicSpecificSettings']["$comicId@$sourceKey"]?["enabled"] == true;
|
||||||
|
}
|
||||||
|
|
||||||
|
dynamic getReaderSetting(String comicId, String sourceKey, String key) {
|
||||||
|
if (!isComicSpecificSettingsEnabled(comicId, sourceKey)) {
|
||||||
|
return _data[key];
|
||||||
|
}
|
||||||
|
return _data['comicSpecificSettings']["$comicId@$sourceKey"]?[key] ??
|
||||||
|
_data[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
void setReaderSetting(
|
||||||
|
String comicId,
|
||||||
|
String sourceKey,
|
||||||
|
String key,
|
||||||
|
dynamic value,
|
||||||
|
) {
|
||||||
|
(_data['comicSpecificSettings'] as Map<String, dynamic>).putIfAbsent(
|
||||||
|
"$comicId@$sourceKey",
|
||||||
|
() => <String, dynamic>{},
|
||||||
|
)[key] = value;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void resetComicReaderSettings(String key) {
|
||||||
|
(_data['comicSpecificSettings'] as Map).remove(key);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,3 +267,6 @@ function processImage(image, cid, eid, page, sourceKey) {
|
|||||||
return futureImage;
|
return futureImage;
|
||||||
}
|
}
|
||||||
''';
|
''';
|
||||||
|
|
||||||
|
const _defaultSourceListUrl =
|
||||||
|
"https://git.nyne.dev/nyne/venera-configs/raw/branch/main/index.json";
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import 'dart:ffi';
|
||||||
|
import 'dart:isolate';
|
||||||
|
|
||||||
import 'package:crypto/crypto.dart';
|
import 'package:crypto/crypto.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:sqlite3/sqlite3.dart';
|
import 'package:sqlite3/sqlite3.dart';
|
||||||
import 'package:venera/utils/io.dart';
|
import 'package:venera/utils/io.dart';
|
||||||
|
|
||||||
@@ -21,7 +23,52 @@ class CacheManager {
|
|||||||
|
|
||||||
int _limitSize = 2 * 1024 * 1024 * 1024;
|
int _limitSize = 2 * 1024 * 1024 * 1024;
|
||||||
|
|
||||||
CacheManager._create(){
|
static Future<int> _scanDir(Pointer<void> dbP, String dir) async {
|
||||||
|
var res = await Isolate.run(() async {
|
||||||
|
int totalSize = 0;
|
||||||
|
List<String> unmanagedFiles = [];
|
||||||
|
var db = sqlite3.fromPointer(dbP);
|
||||||
|
await for (var file in Directory(dir).list(recursive: true)) {
|
||||||
|
if (file is File) {
|
||||||
|
var size = await file.length();
|
||||||
|
var segments = file.uri.pathSegments;
|
||||||
|
var name = segments.last;
|
||||||
|
var dir = segments.elementAtOrNull(segments.length - 2) ?? "*";
|
||||||
|
var res = db.select('''
|
||||||
|
SELECT * FROM cache
|
||||||
|
WHERE dir = ? AND name = ?
|
||||||
|
''', [dir, name]);
|
||||||
|
if (res.isEmpty) {
|
||||||
|
unmanagedFiles.add(file.path);
|
||||||
|
} else {
|
||||||
|
totalSize += size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
'totalSize': totalSize,
|
||||||
|
'unmanagedFiles': unmanagedFiles,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
// delete unmanaged files
|
||||||
|
// Only modify the database in the main isolate to avoid deadlock
|
||||||
|
for (var filePath in res['unmanagedFiles'] as List<String>) {
|
||||||
|
var file = File(filePath);
|
||||||
|
if (await file.exists()) {
|
||||||
|
await file.delete();
|
||||||
|
}
|
||||||
|
var segments = file.uri.pathSegments;
|
||||||
|
var name = segments.last;
|
||||||
|
var dir = segments.elementAtOrNull(segments.length - 2) ?? "*";
|
||||||
|
CacheManager()._db.execute('''
|
||||||
|
DELETE FROM cache
|
||||||
|
WHERE dir = ? AND name = ?
|
||||||
|
''', [dir, name]);
|
||||||
|
}
|
||||||
|
return res['totalSize'] as int;
|
||||||
|
}
|
||||||
|
|
||||||
|
CacheManager._create() {
|
||||||
Directory(cachePath).createSync(recursive: true);
|
Directory(cachePath).createSync(recursive: true);
|
||||||
_db = sqlite3.open('${App.dataPath}/cache.db');
|
_db = sqlite3.open('${App.dataPath}/cache.db');
|
||||||
_db.execute('''
|
_db.execute('''
|
||||||
@@ -33,100 +80,103 @@ class CacheManager {
|
|||||||
type TEXT
|
type TEXT
|
||||||
)
|
)
|
||||||
''');
|
''');
|
||||||
compute((path) => Directory(path).size, cachePath)
|
_scanDir(_db.handle, cachePath).then((value) {
|
||||||
.then((value) => _currentSize = value);
|
_currentSize = value;
|
||||||
|
checkCache();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the singleton instance of CacheManager.
|
||||||
factory CacheManager() => instance ??= CacheManager._create();
|
factory CacheManager() => instance ??= CacheManager._create();
|
||||||
|
|
||||||
/// set cache size limit in MB
|
/// set cache size limit in MB
|
||||||
void setLimitSize(int size){
|
void setLimitSize(int size) {
|
||||||
_limitSize = size * 1024 * 1024;
|
_limitSize = size * 1024 * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setType(String key, String? type){
|
/// Write cache to disk.
|
||||||
_db.execute('''
|
Future<void> writeCache(String key, List<int> data,
|
||||||
UPDATE cache
|
[int duration = 7 * 24 * 60 * 60 * 1000]) async {
|
||||||
SET type = ?
|
await delete(key);
|
||||||
WHERE key = ?
|
|
||||||
''', [type, key]);
|
|
||||||
}
|
|
||||||
|
|
||||||
String? getType(String key){
|
|
||||||
var res = _db.select('''
|
|
||||||
SELECT type FROM cache
|
|
||||||
WHERE key = ?
|
|
||||||
''', [key]);
|
|
||||||
if(res.isEmpty){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return res.first[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> writeCache(String key, List<int> data, [int duration = 7 * 24 * 60 * 60 * 1000]) async{
|
|
||||||
this.dir++;
|
this.dir++;
|
||||||
this.dir %= 100;
|
this.dir %= 100;
|
||||||
var dir = this.dir;
|
var dir = this.dir;
|
||||||
var name = md5.convert(Uint8List.fromList(key.codeUnits)).toString();
|
var name = md5.convert(key.codeUnits).toString();
|
||||||
var file = File('$cachePath/$dir/$name');
|
var file = File('$cachePath/$dir/$name');
|
||||||
while(await file.exists()){
|
|
||||||
name = md5.convert(Uint8List.fromList(name.codeUnits)).toString();
|
|
||||||
file = File('$cachePath/$dir/$name');
|
|
||||||
}
|
|
||||||
await file.create(recursive: true);
|
await file.create(recursive: true);
|
||||||
await file.writeAsBytes(data);
|
await file.writeAsBytes(data);
|
||||||
var expires = DateTime.now().millisecondsSinceEpoch + duration;
|
var expires = DateTime.now().millisecondsSinceEpoch + duration;
|
||||||
_db.execute('''
|
_db.execute('''
|
||||||
INSERT OR REPLACE INTO cache (key, dir, name, expires) VALUES (?, ?, ?, ?)
|
INSERT OR REPLACE INTO cache (key, dir, name, expires) VALUES (?, ?, ?, ?)
|
||||||
''', [key, dir.toString(), name, expires]);
|
''', [key, dir.toString(), name, expires]);
|
||||||
if(_currentSize != null) {
|
if (_currentSize != null) {
|
||||||
_currentSize = _currentSize! + data.length;
|
_currentSize = _currentSize! + data.length;
|
||||||
}
|
}
|
||||||
checkCacheIfRequired();
|
checkCacheIfRequired();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<CachingFile> openWrite(String key) async{
|
/// Find cache by key.
|
||||||
this.dir++;
|
/// If cache is expired, it will be deleted and return null.
|
||||||
this.dir %= 100;
|
/// If cache is not found, it will return null.
|
||||||
var dir = this.dir;
|
/// If cache is found, it will return the file, and update the expires time.
|
||||||
var name = md5.convert(Uint8List.fromList(key.codeUnits)).toString();
|
Future<File?> findCache(String key) async {
|
||||||
var file = File('$cachePath/$dir/$name');
|
|
||||||
while(await file.exists()){
|
|
||||||
name = md5.convert(Uint8List.fromList(name.codeUnits)).toString();
|
|
||||||
file = File('$cachePath/$dir/$name');
|
|
||||||
}
|
|
||||||
await file.create(recursive: true);
|
|
||||||
return CachingFile._(key, dir.toString(), name, file);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<File?> findCache(String key) async{
|
|
||||||
var res = _db.select('''
|
var res = _db.select('''
|
||||||
SELECT * FROM cache
|
SELECT * FROM cache
|
||||||
WHERE key = ?
|
WHERE key = ?
|
||||||
''', [key]);
|
''', [key]);
|
||||||
if(res.isEmpty){
|
if (res.isEmpty) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
var row = res.first;
|
var row = res.first;
|
||||||
var dir = row[1] as String;
|
var dir = row[1] as String;
|
||||||
var name = row[2] as String;
|
var name = row[2] as String;
|
||||||
|
var expires = row[3] as int;
|
||||||
var file = File('$cachePath/$dir/$name');
|
var file = File('$cachePath/$dir/$name');
|
||||||
if(await file.exists()){
|
var now = DateTime.now().millisecondsSinceEpoch;
|
||||||
|
if (expires < now) {
|
||||||
|
// expired
|
||||||
|
_db.execute('''
|
||||||
|
DELETE FROM cache
|
||||||
|
WHERE key = ?
|
||||||
|
''', [key]);
|
||||||
|
if (await file.exists()) {
|
||||||
|
await file.delete();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (await file.exists()) {
|
||||||
|
// update time
|
||||||
|
var expires = now + 7 * 24 * 60 * 60 * 1000;
|
||||||
|
_db.execute('''
|
||||||
|
UPDATE cache
|
||||||
|
SET expires = ?
|
||||||
|
WHERE key = ?
|
||||||
|
''', [expires, key]);
|
||||||
return file;
|
return file;
|
||||||
|
} else {
|
||||||
|
_db.execute('''
|
||||||
|
DELETE FROM cache
|
||||||
|
WHERE key = ?
|
||||||
|
''', [key]);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _isChecking = false;
|
bool _isChecking = false;
|
||||||
|
|
||||||
|
/// Check cache size and delete expired cache.
|
||||||
|
/// Only check cache if current size is greater than limit size.
|
||||||
void checkCacheIfRequired() {
|
void checkCacheIfRequired() {
|
||||||
if(_currentSize != null && _currentSize! > _limitSize){
|
if (_currentSize != null && _currentSize! > _limitSize) {
|
||||||
checkCache();
|
checkCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> checkCache() async{
|
/// Check cache size and delete expired cache.
|
||||||
if(_isChecking){
|
/// If current size is greater than limit size,
|
||||||
|
/// delete cache until current size is less than limit size.
|
||||||
|
Future<void> checkCache() async {
|
||||||
|
if (_isChecking) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_isChecking = true;
|
_isChecking = true;
|
||||||
@@ -134,39 +184,42 @@ class CacheManager {
|
|||||||
SELECT * FROM cache
|
SELECT * FROM cache
|
||||||
WHERE expires < ?
|
WHERE expires < ?
|
||||||
''', [DateTime.now().millisecondsSinceEpoch]);
|
''', [DateTime.now().millisecondsSinceEpoch]);
|
||||||
for(var row in res){
|
for (var row in res) {
|
||||||
var dir = row[1] as String;
|
var dir = row[1] as String;
|
||||||
var name = row[2] as String;
|
var name = row[2] as String;
|
||||||
var file = File('$cachePath/$dir/$name');
|
var file = File('$cachePath/$dir/$name');
|
||||||
if(await file.exists()){
|
if (await file.exists()) {
|
||||||
|
var size = await file.length();
|
||||||
|
_currentSize = _currentSize! - size;
|
||||||
await file.delete();
|
await file.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_db.execute('''
|
if (res.isNotEmpty) {
|
||||||
|
_db.execute('''
|
||||||
DELETE FROM cache
|
DELETE FROM cache
|
||||||
WHERE expires < ?
|
WHERE expires < ?
|
||||||
''', [DateTime.now().millisecondsSinceEpoch]);
|
''', [DateTime.now().millisecondsSinceEpoch]);
|
||||||
|
|
||||||
int count = 0;
|
|
||||||
var res2 = _db.select('''
|
|
||||||
SELECT COUNT(*) FROM cache
|
|
||||||
''');
|
|
||||||
if(res2.isNotEmpty){
|
|
||||||
count = res2.first[0] as int;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while((_currentSize != null && _currentSize! > _limitSize) || count > 2000){
|
while (_currentSize != null && _currentSize! > _limitSize) {
|
||||||
var res = _db.select('''
|
var res = _db.select('''
|
||||||
SELECT * FROM cache
|
SELECT * FROM cache
|
||||||
ORDER BY expires ASC
|
ORDER BY expires ASC
|
||||||
limit 10
|
limit 10
|
||||||
''');
|
''');
|
||||||
for(var row in res){
|
if (res.isEmpty) {
|
||||||
|
// There are many files unmanaged by the cache manager.
|
||||||
|
// Clear all cache.
|
||||||
|
await Directory(cachePath).delete(recursive: true);
|
||||||
|
Directory(cachePath).createSync(recursive: true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (var row in res) {
|
||||||
var key = row[0] as String;
|
var key = row[0] as String;
|
||||||
var dir = row[1] as String;
|
var dir = row[1] as String;
|
||||||
var name = row[2] as String;
|
var name = row[2] as String;
|
||||||
var file = File('$cachePath/$dir/$name');
|
var file = File('$cachePath/$dir/$name');
|
||||||
if(await file.exists()){
|
if (await file.exists()) {
|
||||||
var size = await file.length();
|
var size = await file.length();
|
||||||
await file.delete();
|
await file.delete();
|
||||||
_db.execute('''
|
_db.execute('''
|
||||||
@@ -174,7 +227,7 @@ class CacheManager {
|
|||||||
WHERE key = ?
|
WHERE key = ?
|
||||||
''', [key]);
|
''', [key]);
|
||||||
_currentSize = _currentSize! - size;
|
_currentSize = _currentSize! - size;
|
||||||
if(_currentSize! <= _limitSize){
|
if (_currentSize! <= _limitSize) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -183,18 +236,18 @@ class CacheManager {
|
|||||||
WHERE key = ?
|
WHERE key = ?
|
||||||
''', [key]);
|
''', [key]);
|
||||||
}
|
}
|
||||||
count--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_isChecking = false;
|
_isChecking = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> delete(String key) async{
|
/// Delete cache by key.
|
||||||
|
Future<void> delete(String key) async {
|
||||||
var res = _db.select('''
|
var res = _db.select('''
|
||||||
SELECT * FROM cache
|
SELECT * FROM cache
|
||||||
WHERE key = ?
|
WHERE key = ?
|
||||||
''', [key]);
|
''', [key]);
|
||||||
if(res.isEmpty){
|
if (res.isEmpty) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var row = res.first;
|
var row = res.first;
|
||||||
@@ -202,7 +255,7 @@ class CacheManager {
|
|||||||
var name = row[2] as String;
|
var name = row[2] as String;
|
||||||
var file = File('$cachePath/$dir/$name');
|
var file = File('$cachePath/$dir/$name');
|
||||||
var fileSize = 0;
|
var fileSize = 0;
|
||||||
if(await file.exists()){
|
if (await file.exists()) {
|
||||||
fileSize = await file.length();
|
fileSize = await file.length();
|
||||||
await file.delete();
|
await file.delete();
|
||||||
}
|
}
|
||||||
@@ -210,11 +263,12 @@ class CacheManager {
|
|||||||
DELETE FROM cache
|
DELETE FROM cache
|
||||||
WHERE key = ?
|
WHERE key = ?
|
||||||
''', [key]);
|
''', [key]);
|
||||||
if(_currentSize != null) {
|
if (_currentSize != null) {
|
||||||
_currentSize = _currentSize! - fileSize;
|
_currentSize = _currentSize! - fileSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Delete all cache.
|
||||||
Future<void> clear() async {
|
Future<void> clear() async {
|
||||||
await Directory(cachePath).delete(recursive: true);
|
await Directory(cachePath).delete(recursive: true);
|
||||||
Directory(cachePath).createSync(recursive: true);
|
Directory(cachePath).createSync(recursive: true);
|
||||||
@@ -223,75 +277,4 @@ class CacheManager {
|
|||||||
''');
|
''');
|
||||||
_currentSize = 0;
|
_currentSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deleteKeyword(String keyword) async{
|
|
||||||
var res = _db.select('''
|
|
||||||
SELECT * FROM cache
|
|
||||||
WHERE key LIKE ?
|
|
||||||
''', ['%$keyword%']);
|
|
||||||
for(var row in res){
|
|
||||||
var key = row[0] as String;
|
|
||||||
var dir = row[1] as String;
|
|
||||||
var name = row[2] as String;
|
|
||||||
var file = File('$cachePath/$dir/$name');
|
|
||||||
var fileSize = 0;
|
|
||||||
if(await file.exists()){
|
|
||||||
fileSize = await file.length();
|
|
||||||
try {
|
|
||||||
await file.delete();
|
|
||||||
}
|
|
||||||
finally {}
|
|
||||||
}
|
|
||||||
_db.execute('''
|
|
||||||
DELETE FROM cache
|
|
||||||
WHERE key = ?
|
|
||||||
''', [key]);
|
|
||||||
if(_currentSize != null) {
|
|
||||||
_currentSize = _currentSize! - fileSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class CachingFile{
|
|
||||||
CachingFile._(this.key, this.dir, this.name, this.file);
|
|
||||||
|
|
||||||
final String key;
|
|
||||||
|
|
||||||
final String dir;
|
|
||||||
|
|
||||||
final String name;
|
|
||||||
|
|
||||||
final File file;
|
|
||||||
|
|
||||||
final List<int> _buffer = [];
|
|
||||||
|
|
||||||
Future<void> writeBytes(List<int> data) async{
|
|
||||||
_buffer.addAll(data);
|
|
||||||
if(_buffer.length > 1024 * 1024){
|
|
||||||
await file.writeAsBytes(_buffer, mode: FileMode.append);
|
|
||||||
_buffer.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> close() async{
|
|
||||||
if(_buffer.isNotEmpty){
|
|
||||||
await file.writeAsBytes(_buffer, mode: FileMode.append);
|
|
||||||
}
|
|
||||||
CacheManager()._db.execute('''
|
|
||||||
INSERT OR REPLACE INTO cache (key, dir, name, expires) VALUES (?, ?, ?, ?)
|
|
||||||
''', [key, dir, name, DateTime.now().millisecondsSinceEpoch + 7 * 24 * 60 * 60 * 1000]);
|
|
||||||
CacheManager().checkCacheIfRequired();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> cancel() async{
|
|
||||||
await file.deleteIgnoreError();
|
|
||||||
}
|
|
||||||
|
|
||||||
void reset() {
|
|
||||||
_buffer.clear();
|
|
||||||
if(file.existsSync()) {
|
|
||||||
file.deleteSync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -34,24 +34,28 @@ class CategoryButtonData {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CategoryItem {
|
||||||
|
final String label;
|
||||||
|
|
||||||
|
final PageJumpTarget target;
|
||||||
|
|
||||||
|
const CategoryItem(this.label, this.target);
|
||||||
|
}
|
||||||
|
|
||||||
abstract class BaseCategoryPart {
|
abstract class BaseCategoryPart {
|
||||||
String get title;
|
String get title;
|
||||||
|
|
||||||
List<String> get categories;
|
List<CategoryItem> get categories;
|
||||||
|
|
||||||
List<String>? get categoryParams => null;
|
|
||||||
|
|
||||||
bool get enableRandom;
|
bool get enableRandom;
|
||||||
|
|
||||||
String get categoryType;
|
|
||||||
|
|
||||||
/// Data class for building a part of category page.
|
/// Data class for building a part of category page.
|
||||||
const BaseCategoryPart();
|
const BaseCategoryPart();
|
||||||
}
|
}
|
||||||
|
|
||||||
class FixedCategoryPart extends BaseCategoryPart {
|
class FixedCategoryPart extends BaseCategoryPart {
|
||||||
@override
|
@override
|
||||||
final List<String> categories;
|
final List<CategoryItem> categories;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get enableRandom => false;
|
bool get enableRandom => false;
|
||||||
@@ -59,19 +63,12 @@ class FixedCategoryPart extends BaseCategoryPart {
|
|||||||
@override
|
@override
|
||||||
final String title;
|
final String title;
|
||||||
|
|
||||||
@override
|
|
||||||
final String categoryType;
|
|
||||||
|
|
||||||
@override
|
|
||||||
final List<String>? categoryParams;
|
|
||||||
|
|
||||||
/// A [BaseCategoryPart] that show fixed tags on category page.
|
/// A [BaseCategoryPart] that show fixed tags on category page.
|
||||||
const FixedCategoryPart(this.title, this.categories, this.categoryType,
|
const FixedCategoryPart(this.title, this.categories);
|
||||||
[this.categoryParams]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class RandomCategoryPart extends BaseCategoryPart {
|
class RandomCategoryPart extends BaseCategoryPart {
|
||||||
final List<String> tags;
|
final List<CategoryItem> all;
|
||||||
|
|
||||||
final int randomNumber;
|
final int randomNumber;
|
||||||
|
|
||||||
@@ -81,67 +78,59 @@ class RandomCategoryPart extends BaseCategoryPart {
|
|||||||
@override
|
@override
|
||||||
bool get enableRandom => true;
|
bool get enableRandom => true;
|
||||||
|
|
||||||
@override
|
List<CategoryItem> _categories() {
|
||||||
final String categoryType;
|
if (randomNumber >= all.length) {
|
||||||
|
return all;
|
||||||
List<String> _categories() {
|
|
||||||
if (randomNumber >= tags.length) {
|
|
||||||
return tags;
|
|
||||||
}
|
}
|
||||||
var start = math.Random().nextInt(tags.length - randomNumber);
|
var start = math.Random().nextInt(all.length - randomNumber);
|
||||||
return tags.sublist(start, start + randomNumber);
|
return all.sublist(start, start + randomNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get categories => _categories();
|
List<CategoryItem> get categories => _categories();
|
||||||
|
|
||||||
/// A [BaseCategoryPart] that show random tags on category page.
|
/// A [BaseCategoryPart] that show a part of random tags on category page.
|
||||||
const RandomCategoryPart(
|
const RandomCategoryPart(
|
||||||
this.title, this.tags, this.randomNumber, this.categoryType);
|
this.title,
|
||||||
|
this.all,
|
||||||
|
this.randomNumber,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class RandomCategoryPartWithRuntimeData extends BaseCategoryPart {
|
class DynamicCategoryPart extends BaseCategoryPart {
|
||||||
final Iterable<String> Function() loadTags;
|
final JSAutoFreeFunction loader;
|
||||||
|
|
||||||
final int randomNumber;
|
final String sourceKey;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final String title;
|
List<CategoryItem> get categories {
|
||||||
|
var data = loader([]);
|
||||||
@override
|
if (data is! List) {
|
||||||
bool get enableRandom => true;
|
throw "DynamicCategoryPart loader must return a List";
|
||||||
|
|
||||||
@override
|
|
||||||
final String categoryType;
|
|
||||||
|
|
||||||
static final random = math.Random();
|
|
||||||
|
|
||||||
List<String> _categories() {
|
|
||||||
var tags = loadTags();
|
|
||||||
if (randomNumber >= tags.length) {
|
|
||||||
return tags.toList();
|
|
||||||
}
|
}
|
||||||
final start = random.nextInt(tags.length - randomNumber);
|
var res = <CategoryItem>[];
|
||||||
var res = List.filled(randomNumber, '');
|
for (var item in data) {
|
||||||
int index = -1;
|
if (item is! Map) {
|
||||||
for (var s in tags) {
|
throw "DynamicCategoryPart loader must return a List of Map";
|
||||||
index++;
|
|
||||||
if (start > index) {
|
|
||||||
continue;
|
|
||||||
} else if (index == start + randomNumber) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
res[index - start] = s;
|
var label = item['label'];
|
||||||
|
var target = PageJumpTarget.parse(sourceKey, item['target']);
|
||||||
|
if (label is! String) {
|
||||||
|
throw "Category label must be a String";
|
||||||
|
}
|
||||||
|
res.add(CategoryItem(label, target));
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<String> get categories => _categories();
|
bool get enableRandom => false;
|
||||||
|
|
||||||
/// A [BaseCategoryPart] that show random tags on category page.
|
@override
|
||||||
RandomCategoryPartWithRuntimeData(
|
final String title;
|
||||||
this.title, this.loadTags, this.randomNumber, this.categoryType);
|
|
||||||
|
/// A [BaseCategoryPart] that show dynamic tags on category page.
|
||||||
|
const DynamicCategoryPart(this.title, this.loader, this.sourceKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
CategoryData getCategoryDataWithKey(String key) {
|
CategoryData getCategoryDataWithKey(String key) {
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import 'package:venera/foundation/app.dart';
|
|||||||
import 'package:venera/foundation/comic_type.dart';
|
import 'package:venera/foundation/comic_type.dart';
|
||||||
import 'package:venera/foundation/history.dart';
|
import 'package:venera/foundation/history.dart';
|
||||||
import 'package:venera/foundation/res.dart';
|
import 'package:venera/foundation/res.dart';
|
||||||
|
import 'package:venera/pages/category_comics_page.dart';
|
||||||
|
import 'package:venera/pages/search_result_page.dart';
|
||||||
import 'package:venera/utils/data_sync.dart';
|
import 'package:venera/utils/data_sync.dart';
|
||||||
import 'package:venera/utils/ext.dart';
|
import 'package:venera/utils/ext.dart';
|
||||||
import 'package:venera/utils/init.dart';
|
import 'package:venera/utils/init.dart';
|
||||||
@@ -182,6 +184,9 @@ class ComicSource {
|
|||||||
|
|
||||||
final HandleClickTagEvent? handleClickTagEvent;
|
final HandleClickTagEvent? handleClickTagEvent;
|
||||||
|
|
||||||
|
/// Callback when a tag suggestion is selected in search.
|
||||||
|
final TagSuggestionSelectFunc? onTagSuggestionSelected;
|
||||||
|
|
||||||
final LinkHandler? linkHandler;
|
final LinkHandler? linkHandler;
|
||||||
|
|
||||||
final bool enableTagsSuggestions;
|
final bool enableTagsSuggestions;
|
||||||
@@ -257,6 +262,7 @@ class ComicSource {
|
|||||||
this.idMatcher,
|
this.idMatcher,
|
||||||
this.translations,
|
this.translations,
|
||||||
this.handleClickTagEvent,
|
this.handleClickTagEvent,
|
||||||
|
this.onTagSuggestionSelected,
|
||||||
this.linkHandler,
|
this.linkHandler,
|
||||||
this.enableTagsSuggestions,
|
this.enableTagsSuggestions,
|
||||||
this.enableTagsTranslate,
|
this.enableTagsTranslate,
|
||||||
@@ -349,7 +355,7 @@ class ExplorePagePart {
|
|||||||
/// - category:categoryName
|
/// - category:categoryName
|
||||||
///
|
///
|
||||||
/// End with `@`+`param` if the category has a parameter.
|
/// End with `@`+`param` if the category has a parameter.
|
||||||
final String? viewMore;
|
final PageJumpTarget? viewMore;
|
||||||
|
|
||||||
const ExplorePagePart(this.title, this.comics, this.viewMore);
|
const ExplorePagePart(this.title, this.comics, this.viewMore);
|
||||||
}
|
}
|
||||||
@@ -395,9 +401,14 @@ class SearchOptions {
|
|||||||
typedef CategoryComicsLoader = Future<Res<List<Comic>>> Function(
|
typedef CategoryComicsLoader = Future<Res<List<Comic>>> Function(
|
||||||
String category, String? param, List<String> options, int page);
|
String category, String? param, List<String> options, int page);
|
||||||
|
|
||||||
|
typedef CategoryOptionsLoader = Future<Res<List<CategoryComicsOptions>>> Function(
|
||||||
|
String category, String? param);
|
||||||
|
|
||||||
class CategoryComicsData {
|
class CategoryComicsData {
|
||||||
/// options
|
/// options
|
||||||
final List<CategoryComicsOptions> options;
|
final List<CategoryComicsOptions>? options;
|
||||||
|
|
||||||
|
final CategoryOptionsLoader? optionsLoader;
|
||||||
|
|
||||||
/// [category] is the one clicked by the user on the category page.
|
/// [category] is the one clicked by the user on the category page.
|
||||||
///
|
///
|
||||||
@@ -408,7 +419,7 @@ class CategoryComicsData {
|
|||||||
|
|
||||||
final RankingData? rankingData;
|
final RankingData? rankingData;
|
||||||
|
|
||||||
const CategoryComicsData(this.options, this.load, {this.rankingData});
|
const CategoryComicsData({this.options, this.optionsLoader, required this.load, this.rankingData});
|
||||||
}
|
}
|
||||||
|
|
||||||
class RankingData {
|
class RankingData {
|
||||||
@@ -423,6 +434,9 @@ class RankingData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CategoryComicsOptions {
|
class CategoryComicsOptions {
|
||||||
|
// The label will not be displayed if it is empty.
|
||||||
|
final String label;
|
||||||
|
|
||||||
/// Use a [LinkedHashMap] to describe an option list.
|
/// Use a [LinkedHashMap] to describe an option list.
|
||||||
/// key is for loading comics, value is the name displayed on screen.
|
/// key is for loading comics, value is the name displayed on screen.
|
||||||
/// Default value will be the first of the Map.
|
/// Default value will be the first of the Map.
|
||||||
@@ -433,7 +447,7 @@ class CategoryComicsOptions {
|
|||||||
|
|
||||||
final List<String>? showWhen;
|
final List<String>? showWhen;
|
||||||
|
|
||||||
const CategoryComicsOptions(this.options, this.notShowWhen, this.showWhen);
|
const CategoryComicsOptions(this.label, this.options, this.notShowWhen, this.showWhen);
|
||||||
}
|
}
|
||||||
|
|
||||||
class LinkHandler {
|
class LinkHandler {
|
||||||
|
|||||||
@@ -116,6 +116,26 @@ class Comic {
|
|||||||
toString() => "$sourceKey@$id";
|
toString() => "$sourceKey@$id";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ComicID {
|
||||||
|
final ComicType type;
|
||||||
|
|
||||||
|
final String id;
|
||||||
|
|
||||||
|
const ComicID(this.type, this.id);
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if (other is! ComicID) return false;
|
||||||
|
return other.type == type && other.id == id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => type.hashCode ^ id.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() => "$type@$id";
|
||||||
|
}
|
||||||
|
|
||||||
class ComicDetails with HistoryMixin {
|
class ComicDetails with HistoryMixin {
|
||||||
@override
|
@override
|
||||||
final String title;
|
final String title;
|
||||||
@@ -169,7 +189,9 @@ class ComicDetails with HistoryMixin {
|
|||||||
static Map<String, List<String>> _generateMap(Map<dynamic, dynamic> map) {
|
static Map<String, List<String>> _generateMap(Map<dynamic, dynamic> map) {
|
||||||
var res = <String, List<String>>{};
|
var res = <String, List<String>>{};
|
||||||
map.forEach((key, value) {
|
map.forEach((key, value) {
|
||||||
res[key] = List<String>.from(value);
|
if (value is List) {
|
||||||
|
res[key] = List<String>.from(value);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -342,7 +364,8 @@ class ComicChapters {
|
|||||||
} else if (groupedChapters.isNotEmpty) {
|
} else if (groupedChapters.isNotEmpty) {
|
||||||
return ComicChapters.grouped(groupedChapters);
|
return ComicChapters.grouped(groupedChapters);
|
||||||
} else {
|
} else {
|
||||||
throw ArgumentError("Empty chapter list");
|
// return a empty list.
|
||||||
|
return ComicChapters(chapters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -429,3 +452,110 @@ class ComicChapters {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PageJumpTarget {
|
||||||
|
final String sourceKey;
|
||||||
|
|
||||||
|
final String page;
|
||||||
|
|
||||||
|
final Map<String, dynamic>? attributes;
|
||||||
|
|
||||||
|
const PageJumpTarget(this.sourceKey, this.page, this.attributes);
|
||||||
|
|
||||||
|
static PageJumpTarget parse(String sourceKey, dynamic value) {
|
||||||
|
if (value is Map) {
|
||||||
|
if (value['page'] != null) {
|
||||||
|
return PageJumpTarget(
|
||||||
|
sourceKey,
|
||||||
|
value["page"] ?? "search",
|
||||||
|
value["attributes"],
|
||||||
|
);
|
||||||
|
} else if (value["action"] != null) {
|
||||||
|
// old version `onClickTag`
|
||||||
|
var page = value["action"];
|
||||||
|
if (page == "search") {
|
||||||
|
return PageJumpTarget(
|
||||||
|
sourceKey,
|
||||||
|
"search",
|
||||||
|
{
|
||||||
|
"text": value["keyword"],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else if (page == "category") {
|
||||||
|
return PageJumpTarget(
|
||||||
|
sourceKey,
|
||||||
|
"category",
|
||||||
|
{
|
||||||
|
"category": value["keyword"],
|
||||||
|
"param": value["param"],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return PageJumpTarget(sourceKey, page, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (value is String) {
|
||||||
|
// old version string encoding. search: `search:keyword`, category: `category:keyword` or `category:keyword@param`
|
||||||
|
var segments = value.split(":");
|
||||||
|
var page = segments[0];
|
||||||
|
if (page == "search") {
|
||||||
|
return PageJumpTarget(
|
||||||
|
sourceKey,
|
||||||
|
"search",
|
||||||
|
{
|
||||||
|
"text": segments[1],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else if (page == "category") {
|
||||||
|
var c = segments[1];
|
||||||
|
if (c.contains('@')) {
|
||||||
|
var parts = c.split('@');
|
||||||
|
return PageJumpTarget(
|
||||||
|
sourceKey,
|
||||||
|
"category",
|
||||||
|
{
|
||||||
|
"category": parts[0],
|
||||||
|
"param": parts[1],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return PageJumpTarget(
|
||||||
|
sourceKey,
|
||||||
|
"category",
|
||||||
|
{
|
||||||
|
"category": c,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return PageJumpTarget(sourceKey, page, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PageJumpTarget(sourceKey, "Invalid Data", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
void jump(BuildContext context) {
|
||||||
|
if (page == "search") {
|
||||||
|
context.to(
|
||||||
|
() => SearchResultPage(
|
||||||
|
text: attributes?["text"] ?? attributes?["keyword"] ?? "",
|
||||||
|
sourceKey: sourceKey,
|
||||||
|
options: List.from(attributes?["options"] ?? []),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else if (page == "category") {
|
||||||
|
var key = ComicSource.find(sourceKey)!.categoryData!.key;
|
||||||
|
context.to(
|
||||||
|
() => CategoryComicsPage(
|
||||||
|
categoryKey: key,
|
||||||
|
category: attributes?["category"] ??
|
||||||
|
(throw ArgumentError("Category name is required")),
|
||||||
|
options: List.from(attributes?["options"] ?? []),
|
||||||
|
param: attributes?["param"],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
Log.error("Page Jump", "Unknown page: $page");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -64,8 +64,13 @@ class ComicSourceParser {
|
|||||||
if (file.existsSync()) {
|
if (file.existsSync()) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (file.existsSync()) {
|
while (file.existsSync()) {
|
||||||
file = File(FilePath.join(App.dataPath, "comic_source",
|
file = File(
|
||||||
"${fileName.split('.').first}($i).js"));
|
FilePath.join(
|
||||||
|
App.dataPath,
|
||||||
|
"comic_source",
|
||||||
|
"${fileName.split('.').first}($i).js",
|
||||||
|
),
|
||||||
|
);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,7 +87,7 @@ class ComicSourceParser {
|
|||||||
js = js.replaceAll("\r\n", "\n");
|
js = js.replaceAll("\r\n", "\n");
|
||||||
var line1 = js
|
var line1 = js
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.firstWhereOrNull((element) => element.removeAllBlank.isNotEmpty);
|
.firstWhereOrNull((e) => e.trim().startsWith("class "));
|
||||||
if (line1 == null ||
|
if (line1 == null ||
|
||||||
!line1.startsWith("class ") ||
|
!line1.startsWith("class ") ||
|
||||||
!line1.contains("extends ComicSource")) {
|
!line1.contains("extends ComicSource")) {
|
||||||
@@ -90,24 +95,27 @@ class ComicSourceParser {
|
|||||||
}
|
}
|
||||||
var className = line1.split("class")[1].split("extends ComicSource").first;
|
var className = line1.split("class")[1].split("extends ComicSource").first;
|
||||||
className = className.trim();
|
className = className.trim();
|
||||||
JsEngine().runCode("""
|
JsEngine().runCode("""(() => { $js
|
||||||
(() => { $js
|
|
||||||
this['temp'] = new $className()
|
this['temp'] = new $className()
|
||||||
}).call()
|
}).call()
|
||||||
""", className);
|
""", className);
|
||||||
_name = JsEngine().runCode("this['temp'].name") ??
|
_name =
|
||||||
|
JsEngine().runCode("this['temp'].name") ??
|
||||||
(throw ComicSourceParseException('name is required'));
|
(throw ComicSourceParseException('name is required'));
|
||||||
var key = JsEngine().runCode("this['temp'].key") ??
|
var key =
|
||||||
|
JsEngine().runCode("this['temp'].key") ??
|
||||||
(throw ComicSourceParseException('key is required'));
|
(throw ComicSourceParseException('key is required'));
|
||||||
var version = JsEngine().runCode("this['temp'].version") ??
|
var version =
|
||||||
|
JsEngine().runCode("this['temp'].version") ??
|
||||||
(throw ComicSourceParseException('version is required'));
|
(throw ComicSourceParseException('version is required'));
|
||||||
var minAppVersion = JsEngine().runCode("this['temp'].minAppVersion");
|
var minAppVersion = JsEngine().runCode("this['temp'].minAppVersion");
|
||||||
var url = JsEngine().runCode("this['temp'].url");
|
var url = JsEngine().runCode("this['temp'].url");
|
||||||
if (minAppVersion != null) {
|
if (minAppVersion != null) {
|
||||||
if (compareSemVer(minAppVersion, App.version.split('-').first)) {
|
if (compareSemVer(minAppVersion, App.version.split('-').first)) {
|
||||||
throw ComicSourceParseException(
|
throw ComicSourceParseException(
|
||||||
"minAppVersion @version is required"
|
"minAppVersion @version is required".tlParams({
|
||||||
.tlParams({"version": minAppVersion}),
|
"version": minAppVersion,
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,6 +157,7 @@ class ComicSourceParser {
|
|||||||
_parseIdMatch(),
|
_parseIdMatch(),
|
||||||
_parseTranslation(),
|
_parseTranslation(),
|
||||||
_parseClickTagEvent(),
|
_parseClickTagEvent(),
|
||||||
|
_parseTagSuggestionSelectFunc(),
|
||||||
_parseLinkHandler(),
|
_parseLinkHandler(),
|
||||||
_getValue("search.enableTagsSuggestions") ?? false,
|
_getValue("search.enableTagsSuggestions") ?? false,
|
||||||
_getValue("comic.enableTagsTranslate") ?? false,
|
_getValue("comic.enableTagsTranslate") ?? false,
|
||||||
@@ -175,8 +184,10 @@ class ComicSourceParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool _checkExists(String index) {
|
bool _checkExists(String index) {
|
||||||
return JsEngine().runCode("ComicSource.sources.$_key.$index !== null "
|
return JsEngine().runCode(
|
||||||
"&& ComicSource.sources.$_key.$index !== undefined");
|
"ComicSource.sources.$_key.$index !== null "
|
||||||
|
"&& ComicSource.sources.$_key.$index !== undefined",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
dynamic _getValue(String index) {
|
dynamic _getValue(String index) {
|
||||||
@@ -277,16 +288,24 @@ class ComicSourceParser {
|
|||||||
if (type == "singlePageWithMultiPart") {
|
if (type == "singlePageWithMultiPart") {
|
||||||
loadMultiPart = () async {
|
loadMultiPart = () async {
|
||||||
try {
|
try {
|
||||||
var res = await JsEngine()
|
var res = await JsEngine().runCode(
|
||||||
.runCode("ComicSource.sources.$_key.explore[$i].load()");
|
"ComicSource.sources.$_key.explore[$i].load()",
|
||||||
return Res(List.from(res.keys
|
);
|
||||||
.map((e) => ExplorePagePart(
|
return Res(
|
||||||
e,
|
List.from(
|
||||||
(res[e] as List)
|
res.keys
|
||||||
.map<Comic>((e) => Comic.fromJson(e, _key!))
|
.map(
|
||||||
.toList(),
|
(e) => ExplorePagePart(
|
||||||
null))
|
e,
|
||||||
.toList()));
|
(res[e] as List)
|
||||||
|
.map<Comic>((e) => Comic.fromJson(e, _key!))
|
||||||
|
.toList(),
|
||||||
|
null,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
|
),
|
||||||
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Log.error("Data Analysis", "$e\n$s");
|
Log.error("Data Analysis", "$e\n$s");
|
||||||
return Res.error(e.toString());
|
return Res.error(e.toString());
|
||||||
@@ -297,11 +316,15 @@ class ComicSourceParser {
|
|||||||
loadPage = (int page) async {
|
loadPage = (int page) async {
|
||||||
try {
|
try {
|
||||||
var res = await JsEngine().runCode(
|
var res = await JsEngine().runCode(
|
||||||
"ComicSource.sources.$_key.explore[$i].load(${jsonEncode(page)})");
|
"ComicSource.sources.$_key.explore[$i].load(${jsonEncode(page)})",
|
||||||
|
);
|
||||||
return Res(
|
return Res(
|
||||||
List.generate(res["comics"].length,
|
List.generate(
|
||||||
(index) => Comic.fromJson(res["comics"][index], _key!)),
|
res["comics"].length,
|
||||||
subData: res["maxPage"]);
|
(index) => Comic.fromJson(res["comics"][index], _key!),
|
||||||
|
),
|
||||||
|
subData: res["maxPage"],
|
||||||
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Log.error("Network", "$e\n$s");
|
Log.error("Network", "$e\n$s");
|
||||||
return Res.error(e.toString());
|
return Res.error(e.toString());
|
||||||
@@ -311,10 +334,13 @@ class ComicSourceParser {
|
|||||||
loadNext = (next) async {
|
loadNext = (next) async {
|
||||||
try {
|
try {
|
||||||
var res = await JsEngine().runCode(
|
var res = await JsEngine().runCode(
|
||||||
"ComicSource.sources.$_key.explore[$i].loadNext(${jsonEncode(next)})");
|
"ComicSource.sources.$_key.explore[$i].loadNext(${jsonEncode(next)})",
|
||||||
|
);
|
||||||
return Res(
|
return Res(
|
||||||
List.generate(res["comics"].length,
|
List.generate(
|
||||||
(index) => Comic.fromJson(res["comics"][index], _key!)),
|
res["comics"].length,
|
||||||
|
(index) => Comic.fromJson(res["comics"][index], _key!),
|
||||||
|
),
|
||||||
subData: res["next"],
|
subData: res["next"],
|
||||||
);
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
@@ -326,8 +352,9 @@ class ComicSourceParser {
|
|||||||
} else if (type == "multiPartPage") {
|
} else if (type == "multiPartPage") {
|
||||||
loadMultiPart = () async {
|
loadMultiPart = () async {
|
||||||
try {
|
try {
|
||||||
var res = await JsEngine()
|
var res = await JsEngine().runCode(
|
||||||
.runCode("ComicSource.sources.$_key.explore[$i].load()");
|
"ComicSource.sources.$_key.explore[$i].load()",
|
||||||
|
);
|
||||||
return Res(
|
return Res(
|
||||||
List.from(
|
List.from(
|
||||||
(res as List).map((e) {
|
(res as List).map((e) {
|
||||||
@@ -336,7 +363,7 @@ class ComicSourceParser {
|
|||||||
(e['comics'] as List).map((e) {
|
(e['comics'] as List).map((e) {
|
||||||
return Comic.fromJson(e, _key!);
|
return Comic.fromJson(e, _key!);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
e['viewMore'],
|
PageJumpTarget.parse(_key!, e['viewMore']),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@@ -350,19 +377,22 @@ class ComicSourceParser {
|
|||||||
loadMixed = (index) async {
|
loadMixed = (index) async {
|
||||||
try {
|
try {
|
||||||
var res = await JsEngine().runCode(
|
var res = await JsEngine().runCode(
|
||||||
"ComicSource.sources.$_key.explore[$i].load(${jsonEncode(index)})");
|
"ComicSource.sources.$_key.explore[$i].load(${jsonEncode(index)})",
|
||||||
|
);
|
||||||
var list = <Object>[];
|
var list = <Object>[];
|
||||||
for (var data in (res['data'] as List)) {
|
for (var data in (res['data'] as List)) {
|
||||||
if (data is List) {
|
if (data is List) {
|
||||||
list.add(data.map((e) => Comic.fromJson(e, _key!)).toList());
|
list.add(data.map((e) => Comic.fromJson(e, _key!)).toList());
|
||||||
} else if (data is Map) {
|
} else if (data is Map) {
|
||||||
list.add(ExplorePagePart(
|
list.add(
|
||||||
data['title'],
|
ExplorePagePart(
|
||||||
(data['comics'] as List).map((e) {
|
data['title'],
|
||||||
return Comic.fromJson(e, _key!);
|
(data['comics'] as List).map((e) {
|
||||||
}).toList(),
|
return Comic.fromJson(e, _key!);
|
||||||
data['viewMore'],
|
}).toList(),
|
||||||
));
|
data['viewMore'],
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Res(list, subData: res['maxPage']);
|
return Res(list, subData: res['maxPage']);
|
||||||
@@ -372,21 +402,25 @@ class ComicSourceParser {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pages.add(ExplorePageData(
|
pages.add(
|
||||||
title,
|
ExplorePageData(
|
||||||
switch (type) {
|
title,
|
||||||
"singlePageWithMultiPart" => ExplorePageType.singlePageWithMultiPart,
|
switch (type) {
|
||||||
"multiPartPage" => ExplorePageType.singlePageWithMultiPart,
|
"singlePageWithMultiPart" =>
|
||||||
"multiPageComicList" => ExplorePageType.multiPageComicList,
|
ExplorePageType.singlePageWithMultiPart,
|
||||||
"mixed" => ExplorePageType.mixed,
|
"multiPartPage" => ExplorePageType.singlePageWithMultiPart,
|
||||||
_ =>
|
"multiPageComicList" => ExplorePageType.multiPageComicList,
|
||||||
throw ComicSourceParseException("Unknown explore page type $type")
|
"mixed" => ExplorePageType.mixed,
|
||||||
},
|
_ => throw ComicSourceParseException(
|
||||||
loadPage,
|
"Unknown explore page type $type",
|
||||||
loadNext,
|
),
|
||||||
loadMultiPart,
|
},
|
||||||
loadMixed,
|
loadPage,
|
||||||
));
|
loadNext,
|
||||||
|
loadMultiPart,
|
||||||
|
loadMixed,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return pages;
|
return pages;
|
||||||
}
|
}
|
||||||
@@ -404,50 +438,163 @@ class ComicSourceParser {
|
|||||||
var categoryParts = <BaseCategoryPart>[];
|
var categoryParts = <BaseCategoryPart>[];
|
||||||
|
|
||||||
for (var c in doc["parts"]) {
|
for (var c in doc["parts"]) {
|
||||||
final String name = c["name"];
|
if (c["categories"] != null && c["categories"] is! List) {
|
||||||
final String type = c["type"];
|
continue;
|
||||||
final List<String> tags = List.from(c["categories"]);
|
|
||||||
final String itemType = c["itemType"];
|
|
||||||
List<String>? categoryParams = ListOrNull.from(c["categoryParams"]);
|
|
||||||
final String? groupParam = c["groupParam"];
|
|
||||||
if (groupParam != null) {
|
|
||||||
categoryParams = List.filled(tags.length, groupParam);
|
|
||||||
}
|
}
|
||||||
if (type == "fixed") {
|
List? categories = c["categories"];
|
||||||
categoryParts
|
if (categories == null || categories[0] is Map) {
|
||||||
.add(FixedCategoryPart(name, tags, itemType, categoryParams));
|
// new format
|
||||||
} else if (type == "random") {
|
final String name = c["name"];
|
||||||
categoryParts.add(
|
final String type = c["type"];
|
||||||
RandomCategoryPart(name, tags, c["randomNumber"] ?? 1, itemType));
|
final cs = categories
|
||||||
|
?.map(
|
||||||
|
(e) => CategoryItem(
|
||||||
|
e['label'],
|
||||||
|
PageJumpTarget.parse(_key!, e['target']),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
if (type != "dynamic" && (cs == null || cs.isEmpty)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (type == "fixed") {
|
||||||
|
categoryParts.add(FixedCategoryPart(name, cs!));
|
||||||
|
} else if (type == "random") {
|
||||||
|
categoryParts.add(
|
||||||
|
RandomCategoryPart(name, cs!, c["randomNumber"] ?? 1),
|
||||||
|
);
|
||||||
|
} else if (type == "dynamic" && categories == null) {
|
||||||
|
var loader = c["loader"];
|
||||||
|
if (loader is! JSInvokable) {
|
||||||
|
throw "DynamicCategoryPart loader must be a function";
|
||||||
|
}
|
||||||
|
categoryParts.add(
|
||||||
|
DynamicCategoryPart(name, JSAutoFreeFunction(loader), _key!),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// old format
|
||||||
|
final String name = c["name"];
|
||||||
|
final String type = c["type"];
|
||||||
|
final List<String> tags = List.from(c["categories"]);
|
||||||
|
final String itemType = c["itemType"];
|
||||||
|
List<String>? categoryParams = ListOrNull.from(c["categoryParams"]);
|
||||||
|
final String? groupParam = c["groupParam"];
|
||||||
|
if (groupParam != null) {
|
||||||
|
categoryParams = List.filled(tags.length, groupParam);
|
||||||
|
}
|
||||||
|
var cs = <CategoryItem>[];
|
||||||
|
for (int i = 0; i < tags.length; i++) {
|
||||||
|
PageJumpTarget target;
|
||||||
|
if (itemType == 'category') {
|
||||||
|
target = PageJumpTarget(_key!, 'category', {
|
||||||
|
"category": tags[i],
|
||||||
|
"param": categoryParams?.elementAtOrNull(i),
|
||||||
|
});
|
||||||
|
} else if (itemType == 'search') {
|
||||||
|
target = PageJumpTarget(_key!, 'search', {"keyword": tags[i]});
|
||||||
|
} else if (itemType == 'search_with_namespace') {
|
||||||
|
target = PageJumpTarget(_key!, 'search', {
|
||||||
|
"keyword": "$name:$tags[i]",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
target = PageJumpTarget(_key!, itemType, null);
|
||||||
|
}
|
||||||
|
cs.add(CategoryItem(tags[i], target));
|
||||||
|
}
|
||||||
|
if (type == "fixed") {
|
||||||
|
categoryParts.add(FixedCategoryPart(name, cs));
|
||||||
|
} else if (type == "random") {
|
||||||
|
categoryParts.add(
|
||||||
|
RandomCategoryPart(name, cs, c["randomNumber"] ?? 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CategoryData(
|
return CategoryData(
|
||||||
title: title,
|
title: title,
|
||||||
categories: categoryParts,
|
categories: categoryParts,
|
||||||
enableRankingPage: enableRankingPage ?? false,
|
enableRankingPage: enableRankingPage ?? false,
|
||||||
key: title);
|
key: title,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
CategoryComicsData? _loadCategoryComicsData() {
|
CategoryComicsData? _loadCategoryComicsData() {
|
||||||
if (!_checkExists("categoryComics")) return null;
|
if (!_checkExists("categoryComics")) return null;
|
||||||
var options = <CategoryComicsOptions>[];
|
|
||||||
for (var element in _getValue("categoryComics.optionList") ?? []) {
|
List<CategoryComicsOptions>? options;
|
||||||
LinkedHashMap<String, String> map = LinkedHashMap<String, String>();
|
if (_checkExists("categoryComics.optionList")) {
|
||||||
for (var option in element["options"]) {
|
options = <CategoryComicsOptions>[];
|
||||||
if (option.isEmpty || !option.contains("-")) {
|
for (var element in _getValue("categoryComics.optionList") ?? []) {
|
||||||
continue;
|
LinkedHashMap<String, String> map = LinkedHashMap<String, String>();
|
||||||
|
for (var option in element["options"]) {
|
||||||
|
if (option.isEmpty || !option.contains("-")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var split = option.split("-");
|
||||||
|
var key = split.removeAt(0);
|
||||||
|
var value = split.join("-");
|
||||||
|
map[key] = value;
|
||||||
}
|
}
|
||||||
var split = option.split("-");
|
options.add(
|
||||||
var key = split.removeAt(0);
|
CategoryComicsOptions(
|
||||||
var value = split.join("-");
|
element["label"] ?? "",
|
||||||
map[key] = value;
|
map,
|
||||||
|
List.from(element["notShowWhen"] ?? []),
|
||||||
|
element["showWhen"] == null ? null : List.from(element["showWhen"]),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
options.add(CategoryComicsOptions(
|
|
||||||
map,
|
|
||||||
List.from(element["notShowWhen"] ?? []),
|
|
||||||
element["showWhen"] == null ? null : List.from(element["showWhen"])));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CategoryOptionsLoader? optionLoader;
|
||||||
|
if (_checkExists("categoryComics.optionLoader")) {
|
||||||
|
optionLoader = (category, param) async {
|
||||||
|
try {
|
||||||
|
dynamic res = JsEngine().runCode("""
|
||||||
|
ComicSource.sources.$_key.categoryComics.optionLoader(
|
||||||
|
${jsonEncode(category)}, ${jsonEncode(param)})
|
||||||
|
""");
|
||||||
|
if (res is Future) {
|
||||||
|
res = await res;
|
||||||
|
}
|
||||||
|
if (res is! List) {
|
||||||
|
return Res.error("Invalid data:\nExpected: List\nGot: ${res.runtimeType}");
|
||||||
|
}
|
||||||
|
var options = <CategoryComicsOptions>[];
|
||||||
|
for (var element in res) {
|
||||||
|
if (element is! Map) {
|
||||||
|
return Res.error("Invalid option data:\nExpected: Map\nGot: ${element.runtimeType}");
|
||||||
|
}
|
||||||
|
LinkedHashMap<String, String> map = LinkedHashMap<String, String>();
|
||||||
|
for (var option in element["options"] ?? []) {
|
||||||
|
if (option.isEmpty || !option.contains("-")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var split = option.split("-");
|
||||||
|
var key = split.removeAt(0);
|
||||||
|
var value = split.join("-");
|
||||||
|
map[key] = value;
|
||||||
|
}
|
||||||
|
options.add(
|
||||||
|
CategoryComicsOptions(
|
||||||
|
element["label"] ?? "",
|
||||||
|
map,
|
||||||
|
List.from(element["notShowWhen"] ?? []),
|
||||||
|
element["showWhen"] == null ? null : List.from(element["showWhen"]),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Res(options);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
Log.error("Data Analysis", "Failed to load category options.\n$e");
|
||||||
|
return Res.error(e.toString());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
RankingData? rankingData;
|
RankingData? rankingData;
|
||||||
if (_checkExists("categoryComics.ranking")) {
|
if (_checkExists("categoryComics.ranking")) {
|
||||||
var options = <String, String>{};
|
var options = <String, String>{};
|
||||||
@@ -462,7 +609,7 @@ class ComicSourceParser {
|
|||||||
}
|
}
|
||||||
Future<Res<List<Comic>>> Function(String option, int page)? load;
|
Future<Res<List<Comic>>> Function(String option, int page)? load;
|
||||||
Future<Res<List<Comic>>> Function(String option, String? next)?
|
Future<Res<List<Comic>>> Function(String option, String? next)?
|
||||||
loadWithNext;
|
loadWithNext;
|
||||||
if (_checkExists("categoryComics.ranking.load")) {
|
if (_checkExists("categoryComics.ranking.load")) {
|
||||||
load = (option, page) async {
|
load = (option, page) async {
|
||||||
try {
|
try {
|
||||||
@@ -471,9 +618,12 @@ class ComicSourceParser {
|
|||||||
${jsonEncode(option)}, ${jsonEncode(page)})
|
${jsonEncode(option)}, ${jsonEncode(page)})
|
||||||
""");
|
""");
|
||||||
return Res(
|
return Res(
|
||||||
List.generate(res["comics"].length,
|
List.generate(
|
||||||
(index) => Comic.fromJson(res["comics"][index], _key!)),
|
res["comics"].length,
|
||||||
subData: res["maxPage"]);
|
(index) => Comic.fromJson(res["comics"][index], _key!),
|
||||||
|
),
|
||||||
|
subData: res["maxPage"],
|
||||||
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Log.error("Network", "$e\n$s");
|
Log.error("Network", "$e\n$s");
|
||||||
return Res.error(e.toString());
|
return Res.error(e.toString());
|
||||||
@@ -487,8 +637,10 @@ class ComicSourceParser {
|
|||||||
${jsonEncode(option)}, ${jsonEncode(next)})
|
${jsonEncode(option)}, ${jsonEncode(next)})
|
||||||
""");
|
""");
|
||||||
return Res(
|
return Res(
|
||||||
List.generate(res["comics"].length,
|
List.generate(
|
||||||
(index) => Comic.fromJson(res["comics"][index], _key!)),
|
res["comics"].length,
|
||||||
|
(index) => Comic.fromJson(res["comics"][index], _key!),
|
||||||
|
),
|
||||||
subData: res["next"],
|
subData: res["next"],
|
||||||
);
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
@@ -499,25 +651,38 @@ class ComicSourceParser {
|
|||||||
}
|
}
|
||||||
rankingData = RankingData(options, load, loadWithNext);
|
rankingData = RankingData(options, load, loadWithNext);
|
||||||
}
|
}
|
||||||
return CategoryComicsData(options, (category, param, options, page) async {
|
|
||||||
try {
|
if (options == null && optionLoader == null) {
|
||||||
var res = await JsEngine().runCode("""
|
options = [];
|
||||||
ComicSource.sources.$_key.categoryComics.load(
|
}
|
||||||
${jsonEncode(category)},
|
|
||||||
${jsonEncode(param)},
|
return CategoryComicsData(
|
||||||
${jsonEncode(options)},
|
options: options,
|
||||||
${jsonEncode(page)}
|
optionsLoader: optionLoader,
|
||||||
)
|
load: (category, param, options, page) async {
|
||||||
""");
|
try {
|
||||||
return Res(
|
var res = await JsEngine().runCode("""
|
||||||
List.generate(res["comics"].length,
|
ComicSource.sources.$_key.categoryComics.load(
|
||||||
(index) => Comic.fromJson(res["comics"][index], _key!)),
|
${jsonEncode(category)},
|
||||||
subData: res["maxPage"]);
|
${jsonEncode(param)},
|
||||||
} catch (e, s) {
|
${jsonEncode(options)},
|
||||||
Log.error("Network", "$e\n$s");
|
${jsonEncode(page)}
|
||||||
return Res.error(e.toString());
|
)
|
||||||
}
|
""");
|
||||||
}, rankingData: rankingData);
|
return Res(
|
||||||
|
List.generate(
|
||||||
|
res["comics"].length,
|
||||||
|
(index) => Comic.fromJson(res["comics"][index], _key!),
|
||||||
|
),
|
||||||
|
subData: res["maxPage"],
|
||||||
|
);
|
||||||
|
} catch (e, s) {
|
||||||
|
Log.error("Network", "$e\n$s");
|
||||||
|
return Res.error(e.toString());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
rankingData: rankingData,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
SearchPageData? _loadSearchData() {
|
SearchPageData? _loadSearchData() {
|
||||||
@@ -534,12 +699,14 @@ class ComicSourceParser {
|
|||||||
var value = split.join("-");
|
var value = split.join("-");
|
||||||
map[key] = value;
|
map[key] = value;
|
||||||
}
|
}
|
||||||
options.add(SearchOptions(
|
options.add(
|
||||||
map,
|
SearchOptions(
|
||||||
element["label"],
|
map,
|
||||||
element['type'] ?? 'select',
|
element["label"],
|
||||||
element['default'] == null ? null : jsonEncode(element['default']),
|
element['type'] ?? 'select',
|
||||||
));
|
element['default'] == null ? null : jsonEncode(element['default']),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
SearchFunction? loadPage;
|
SearchFunction? loadPage;
|
||||||
@@ -554,9 +721,12 @@ class ComicSourceParser {
|
|||||||
${jsonEncode(keyword)}, ${jsonEncode(searchOption)}, ${jsonEncode(page)})
|
${jsonEncode(keyword)}, ${jsonEncode(searchOption)}, ${jsonEncode(page)})
|
||||||
""");
|
""");
|
||||||
return Res(
|
return Res(
|
||||||
List.generate(res["comics"].length,
|
List.generate(
|
||||||
(index) => Comic.fromJson(res["comics"][index], _key!)),
|
res["comics"].length,
|
||||||
subData: res["maxPage"]);
|
(index) => Comic.fromJson(res["comics"][index], _key!),
|
||||||
|
),
|
||||||
|
subData: res["maxPage"],
|
||||||
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Log.error("Network", "$e\n$s");
|
Log.error("Network", "$e\n$s");
|
||||||
return Res.error(e.toString());
|
return Res.error(e.toString());
|
||||||
@@ -570,8 +740,10 @@ class ComicSourceParser {
|
|||||||
${jsonEncode(keyword)}, ${jsonEncode(searchOption)}, ${jsonEncode(next)})
|
${jsonEncode(keyword)}, ${jsonEncode(searchOption)}, ${jsonEncode(next)})
|
||||||
""");
|
""");
|
||||||
return Res(
|
return Res(
|
||||||
List.generate(res["comics"].length,
|
List.generate(
|
||||||
(index) => Comic.fromJson(res["comics"][index], _key!)),
|
res["comics"].length,
|
||||||
|
(index) => Comic.fromJson(res["comics"][index], _key!),
|
||||||
|
),
|
||||||
subData: res["next"],
|
subData: res["next"],
|
||||||
);
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
@@ -620,7 +792,9 @@ class ComicSourceParser {
|
|||||||
|
|
||||||
final bool multiFolder = _getValue("favorites.multiFolder");
|
final bool multiFolder = _getValue("favorites.multiFolder");
|
||||||
final bool? isOldToNewSort = _getValue("favorites.isOldToNewSort");
|
final bool? isOldToNewSort = _getValue("favorites.isOldToNewSort");
|
||||||
final bool? singleFolderForSingleComic = _getValue("favorites.singleFolderForSingleComic");
|
final bool? singleFolderForSingleComic = _getValue(
|
||||||
|
"favorites.singleFolderForSingleComic",
|
||||||
|
);
|
||||||
|
|
||||||
Future<Res<T>> retryZone<T>(Future<Res<T>> Function() func) async {
|
Future<Res<T>> retryZone<T>(Future<Res<T>> Function() func) async {
|
||||||
if (!ComicSource.find(_key!)!.isLogged) {
|
if (!ComicSource.find(_key!)!.isLogged) {
|
||||||
@@ -673,9 +847,12 @@ class ComicSourceParser {
|
|||||||
${jsonEncode(page)}, ${jsonEncode(folder)})
|
${jsonEncode(page)}, ${jsonEncode(folder)})
|
||||||
""");
|
""");
|
||||||
return Res(
|
return Res(
|
||||||
List.generate(res["comics"].length,
|
List.generate(
|
||||||
(index) => Comic.fromJson(res["comics"][index], _key!)),
|
res["comics"].length,
|
||||||
subData: res["maxPage"]);
|
(index) => Comic.fromJson(res["comics"][index], _key!),
|
||||||
|
),
|
||||||
|
subData: res["maxPage"],
|
||||||
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Log.error("Network", "$e\n$s");
|
Log.error("Network", "$e\n$s");
|
||||||
return Res.error(e.toString());
|
return Res.error(e.toString());
|
||||||
@@ -695,8 +872,10 @@ class ComicSourceParser {
|
|||||||
${jsonEncode(next)}, ${jsonEncode(folder)})
|
${jsonEncode(next)}, ${jsonEncode(folder)})
|
||||||
""");
|
""");
|
||||||
return Res(
|
return Res(
|
||||||
List.generate(res["comics"].length,
|
List.generate(
|
||||||
(index) => Comic.fromJson(res["comics"][index], _key!)),
|
res["comics"].length,
|
||||||
|
(index) => Comic.fromJson(res["comics"][index], _key!),
|
||||||
|
),
|
||||||
subData: res["next"],
|
subData: res["next"],
|
||||||
);
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
@@ -787,8 +966,9 @@ class ComicSourceParser {
|
|||||||
${jsonEncode(id)}, ${jsonEncode(subId)}, ${jsonEncode(page)}, ${jsonEncode(replyTo)})
|
${jsonEncode(id)}, ${jsonEncode(subId)}, ${jsonEncode(page)}, ${jsonEncode(replyTo)})
|
||||||
""");
|
""");
|
||||||
return Res(
|
return Res(
|
||||||
(res["comments"] as List).map((e) => Comment.fromJson(e)).toList(),
|
(res["comments"] as List).map((e) => Comment.fromJson(e)).toList(),
|
||||||
subData: res["maxPage"]);
|
subData: res["maxPage"],
|
||||||
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Log.error("Network", "$e\n$s");
|
Log.error("Network", "$e\n$s");
|
||||||
return Res.error(e.toString());
|
return Res.error(e.toString());
|
||||||
@@ -978,9 +1158,25 @@ class ComicSourceParser {
|
|||||||
var res = JsEngine().runCode("""
|
var res = JsEngine().runCode("""
|
||||||
ComicSource.sources.$_key.comic.onClickTag(${jsonEncode(namespace)}, ${jsonEncode(tag)})
|
ComicSource.sources.$_key.comic.onClickTag(${jsonEncode(namespace)}, ${jsonEncode(tag)})
|
||||||
""");
|
""");
|
||||||
var r = Map<String, String?>.from(res);
|
if (res is! Map) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var r = Map<String, dynamic>.from(res);
|
||||||
r.removeWhere((key, value) => value == null);
|
r.removeWhere((key, value) => value == null);
|
||||||
return Map.from(r);
|
return PageJumpTarget.parse(_key!, r);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
TagSuggestionSelectFunc? _parseTagSuggestionSelectFunc() {
|
||||||
|
if (!_checkExists("search.onTagSuggestionSelected")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (namespace, tag) {
|
||||||
|
var res = JsEngine().runCode("""
|
||||||
|
ComicSource.sources.$_key.search.onTagSuggestionSelected(
|
||||||
|
${jsonEncode(namespace)}, ${jsonEncode(tag)})
|
||||||
|
""");
|
||||||
|
return res is String ? res : "$namespace:$tag";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1027,7 +1223,8 @@ class ComicSourceParser {
|
|||||||
ComicSource.sources.$_key.comic.archive.getArchives(${jsonEncode(cid)})
|
ComicSource.sources.$_key.comic.archive.getArchives(${jsonEncode(cid)})
|
||||||
""");
|
""");
|
||||||
return Res(
|
return Res(
|
||||||
(res as List).map((e) => ArchiveInfo.fromJson(e)).toList());
|
(res as List).map((e) => ArchiveInfo.fromJson(e)).toList(),
|
||||||
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Log.error("Network", "$e\n$s");
|
Log.error("Network", "$e\n$s");
|
||||||
return Res.error(e.toString());
|
return Res.error(e.toString());
|
||||||
|
|||||||
@@ -41,7 +41,12 @@ typedef LikeCommentFunc = Future<Res<int?>> Function(
|
|||||||
typedef VoteCommentFunc = Future<Res<int?>> Function(
|
typedef VoteCommentFunc = Future<Res<int?>> Function(
|
||||||
String comicId, String? subId, String commentId, bool isUp, bool isCancel);
|
String comicId, String? subId, String commentId, bool isUp, bool isCancel);
|
||||||
|
|
||||||
typedef HandleClickTagEvent = Map<String, String> Function(
|
typedef HandleClickTagEvent = PageJumpTarget? Function(
|
||||||
|
String namespace, String tag);
|
||||||
|
|
||||||
|
/// Handle tag suggestion selection event. Should return the text to insert
|
||||||
|
/// into the search field.
|
||||||
|
typedef TagSuggestionSelectFunc = String Function(
|
||||||
String namespace, String tag);
|
String namespace, String tag);
|
||||||
|
|
||||||
/// [rating] is the rating value, 0-10. 1 represents 0.5 star.
|
/// [rating] is the rating value, 0-10. 1 represents 0.5 star.
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
import 'dart:collection';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:ffi';
|
||||||
|
import 'dart:isolate';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:sqlite3/sqlite3.dart';
|
import 'package:sqlite3/sqlite3.dart';
|
||||||
@@ -209,7 +212,20 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
|
|
||||||
late Database _db;
|
late Database _db;
|
||||||
|
|
||||||
|
late Map<String, int> counts;
|
||||||
|
|
||||||
|
var _hashedIds = <int, int>{};
|
||||||
|
|
||||||
|
int get totalComics {
|
||||||
|
return _hashedIds.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
int folderComics(String folder) {
|
||||||
|
return counts[folder] ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
|
counts = {};
|
||||||
_db = sqlite3.open("${App.dataPath}/local_favorite.db");
|
_db = sqlite3.open("${App.dataPath}/local_favorite.db");
|
||||||
_db.execute("""
|
_db.execute("""
|
||||||
create table if not exists folder_order (
|
create table if not exists folder_order (
|
||||||
@@ -234,7 +250,7 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
alter table "$folder"
|
alter table "$folder"
|
||||||
add column translated_tags TEXT;
|
add column translated_tags TEXT;
|
||||||
""");
|
""");
|
||||||
var comics = getAllComics(folder);
|
var comics = getFolderComics(folder);
|
||||||
for (var comic in comics) {
|
for (var comic in comics) {
|
||||||
var translatedTags = _translateTags(comic.tags);
|
var translatedTags = _translateTags(comic.tags);
|
||||||
_db.execute("""
|
_db.execute("""
|
||||||
@@ -256,6 +272,55 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
} else {
|
} else {
|
||||||
appdata.settings['followUpdatesFolder'] = null;
|
appdata.settings['followUpdatesFolder'] = null;
|
||||||
}
|
}
|
||||||
|
initCounts();
|
||||||
|
}
|
||||||
|
|
||||||
|
void initCounts() {
|
||||||
|
for (var folder in folderNames) {
|
||||||
|
counts[folder] = count(folder);
|
||||||
|
}
|
||||||
|
_initHashedIds(folderNames, _db.handle).then((value) {
|
||||||
|
_hashedIds = value;
|
||||||
|
notifyListeners();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void refreshHashedIds() {
|
||||||
|
_initHashedIds(folderNames, _db.handle).then((value) {
|
||||||
|
_hashedIds = value;
|
||||||
|
notifyListeners();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void reduceHashedId(String id, int type) {
|
||||||
|
var hash = id.hashCode ^ type;
|
||||||
|
if (_hashedIds.containsKey(hash)) {
|
||||||
|
if (_hashedIds[hash]! > 1) {
|
||||||
|
_hashedIds[hash] = _hashedIds[hash]! - 1;
|
||||||
|
} else {
|
||||||
|
_hashedIds.remove(hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<Map<int, int>> _initHashedIds(
|
||||||
|
List<String> folders, Pointer<void> p) {
|
||||||
|
return Isolate.run(() {
|
||||||
|
var db = sqlite3.fromPointer(p);
|
||||||
|
var hashedIds = <int, int>{};
|
||||||
|
for (var folder in folders) {
|
||||||
|
var rows = db.select("""
|
||||||
|
select id, type from "$folder";
|
||||||
|
""");
|
||||||
|
for (var row in rows) {
|
||||||
|
var id = row["id"] as String;
|
||||||
|
var type = row["type"] as int;
|
||||||
|
var hash = id.hashCode ^ type;
|
||||||
|
hashedIds[hash] = (hashedIds[hash] ?? 0) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hashedIds;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> find(String id, ComicType type) {
|
List<String> find(String id, ComicType type) {
|
||||||
@@ -349,7 +414,7 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
""").firstOrNull?["min_value"] ?? 0;
|
""").firstOrNull?["min_value"] ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<FavoriteItem> getAllComics(String folder) {
|
List<FavoriteItem> getFolderComics(String folder) {
|
||||||
var rows = _db.select("""
|
var rows = _db.select("""
|
||||||
select * from "$folder"
|
select * from "$folder"
|
||||||
ORDER BY display_order;
|
ORDER BY display_order;
|
||||||
@@ -357,6 +422,54 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
return rows.map((element) => FavoriteItem.fromRow(element)).toList();
|
return rows.map((element) => FavoriteItem.fromRow(element)).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<List<FavoriteItem>> _getFolderComicsAsync(
|
||||||
|
String folder, Pointer<void> p) {
|
||||||
|
return Isolate.run(() {
|
||||||
|
var db = sqlite3.fromPointer(p);
|
||||||
|
var rows = db.select("""
|
||||||
|
select * from "$folder"
|
||||||
|
ORDER BY display_order;
|
||||||
|
""");
|
||||||
|
return rows.map((element) => FavoriteItem.fromRow(element)).toList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start a new isolate to get the comics in the folder
|
||||||
|
Future<List<FavoriteItem>> getFolderComicsAsync(String folder) {
|
||||||
|
return _getFolderComicsAsync(folder, _db.handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<FavoriteItem> getAllComics() {
|
||||||
|
var res = <FavoriteItem>{};
|
||||||
|
for (final folder in folderNames) {
|
||||||
|
var comics = _db.select("""
|
||||||
|
select * from "$folder";
|
||||||
|
""");
|
||||||
|
res.addAll(comics.map((element) => FavoriteItem.fromRow(element)));
|
||||||
|
}
|
||||||
|
return res.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<List<FavoriteItem>> _getAllComicsAsync(
|
||||||
|
List<String> folders, Pointer<void> p) {
|
||||||
|
return Isolate.run(() {
|
||||||
|
var db = sqlite3.fromPointer(p);
|
||||||
|
var res = <FavoriteItem>{};
|
||||||
|
for (final folder in folders) {
|
||||||
|
var comics = db.select("""
|
||||||
|
select * from "$folder";
|
||||||
|
""");
|
||||||
|
res.addAll(comics.map((element) => FavoriteItem.fromRow(element)));
|
||||||
|
}
|
||||||
|
return res.toList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start a new isolate to get all the comics
|
||||||
|
Future<List<FavoriteItem>> getAllComicsAsync() {
|
||||||
|
return _getAllComicsAsync(folderNames, _db.handle);
|
||||||
|
}
|
||||||
|
|
||||||
void addTagTo(String folder, String id, String tag) {
|
void addTagTo(String folder, String id, String tag) {
|
||||||
_db.execute("""
|
_db.execute("""
|
||||||
update "$folder"
|
update "$folder"
|
||||||
@@ -422,6 +535,7 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
);
|
);
|
||||||
""");
|
""");
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
counts[name] = 0;
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,7 +600,6 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
/// return true if success, false if already exists
|
/// return true if success, false if already exists
|
||||||
bool addComic(String folder, FavoriteItem comic,
|
bool addComic(String folder, FavoriteItem comic,
|
||||||
[int? order, String? updateTime]) {
|
[int? order, String? updateTime]) {
|
||||||
_modifiedAfterLastCache = true;
|
|
||||||
if (!existsFolder(folder)) {
|
if (!existsFolder(folder)) {
|
||||||
throw Exception("Folder does not exists");
|
throw Exception("Folder does not exists");
|
||||||
}
|
}
|
||||||
@@ -536,14 +649,19 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
""", [updateTime, comic.id, comic.type.value]);
|
""", [updateTime, comic.id, comic.type.value]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (counts[folder] == null) {
|
||||||
|
counts[folder] = count(folder);
|
||||||
|
} else {
|
||||||
|
counts[folder] = counts[folder]! + 1;
|
||||||
|
}
|
||||||
|
var hash = comic.id.hashCode ^ comic.type.value;
|
||||||
|
_hashedIds[hash] = (_hashedIds[hash] ?? 0) + 1;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveFavorite(
|
void moveFavorite(
|
||||||
String sourceFolder, String targetFolder, String id, ComicType type) {
|
String sourceFolder, String targetFolder, String id, ComicType type) {
|
||||||
_modifiedAfterLastCache = true;
|
|
||||||
|
|
||||||
if (!existsFolder(sourceFolder)) {
|
if (!existsFolder(sourceFolder)) {
|
||||||
throw Exception("Source folder does not exist");
|
throw Exception("Source folder does not exist");
|
||||||
}
|
}
|
||||||
@@ -575,9 +693,89 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void batchMoveFavorites(
|
||||||
|
String sourceFolder, String targetFolder, List<FavoriteItem> items) {
|
||||||
|
if (!existsFolder(sourceFolder)) {
|
||||||
|
throw Exception("Source folder does not exist");
|
||||||
|
}
|
||||||
|
if (!existsFolder(targetFolder)) {
|
||||||
|
throw Exception("Target folder does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
_db.execute("BEGIN TRANSACTION");
|
||||||
|
var displayOrder = maxValue(targetFolder) + 1;
|
||||||
|
try {
|
||||||
|
for (var item in items) {
|
||||||
|
_db.execute("""
|
||||||
|
insert or ignore into "$targetFolder" (id, name, author, type, tags, cover_path, time, display_order)
|
||||||
|
select id, name, author, type, tags, cover_path, time, ?
|
||||||
|
from "$sourceFolder"
|
||||||
|
where id == ? and type == ?;
|
||||||
|
""", [displayOrder, item.id, item.type.value]);
|
||||||
|
|
||||||
|
_db.execute("""
|
||||||
|
delete from "$sourceFolder"
|
||||||
|
where id == ? and type == ?;
|
||||||
|
""", [item.id, item.type.value]);
|
||||||
|
|
||||||
|
displayOrder++;
|
||||||
|
}
|
||||||
|
notifyListeners();
|
||||||
|
} catch (e) {
|
||||||
|
Log.error("Batch Move Favorites", e.toString());
|
||||||
|
_db.execute("ROLLBACK");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_db.execute("COMMIT");
|
||||||
|
|
||||||
|
// Update counts
|
||||||
|
counts[targetFolder] = count(targetFolder);
|
||||||
|
counts[sourceFolder] = count(sourceFolder);
|
||||||
|
refreshHashedIds();
|
||||||
|
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void batchCopyFavorites(
|
||||||
|
String sourceFolder, String targetFolder, List<FavoriteItem> items) {
|
||||||
|
if (!existsFolder(sourceFolder)) {
|
||||||
|
throw Exception("Source folder does not exist");
|
||||||
|
}
|
||||||
|
if (!existsFolder(targetFolder)) {
|
||||||
|
throw Exception("Target folder does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
_db.execute("BEGIN TRANSACTION");
|
||||||
|
var displayOrder = maxValue(targetFolder) + 1;
|
||||||
|
try {
|
||||||
|
for (var item in items) {
|
||||||
|
_db.execute("""
|
||||||
|
insert or ignore into "$targetFolder" (id, name, author, type, tags, cover_path, time, display_order)
|
||||||
|
select id, name, author, type, tags, cover_path, time, ?
|
||||||
|
from "$sourceFolder"
|
||||||
|
where id == ? and type == ?;
|
||||||
|
""", [displayOrder, item.id, item.type.value]);
|
||||||
|
|
||||||
|
displayOrder++;
|
||||||
|
}
|
||||||
|
notifyListeners();
|
||||||
|
} catch (e) {
|
||||||
|
Log.error("Batch Copy Favorites", e.toString());
|
||||||
|
_db.execute("ROLLBACK");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_db.execute("COMMIT");
|
||||||
|
|
||||||
|
// Update counts
|
||||||
|
counts[targetFolder] = count(targetFolder);
|
||||||
|
refreshHashedIds();
|
||||||
|
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
/// delete a folder
|
/// delete a folder
|
||||||
void deleteFolder(String name) {
|
void deleteFolder(String name) {
|
||||||
_modifiedAfterLastCache = true;
|
|
||||||
_db.execute("""
|
_db.execute("""
|
||||||
drop table "$name";
|
drop table "$name";
|
||||||
""");
|
""");
|
||||||
@@ -585,21 +783,77 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
delete from folder_order
|
delete from folder_order
|
||||||
where folder_name == ?;
|
where folder_name == ?;
|
||||||
""", [name]);
|
""", [name]);
|
||||||
|
counts.remove(name);
|
||||||
|
refreshHashedIds();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteComic(String folder, FavoriteItem comic) {
|
|
||||||
_modifiedAfterLastCache = true;
|
|
||||||
deleteComicWithId(folder, comic.id, comic.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
void deleteComicWithId(String folder, String id, ComicType type) {
|
void deleteComicWithId(String folder, String id, ComicType type) {
|
||||||
_modifiedAfterLastCache = true;
|
|
||||||
LocalFavoriteImageProvider.delete(id, type.value);
|
LocalFavoriteImageProvider.delete(id, type.value);
|
||||||
_db.execute("""
|
_db.execute("""
|
||||||
delete from "$folder"
|
delete from "$folder"
|
||||||
where id == ? and type == ?;
|
where id == ? and type == ?;
|
||||||
""", [id, type.value]);
|
""", [id, type.value]);
|
||||||
|
if (counts[folder] != null) {
|
||||||
|
counts[folder] = counts[folder]! - 1;
|
||||||
|
} else {
|
||||||
|
counts[folder] = count(folder);
|
||||||
|
}
|
||||||
|
reduceHashedId(id, type.value);
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void batchDeleteComics(String folder, List<FavoriteItem> comics) {
|
||||||
|
_db.execute("BEGIN TRANSACTION");
|
||||||
|
try {
|
||||||
|
for (var comic in comics) {
|
||||||
|
LocalFavoriteImageProvider.delete(comic.id, comic.type.value);
|
||||||
|
_db.execute("""
|
||||||
|
delete from "$folder"
|
||||||
|
where id == ? and type == ?;
|
||||||
|
""", [comic.id, comic.type.value]);
|
||||||
|
}
|
||||||
|
if (counts[folder] != null) {
|
||||||
|
counts[folder] = counts[folder]! - comics.length;
|
||||||
|
} else {
|
||||||
|
counts[folder] = count(folder);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
Log.error("Batch Delete Comics", e.toString());
|
||||||
|
_db.execute("ROLLBACK");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_db.execute("COMMIT");
|
||||||
|
for (var comic in comics) {
|
||||||
|
reduceHashedId(comic.id, comic.type.value);
|
||||||
|
}
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void batchDeleteComicsInAllFolders(List<ComicID> comics) {
|
||||||
|
_db.execute("BEGIN TRANSACTION");
|
||||||
|
var folderNames = _getFolderNamesWithDB();
|
||||||
|
try {
|
||||||
|
for (var comic in comics) {
|
||||||
|
LocalFavoriteImageProvider.delete(comic.id, comic.type.value);
|
||||||
|
for (var folder in folderNames) {
|
||||||
|
_db.execute("""
|
||||||
|
delete from "$folder"
|
||||||
|
where id == ? and type == ?;
|
||||||
|
""", [comic.id, comic.type.value]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
Log.error("Batch Delete Comics in All Folders", e.toString());
|
||||||
|
_db.execute("ROLLBACK");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
initCounts();
|
||||||
|
_db.execute("COMMIT");
|
||||||
|
for (var comic in comics) {
|
||||||
|
var hash = comic.id.hashCode ^ comic.type.value;
|
||||||
|
_hashedIds.remove(hash);
|
||||||
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -630,11 +884,26 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
if (!existsFolder(folder)) {
|
if (!existsFolder(folder)) {
|
||||||
throw Exception("Failed to reorder: folder not found");
|
throw Exception("Failed to reorder: folder not found");
|
||||||
}
|
}
|
||||||
deleteFolder(folder);
|
_db.execute("BEGIN TRANSACTION");
|
||||||
createFolder(folder);
|
try {
|
||||||
for (int i = 0; i < newFolder.length; i++) {
|
for (int i = 0; i < newFolder.length; i++) {
|
||||||
addComic(folder, newFolder[i], i);
|
_db.execute("""
|
||||||
|
update "$folder"
|
||||||
|
set display_order = ?
|
||||||
|
where id == ? and type == ?;
|
||||||
|
""", [
|
||||||
|
i,
|
||||||
|
newFolder[i].id,
|
||||||
|
newFolder[i].type.value
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
catch (e) {
|
||||||
|
Log.error("Reorder", e.toString());
|
||||||
|
_db.execute("ROLLBACK");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_db.execute("COMMIT");
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -659,6 +928,8 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
set folder_name = ?
|
set folder_name = ?
|
||||||
where folder_name == ?;
|
where folder_name == ?;
|
||||||
""", [after, before]);
|
""", [after, before]);
|
||||||
|
counts[after] = counts[before] ?? 0;
|
||||||
|
counts.remove(before);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -667,7 +938,6 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
markAsRead(id, type);
|
markAsRead(id, type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_modifiedAfterLastCache = true;
|
|
||||||
var followUpdatesFolder = appdata.settings['followUpdatesFolder'];
|
var followUpdatesFolder = appdata.settings['followUpdatesFolder'];
|
||||||
for (final folder in folderNames) {
|
for (final folder in folderNames) {
|
||||||
var rows = _db.select("""
|
var rows = _db.select("""
|
||||||
@@ -736,10 +1006,10 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
return comics;
|
return comics;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<FavoriteItemWithFolderInfo> search(String keyword) {
|
List<FavoriteItem> search(String keyword) {
|
||||||
var keywordList = keyword.split(" ");
|
var keywordList = keyword.split(" ");
|
||||||
keyword = keywordList.first;
|
keyword = keywordList.first;
|
||||||
var comics = <FavoriteItemWithFolderInfo>[];
|
var comics = <FavoriteItem>{};
|
||||||
for (var table in folderNames) {
|
for (var table in folderNames) {
|
||||||
keyword = "%$keyword%";
|
keyword = "%$keyword%";
|
||||||
var res = _db.select("""
|
var res = _db.select("""
|
||||||
@@ -747,15 +1017,18 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
WHERE name LIKE ? OR author LIKE ? OR tags LIKE ? OR translated_tags LIKE ?;
|
WHERE name LIKE ? OR author LIKE ? OR tags LIKE ? OR translated_tags LIKE ?;
|
||||||
""", [keyword, keyword, keyword, keyword]);
|
""", [keyword, keyword, keyword, keyword]);
|
||||||
for (var comic in res) {
|
for (var comic in res) {
|
||||||
comics.add(
|
comics.add(FavoriteItem.fromRow(comic));
|
||||||
FavoriteItemWithFolderInfo(FavoriteItem.fromRow(comic), table));
|
|
||||||
}
|
}
|
||||||
if (comics.length > 200) {
|
if (comics.length > 200) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool test(FavoriteItemWithFolderInfo comic, String keyword) {
|
bool test(FavoriteItem comic, String keyword) {
|
||||||
|
keyword = keyword.trim();
|
||||||
|
if (keyword.isEmpty) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (comic.name.contains(keyword)) {
|
if (comic.name.contains(keyword)) {
|
||||||
return true;
|
return true;
|
||||||
} else if (comic.author.contains(keyword)) {
|
} else if (comic.author.contains(keyword)) {
|
||||||
@@ -766,12 +1039,14 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 1; i < keywordList.length; i++) {
|
return comics.where((element) {
|
||||||
comics =
|
for (var i = 1; i < keywordList.length; i++) {
|
||||||
comics.where((element) => test(element, keywordList[i])).toList();
|
if (!test(element, keywordList[i])) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
return comics;
|
}
|
||||||
|
return true;
|
||||||
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void editTags(String id, String folder, List<String> tags) {
|
void editTags(String id, String folder, List<String> tags) {
|
||||||
@@ -783,28 +1058,9 @@ class LocalFavoritesManager with ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
final _cachedFavoritedIds = <String, bool>{};
|
|
||||||
|
|
||||||
bool isExist(String id, ComicType type) {
|
bool isExist(String id, ComicType type) {
|
||||||
if (_modifiedAfterLastCache) {
|
var hash = id.hashCode ^ type.value;
|
||||||
_cacheFavoritedIds();
|
return _hashedIds.containsKey(hash);
|
||||||
}
|
|
||||||
return _cachedFavoritedIds.containsKey("$id@${type.value}");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _modifiedAfterLastCache = true;
|
|
||||||
|
|
||||||
void _cacheFavoritedIds() {
|
|
||||||
_modifiedAfterLastCache = false;
|
|
||||||
_cachedFavoritedIds.clear();
|
|
||||||
for (var folder in folderNames) {
|
|
||||||
var rows = _db.select("""
|
|
||||||
select id, type from "$folder";
|
|
||||||
""");
|
|
||||||
for (var row in rows) {
|
|
||||||
_cachedFavoritedIds["${row["id"]}@${row["type"]}"] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateInfo(String folder, FavoriteItem comic, [bool notify = true]) {
|
void updateInfo(String folder, FavoriteItem comic, [bool notify = true]) {
|
||||||
|
|||||||
191
lib/foundation/follow_updates.dart
Normal file
191
lib/foundation/follow_updates.dart
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'package:venera/foundation/favorites.dart';
|
||||||
|
import 'package:venera/foundation/log.dart';
|
||||||
|
import 'package:venera/utils/channel.dart';
|
||||||
|
|
||||||
|
class ComicUpdateResult {
|
||||||
|
final bool updated;
|
||||||
|
final String? errorMessage;
|
||||||
|
|
||||||
|
ComicUpdateResult(this.updated, this.errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<ComicUpdateResult> updateComic(
|
||||||
|
FavoriteItemWithUpdateInfo c, String folder) async {
|
||||||
|
int retries = 3;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
var comicSource = c.type.comicSource;
|
||||||
|
if (comicSource == null) {
|
||||||
|
return ComicUpdateResult(false, "Comic source not found");
|
||||||
|
}
|
||||||
|
var newInfo = (await comicSource.loadComicInfo!(c.id)).data;
|
||||||
|
|
||||||
|
var newTags = <String>[];
|
||||||
|
for (var entry in newInfo.tags.entries) {
|
||||||
|
const shouldIgnore = ['author', 'artist', 'time'];
|
||||||
|
var namespace = entry.key;
|
||||||
|
if (shouldIgnore.contains(namespace.toLowerCase())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (var tag in entry.value) {
|
||||||
|
newTags.add("$namespace:$tag");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var item = FavoriteItem(
|
||||||
|
id: c.id,
|
||||||
|
name: newInfo.title,
|
||||||
|
coverPath: newInfo.cover,
|
||||||
|
author: newInfo.subTitle ??
|
||||||
|
newInfo.tags['author']?.firstOrNull ??
|
||||||
|
c.author,
|
||||||
|
type: c.type,
|
||||||
|
tags: newTags,
|
||||||
|
);
|
||||||
|
|
||||||
|
LocalFavoritesManager().updateInfo(folder, item, false);
|
||||||
|
|
||||||
|
var updated = false;
|
||||||
|
var updateTime = newInfo.findUpdateTime();
|
||||||
|
if (updateTime != null && updateTime != c.updateTime) {
|
||||||
|
LocalFavoritesManager().updateUpdateTime(
|
||||||
|
folder,
|
||||||
|
c.id,
|
||||||
|
c.type,
|
||||||
|
updateTime,
|
||||||
|
);
|
||||||
|
updated = true;
|
||||||
|
} else {
|
||||||
|
LocalFavoritesManager().updateCheckTime(folder, c.id, c.type);
|
||||||
|
}
|
||||||
|
return ComicUpdateResult(updated, null);
|
||||||
|
} catch (e, s) {
|
||||||
|
Log.error("Check Updates", e, s);
|
||||||
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
|
retries--;
|
||||||
|
if (retries == 0) {
|
||||||
|
return ComicUpdateResult(false, e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class UpdateProgress {
|
||||||
|
final int total;
|
||||||
|
final int current;
|
||||||
|
final int errors;
|
||||||
|
final int updated;
|
||||||
|
final FavoriteItemWithUpdateInfo? comic;
|
||||||
|
final String? errorMessage;
|
||||||
|
|
||||||
|
UpdateProgress(this.total, this.current, this.errors, this.updated,
|
||||||
|
[this.comic, this.errorMessage]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateFolderBase(
|
||||||
|
String folder,
|
||||||
|
StreamController<UpdateProgress> stream,
|
||||||
|
bool ignoreCheckTime,
|
||||||
|
) async {
|
||||||
|
var comics = LocalFavoritesManager().getComicsWithUpdatesInfo(folder);
|
||||||
|
int total = comics.length;
|
||||||
|
int current = 0;
|
||||||
|
int errors = 0;
|
||||||
|
int updated = 0;
|
||||||
|
|
||||||
|
stream.add(UpdateProgress(total, current, errors, updated));
|
||||||
|
|
||||||
|
var comicsToUpdate = <FavoriteItemWithUpdateInfo>[];
|
||||||
|
|
||||||
|
for (var comic in comics) {
|
||||||
|
if (!ignoreCheckTime) {
|
||||||
|
var lastCheckTime = comic.lastCheckTime;
|
||||||
|
if (lastCheckTime != null &&
|
||||||
|
DateTime.now().difference(lastCheckTime).inDays < 1) {
|
||||||
|
current++;
|
||||||
|
stream.add(UpdateProgress(total, current, errors, updated));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
comicsToUpdate.add(comic);
|
||||||
|
}
|
||||||
|
|
||||||
|
total = comicsToUpdate.length;
|
||||||
|
current = 0;
|
||||||
|
stream.add(UpdateProgress(total, current, errors, updated));
|
||||||
|
|
||||||
|
var channel = Channel<FavoriteItemWithUpdateInfo>(10);
|
||||||
|
|
||||||
|
// Producer
|
||||||
|
() async {
|
||||||
|
var c = 0;
|
||||||
|
for (var comic in comicsToUpdate) {
|
||||||
|
await channel.push(comic);
|
||||||
|
c++;
|
||||||
|
// Throttle
|
||||||
|
if (c % 5 == 0) {
|
||||||
|
var delay = c % 100 + 1;
|
||||||
|
if (delay > 10) {
|
||||||
|
delay = 10;
|
||||||
|
}
|
||||||
|
await Future.delayed(Duration(seconds: delay));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
channel.close();
|
||||||
|
}();
|
||||||
|
|
||||||
|
// Consumers
|
||||||
|
var updateFutures = <Future>[];
|
||||||
|
for (var i = 0; i < 5; i++) {
|
||||||
|
var f = () async {
|
||||||
|
while (true) {
|
||||||
|
var comic = await channel.pop();
|
||||||
|
if (comic == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
var result = await updateComic(comic, folder);
|
||||||
|
current++;
|
||||||
|
if (result.updated) {
|
||||||
|
updated++;
|
||||||
|
}
|
||||||
|
if (result.errorMessage != null) {
|
||||||
|
errors++;
|
||||||
|
}
|
||||||
|
stream.add(UpdateProgress(total, current, errors, updated, comic, result.errorMessage));
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
updateFutures.add(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
await Future.wait(updateFutures);
|
||||||
|
|
||||||
|
if (updated > 0) {
|
||||||
|
LocalFavoritesManager().notifyChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Stream<UpdateProgress> updateFolder(String folder, bool ignoreCheckTime) {
|
||||||
|
var stream = StreamController<UpdateProgress>();
|
||||||
|
updateFolderBase(folder, stream, ignoreCheckTime);
|
||||||
|
return stream.stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<String> getUpdatedComicsAsJson(String folder) async {
|
||||||
|
var comics = LocalFavoritesManager().getComicsWithUpdatesInfo(folder);
|
||||||
|
var updatedComics = comics.where((c) => c.hasNewUpdate).toList();
|
||||||
|
var jsonList = updatedComics.map((c) => {
|
||||||
|
'id': c.id,
|
||||||
|
'name': c.name,
|
||||||
|
'coverUrl': c.coverPath,
|
||||||
|
'author': c.author,
|
||||||
|
'type': c.type.sourceKey,
|
||||||
|
'updateTime': c.updateTime,
|
||||||
|
'tags': c.tags,
|
||||||
|
}).toList();
|
||||||
|
return jsonEncode(jsonList);
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import 'package:flutter/widgets.dart' show ChangeNotifier;
|
|||||||
import 'package:sqlite3/sqlite3.dart';
|
import 'package:sqlite3/sqlite3.dart';
|
||||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||||
import 'package:venera/foundation/comic_type.dart';
|
import 'package:venera/foundation/comic_type.dart';
|
||||||
|
import 'package:venera/foundation/favorites.dart';
|
||||||
import 'package:venera/foundation/image_provider/image_favorites_provider.dart';
|
import 'package:venera/foundation/image_provider/image_favorites_provider.dart';
|
||||||
import 'package:venera/foundation/log.dart';
|
import 'package:venera/foundation/log.dart';
|
||||||
import 'package:venera/utils/ext.dart';
|
import 'package:venera/utils/ext.dart';
|
||||||
@@ -132,6 +133,11 @@ class History implements Comic {
|
|||||||
@override
|
@override
|
||||||
String get description {
|
String get description {
|
||||||
var res = "";
|
var res = "";
|
||||||
|
if (group != null){
|
||||||
|
res += "${"Group @group".tlParams({
|
||||||
|
"group": group!,
|
||||||
|
})} - ";
|
||||||
|
}
|
||||||
if (ep >= 1) {
|
if (ep >= 1) {
|
||||||
res += "Chapter @ep".tlParams({
|
res += "Chapter @ep".tlParams({
|
||||||
"ep": ep,
|
"ep": ep,
|
||||||
@@ -305,6 +311,31 @@ class HistoryManager with ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clearUnfavoritedHistory() {
|
||||||
|
_db.execute('BEGIN TRANSACTION;');
|
||||||
|
try {
|
||||||
|
final idAndTypes = _db.select("""
|
||||||
|
select id, type from history;
|
||||||
|
""");
|
||||||
|
for (var element in idAndTypes) {
|
||||||
|
final id = element["id"] as String;
|
||||||
|
final type = ComicType(element["type"] as int);
|
||||||
|
if (!LocalFavoritesManager().isExist(id, type)) {
|
||||||
|
_db.execute("""
|
||||||
|
delete from history
|
||||||
|
where id == ? and type == ?;
|
||||||
|
""", [id, type.value]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_db.execute('COMMIT;');
|
||||||
|
} catch (e) {
|
||||||
|
_db.execute('ROLLBACK;');
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
updateCache();
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
void remove(String id, ComicType type) async {
|
void remove(String id, ComicType type) async {
|
||||||
_db.execute("""
|
_db.execute("""
|
||||||
delete from history
|
delete from history
|
||||||
@@ -380,4 +411,23 @@ class HistoryManager with ChangeNotifier {
|
|||||||
isInitialized = false;
|
isInitialized = false;
|
||||||
_db.dispose();
|
_db.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void batchDeleteHistories(List<ComicID> histories) {
|
||||||
|
if (histories.isEmpty) return;
|
||||||
|
_db.execute('BEGIN TRANSACTION;');
|
||||||
|
try {
|
||||||
|
for (var history in histories) {
|
||||||
|
_db.execute("""
|
||||||
|
delete from history
|
||||||
|
where id == ? and type == ?;
|
||||||
|
""", [history.id, history.type.value]);
|
||||||
|
}
|
||||||
|
_db.execute('COMMIT;');
|
||||||
|
} catch (e) {
|
||||||
|
_db.execute('ROLLBACK;');
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
updateCache();
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import 'dart:async' show Future;
|
import 'dart:async' show Future;
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:venera/foundation/comic_type.dart';
|
||||||
|
import 'package:venera/foundation/local.dart';
|
||||||
import 'package:venera/network/images.dart';
|
import 'package:venera/network/images.dart';
|
||||||
import 'package:venera/utils/io.dart';
|
import 'package:venera/utils/io.dart';
|
||||||
import 'base_image_provider.dart';
|
import 'base_image_provider.dart';
|
||||||
@@ -11,7 +13,12 @@ class CachedImageProvider
|
|||||||
/// Image provider for normal image.
|
/// Image provider for normal image.
|
||||||
///
|
///
|
||||||
/// [url] is the url of the image. Local file path is also supported.
|
/// [url] is the url of the image. Local file path is also supported.
|
||||||
const CachedImageProvider(this.url, {this.headers, this.sourceKey, this.cid});
|
const CachedImageProvider(this.url, {
|
||||||
|
this.headers,
|
||||||
|
this.sourceKey,
|
||||||
|
this.cid,
|
||||||
|
this.fallbackToLocalCover = false,
|
||||||
|
});
|
||||||
|
|
||||||
final String url;
|
final String url;
|
||||||
|
|
||||||
@@ -21,6 +28,9 @@ class CachedImageProvider
|
|||||||
|
|
||||||
final String? cid;
|
final String? cid;
|
||||||
|
|
||||||
|
// Use local cover if network image fails to load.
|
||||||
|
final bool fallbackToLocalCover;
|
||||||
|
|
||||||
static int loadingCount = 0;
|
static int loadingCount = 0;
|
||||||
|
|
||||||
static const _kMaxLoadingCount = 8;
|
static const _kMaxLoadingCount = 8;
|
||||||
@@ -49,6 +59,24 @@ class CachedImageProvider
|
|||||||
}
|
}
|
||||||
throw "Error: Empty response body.";
|
throw "Error: Empty response body.";
|
||||||
}
|
}
|
||||||
|
catch(e) {
|
||||||
|
if (fallbackToLocalCover && sourceKey != null && cid != null) {
|
||||||
|
final localComic = LocalManager().find(
|
||||||
|
cid!,
|
||||||
|
ComicType.fromKey(sourceKey!),
|
||||||
|
);
|
||||||
|
if (localComic != null) {
|
||||||
|
var file = localComic.coverFile;
|
||||||
|
if (await file.exists()) {
|
||||||
|
var data = await file.readAsBytes();
|
||||||
|
if (data.isNotEmpty) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
finally {
|
finally {
|
||||||
loadingCount--;
|
loadingCount--;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'dart:io';
|
|||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
import 'package:crypto/crypto.dart';
|
import 'package:crypto/crypto.dart';
|
||||||
import 'package:dio/io.dart';
|
import 'package:dio/io.dart';
|
||||||
|
import 'package:enough_convert/enough_convert.dart';
|
||||||
import 'package:flutter/foundation.dart' show protected;
|
import 'package:flutter/foundation.dart' show protected;
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:html/parser.dart' as html;
|
import 'package:html/parser.dart' as html;
|
||||||
@@ -23,8 +24,10 @@ import 'package:pointycastle/block/modes/ofb.dart';
|
|||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
import 'package:venera/components/js_ui.dart';
|
import 'package:venera/components/js_ui.dart';
|
||||||
import 'package:venera/foundation/app.dart';
|
import 'package:venera/foundation/app.dart';
|
||||||
|
import 'package:venera/foundation/js_pool.dart';
|
||||||
import 'package:venera/network/app_dio.dart';
|
import 'package:venera/network/app_dio.dart';
|
||||||
import 'package:venera/network/cookie_jar.dart';
|
import 'package:venera/network/cookie_jar.dart';
|
||||||
|
import 'package:venera/network/proxy.dart';
|
||||||
import 'package:venera/utils/init.dart';
|
import 'package:venera/utils/init.dart';
|
||||||
|
|
||||||
import 'comic_source/comic_source.dart';
|
import 'comic_source/comic_source.dart';
|
||||||
@@ -66,6 +69,12 @@ class JsEngine with _JSEngineApi, JsUiApi, Init {
|
|||||||
responseType: ResponseType.plain, validateStatus: (status) => true));
|
responseType: ResponseType.plain, validateStatus: (status) => true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Uint8List? _jsInitCache;
|
||||||
|
|
||||||
|
static void cacheJsInit(Uint8List jsInit) {
|
||||||
|
_jsInitCache = jsInit;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@protected
|
@protected
|
||||||
Future<void> doInit() async {
|
Future<void> doInit() async {
|
||||||
@@ -73,9 +82,11 @@ class JsEngine with _JSEngineApi, JsUiApi, Init {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
if (App.isInitialized) {
|
||||||
|
_cookieJar ??= await SingleInstanceCookieJar.createInstance();
|
||||||
|
}
|
||||||
_dio ??= AppDio(BaseOptions(
|
_dio ??= AppDio(BaseOptions(
|
||||||
responseType: ResponseType.plain, validateStatus: (status) => true));
|
responseType: ResponseType.plain, validateStatus: (status) => true));
|
||||||
_cookieJar ??= SingleInstanceCookieJar.instance!;
|
|
||||||
_closed = false;
|
_closed = false;
|
||||||
_engine = FlutterQjs();
|
_engine = FlutterQjs();
|
||||||
_engine!.dispatch();
|
_engine!.dispatch();
|
||||||
@@ -84,9 +95,15 @@ class JsEngine with _JSEngineApi, JsUiApi, Init {
|
|||||||
(setGlobalFunc as JSInvokable)(["sendMessage", _messageReceiver]);
|
(setGlobalFunc as JSInvokable)(["sendMessage", _messageReceiver]);
|
||||||
setGlobalFunc(["appVersion", App.version]);
|
setGlobalFunc(["appVersion", App.version]);
|
||||||
setGlobalFunc.free();
|
setGlobalFunc.free();
|
||||||
var jsInit = await rootBundle.load("assets/init.js");
|
Uint8List jsInit;
|
||||||
|
if (_jsInitCache != null) {
|
||||||
|
jsInit = _jsInitCache!;
|
||||||
|
} else {
|
||||||
|
var buffer = await rootBundle.load("assets/init.js");
|
||||||
|
jsInit = buffer.buffer.asUint8List();
|
||||||
|
}
|
||||||
_engine!
|
_engine!
|
||||||
.evaluate(utf8.decode(jsInit.buffer.asUint8List()), name: "<init>");
|
.evaluate(utf8.decode(jsInit), name: "<init>");
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Log.error('JS Engine', 'JS Engine Init Error:\n$e\n$s');
|
Log.error('JS Engine', 'JS Engine Init Error:\n$e\n$s');
|
||||||
}
|
}
|
||||||
@@ -95,6 +112,7 @@ class JsEngine with _JSEngineApi, JsUiApi, Init {
|
|||||||
Object? _messageReceiver(dynamic message) {
|
Object? _messageReceiver(dynamic message) {
|
||||||
try {
|
try {
|
||||||
if (message is Map<dynamic, dynamic>) {
|
if (message is Map<dynamic, dynamic>) {
|
||||||
|
if (message["method"] == null) return null;
|
||||||
String method = message["method"] as String;
|
String method = message["method"] as String;
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case "log":
|
case "log":
|
||||||
@@ -163,6 +181,27 @@ class JsEngine with _JSEngineApi, JsUiApi, Init {
|
|||||||
return "${App.locale.languageCode}_${App.locale.countryCode}";
|
return "${App.locale.languageCode}_${App.locale.countryCode}";
|
||||||
case "getPlatform":
|
case "getPlatform":
|
||||||
return Platform.operatingSystem;
|
return Platform.operatingSystem;
|
||||||
|
case "setClipboard":
|
||||||
|
return Clipboard.setData(ClipboardData(text: message["text"]));
|
||||||
|
case "getClipboard":
|
||||||
|
return Future.sync(() async {
|
||||||
|
var res = await Clipboard.getData(Clipboard.kTextPlain);
|
||||||
|
return res?.text;
|
||||||
|
});
|
||||||
|
case "compute":
|
||||||
|
final func = message["function"];
|
||||||
|
final args = message["args"];
|
||||||
|
if (func is JSInvokable) {
|
||||||
|
func.free();
|
||||||
|
throw "Function must be a string";
|
||||||
|
}
|
||||||
|
if (func is! String) {
|
||||||
|
throw "Function must be a string";
|
||||||
|
}
|
||||||
|
if (args != null && args is! List) {
|
||||||
|
throw "Args must be a list";
|
||||||
|
}
|
||||||
|
return JSPool().execute(func, args ?? []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -187,7 +226,7 @@ class JsEngine with _JSEngineApi, JsUiApi, Init {
|
|||||||
responseType: ResponseType.plain,
|
responseType: ResponseType.plain,
|
||||||
validateStatus: (status) => true,
|
validateStatus: (status) => true,
|
||||||
));
|
));
|
||||||
var proxy = await AppDio.getProxy();
|
var proxy = await getProxy();
|
||||||
dio.httpClientAdapter = IOHttpClientAdapter(
|
dio.httpClientAdapter = IOHttpClientAdapter(
|
||||||
createHttpClient: () {
|
createHttpClient: () {
|
||||||
return HttpClient()
|
return HttpClient()
|
||||||
@@ -364,6 +403,11 @@ mixin class _JSEngineApi {
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case "utf8":
|
case "utf8":
|
||||||
return isEncode ? utf8.encode(value) : utf8.decode(value);
|
return isEncode ? utf8.encode(value) : utf8.decode(value);
|
||||||
|
case "gbk":
|
||||||
|
final codec = const GbkCodec();
|
||||||
|
return isEncode
|
||||||
|
? Uint8List.fromList(codec.encode(value))
|
||||||
|
: codec.decode(value);
|
||||||
case "base64":
|
case "base64":
|
||||||
return isEncode ? base64Encode(value) : base64Decode(value);
|
return isEncode ? base64Encode(value) : base64Decode(value);
|
||||||
case "md5":
|
case "md5":
|
||||||
|
|||||||
163
lib/foundation/js_pool.dart
Normal file
163
lib/foundation/js_pool.dart
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:isolate';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_qjs/flutter_qjs.dart';
|
||||||
|
import 'package:venera/foundation/js_engine.dart';
|
||||||
|
import 'package:venera/foundation/log.dart';
|
||||||
|
|
||||||
|
class JSPool {
|
||||||
|
static final int _maxInstances = 4;
|
||||||
|
final List<IsolateJsEngine> _instances = [];
|
||||||
|
bool _isInitializing = false;
|
||||||
|
|
||||||
|
static final JSPool _singleton = JSPool._internal();
|
||||||
|
factory JSPool() {
|
||||||
|
return _singleton;
|
||||||
|
}
|
||||||
|
JSPool._internal();
|
||||||
|
|
||||||
|
Future<void> init() async {
|
||||||
|
if (_isInitializing) return;
|
||||||
|
_isInitializing = true;
|
||||||
|
var jsInitBuffer = await rootBundle.load("assets/init.js");
|
||||||
|
var jsInit = jsInitBuffer.buffer.asUint8List();
|
||||||
|
for (int i = 0; i < _maxInstances; i++) {
|
||||||
|
_instances.add(IsolateJsEngine(jsInit));
|
||||||
|
}
|
||||||
|
_isInitializing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<dynamic> execute(String jsFunction, List<dynamic> args) async {
|
||||||
|
await init();
|
||||||
|
var selectedInstance = _instances[0];
|
||||||
|
for (var instance in _instances) {
|
||||||
|
if (instance.pendingTasks < selectedInstance.pendingTasks) {
|
||||||
|
selectedInstance = instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return selectedInstance.execute(jsFunction, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _IsolateJsEngineInitParam {
|
||||||
|
final SendPort sendPort;
|
||||||
|
|
||||||
|
final Uint8List jsInit;
|
||||||
|
|
||||||
|
_IsolateJsEngineInitParam(this.sendPort, this.jsInit);
|
||||||
|
}
|
||||||
|
|
||||||
|
class IsolateJsEngine {
|
||||||
|
Isolate? _isolate;
|
||||||
|
|
||||||
|
SendPort? _sendPort;
|
||||||
|
ReceivePort? _receivePort;
|
||||||
|
|
||||||
|
int _counter = 0;
|
||||||
|
final Map<int, Completer<dynamic>> _tasks = {};
|
||||||
|
|
||||||
|
bool _isClosed = false;
|
||||||
|
|
||||||
|
int get pendingTasks => _tasks.length;
|
||||||
|
|
||||||
|
IsolateJsEngine(Uint8List jsInit) {
|
||||||
|
_receivePort = ReceivePort();
|
||||||
|
_receivePort!.listen(_onMessage);
|
||||||
|
Isolate.spawn(_run, _IsolateJsEngineInitParam(_receivePort!.sendPort, jsInit));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onMessage(dynamic message) {
|
||||||
|
if (message is SendPort) {
|
||||||
|
_sendPort = message;
|
||||||
|
} else if (message is TaskResult) {
|
||||||
|
final completer = _tasks.remove(message.id);
|
||||||
|
if (completer != null) {
|
||||||
|
if (message.error != null) {
|
||||||
|
completer.completeError(message.error!);
|
||||||
|
} else {
|
||||||
|
completer.complete(message.result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (message is Exception) {
|
||||||
|
Log.error("IsolateJsEngine", message.toString());
|
||||||
|
for (var completer in _tasks.values) {
|
||||||
|
completer.completeError(message);
|
||||||
|
}
|
||||||
|
_tasks.clear();
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _run(_IsolateJsEngineInitParam params) async {
|
||||||
|
var sendPort = params.sendPort;
|
||||||
|
final port = ReceivePort();
|
||||||
|
sendPort.send(port.sendPort);
|
||||||
|
final engine = JsEngine();
|
||||||
|
try {
|
||||||
|
JsEngine.cacheJsInit(params.jsInit);
|
||||||
|
await engine.init();
|
||||||
|
}
|
||||||
|
catch(e, s) {
|
||||||
|
sendPort.send(Exception("Failed to initialize JS engine: $e\n$s"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await for (final message in port) {
|
||||||
|
if (message is Task) {
|
||||||
|
try {
|
||||||
|
final jsFunc = engine.runCode(message.jsFunction);
|
||||||
|
if (jsFunc is! JSInvokable) {
|
||||||
|
throw Exception("The provided code does not evaluate to a function.");
|
||||||
|
}
|
||||||
|
final result = jsFunc.invoke(message.args);
|
||||||
|
jsFunc.free();
|
||||||
|
sendPort.send(TaskResult(message.id, result, null));
|
||||||
|
} catch (e) {
|
||||||
|
sendPort.send(TaskResult(message.id, null, e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<dynamic> execute(String jsFunction, List<dynamic> args) async {
|
||||||
|
if (_isClosed) {
|
||||||
|
throw Exception("IsolateJsEngine is closed.");
|
||||||
|
}
|
||||||
|
while (_sendPort == null) {
|
||||||
|
await Future.delayed(const Duration(milliseconds: 10));
|
||||||
|
}
|
||||||
|
final completer = Completer<dynamic>();
|
||||||
|
final taskId = _counter++;
|
||||||
|
_tasks[taskId] = completer;
|
||||||
|
final task = Task(taskId, jsFunction, args);
|
||||||
|
_sendPort?.send(task);
|
||||||
|
return completer.future;
|
||||||
|
}
|
||||||
|
|
||||||
|
void close() async {
|
||||||
|
if (!_isClosed) {
|
||||||
|
_isClosed = true;
|
||||||
|
while (_tasks.isNotEmpty) {
|
||||||
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
|
}
|
||||||
|
_receivePort?.close();
|
||||||
|
_isolate?.kill(priority: Isolate.immediate);
|
||||||
|
_isolate = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Task {
|
||||||
|
final int id;
|
||||||
|
final String jsFunction;
|
||||||
|
final List<dynamic> args;
|
||||||
|
|
||||||
|
const Task(this.id, this.jsFunction, this.args);
|
||||||
|
}
|
||||||
|
|
||||||
|
class TaskResult {
|
||||||
|
final int id;
|
||||||
|
final Object? result;
|
||||||
|
final String? error;
|
||||||
|
|
||||||
|
const TaskResult(this.id, this.result, this.error);
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:isolate';
|
||||||
|
|
||||||
import 'package:flutter/widgets.dart' show ChangeNotifier;
|
import 'package:flutter/widgets.dart' show ChangeNotifier;
|
||||||
|
import 'package:flutter_saf/flutter_saf.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:sqlite3/sqlite3.dart';
|
import 'package:sqlite3/sqlite3.dart';
|
||||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||||
@@ -107,15 +109,42 @@ class LocalComic with HistoryMixin implements Comic {
|
|||||||
|
|
||||||
void read() {
|
void read() {
|
||||||
var history = HistoryManager().find(id, comicType);
|
var history = HistoryManager().find(id, comicType);
|
||||||
|
int? firstDownloadedChapter;
|
||||||
|
int? firstDownloadedChapterGroup;
|
||||||
|
if (downloadedChapters.isNotEmpty && chapters != null) {
|
||||||
|
final chapters = this.chapters!;
|
||||||
|
if (chapters.isGrouped) {
|
||||||
|
for (int i=0; i<chapters.groupCount; i++) {
|
||||||
|
var group = chapters.getGroupByIndex(i);
|
||||||
|
var keys = group.keys.toList();
|
||||||
|
for (int j=0; j<keys.length; j++) {
|
||||||
|
var chapterId = keys[j];
|
||||||
|
if (downloadedChapters.contains(chapterId)) {
|
||||||
|
firstDownloadedChapter = j + 1;
|
||||||
|
firstDownloadedChapterGroup = i + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var keys = chapters.allChapters.keys;
|
||||||
|
for (int i = 0; i < keys.length; i++) {
|
||||||
|
if (downloadedChapters.contains(keys.elementAt(i))) {
|
||||||
|
firstDownloadedChapter = i + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
App.rootContext.to(
|
App.rootContext.to(
|
||||||
() => Reader(
|
() => Reader(
|
||||||
type: comicType,
|
type: comicType,
|
||||||
cid: id,
|
cid: id,
|
||||||
name: title,
|
name: title,
|
||||||
chapters: chapters,
|
chapters: chapters,
|
||||||
initialChapter: history?.ep,
|
initialChapter: history?.ep ?? firstDownloadedChapter,
|
||||||
initialPage: history?.page,
|
initialPage: history?.page,
|
||||||
initialChapterGroup: history?.group,
|
initialChapterGroup: history?.group ?? firstDownloadedChapterGroup,
|
||||||
history: history ??
|
history: history ??
|
||||||
History.fromModel(
|
History.fromModel(
|
||||||
model: this,
|
model: this,
|
||||||
@@ -394,6 +423,7 @@ class LocalManager with ChangeNotifier {
|
|||||||
if (comic.hasChapters) {
|
if (comic.hasChapters) {
|
||||||
var cid =
|
var cid =
|
||||||
ep is int ? comic.chapters!.ids.elementAt(ep - 1) : (ep as String);
|
ep is int ? comic.chapters!.ids.elementAt(ep - 1) : (ep as String);
|
||||||
|
cid = getChapterDirectoryName(cid);
|
||||||
directory = Directory(FilePath.join(directory.path, cid));
|
directory = Directory(FilePath.join(directory.path, cid));
|
||||||
}
|
}
|
||||||
var files = <File>[];
|
var files = <File>[];
|
||||||
@@ -461,6 +491,10 @@ class LocalManager with ChangeNotifier {
|
|||||||
if (comic != null) {
|
if (comic != null) {
|
||||||
return Directory(FilePath.join(path, comic.directory));
|
return Directory(FilePath.join(path, comic.directory));
|
||||||
}
|
}
|
||||||
|
const comicDirectoryMaxLength = 80;
|
||||||
|
if (name.length > comicDirectoryMaxLength) {
|
||||||
|
name = name.substring(0, comicDirectoryMaxLength);
|
||||||
|
}
|
||||||
var dir = findValidDirectoryName(path, name);
|
var dir = findValidDirectoryName(path, name);
|
||||||
return Directory(FilePath.join(path, dir)).create().then((value) => value);
|
return Directory(FilePath.join(path, dir)).create().then((value) => value);
|
||||||
}
|
}
|
||||||
@@ -542,6 +576,117 @@ class LocalManager with ChangeNotifier {
|
|||||||
remove(c.id, c.comicType);
|
remove(c.id, c.comicType);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void deleteComicChapters(LocalComic c, List<String> chapters) {
|
||||||
|
if (chapters.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var newDownloadedChapters = c.downloadedChapters
|
||||||
|
.where((e) => !chapters.contains(e))
|
||||||
|
.toList();
|
||||||
|
if (newDownloadedChapters.isNotEmpty) {
|
||||||
|
_db.execute(
|
||||||
|
'UPDATE comics SET downloadedChapters = ? WHERE id = ? AND comic_type = ?;',
|
||||||
|
[
|
||||||
|
jsonEncode(newDownloadedChapters),
|
||||||
|
c.id,
|
||||||
|
c.comicType.value,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
_db.execute(
|
||||||
|
'DELETE FROM comics WHERE id = ? AND comic_type = ?;',
|
||||||
|
[c.id, c.comicType.value],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
var shouldRemovedDirs = <Directory>[];
|
||||||
|
for (var chapter in chapters) {
|
||||||
|
var dir = Directory(FilePath.join(
|
||||||
|
c.baseDir,
|
||||||
|
getChapterDirectoryName(chapter),
|
||||||
|
));
|
||||||
|
if (dir.existsSync()) {
|
||||||
|
shouldRemovedDirs.add(dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (shouldRemovedDirs.isNotEmpty) {
|
||||||
|
_deleteDirectories(shouldRemovedDirs);
|
||||||
|
}
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void batchDeleteComics(List<LocalComic> comics, [bool removeFileOnDisk = true, bool removeFavoriteAndHistory = true]) {
|
||||||
|
if (comics.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var shouldRemovedDirs = <Directory>[];
|
||||||
|
_db.execute('BEGIN TRANSACTION;');
|
||||||
|
try {
|
||||||
|
for (var c in comics) {
|
||||||
|
if (removeFileOnDisk) {
|
||||||
|
var dir = Directory(FilePath.join(path, c.directory));
|
||||||
|
if (dir.existsSync()) {
|
||||||
|
shouldRemovedDirs.add(dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_db.execute(
|
||||||
|
'DELETE FROM comics WHERE id = ? AND comic_type = ?;',
|
||||||
|
[c.id, c.comicType.value],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(e, s) {
|
||||||
|
Log.error("LocalManager", "Failed to batch delete comics: $e", s);
|
||||||
|
_db.execute('ROLLBACK;');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_db.execute('COMMIT;');
|
||||||
|
|
||||||
|
var comicIDs = comics.map((e) => ComicID(e.comicType, e.id)).toList();
|
||||||
|
|
||||||
|
if (removeFavoriteAndHistory) {
|
||||||
|
LocalFavoritesManager().batchDeleteComicsInAllFolders(comicIDs);
|
||||||
|
HistoryManager().batchDeleteHistories(comicIDs);
|
||||||
|
}
|
||||||
|
|
||||||
|
notifyListeners();
|
||||||
|
|
||||||
|
if (removeFileOnDisk) {
|
||||||
|
_deleteDirectories(shouldRemovedDirs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deletes the directories in a separate isolate to avoid blocking the UI thread.
|
||||||
|
static void _deleteDirectories(List<Directory> directories) {
|
||||||
|
Isolate.run(() async {
|
||||||
|
await SAFTaskWorker().init();
|
||||||
|
for (var dir in directories) {
|
||||||
|
try {
|
||||||
|
if (dir.existsSync()) {
|
||||||
|
await dir.delete(recursive: true);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getChapterDirectoryName(String name) {
|
||||||
|
var builder = StringBuffer();
|
||||||
|
for (var i = 0; i < name.length; i++) {
|
||||||
|
var char = name[i];
|
||||||
|
if (char == '/' || char == '\\' || char == ':' || char == '*' ||
|
||||||
|
char == '?'
|
||||||
|
|| char == '"' || char == '<' || char == '>' || char == '|') {
|
||||||
|
builder.write('_');
|
||||||
|
} else {
|
||||||
|
builder.write(char);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum LocalSortType {
|
enum LocalSortType {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:venera/foundation/app.dart';
|
||||||
import 'package:venera/utils/ext.dart';
|
import 'package:venera/utils/ext.dart';
|
||||||
|
import 'package:venera/utils/io.dart';
|
||||||
|
|
||||||
class LogItem {
|
class LogItem {
|
||||||
final LogLevel level;
|
final LogLevel level;
|
||||||
@@ -28,8 +28,7 @@ class Log {
|
|||||||
|
|
||||||
static bool ignoreLimitation = false;
|
static bool ignoreLimitation = false;
|
||||||
|
|
||||||
/// only for debug
|
static bool isMuted = false;
|
||||||
static const String? logFile = null;
|
|
||||||
|
|
||||||
static void printWarning(String text) {
|
static void printWarning(String text) {
|
||||||
debugPrint('\x1B[33m$text\x1B[0m');
|
debugPrint('\x1B[33m$text\x1B[0m');
|
||||||
@@ -39,7 +38,21 @@ class Log {
|
|||||||
debugPrint('\x1B[31m$text\x1B[0m');
|
debugPrint('\x1B[31m$text\x1B[0m');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static IOSink? _file;
|
||||||
|
|
||||||
static void addLog(LogLevel level, String title, String content) {
|
static void addLog(LogLevel level, String title, String content) {
|
||||||
|
if (isMuted) return;
|
||||||
|
if (_file == null && App.isInitialized) {
|
||||||
|
Directory dir;
|
||||||
|
if (App.isAndroid) {
|
||||||
|
dir = Directory(App.externalStoragePath!);
|
||||||
|
} else {
|
||||||
|
dir = Directory(App.dataPath);
|
||||||
|
}
|
||||||
|
var file = dir.joinFile("logs.txt");
|
||||||
|
_file = file.openWrite();
|
||||||
|
}
|
||||||
|
|
||||||
if (!ignoreLimitation && content.length > maxLogLength) {
|
if (!ignoreLimitation && content.length > maxLogLength) {
|
||||||
content = "${content.substring(0, maxLogLength)}...";
|
content = "${content.substring(0, maxLogLength)}...";
|
||||||
}
|
}
|
||||||
@@ -62,8 +75,8 @@ class Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_logs.add(newLog);
|
_logs.add(newLog);
|
||||||
if(logFile != null) {
|
if(_file != null) {
|
||||||
File(logFile!).writeAsString(newLog.toString(), mode: FileMode.append);
|
_file!.write(newLog.toString());
|
||||||
}
|
}
|
||||||
if (_logs.length > maxLogNumber) {
|
if (_logs.length > maxLogNumber) {
|
||||||
var res = _logs.remove(
|
var res = _logs.remove(
|
||||||
|
|||||||
244
lib/headless.dart
Normal file
244
lib/headless.dart
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:venera/utils/data_sync.dart';
|
||||||
|
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||||
|
import 'package:venera/foundation/log.dart';
|
||||||
|
import 'package:venera/pages/comic_source_page.dart';
|
||||||
|
import 'package:venera/init.dart';
|
||||||
|
import 'package:venera/foundation/follow_updates.dart';
|
||||||
|
import 'package:venera/foundation/appdata.dart';
|
||||||
|
import 'package:venera/foundation/favorites.dart';
|
||||||
|
|
||||||
|
void cliPrint(Map<String, dynamic> data) {
|
||||||
|
print('[CLI PRINT] ${jsonEncode(data)}');
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> runHeadlessMode(List<String> args) async {
|
||||||
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
if (args.contains('--ignore-disheadless-log')) {
|
||||||
|
Log.isMuted = true;
|
||||||
|
}
|
||||||
|
if(Platform.isLinux || Platform.isMacOS){
|
||||||
|
Directory.current = Platform.environment['HOME']!;
|
||||||
|
}
|
||||||
|
// The first arg is '--headless', so we look at the next ones.
|
||||||
|
var commandIndex = args.indexOf('--headless') + 1;
|
||||||
|
if (commandIndex >= args.length) {
|
||||||
|
cliPrint({'status': 'error', 'message': 'No command provided for headless mode.'});
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Need to initialize the app for some features to work
|
||||||
|
await init();
|
||||||
|
|
||||||
|
var command = args[commandIndex];
|
||||||
|
var subCommand = (commandIndex + 1 < args.length) ? args[commandIndex + 1] : null;
|
||||||
|
|
||||||
|
switch (command) {
|
||||||
|
case 'webdav':
|
||||||
|
if (subCommand == 'up') {
|
||||||
|
cliPrint({'status': 'running', 'message': 'Uploading WebDAV data...'});
|
||||||
|
await DataSync().uploadData();
|
||||||
|
cliPrint({'status': 'success', 'message': 'Upload complete.'});
|
||||||
|
} else if (subCommand == 'down') {
|
||||||
|
cliPrint({'status': 'running', 'message': 'Downloading WebDAV data...'});
|
||||||
|
await DataSync().downloadData();
|
||||||
|
cliPrint({'status': 'success', 'message': 'Download complete.'});
|
||||||
|
} else {
|
||||||
|
cliPrint({'status': 'error', 'message': 'Invalid webdav command. Use "up" or "down".'});
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'updatescript':
|
||||||
|
if (subCommand == 'all') {
|
||||||
|
cliPrint({'status': 'running', 'message': 'Checking for comic source script updates...'});
|
||||||
|
await ComicSourcePage.checkComicSourceUpdate();
|
||||||
|
var updates = ComicSourceManager().availableUpdates;
|
||||||
|
if (updates.isEmpty) {
|
||||||
|
cliPrint({'status': 'success', 'message': 'No updates found.'});
|
||||||
|
} else {
|
||||||
|
var total = updates.length;
|
||||||
|
var current = 0;
|
||||||
|
var errors = 0;
|
||||||
|
var updated = 0;
|
||||||
|
cliPrint({
|
||||||
|
'status': 'running',
|
||||||
|
'message': 'Updating all comic source scripts...',
|
||||||
|
'data': {
|
||||||
|
'total': total,
|
||||||
|
'current': 0,
|
||||||
|
'updated': 0,
|
||||||
|
'errors': 0,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for (var key in updates.keys) {
|
||||||
|
var source = ComicSource.find(key);
|
||||||
|
if (source != null) {
|
||||||
|
current++;
|
||||||
|
var data = {
|
||||||
|
'current': current,
|
||||||
|
'total': total,
|
||||||
|
'source': {
|
||||||
|
'key': source.key,
|
||||||
|
'name': source.name,
|
||||||
|
'version': source.version,
|
||||||
|
'url': source.url,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
await ComicSourcePage.update(source, false);
|
||||||
|
updated++;
|
||||||
|
cliPrint({
|
||||||
|
'status': 'running',
|
||||||
|
'message': 'Progress',
|
||||||
|
'data': data,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
errors++;
|
||||||
|
cliPrint({
|
||||||
|
'status': 'running',
|
||||||
|
'message': 'ProgressError',
|
||||||
|
'data': {
|
||||||
|
...data,
|
||||||
|
'error': e.toString(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cliPrint({
|
||||||
|
'status': 'success',
|
||||||
|
'message': 'All scripts updated.',
|
||||||
|
'data': {
|
||||||
|
'total': total,
|
||||||
|
'updated': updated,
|
||||||
|
'errors': errors,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cliPrint({'status': 'error', 'message': 'Invalid updatescript command. Use "all".'});
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'updatesubscribe':
|
||||||
|
cliPrint({'status': 'running', 'message': 'Updating subscribed comics...'});
|
||||||
|
var folder = appdata.settings["followUpdatesFolder"];
|
||||||
|
if (folder == null) {
|
||||||
|
cliPrint({'status': 'error', 'message': 'Follow updates folder is not configured.'});
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
var updateIndex = args.indexOf('--update-comic-by-id-type');
|
||||||
|
if (updateIndex != -1) {
|
||||||
|
var id = args[updateIndex + 1];
|
||||||
|
var type = args[updateIndex + 2];
|
||||||
|
var comics = LocalFavoritesManager().getComicsWithUpdatesInfo(folder);
|
||||||
|
var comic = comics.firstWhere((c) => c.id == id && c.type.sourceKey == type);
|
||||||
|
|
||||||
|
var result = await updateComic(comic, folder);
|
||||||
|
|
||||||
|
Map<String, dynamic> data = {
|
||||||
|
'current': 1,
|
||||||
|
'total': 1,
|
||||||
|
'comic': {
|
||||||
|
'id': comic.id,
|
||||||
|
'name': comic.name,
|
||||||
|
'coverUrl': comic.coverPath,
|
||||||
|
'author': comic.author,
|
||||||
|
'type': comic.type.sourceKey,
|
||||||
|
'updateTime': comic.updateTime,
|
||||||
|
'tags': comic.tags,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var message = 'Progress';
|
||||||
|
if (result.errorMessage != null) {
|
||||||
|
message = 'ProgressError';
|
||||||
|
data['error'] = result.errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
cliPrint({
|
||||||
|
'status': 'running',
|
||||||
|
'message': message,
|
||||||
|
'data': data,
|
||||||
|
});
|
||||||
|
|
||||||
|
cliPrint({
|
||||||
|
'status': 'running',
|
||||||
|
'message': 'Update check complete.',
|
||||||
|
'data': {
|
||||||
|
'total': 1,
|
||||||
|
'updated': result.updated ? 1 : 0,
|
||||||
|
'errors': result.errorMessage != null ? 1 : 0,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
var json = await getUpdatedComicsAsJson(folder);
|
||||||
|
cliPrint({
|
||||||
|
'status': result.errorMessage != null ? 'error' : 'success',
|
||||||
|
'message': 'Updated comics list.',
|
||||||
|
'data': jsonDecode(json),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
int total = 0;
|
||||||
|
int updated = 0;
|
||||||
|
int errors = 0;
|
||||||
|
await for (var progress in updateFolder(folder, true)) {
|
||||||
|
total = progress.total;
|
||||||
|
updated = progress.updated;
|
||||||
|
errors = progress.errors;
|
||||||
|
Map<String, dynamic> data = {
|
||||||
|
'current': progress.current,
|
||||||
|
'total': progress.total,
|
||||||
|
};
|
||||||
|
if (progress.comic != null) {
|
||||||
|
data['comic'] = {
|
||||||
|
'id': progress.comic!.id,
|
||||||
|
'name': progress.comic!.name,
|
||||||
|
'coverUrl': progress.comic!.coverPath,
|
||||||
|
'author': progress.comic!.author,
|
||||||
|
'type': progress.comic!.type.sourceKey,
|
||||||
|
'updateTime': progress.comic!.updateTime,
|
||||||
|
'tags': progress.comic!.tags,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var message = 'Progress';
|
||||||
|
if (progress.errorMessage != null) {
|
||||||
|
message = 'ProgressError';
|
||||||
|
data['error'] = progress.errorMessage;
|
||||||
|
}
|
||||||
|
cliPrint({
|
||||||
|
'status': 'running',
|
||||||
|
'message': message,
|
||||||
|
'data': data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
cliPrint({
|
||||||
|
'status': 'running',
|
||||||
|
'message': 'Update check complete.',
|
||||||
|
'data': {
|
||||||
|
'total': total,
|
||||||
|
'updated': updated,
|
||||||
|
'errors': errors,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
var json = await getUpdatedComicsAsJson(folder);
|
||||||
|
cliPrint({
|
||||||
|
'status': errors > 0 ? 'error' : 'success',
|
||||||
|
'message': 'Updated comics list.',
|
||||||
|
'data': jsonDecode(json),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
cliPrint({'status': 'error', 'message': 'Unknown command: $command'});
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit after command execution
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
@@ -1,4 +1,8 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:display_mode/display_mode.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_saf/flutter_saf.dart';
|
import 'package:flutter_saf/flutter_saf.dart';
|
||||||
import 'package:rhttp/rhttp.dart';
|
import 'package:rhttp/rhttp.dart';
|
||||||
import 'package:venera/foundation/app.dart';
|
import 'package:venera/foundation/app.dart';
|
||||||
@@ -12,6 +16,7 @@ import 'package:venera/pages/follow_updates_page.dart';
|
|||||||
import 'package:venera/pages/settings/settings_page.dart';
|
import 'package:venera/pages/settings/settings_page.dart';
|
||||||
import 'package:venera/utils/app_links.dart';
|
import 'package:venera/utils/app_links.dart';
|
||||||
import 'package:venera/utils/handle_text_share.dart';
|
import 'package:venera/utils/handle_text_share.dart';
|
||||||
|
import 'package:venera/utils/opencc.dart';
|
||||||
import 'package:venera/utils/tags_translation.dart';
|
import 'package:venera/utils/tags_translation.dart';
|
||||||
import 'package:venera/utils/translations.dart';
|
import 'package:venera/utils/translations.dart';
|
||||||
import 'foundation/appdata.dart';
|
import 'foundation/appdata.dart';
|
||||||
@@ -32,25 +37,43 @@ extension _FutureInit<T> on Future<T> {
|
|||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
await App.init().wait();
|
await App.init().wait();
|
||||||
await SingleInstanceCookieJar.createInstance();
|
await SingleInstanceCookieJar.createInstance();
|
||||||
var futures = [
|
try {
|
||||||
Rhttp.init(),
|
var futures = [
|
||||||
App.initComponents(),
|
Rhttp.init(),
|
||||||
SAFTaskWorker().init().wait(),
|
App.initComponents(),
|
||||||
AppTranslation.init().wait(),
|
SAFTaskWorker().init().wait(),
|
||||||
TagsTranslation.readData().wait(),
|
AppTranslation.init().wait(),
|
||||||
JsEngine().init().wait(),
|
TagsTranslation.readData().wait(),
|
||||||
ComicSourceManager().init().wait(),
|
JsEngine().init().wait(),
|
||||||
];
|
ComicSourceManager().init().wait(),
|
||||||
await Future.wait(futures);
|
OpenCC.init(),
|
||||||
|
];
|
||||||
|
await Future.wait(futures);
|
||||||
|
} catch (e, s) {
|
||||||
|
Log.error("init", "$e\n$s");
|
||||||
|
}
|
||||||
CacheManager().setLimitSize(appdata.settings['cacheSize']);
|
CacheManager().setLimitSize(appdata.settings['cacheSize']);
|
||||||
_checkOldConfigs();
|
_checkOldConfigs();
|
||||||
if (App.isAndroid) {
|
if (App.isAndroid) {
|
||||||
handleLinks();
|
handleLinks();
|
||||||
handleTextShare();
|
handleTextShare();
|
||||||
|
try {
|
||||||
|
await FlutterDisplayMode.setHighRefreshRate();
|
||||||
|
} catch(e) {
|
||||||
|
Log.error("Display Mode", "Failed to set high refresh rate: $e");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FlutterError.onError = (details) {
|
FlutterError.onError = (details) {
|
||||||
Log.error("Unhandled Exception", "${details.exception}\n${details.stack}");
|
Log.error("Unhandled Exception", "${details.exception}\n${details.stack}");
|
||||||
};
|
};
|
||||||
|
if (App.isWindows) {
|
||||||
|
// Report to the monitor thread that the app is running
|
||||||
|
// https://github.com/venera-app/venera/issues/343
|
||||||
|
Timer.periodic(const Duration(seconds: 1), (_) {
|
||||||
|
const methodChannel = MethodChannel('venera/method_channel');
|
||||||
|
methodChannel.invokeMethod("heartBeat");
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _checkOldConfigs() {
|
void _checkOldConfigs() {
|
||||||
@@ -84,8 +107,7 @@ Future<void> _checkAppUpdates() async {
|
|||||||
appdata.writeImplicitData();
|
appdata.writeImplicitData();
|
||||||
ComicSourcePage.checkComicSourceUpdate();
|
ComicSourcePage.checkComicSourceUpdate();
|
||||||
if (appdata.settings['checkUpdateOnStart']) {
|
if (appdata.settings['checkUpdateOnStart']) {
|
||||||
await Future.delayed(const Duration(milliseconds: 300));
|
await checkUpdateUi(false, true);
|
||||||
await checkUpdateUi(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,14 @@ import 'components/components.dart';
|
|||||||
import 'components/window_frame.dart';
|
import 'components/window_frame.dart';
|
||||||
import 'foundation/app.dart';
|
import 'foundation/app.dart';
|
||||||
import 'foundation/appdata.dart';
|
import 'foundation/appdata.dart';
|
||||||
|
import 'headless.dart';
|
||||||
import 'init.dart';
|
import 'init.dart';
|
||||||
|
|
||||||
void main(List<String> args) {
|
void main(List<String> args) {
|
||||||
|
if (args.contains('--headless')) {
|
||||||
|
runHeadlessMode(args);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (runWebViewTitleBarWidget(args)) return;
|
if (runWebViewTitleBarWidget(args)) return;
|
||||||
overrideIO(() {
|
overrideIO(() {
|
||||||
runZonedGuarded(() async {
|
runZonedGuarded(() async {
|
||||||
@@ -34,13 +39,16 @@ void main(List<String> args) {
|
|||||||
await windowManager.setBackgroundColor(Colors.transparent);
|
await windowManager.setBackgroundColor(Colors.transparent);
|
||||||
}
|
}
|
||||||
await windowManager.setMinimumSize(const Size(500, 600));
|
await windowManager.setMinimumSize(const Size(500, 600));
|
||||||
if (!App.isLinux) {
|
var placement = await WindowPlacement.loadFromFile();
|
||||||
// https://github.com/leanflutter/window_manager/issues/460
|
if (App.isLinux) {
|
||||||
var placement = await WindowPlacement.loadFromFile();
|
await windowManager.show();
|
||||||
|
await placement.applyToWindow();
|
||||||
|
} else {
|
||||||
await placement.applyToWindow();
|
await placement.applyToWindow();
|
||||||
await windowManager.show();
|
await windowManager.show();
|
||||||
WindowPlacement.loop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WindowPlacement.loop();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, (error, stack) {
|
}, (error, stack) {
|
||||||
@@ -191,6 +199,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|||||||
tertiary = light.tertiary;
|
tertiary = light.tertiary;
|
||||||
}
|
}
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
|
title: "venera",
|
||||||
home: home,
|
home: home,
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
theme: getTheme(primary, secondary, tertiary, Brightness.light),
|
theme: getTheme(primary, secondary, tertiary, Brightness.light),
|
||||||
@@ -201,6 +210,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|||||||
'dark' => ThemeMode.dark,
|
'dark' => ThemeMode.dark,
|
||||||
_ => ThemeMode.system
|
_ => ThemeMode.system
|
||||||
},
|
},
|
||||||
|
color: Colors.transparent,
|
||||||
localizationsDelegates: [
|
localizationsDelegates: [
|
||||||
GlobalMaterialLocalizations.delegate,
|
GlobalMaterialLocalizations.delegate,
|
||||||
GlobalCupertinoLocalizations.delegate,
|
GlobalCupertinoLocalizations.delegate,
|
||||||
@@ -233,6 +243,27 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
if (widget != null) {
|
if (widget != null) {
|
||||||
|
/// 如果无法检测到状态栏高度设定指定高度
|
||||||
|
/// https://github.com/flutter/flutter/issues/161086
|
||||||
|
var isPaddingCheckError =
|
||||||
|
MediaQuery.of(context).viewPadding.top <= 0 ||
|
||||||
|
MediaQuery.of(context).viewPadding.top > 200;
|
||||||
|
|
||||||
|
if (isPaddingCheckError && Platform.isAndroid) {
|
||||||
|
widget = MediaQuery(
|
||||||
|
data: MediaQuery.of(context).copyWith(
|
||||||
|
viewPadding: const EdgeInsets.only(
|
||||||
|
top: 15,
|
||||||
|
bottom: 15,
|
||||||
|
),
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
top: 15,
|
||||||
|
bottom: 15,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: widget);
|
||||||
|
}
|
||||||
|
|
||||||
widget = OverlayWidget(widget);
|
widget = OverlayWidget(widget);
|
||||||
if (App.isDesktop) {
|
if (App.isDesktop) {
|
||||||
widget = Shortcuts(
|
widget = Shortcuts(
|
||||||
@@ -248,6 +279,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return _SystemUiProvider(Material(
|
return _SystemUiProvider(Material(
|
||||||
|
color: App.isLinux ? Colors.transparent : null,
|
||||||
child: widget,
|
child: widget,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import 'package:rhttp/rhttp.dart' as rhttp;
|
|||||||
import 'package:venera/foundation/appdata.dart';
|
import 'package:venera/foundation/appdata.dart';
|
||||||
import 'package:venera/foundation/log.dart';
|
import 'package:venera/foundation/log.dart';
|
||||||
import 'package:venera/network/cache.dart';
|
import 'package:venera/network/cache.dart';
|
||||||
import 'package:venera/utils/ext.dart';
|
import 'package:venera/network/proxy.dart';
|
||||||
|
|
||||||
import '../foundation/app.dart';
|
import '../foundation/app.dart';
|
||||||
import 'cloudflare.dart';
|
import 'cloudflare.dart';
|
||||||
@@ -96,9 +96,11 @@ class MyLogInterceptor implements Interceptor {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
||||||
Log.info("Network", "${options.method} ${options.uri}\n"
|
Log.info(
|
||||||
"headers:\n${options.headers}\n"
|
"Network",
|
||||||
"data:\n${options.data}");
|
"${options.method} ${options.uri}\n"
|
||||||
|
"headers:\n${options.headers}\n"
|
||||||
|
"data:\n${options.data}");
|
||||||
options.connectTimeout = const Duration(seconds: 15);
|
options.connectTimeout = const Duration(seconds: 15);
|
||||||
options.receiveTimeout = const Duration(seconds: 15);
|
options.receiveTimeout = const Duration(seconds: 15);
|
||||||
options.sendTimeout = const Duration(seconds: 15);
|
options.sendTimeout = const Duration(seconds: 15);
|
||||||
@@ -107,62 +109,15 @@ class MyLogInterceptor implements Interceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class AppDio with DioMixin {
|
class AppDio with DioMixin {
|
||||||
String? _proxy = proxy;
|
|
||||||
|
|
||||||
AppDio([BaseOptions? options]) {
|
AppDio([BaseOptions? options]) {
|
||||||
this.options = options ?? BaseOptions();
|
this.options = options ?? BaseOptions();
|
||||||
httpClientAdapter = RHttpAdapter(rhttp.ClientSettings(
|
httpClientAdapter = RHttpAdapter();
|
||||||
proxySettings: proxy == null
|
if (App.isInitialized) {
|
||||||
? const rhttp.ProxySettings.noProxy()
|
interceptors.add(CookieManagerSql(SingleInstanceCookieJar.instance!));
|
||||||
: rhttp.ProxySettings.proxy(proxy!),
|
interceptors.add(NetworkCacheManager());
|
||||||
));
|
interceptors.add(CloudflareInterceptor());
|
||||||
interceptors.add(CookieManagerSql(SingleInstanceCookieJar.instance!));
|
interceptors.add(MyLogInterceptor());
|
||||||
interceptors.add(NetworkCacheManager());
|
|
||||||
interceptors.add(CloudflareInterceptor());
|
|
||||||
interceptors.add(MyLogInterceptor());
|
|
||||||
}
|
|
||||||
|
|
||||||
static String? proxy;
|
|
||||||
|
|
||||||
static Future<String?> getProxy() async {
|
|
||||||
if ((appdata.settings['proxy'] as String).removeAllBlank == "direct") {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
if (appdata.settings['proxy'] != "system") return appdata.settings['proxy'];
|
|
||||||
|
|
||||||
String res;
|
|
||||||
if (!App.isLinux) {
|
|
||||||
const channel = MethodChannel("venera/method_channel");
|
|
||||||
try {
|
|
||||||
res = await channel.invokeMethod("getProxy");
|
|
||||||
} catch (e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
res = "No Proxy";
|
|
||||||
}
|
|
||||||
if (res == "No Proxy") return null;
|
|
||||||
|
|
||||||
if (res.contains(";")) {
|
|
||||||
var proxies = res.split(";");
|
|
||||||
for (String proxy in proxies) {
|
|
||||||
proxy = proxy.removeAllBlank;
|
|
||||||
if (proxy.startsWith('https=')) {
|
|
||||||
return proxy.substring(6);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final RegExp regex = RegExp(
|
|
||||||
r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+$',
|
|
||||||
caseSensitive: false,
|
|
||||||
multiLine: false,
|
|
||||||
);
|
|
||||||
if (!regex.hasMatch(res)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static final Map<String, bool> _requests = {};
|
static final Map<String, bool> _requests = {};
|
||||||
@@ -184,16 +139,6 @@ class AppDio with DioMixin {
|
|||||||
_requests[path] = true;
|
_requests[path] = true;
|
||||||
options!.headers!.remove('prevent-parallel');
|
options!.headers!.remove('prevent-parallel');
|
||||||
}
|
}
|
||||||
proxy = await getProxy();
|
|
||||||
if (_proxy != proxy) {
|
|
||||||
Log.info("Network", "Proxy changed to $proxy");
|
|
||||||
_proxy = proxy;
|
|
||||||
httpClientAdapter = RHttpAdapter(rhttp.ClientSettings(
|
|
||||||
proxySettings: proxy == null
|
|
||||||
? const rhttp.ProxySettings.noProxy()
|
|
||||||
: rhttp.ProxySettings.proxy(proxy!),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
return super.request<T>(
|
return super.request<T>(
|
||||||
path,
|
path,
|
||||||
@@ -213,7 +158,27 @@ class AppDio with DioMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class RHttpAdapter implements HttpClientAdapter {
|
class RHttpAdapter implements HttpClientAdapter {
|
||||||
rhttp.ClientSettings settings;
|
Future<rhttp.ClientSettings> get settings async {
|
||||||
|
var proxy = await getProxy();
|
||||||
|
|
||||||
|
return rhttp.ClientSettings(
|
||||||
|
proxySettings: proxy == null
|
||||||
|
? const rhttp.ProxySettings.noProxy()
|
||||||
|
: rhttp.ProxySettings.proxy(proxy),
|
||||||
|
redirectSettings: const rhttp.RedirectSettings.limited(5),
|
||||||
|
timeoutSettings: const rhttp.TimeoutSettings(
|
||||||
|
connectTimeout: Duration(seconds: 15),
|
||||||
|
keepAliveTimeout: Duration(seconds: 60),
|
||||||
|
keepAlivePing: Duration(seconds: 30),
|
||||||
|
),
|
||||||
|
throwOnStatusCode: false,
|
||||||
|
dnsSettings: rhttp.DnsSettings.static(overrides: _getOverrides()),
|
||||||
|
tlsSettings: rhttp.TlsSettings(
|
||||||
|
sni: appdata.settings['sni'] != false,
|
||||||
|
verifyCertificates: appdata.settings['ignoreBadCertificate'] != true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static Map<String, List<String>> _getOverrides() {
|
static Map<String, List<String>> _getOverrides() {
|
||||||
if (!appdata.settings['enableDnsOverrides'] == true) {
|
if (!appdata.settings['enableDnsOverrides'] == true) {
|
||||||
@@ -231,22 +196,6 @@ class RHttpAdapter implements HttpClientAdapter {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
RHttpAdapter([this.settings = const rhttp.ClientSettings()]) {
|
|
||||||
settings = settings.copyWith(
|
|
||||||
redirectSettings: const rhttp.RedirectSettings.limited(5),
|
|
||||||
timeoutSettings: const rhttp.TimeoutSettings(
|
|
||||||
connectTimeout: Duration(seconds: 15),
|
|
||||||
keepAliveTimeout: Duration(seconds: 60),
|
|
||||||
keepAlivePing: Duration(seconds: 30),
|
|
||||||
),
|
|
||||||
throwOnStatusCode: false,
|
|
||||||
dnsSettings: rhttp.DnsSettings.static(overrides: _getOverrides()),
|
|
||||||
tlsSettings: rhttp.TlsSettings(
|
|
||||||
sni: appdata.settings['sni'] != false,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void close({bool force = false}) {}
|
void close({bool force = false}) {}
|
||||||
|
|
||||||
@@ -256,10 +205,15 @@ class RHttpAdapter implements HttpClientAdapter {
|
|||||||
Stream<Uint8List>? requestStream,
|
Stream<Uint8List>? requestStream,
|
||||||
Future<void>? cancelFuture,
|
Future<void>? cancelFuture,
|
||||||
) async {
|
) async {
|
||||||
|
if (options.headers['User-Agent'] == null &&
|
||||||
|
options.headers['user-agent'] == null) {
|
||||||
|
options.headers['User-Agent'] = "venera/v${App.version}";
|
||||||
|
}
|
||||||
|
|
||||||
var res = await rhttp.Rhttp.request(
|
var res = await rhttp.Rhttp.request(
|
||||||
method: rhttp.HttpMethod(options.method),
|
method: rhttp.HttpMethod(options.method),
|
||||||
url: options.uri.toString(),
|
url: options.uri.toString(),
|
||||||
settings: settings,
|
settings: await settings,
|
||||||
expectBody: rhttp.HttpExpectBody.stream,
|
expectBody: rhttp.HttpExpectBody.stream,
|
||||||
body: requestStream == null ? null : rhttp.HttpBody.stream(requestStream),
|
body: requestStream == null ? null : rhttp.HttpBody.stream(requestStream),
|
||||||
headers: rhttp.HttpHeaders.rawMap(
|
headers: rhttp.HttpHeaders.rawMap(
|
||||||
@@ -289,7 +243,7 @@ class RHttpAdapter implements HttpClientAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static String _getStatusMessage(int statusCode) {
|
static String _getStatusMessage(int statusCode) {
|
||||||
return switch(statusCode) {
|
return switch (statusCode) {
|
||||||
200 => "OK",
|
200 => "OK",
|
||||||
201 => "Created",
|
201 => "Created",
|
||||||
202 => "Accepted",
|
202 => "Accepted",
|
||||||
@@ -299,9 +253,11 @@ class RHttpAdapter implements HttpClientAdapter {
|
|||||||
302 => "Found",
|
302 => "Found",
|
||||||
400 => "Invalid Status Code 400: The Request is invalid.",
|
400 => "Invalid Status Code 400: The Request is invalid.",
|
||||||
401 => "Invalid Status Code 401: The Request is unauthorized.",
|
401 => "Invalid Status Code 401: The Request is unauthorized.",
|
||||||
403 => "Invalid Status Code 403: No permission to access the resource. Check your account or network.",
|
403 =>
|
||||||
|
"Invalid Status Code 403: No permission to access the resource. Check your account or network.",
|
||||||
404 => "Invalid Status Code 404: Not found.",
|
404 => "Invalid Status Code 404: Not found.",
|
||||||
429 => "Invalid Status Code 429: Too many requests. Please try again later.",
|
429 =>
|
||||||
|
"Invalid Status Code 429: Too many requests. Please try again later.",
|
||||||
_ => "Invalid Status Code $statusCode",
|
_ => "Invalid Status Code $statusCode",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,9 +202,13 @@ class SingleInstanceCookieJar extends CookieJarSql {
|
|||||||
|
|
||||||
static SingleInstanceCookieJar? instance;
|
static SingleInstanceCookieJar? instance;
|
||||||
|
|
||||||
static Future<void> createInstance() async {
|
static Future<SingleInstanceCookieJar> createInstance() async {
|
||||||
|
if (instance != null) {
|
||||||
|
return instance!;
|
||||||
|
}
|
||||||
var dataPath = (await getApplicationSupportDirectory()).path;
|
var dataPath = (await getApplicationSupportDirectory()).path;
|
||||||
instance = SingleInstanceCookieJar("$dataPath/cookie.db");
|
instance = SingleInstanceCookieJar("$dataPath/cookie.db");
|
||||||
|
return instance!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,21 @@ class ImagesDownloadTask extends DownloadTask with _TransferSpeedMixin {
|
|||||||
var local = LocalManager().find(id, comicType);
|
var local = LocalManager().find(id, comicType);
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
if (local == null) {
|
if (local == null) {
|
||||||
Directory(path!).deleteIgnoreError(recursive: true);
|
Future.sync(() async {
|
||||||
|
var tasks = this.tasks.values.toList();
|
||||||
|
for (var i = 0; i < tasks.length; i++) {
|
||||||
|
if (!tasks[i].isComplete) {
|
||||||
|
tasks[i].cancel();
|
||||||
|
await tasks[i].wait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await Directory(path!).delete(recursive: true);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
Log.error("Download", "Failed to delete directory: $e");
|
||||||
|
}
|
||||||
|
});
|
||||||
} else if (chapters != null) {
|
} else if (chapters != null) {
|
||||||
for (var c in chapters!) {
|
for (var c in chapters!) {
|
||||||
var dir = Directory(FilePath.join(path!, c));
|
var dir = Directory(FilePath.join(path!, c));
|
||||||
@@ -197,7 +211,9 @@ class ImagesDownloadTask extends DownloadTask with _TransferSpeedMixin {
|
|||||||
if (comic!.chapters != null) {
|
if (comic!.chapters != null) {
|
||||||
saveTo = Directory(FilePath.join(
|
saveTo = Directory(FilePath.join(
|
||||||
path!,
|
path!,
|
||||||
_images!.keys.elementAt(_chapter),
|
LocalManager.getChapterDirectoryName(
|
||||||
|
_images!.keys.elementAt(_chapter),
|
||||||
|
),
|
||||||
));
|
));
|
||||||
if (!saveTo.existsSync()) {
|
if (!saveTo.existsSync()) {
|
||||||
saveTo.createSync(recursive: true);
|
saveTo.createSync(recursive: true);
|
||||||
@@ -482,7 +498,7 @@ class ImagesDownloadTask extends DownloadTask with _TransferSpeedMixin {
|
|||||||
chapters: comic!.chapters,
|
chapters: comic!.chapters,
|
||||||
cover: File(_cover!.split("file://").last).name,
|
cover: File(_cover!.split("file://").last).name,
|
||||||
comicType: ComicType(source.key.hashCode),
|
comicType: ComicType(source.key.hashCode),
|
||||||
downloadedChapters: chapters ?? [],
|
downloadedChapters: chapters ?? comic?.chapters?.ids.toList() ?? [],
|
||||||
createdAt: DateTime.now(),
|
createdAt: DateTime.now(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -552,7 +568,7 @@ class _ImageDownloadWrapper {
|
|||||||
void start() async {
|
void start() async {
|
||||||
int lastBytes = 0;
|
int lastBytes = 0;
|
||||||
try {
|
try {
|
||||||
await for (var p in ImageDownloader.loadComicImage(
|
await for (var p in ImageDownloader.loadComicImageUnwrapped(
|
||||||
image, task.source.key, task.comicId, chapter)) {
|
image, task.source.key, task.comicId, chapter)) {
|
||||||
if (isCancelled) {
|
if (isCancelled) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:dio/io.dart';
|
import 'package:dio/io.dart';
|
||||||
import 'package:venera/network/app_dio.dart';
|
import 'package:venera/network/app_dio.dart';
|
||||||
|
import 'package:venera/network/proxy.dart';
|
||||||
import 'package:venera/utils/ext.dart';
|
import 'package:venera/utils/ext.dart';
|
||||||
|
|
||||||
class FileDownloader {
|
class FileDownloader {
|
||||||
@@ -105,7 +106,7 @@ class FileDownloader {
|
|||||||
|
|
||||||
void _download(StreamController<DownloadingStatus> resultStream) async {
|
void _download(StreamController<DownloadingStatus> resultStream) async {
|
||||||
try {
|
try {
|
||||||
var proxy = await AppDio.getProxy();
|
var proxy = await getProxy();
|
||||||
_dio.httpClientAdapter = IOHttpClientAdapter(
|
_dio.httpClientAdapter = IOHttpClientAdapter(
|
||||||
createHttpClient: () {
|
createHttpClient: () {
|
||||||
return HttpClient()
|
return HttpClient()
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter_qjs/flutter_qjs.dart';
|
import 'package:flutter_qjs/flutter_qjs.dart';
|
||||||
@@ -8,7 +9,7 @@ import 'package:venera/utils/image.dart';
|
|||||||
|
|
||||||
import 'app_dio.dart';
|
import 'app_dio.dart';
|
||||||
|
|
||||||
class ImageDownloader {
|
abstract class ImageDownloader {
|
||||||
static Stream<ImageDownloadProgress> loadThumbnail(
|
static Stream<ImageDownloadProgress> loadThumbnail(
|
||||||
String url, String? sourceKey,
|
String url, String? sourceKey,
|
||||||
[String? cid]) async* {
|
[String? cid]) async* {
|
||||||
@@ -70,7 +71,8 @@ class ImageDownloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (configs['onResponse'] is JSInvokable) {
|
if (configs['onResponse'] is JSInvokable) {
|
||||||
buffer = (configs['onResponse'] as JSInvokable)([buffer]);
|
final uint8List = Uint8List.fromList(buffer);
|
||||||
|
buffer = (configs['onResponse'] as JSInvokable)([uint8List]);
|
||||||
(configs['onResponse'] as JSInvokable).free();
|
(configs['onResponse'] as JSInvokable).free();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +84,40 @@ class ImageDownloader {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static final _loadingImages = <String, _StreamWrapper<ImageDownloadProgress>>{};
|
||||||
|
|
||||||
|
/// Cancel all loading images.
|
||||||
|
static void cancelAllLoadingImages() {
|
||||||
|
for (var wrapper in _loadingImages.values) {
|
||||||
|
wrapper.cancel();
|
||||||
|
}
|
||||||
|
_loadingImages.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Load a comic image from the network or cache.
|
||||||
|
/// The function will prevent multiple requests for the same image.
|
||||||
static Stream<ImageDownloadProgress> loadComicImage(
|
static Stream<ImageDownloadProgress> loadComicImage(
|
||||||
|
String imageKey, String? sourceKey, String cid, String eid) {
|
||||||
|
final cacheKey = "$imageKey@$sourceKey@$cid@$eid";
|
||||||
|
if (_loadingImages.containsKey(cacheKey)) {
|
||||||
|
return _loadingImages[cacheKey]!.stream;
|
||||||
|
}
|
||||||
|
final stream = _StreamWrapper<ImageDownloadProgress>(
|
||||||
|
_loadComicImage(imageKey, sourceKey, cid, eid),
|
||||||
|
(wrapper) {
|
||||||
|
_loadingImages.remove(cacheKey);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
_loadingImages[cacheKey] = stream;
|
||||||
|
return stream.stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Stream<ImageDownloadProgress> loadComicImageUnwrapped(
|
||||||
|
String imageKey, String? sourceKey, String cid, String eid) {
|
||||||
|
return _loadComicImage(imageKey, sourceKey, cid, eid);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Stream<ImageDownloadProgress> _loadComicImage(
|
||||||
String imageKey, String? sourceKey, String cid, String eid) async* {
|
String imageKey, String? sourceKey, String cid, String eid) async* {
|
||||||
final cacheKey = "$imageKey@$sourceKey@$cid@$eid";
|
final cacheKey = "$imageKey@$sourceKey@$cid@$eid";
|
||||||
final cache = await CacheManager().findCache(cacheKey);
|
final cache = await CacheManager().findCache(cacheKey);
|
||||||
@@ -146,12 +181,25 @@ class ImageDownloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (configs['onResponse'] is JSInvokable) {
|
if (configs['onResponse'] is JSInvokable) {
|
||||||
buffer = (configs['onResponse'] as JSInvokable)([buffer]);
|
dynamic result = (configs['onResponse'] as JSInvokable)([Uint8List.fromList(buffer)]);
|
||||||
|
if (result is Future) {
|
||||||
|
result = await result;
|
||||||
|
}
|
||||||
|
if (result is List<int>) {
|
||||||
|
buffer = result;
|
||||||
|
} else {
|
||||||
|
throw "Error: Invalid onResponse result.";
|
||||||
|
}
|
||||||
(configs['onResponse'] as JSInvokable).free();
|
(configs['onResponse'] as JSInvokable).free();
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = Uint8List.fromList(buffer);
|
Uint8List data;
|
||||||
buffer.clear();
|
if (buffer is Uint8List) {
|
||||||
|
data = buffer;
|
||||||
|
} else {
|
||||||
|
data = Uint8List.fromList(buffer);
|
||||||
|
buffer.clear();
|
||||||
|
}
|
||||||
|
|
||||||
if (configs['modifyImage'] != null) {
|
if (configs['modifyImage'] != null) {
|
||||||
var newData = await modifyImageWithScript(
|
var newData = await modifyImageWithScript(
|
||||||
@@ -189,6 +237,74 @@ class ImageDownloader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A wrapper class for a stream that
|
||||||
|
/// allows multiple listeners to listen to the same stream.
|
||||||
|
class _StreamWrapper<T> {
|
||||||
|
final Stream<T> _stream;
|
||||||
|
|
||||||
|
final List<StreamController> controllers = [];
|
||||||
|
|
||||||
|
final void Function(_StreamWrapper<T> wrapper) onClosed;
|
||||||
|
|
||||||
|
bool isClosed = false;
|
||||||
|
|
||||||
|
_StreamWrapper(this._stream, this.onClosed) {
|
||||||
|
_listen();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _listen() async {
|
||||||
|
try {
|
||||||
|
await for (var data in _stream) {
|
||||||
|
if (isClosed) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (var controller in controllers) {
|
||||||
|
if (!controller.isClosed) {
|
||||||
|
controller.add(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
for (var controller in controllers) {
|
||||||
|
if (!controller.isClosed) {
|
||||||
|
controller.addError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
for (var controller in controllers) {
|
||||||
|
if (!controller.isClosed) {
|
||||||
|
controller.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
controllers.clear();
|
||||||
|
isClosed = true;
|
||||||
|
onClosed(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream<T> get stream {
|
||||||
|
if (isClosed) {
|
||||||
|
throw Exception('Stream is closed');
|
||||||
|
}
|
||||||
|
var controller = StreamController<T>();
|
||||||
|
controllers.add(controller);
|
||||||
|
controller.onCancel = () {
|
||||||
|
controllers.remove(controller);
|
||||||
|
};
|
||||||
|
return controller.stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cancel() {
|
||||||
|
for (var controller in controllers) {
|
||||||
|
controller.close();
|
||||||
|
}
|
||||||
|
controllers.clear();
|
||||||
|
isClosed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ImageDownloadProgress {
|
class ImageDownloadProgress {
|
||||||
final int currentBytes;
|
final int currentBytes;
|
||||||
|
|
||||||
|
|||||||
60
lib/network/proxy.dart
Normal file
60
lib/network/proxy.dart
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:venera/foundation/app.dart';
|
||||||
|
import 'package:venera/foundation/appdata.dart';
|
||||||
|
import 'package:venera/utils/ext.dart';
|
||||||
|
|
||||||
|
String? _cachedProxy;
|
||||||
|
|
||||||
|
DateTime? _cachedProxyTime;
|
||||||
|
|
||||||
|
Future<String?> getProxy() async {
|
||||||
|
if (_cachedProxyTime != null &&
|
||||||
|
DateTime.now().difference(_cachedProxyTime!).inSeconds < 1) {
|
||||||
|
return _cachedProxy;
|
||||||
|
}
|
||||||
|
String? proxy = await _getProxy();
|
||||||
|
_cachedProxy = proxy;
|
||||||
|
_cachedProxyTime = DateTime.now();
|
||||||
|
return proxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<String?> _getProxy() async {
|
||||||
|
if ((appdata.settings['proxy'] as String).removeAllBlank == "direct") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (appdata.settings['proxy'] != "system") return appdata.settings['proxy'];
|
||||||
|
|
||||||
|
String res;
|
||||||
|
if (!App.isLinux) {
|
||||||
|
const channel = MethodChannel("venera/method_channel");
|
||||||
|
try {
|
||||||
|
res = await channel.invokeMethod("getProxy");
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res = "No Proxy";
|
||||||
|
}
|
||||||
|
if (res == "No Proxy") return null;
|
||||||
|
|
||||||
|
if (res.contains(";")) {
|
||||||
|
var proxies = res.split(";");
|
||||||
|
for (String proxy in proxies) {
|
||||||
|
proxy = proxy.removeAllBlank;
|
||||||
|
if (proxy.startsWith('https=')) {
|
||||||
|
return proxy.substring(6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final RegExp regex = RegExp(
|
||||||
|
r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+$',
|
||||||
|
caseSensitive: false,
|
||||||
|
multiLine: false,
|
||||||
|
);
|
||||||
|
if (!regex.hasMatch(res)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
@@ -4,12 +4,10 @@ import 'package:venera/foundation/app.dart';
|
|||||||
import 'package:venera/foundation/appdata.dart';
|
import 'package:venera/foundation/appdata.dart';
|
||||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||||
import 'package:venera/pages/ranking_page.dart';
|
import 'package:venera/pages/ranking_page.dart';
|
||||||
import 'package:venera/pages/search_result_page.dart';
|
|
||||||
import 'package:venera/pages/settings/settings_page.dart';
|
import 'package:venera/pages/settings/settings_page.dart';
|
||||||
import 'package:venera/utils/ext.dart';
|
import 'package:venera/utils/ext.dart';
|
||||||
import 'package:venera/utils/translations.dart';
|
import 'package:venera/utils/translations.dart';
|
||||||
|
|
||||||
import 'category_comics_page.dart';
|
|
||||||
import 'comic_source_page.dart';
|
import 'comic_source_page.dart';
|
||||||
|
|
||||||
class CategoriesPage extends StatefulWidget {
|
class CategoriesPage extends StatefulWidget {
|
||||||
@@ -19,39 +17,50 @@ class CategoriesPage extends StatefulWidget {
|
|||||||
State<CategoriesPage> createState() => _CategoriesPageState();
|
State<CategoriesPage> createState() => _CategoriesPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CategoriesPageState extends State<CategoriesPage> {
|
class _CategoriesPageState extends State<CategoriesPage>
|
||||||
|
with
|
||||||
|
TickerProviderStateMixin,
|
||||||
|
AutomaticKeepAliveClientMixin<CategoriesPage> {
|
||||||
var categories = <String>[];
|
var categories = <String>[];
|
||||||
|
|
||||||
|
late TabController controller;
|
||||||
|
|
||||||
void onSettingsChanged() {
|
void onSettingsChanged() {
|
||||||
var categories =
|
var categories = List.from(
|
||||||
List.from(appdata.settings["categories"]).whereType<String>().toList();
|
appdata.settings["categories"],
|
||||||
|
).whereType<String>().toList();
|
||||||
var allCategories = ComicSource.all()
|
var allCategories = ComicSource.all()
|
||||||
.map((e) => e.categoryData?.key)
|
.map((e) => e.categoryData?.key)
|
||||||
.where((element) => element != null)
|
.where((element) => element != null)
|
||||||
.map((e) => e!)
|
.map((e) => e!)
|
||||||
.toList();
|
.toList();
|
||||||
categories =
|
categories = categories
|
||||||
categories.where((element) => allCategories.contains(element)).toList();
|
.where((element) => allCategories.contains(element))
|
||||||
|
.toList();
|
||||||
if (!categories.isEqualTo(this.categories)) {
|
if (!categories.isEqualTo(this.categories)) {
|
||||||
setState(() {
|
setState(() {
|
||||||
this.categories = categories;
|
this.categories = categories;
|
||||||
});
|
});
|
||||||
|
controller = TabController(length: categories.length, vsync: this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
var categories =
|
var categories = List.from(
|
||||||
List.from(appdata.settings["categories"]).whereType<String>().toList();
|
appdata.settings["categories"],
|
||||||
|
).whereType<String>().toList();
|
||||||
var allCategories = ComicSource.all()
|
var allCategories = ComicSource.all()
|
||||||
.map((e) => e.categoryData?.key)
|
.map((e) => e.categoryData?.key)
|
||||||
.where((element) => element != null)
|
.where((element) => element != null)
|
||||||
.map((e) => e!)
|
.map((e) => e!)
|
||||||
.toList();
|
.toList();
|
||||||
this.categories =
|
this.categories = categories
|
||||||
categories.where((element) => allCategories.contains(element)).toList();
|
.where((element) => allCategories.contains(element))
|
||||||
|
.toList();
|
||||||
appdata.settings.addListener(onSettingsChanged);
|
appdata.settings.addListener(onSettingsChanged);
|
||||||
|
controller = TabController(length: categories.length, vsync: this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addPage() {
|
void addPage() {
|
||||||
@@ -61,6 +70,7 @@ class _CategoriesPageState extends State<CategoriesPage> {
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
controller.dispose();
|
||||||
appdata.settings.removeListener(onSettingsChanged);
|
appdata.settings.removeListener(onSettingsChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,46 +97,45 @@ class _CategoriesPageState extends State<CategoriesPage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
super.build(context);
|
||||||
if (categories.isEmpty) {
|
if (categories.isEmpty) {
|
||||||
return buildEmpty();
|
return buildEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Material(
|
return Material(
|
||||||
child: DefaultTabController(
|
child: Column(
|
||||||
length: categories.length,
|
children: [
|
||||||
key: Key(categories.toString()),
|
AppTabBar(
|
||||||
child: Column(
|
controller: controller,
|
||||||
children: [
|
key: PageStorageKey(categories.toString()),
|
||||||
AppTabBar(
|
tabs: categories.map((e) {
|
||||||
key: PageStorageKey(categories.toString()),
|
String title = e;
|
||||||
tabs: categories.map((e) {
|
try {
|
||||||
String title = e;
|
title = getCategoryDataWithKey(e).title;
|
||||||
try {
|
} catch (e) {
|
||||||
title = getCategoryDataWithKey(e).title;
|
//
|
||||||
} catch (e) {
|
}
|
||||||
//
|
return Tab(text: title, key: Key(e));
|
||||||
}
|
}).toList(),
|
||||||
return Tab(
|
actionButton: TabActionButton(
|
||||||
text: title,
|
icon: const Icon(Icons.add),
|
||||||
key: Key(e),
|
text: "Add".tl,
|
||||||
);
|
onPressed: addPage,
|
||||||
}).toList(),
|
),
|
||||||
actionButton: TabActionButton(
|
).paddingTop(context.padding.top),
|
||||||
icon: const Icon(Icons.add),
|
Expanded(
|
||||||
text: "Add".tl,
|
child: TabBarView(
|
||||||
onPressed: addPage,
|
controller: controller,
|
||||||
),
|
children: categories.map((e) => _CategoryPage(e)).toList(),
|
||||||
).paddingTop(context.padding.top),
|
),
|
||||||
Expanded(
|
),
|
||||||
child: TabBarView(
|
],
|
||||||
children: categories.map((e) => _CategoryPage(e)).toList(),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool get wantKeepAlive => true;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef ClickTagCallback = void Function(String, String?);
|
typedef ClickTagCallback = void Function(String, String?);
|
||||||
@@ -147,102 +156,47 @@ class _CategoryPage extends StatelessWidget {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleClick(
|
|
||||||
String tag,
|
|
||||||
String? param,
|
|
||||||
String type,
|
|
||||||
String namespace,
|
|
||||||
String categoryKey,
|
|
||||||
) {
|
|
||||||
if (type == 'search') {
|
|
||||||
App.mainNavigatorKey?.currentContext?.to(
|
|
||||||
() => SearchResultPage(
|
|
||||||
text: tag,
|
|
||||||
options: const [],
|
|
||||||
sourceKey: findComicSourceKey(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else if (type == "search_with_namespace") {
|
|
||||||
if (tag.contains(" ")) {
|
|
||||||
tag = '"$tag"';
|
|
||||||
}
|
|
||||||
App.mainNavigatorKey?.currentContext?.to(
|
|
||||||
() => SearchResultPage(
|
|
||||||
text: "$namespace:$tag",
|
|
||||||
options: const [],
|
|
||||||
sourceKey: findComicSourceKey(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else if (type == "category") {
|
|
||||||
App.mainNavigatorKey!.currentContext!.to(
|
|
||||||
() => CategoryComicsPage(
|
|
||||||
category: tag,
|
|
||||||
categoryKey: categoryKey,
|
|
||||||
param: param,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var children = <Widget>[];
|
var children = <Widget>[];
|
||||||
if (data.enableRankingPage || data.buttons.isNotEmpty) {
|
if (data.enableRankingPage || data.buttons.isNotEmpty) {
|
||||||
children.add(buildTitle(data.title));
|
children.add(buildTitle(data.title));
|
||||||
children.add(Padding(
|
children.add(
|
||||||
padding: const EdgeInsets.fromLTRB(10, 0, 10, 16),
|
Padding(
|
||||||
child: Wrap(
|
padding: const EdgeInsets.fromLTRB(10, 0, 10, 16),
|
||||||
children: [
|
child: Wrap(
|
||||||
if (data.enableRankingPage)
|
children: [
|
||||||
buildTag("Ranking".tl, (p0, p1) {
|
if (data.enableRankingPage)
|
||||||
context.to(() => RankingPage(categoryKey: data.key));
|
buildTag("Ranking".tl, () {
|
||||||
}),
|
context.to(() => RankingPage(categoryKey: data.key));
|
||||||
for (var buttonData in data.buttons)
|
}),
|
||||||
buildTag(buttonData.label.tl, (p0, p1) => buttonData.onTap())
|
for (var buttonData in data.buttons)
|
||||||
],
|
buildTag(buttonData.label.tl, buttonData.onTap),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var part in data.categories) {
|
for (var part in data.categories) {
|
||||||
if (part.enableRandom) {
|
if (part.enableRandom) {
|
||||||
children.add(StatefulBuilder(builder: (context, updater) {
|
|
||||||
return Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
buildTitleWithRefresh(part.title, () => updater(() {})),
|
|
||||||
buildTagsWithParams(
|
|
||||||
part.categories,
|
|
||||||
part.categoryParams,
|
|
||||||
part.title,
|
|
||||||
(key, param) => handleClick(
|
|
||||||
key,
|
|
||||||
param,
|
|
||||||
part.categoryType,
|
|
||||||
part.title,
|
|
||||||
category,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
children.add(buildTitle(part.title));
|
|
||||||
children.add(
|
children.add(
|
||||||
buildTagsWithParams(
|
StatefulBuilder(
|
||||||
part.categories,
|
builder: (context, updater) {
|
||||||
part.categoryParams,
|
return Column(
|
||||||
part.title,
|
mainAxisSize: MainAxisSize.min,
|
||||||
(tag, param) => handleClick(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
tag,
|
children: [
|
||||||
param,
|
buildTitleWithRefresh(part.title, () => updater(() {})),
|
||||||
part.categoryType,
|
buildTags(part.categories),
|
||||||
part.title,
|
],
|
||||||
data.key,
|
);
|
||||||
),
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
children.add(buildTitle(part.title));
|
||||||
|
children.add(buildTags(part.categories));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
@@ -256,8 +210,10 @@ class _CategoryPage extends StatelessWidget {
|
|||||||
Widget buildTitle(String title) {
|
Widget buildTitle(String title) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(16, 10, 5, 10),
|
padding: const EdgeInsets.fromLTRB(16, 10, 5, 10),
|
||||||
child: Text(title.tl,
|
child: Text(
|
||||||
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w500)),
|
title.tl,
|
||||||
|
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,42 +224,35 @@ class _CategoryPage extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
title.tl,
|
title.tl,
|
||||||
style: const TextStyle(
|
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
|
||||||
fontSize: 20,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
IconButton(onPressed: onRefresh, icon: const Icon(Icons.refresh))
|
IconButton(onPressed: onRefresh, icon: const Icon(Icons.refresh)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildTagsWithParams(
|
Widget buildTags(List<CategoryItem> categories) {
|
||||||
List<String> tags,
|
|
||||||
List<String>? params,
|
|
||||||
String? namespace,
|
|
||||||
ClickTagCallback onClick,
|
|
||||||
) {
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(10, 0, 10, 16),
|
padding: const EdgeInsets.fromLTRB(10, 0, 10, 16),
|
||||||
child: Wrap(
|
child: Wrap(
|
||||||
children: List<Widget>.generate(
|
children: List<Widget>.generate(
|
||||||
tags.length,
|
categories.length,
|
||||||
(index) => buildTag(
|
(index) => buildCategory(categories[index]),
|
||||||
tags[index],
|
|
||||||
onClick,
|
|
||||||
namespace,
|
|
||||||
params?.elementAtOrNull(index),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildTag(String tag, ClickTagCallback onClick,
|
Widget buildCategory(CategoryItem c) {
|
||||||
[String? namespace, String? param]) {
|
return buildTag(c.label, () {
|
||||||
|
var context = App.mainNavigatorKey!.currentContext!;
|
||||||
|
c.target.jump(context);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget buildTag(String label, VoidCallback onClick) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(8, 6, 8, 6),
|
padding: const EdgeInsets.fromLTRB(8, 6, 8, 6),
|
||||||
child: Builder(
|
child: Builder(
|
||||||
@@ -313,10 +262,10 @@ class _CategoryPage extends StatelessWidget {
|
|||||||
color: context.colorScheme.primaryContainer.toOpacity(0.72),
|
color: context.colorScheme.primaryContainer.toOpacity(0.72),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||||
onTap: () => onClick(tag, param),
|
onTap: onClick,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
|
||||||
child: Text(tag),
|
child: Text(label),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ class CategoryComicsPage extends StatefulWidget {
|
|||||||
required this.category,
|
required this.category,
|
||||||
this.param,
|
this.param,
|
||||||
required this.categoryKey,
|
required this.categoryKey,
|
||||||
|
this.options,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -18,29 +19,44 @@ class CategoryComicsPage extends StatefulWidget {
|
|||||||
|
|
||||||
final String categoryKey;
|
final String categoryKey;
|
||||||
|
|
||||||
|
final List<String>? options;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<CategoryComicsPage> createState() => _CategoryComicsPageState();
|
State<CategoryComicsPage> createState() => _CategoryComicsPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CategoryComicsPageState extends State<CategoryComicsPage> {
|
class _CategoryComicsPageState extends State<CategoryComicsPage> {
|
||||||
late final CategoryComicsData data;
|
late final CategoryComicsData data;
|
||||||
late final List<CategoryComicsOptions> options;
|
late List<CategoryComicsOptions>? options;
|
||||||
|
late final CategoryOptionsLoader? optionsLoader;
|
||||||
late List<String> optionsValue;
|
late List<String> optionsValue;
|
||||||
late String sourceKey;
|
late String sourceKey;
|
||||||
|
String? error;
|
||||||
|
|
||||||
void findData() {
|
void findData() {
|
||||||
for (final source in ComicSource.all()) {
|
for (final source in ComicSource.all()) {
|
||||||
if (source.categoryData?.key == widget.categoryKey) {
|
if (source.categoryData?.key == widget.categoryKey) {
|
||||||
|
if (source.categoryComicsData == null) {
|
||||||
|
throw "The comic source ${source.name} does not support category comics";
|
||||||
|
}
|
||||||
data = source.categoryComicsData!;
|
data = source.categoryComicsData!;
|
||||||
options = data.options.where((element) {
|
if (data.options != null) {
|
||||||
if (element.notShowWhen.contains(widget.category)) {
|
options = data.options!.where((element) {
|
||||||
return false;
|
if (element.notShowWhen.contains(widget.category)) {
|
||||||
} else if (element.showWhen != null) {
|
return false;
|
||||||
return element.showWhen!.contains(widget.category);
|
} else if (element.showWhen != null) {
|
||||||
}
|
return element.showWhen!.contains(widget.category);
|
||||||
return true;
|
}
|
||||||
}).toList();
|
return true;
|
||||||
optionsValue = options.map((e) => e.options.keys.first).toList();
|
}).toList();
|
||||||
|
} else {
|
||||||
|
options = null;
|
||||||
|
}
|
||||||
|
if (data.optionsLoader != null) {
|
||||||
|
optionsLoader = data.optionsLoader;
|
||||||
|
loadOptions();
|
||||||
|
}
|
||||||
|
resetOptionsValue();
|
||||||
sourceKey = source.key;
|
sourceKey = source.key;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -48,8 +64,43 @@ class _CategoryComicsPageState extends State<CategoryComicsPage> {
|
|||||||
throw "${widget.categoryKey} Not found";
|
throw "${widget.categoryKey} Not found";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void resetOptionsValue() {
|
||||||
|
if (options == null) return;
|
||||||
|
var defaultOptionsValue = options!
|
||||||
|
.map((e) => e.options.keys.first)
|
||||||
|
.toList();
|
||||||
|
if (optionsValue.length != options!.length) {
|
||||||
|
var newOptionsValue = List<String>.filled(options!.length, "");
|
||||||
|
for (var i = 0; i < options!.length; i++) {
|
||||||
|
newOptionsValue[i] =
|
||||||
|
optionsValue.elementAtOrNull(i) ?? defaultOptionsValue[i];
|
||||||
|
}
|
||||||
|
optionsValue = newOptionsValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loadOptions() async {
|
||||||
|
final res = await optionsLoader!(widget.category, widget.param);
|
||||||
|
if (res.error) {
|
||||||
|
setState(() {
|
||||||
|
error = res.errorMessage;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
options = res.data;
|
||||||
|
resetOptionsValue();
|
||||||
|
error = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
if (widget.options != null) {
|
||||||
|
optionsValue = widget.options!;
|
||||||
|
} else {
|
||||||
|
optionsValue = [];
|
||||||
|
}
|
||||||
findData();
|
findData();
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
@@ -57,27 +108,44 @@ class _CategoryComicsPageState extends State<CategoryComicsPage> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var topPadding = context.padding.top + 56.0;
|
var topPadding = context.padding.top + 56.0;
|
||||||
|
|
||||||
|
Widget body;
|
||||||
|
|
||||||
|
if (options == null) {
|
||||||
|
body = Center(child: CircularProgressIndicator());
|
||||||
|
} else if (error != null) {
|
||||||
|
body = NetworkError(
|
||||||
|
message: error!,
|
||||||
|
retry: () {
|
||||||
|
setState(() {
|
||||||
|
error = null;
|
||||||
|
});
|
||||||
|
loadOptions();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
body = ComicList(
|
||||||
|
key: Key(widget.category + optionsValue.toString()),
|
||||||
|
errorLeading: buildOptions().paddingTop(topPadding),
|
||||||
|
leadingSliver: buildOptions().paddingTop(topPadding).toSliver(),
|
||||||
|
loadPage: (i) =>
|
||||||
|
data.load(widget.category, widget.param, optionsValue, i),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
extendBodyBehindAppBar: true,
|
extendBodyBehindAppBar: true,
|
||||||
appBar: Appbar(
|
appBar: Appbar(title: Text(widget.category)),
|
||||||
title: Text(widget.category),
|
body: body,
|
||||||
),
|
|
||||||
body: ComicList(
|
|
||||||
key: Key(widget.category + optionsValue.toString()),
|
|
||||||
errorLeading: SizedBox(height: topPadding),
|
|
||||||
leadingSliver: buildOptions().paddingTop(topPadding).toSliver(),
|
|
||||||
loadPage: (i) => data.load(
|
|
||||||
widget.category,
|
|
||||||
widget.param,
|
|
||||||
optionsValue,
|
|
||||||
i,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildOptionItem(
|
Widget buildOptionItem(
|
||||||
String text, String value, int group, BuildContext context) {
|
String text,
|
||||||
|
String value,
|
||||||
|
int group,
|
||||||
|
BuildContext context,
|
||||||
|
) {
|
||||||
return OptionChip(
|
return OptionChip(
|
||||||
text: text.ts(sourceKey),
|
text: text.ts(sourceKey),
|
||||||
isSelected: value == optionsValue[group],
|
isSelected: value == optionsValue[group],
|
||||||
@@ -92,23 +160,57 @@ class _CategoryComicsPageState extends State<CategoryComicsPage> {
|
|||||||
|
|
||||||
Widget buildOptions() {
|
Widget buildOptions() {
|
||||||
List<Widget> children = [];
|
List<Widget> children = [];
|
||||||
for (var optionList in options) {
|
var group = 0;
|
||||||
children.add(Wrap(
|
for (var optionList in options!) {
|
||||||
spacing: 8,
|
if (optionList.label.isNotEmpty) {
|
||||||
runSpacing: 8,
|
children.add(Padding(
|
||||||
children: [
|
padding: const EdgeInsets.only(
|
||||||
for (var option in optionList.options.entries)
|
bottom: 8.0,
|
||||||
buildOptionItem(
|
left: 4.0,
|
||||||
option.value.tl,
|
),
|
||||||
option.key,
|
child: Text(
|
||||||
options.indexOf(optionList),
|
optionList.label.ts(sourceKey),
|
||||||
context,
|
style: TextStyle(
|
||||||
)
|
fontSize: 14,
|
||||||
],
|
fontWeight: FontWeight.bold,
|
||||||
));
|
),
|
||||||
if (options.last != optionList) {
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if (optionList.options.length <= 8) {
|
||||||
|
children.add(
|
||||||
|
Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
runSpacing: 8,
|
||||||
|
children: [
|
||||||
|
for (var option in optionList.options.entries)
|
||||||
|
buildOptionItem(
|
||||||
|
option.value.tl,
|
||||||
|
option.key,
|
||||||
|
group,
|
||||||
|
context,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
var g = group;
|
||||||
|
children.add(Select(
|
||||||
|
current: optionList.options[optionsValue[g]],
|
||||||
|
values: optionList.options.values.toList(),
|
||||||
|
onTap: (i) {
|
||||||
|
var key = optionList.options.keys.elementAt(i);
|
||||||
|
if (key == optionsValue[g]) return;
|
||||||
|
setState(() {
|
||||||
|
optionsValue[g] = key;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if (options!.last != optionList) {
|
||||||
children.add(const SizedBox(height: 8));
|
children.add(const SizedBox(height: 8));
|
||||||
}
|
}
|
||||||
|
group++;
|
||||||
}
|
}
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
|||||||
@@ -56,8 +56,12 @@ abstract mixin class _ComicPageActions {
|
|||||||
type: comic.comicType,
|
type: comic.comicType,
|
||||||
isFavorite: isFavorite,
|
isFavorite: isFavorite,
|
||||||
onFavorite: (local, network) {
|
onFavorite: (local, network) {
|
||||||
isFavorite = network ?? isFavorite;
|
if (network != null) {
|
||||||
isAddToLocalFav = local ?? isAddToLocalFav;
|
isFavorite = network;
|
||||||
|
}
|
||||||
|
if (local != null) {
|
||||||
|
isAddToLocalFav = local;
|
||||||
|
}
|
||||||
update();
|
update();
|
||||||
},
|
},
|
||||||
favoriteItem: _toFavoriteItem(),
|
favoriteItem: _toFavoriteItem(),
|
||||||
@@ -151,64 +155,60 @@ abstract mixin class _ComicPageActions {
|
|||||||
builder: (context, setState) {
|
builder: (context, setState) {
|
||||||
return ContentDialog(
|
return ContentDialog(
|
||||||
title: "Download".tl,
|
title: "Download".tl,
|
||||||
content: Column(
|
content: RadioGroup<int>(
|
||||||
mainAxisSize: MainAxisSize.min,
|
groupValue: selected,
|
||||||
children: [
|
onChanged: (v) {
|
||||||
RadioListTile<int>(
|
setState(() {
|
||||||
value: -1,
|
selected = v ?? selected;
|
||||||
groupValue: selected,
|
});
|
||||||
title: Text("Normal".tl),
|
},
|
||||||
onChanged: (v) {
|
child: Column(
|
||||||
setState(() {
|
mainAxisSize: MainAxisSize.min,
|
||||||
selected = v!;
|
children: [
|
||||||
});
|
RadioListTile<int>(
|
||||||
},
|
value: -1,
|
||||||
),
|
title: Text("Normal".tl),
|
||||||
ExpansionTile(
|
|
||||||
title: Text("Archive".tl),
|
|
||||||
shape: const RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.zero,
|
|
||||||
),
|
),
|
||||||
collapsedShape: const RoundedRectangleBorder(
|
ExpansionTile(
|
||||||
borderRadius: BorderRadius.zero,
|
title: Text("Archive".tl),
|
||||||
),
|
shape: const RoundedRectangleBorder(
|
||||||
onExpansionChanged: (b) {
|
borderRadius: BorderRadius.zero,
|
||||||
if (!isLoading && b && archives == null) {
|
),
|
||||||
isLoading = true;
|
collapsedShape: const RoundedRectangleBorder(
|
||||||
comicSource.archiveDownloader!
|
borderRadius: BorderRadius.zero,
|
||||||
.getArchives(comic.id)
|
),
|
||||||
.then((value) {
|
onExpansionChanged: (b) {
|
||||||
if (value.success) {
|
if (!isLoading && b && archives == null) {
|
||||||
archives = value.data;
|
isLoading = true;
|
||||||
} else {
|
comicSource.archiveDownloader!
|
||||||
App.rootContext
|
.getArchives(comic.id)
|
||||||
.showMessage(message: value.errorMessage!);
|
.then((value) {
|
||||||
}
|
if (value.success) {
|
||||||
setState(() {
|
archives = value.data;
|
||||||
isLoading = false;
|
} else {
|
||||||
|
App.rootContext
|
||||||
|
.showMessage(message: value.errorMessage!);
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
},
|
||||||
},
|
children: [
|
||||||
children: [
|
if (archives == null)
|
||||||
if (archives == null)
|
const ListLoadingIndicator().toCenter()
|
||||||
const ListLoadingIndicator().toCenter()
|
else
|
||||||
else
|
for (int i = 0; i < archives!.length; i++)
|
||||||
for (int i = 0; i < archives!.length; i++)
|
RadioListTile<int>(
|
||||||
RadioListTile<int>(
|
value: i,
|
||||||
value: i,
|
title: Text(archives![i].title),
|
||||||
groupValue: selected,
|
subtitle: Text(archives![i].description),
|
||||||
onChanged: (v) {
|
)
|
||||||
setState(() {
|
],
|
||||||
selected = v!;
|
)
|
||||||
});
|
],
|
||||||
},
|
),
|
||||||
title: Text(archives![i].title),
|
|
||||||
subtitle: Text(archives![i].description),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
Button.filled(
|
Button.filled(
|
||||||
@@ -233,10 +233,12 @@ abstract mixin class _ComicPageActions {
|
|||||||
isGettingLink = false;
|
isGettingLink = false;
|
||||||
});
|
});
|
||||||
} else if (context.mounted) {
|
} else if (context.mounted) {
|
||||||
LocalManager()
|
if (res.data.isNotEmpty) {
|
||||||
|
LocalManager()
|
||||||
.addTask(ArchiveDownloadTask(res.data, comic));
|
.addTask(ArchiveDownloadTask(res.data, comic));
|
||||||
App.rootContext
|
App.rootContext
|
||||||
.showMessage(message: "Download started".tl);
|
.showMessage(message: "Download started".tl);
|
||||||
|
}
|
||||||
context.pop();
|
context.pop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -294,27 +296,9 @@ abstract mixin class _ComicPageActions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onTapTag(String tag, String namespace) {
|
void onTapTag(String tag, String namespace) {
|
||||||
var config = comicSource.handleClickTagEvent?.call(namespace, tag) ??
|
var target = comicSource.handleClickTagEvent?.call(namespace, tag);
|
||||||
{
|
|
||||||
'action': 'search',
|
|
||||||
'keyword': tag,
|
|
||||||
};
|
|
||||||
var context = App.mainNavigatorKey!.currentContext!;
|
var context = App.mainNavigatorKey!.currentContext!;
|
||||||
if (config['action'] == 'search') {
|
target?.jump(context);
|
||||||
context.to(() => SearchResultPage(
|
|
||||||
text: config['keyword'] ?? '',
|
|
||||||
sourceKey: comicSource.key,
|
|
||||||
options: const [],
|
|
||||||
));
|
|
||||||
} else if (config['action'] == 'category') {
|
|
||||||
context.to(
|
|
||||||
() => CategoryComicsPage(
|
|
||||||
category: config['keyword'] ?? '',
|
|
||||||
categoryKey: comicSource.categoryData!.key,
|
|
||||||
param: config['param'],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void showMoreActions() {
|
void showMoreActions() {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class _NormalComicChapters extends StatefulWidget {
|
|||||||
class _NormalComicChaptersState extends State<_NormalComicChapters> {
|
class _NormalComicChaptersState extends State<_NormalComicChapters> {
|
||||||
late _ComicPageState state;
|
late _ComicPageState state;
|
||||||
|
|
||||||
bool reverse = false;
|
late bool reverse;
|
||||||
|
|
||||||
bool showAll = false;
|
bool showAll = false;
|
||||||
|
|
||||||
@@ -38,6 +38,7 @@ class _NormalComicChaptersState extends State<_NormalComicChapters> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
reverse = appdata.settings["reverseChapterOrder"] ?? false;
|
||||||
history = widget.history;
|
history = widget.history;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +106,7 @@ class _NormalComicChaptersState extends State<_NormalComicChapters> {
|
|||||||
var value = chapters[key]!;
|
var value = chapters[key]!;
|
||||||
bool visited = (history?.readEpisode ?? {}).contains(i + 1);
|
bool visited = (history?.readEpisode ?? {}).contains(i + 1);
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(6, 4, 6, 4),
|
padding: const EdgeInsets.fromLTRB(4, 4, 4, 4),
|
||||||
child: Material(
|
child: Material(
|
||||||
color: context.colorScheme.surfaceContainer,
|
color: context.colorScheme.surfaceContainer,
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
@@ -113,7 +114,7 @@ class _NormalComicChaptersState extends State<_NormalComicChapters> {
|
|||||||
onTap: () => state.read(i + 1),
|
onTap: () => state.read(i + 1),
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
value,
|
value,
|
||||||
@@ -134,7 +135,7 @@ class _NormalComicChaptersState extends State<_NormalComicChapters> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
gridDelegate: const SliverGridDelegateWithFixedHeight(
|
gridDelegate: const SliverGridDelegateWithFixedHeight(
|
||||||
maxCrossAxisExtent: 200,
|
maxCrossAxisExtent: 250,
|
||||||
itemHeight: 48,
|
itemHeight: 48,
|
||||||
),
|
),
|
||||||
).sliverPadding(const EdgeInsets.symmetric(horizontal: 8)),
|
).sliverPadding(const EdgeInsets.symmetric(horizontal: 8)),
|
||||||
@@ -176,7 +177,7 @@ class _GroupedComicChaptersState extends State<_GroupedComicChapters>
|
|||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
late _ComicPageState state;
|
late _ComicPageState state;
|
||||||
|
|
||||||
bool reverse = false;
|
late bool reverse;
|
||||||
|
|
||||||
bool showAll = false;
|
bool showAll = false;
|
||||||
|
|
||||||
@@ -191,6 +192,7 @@ class _GroupedComicChaptersState extends State<_GroupedComicChapters>
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
reverse = appdata.settings["reverseChapterOrder"] ?? false;
|
||||||
history = widget.history;
|
history = widget.history;
|
||||||
if (history?.group != null) {
|
if (history?.group != null) {
|
||||||
index = history!.group! - 1;
|
index = history!.group! - 1;
|
||||||
@@ -300,15 +302,15 @@ class _GroupedComicChaptersState extends State<_GroupedComicChapters>
|
|||||||
history!.readEpisode.contains(rawIndex);
|
history!.readEpisode.contains(rawIndex);
|
||||||
}
|
}
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(6, 4, 6, 4),
|
padding: const EdgeInsets.fromLTRB(4, 4, 4, 4),
|
||||||
child: Material(
|
child: Material(
|
||||||
color: context.colorScheme.surfaceContainer,
|
color: context.colorScheme.surfaceContainerLow,
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(12),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () => state.read(chapterIndex + 1),
|
onTap: () => state.read(chapterIndex + 1),
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(12),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
value,
|
value,
|
||||||
@@ -329,7 +331,7 @@ class _GroupedComicChaptersState extends State<_GroupedComicChapters>
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
gridDelegate: const SliverGridDelegateWithFixedHeight(
|
gridDelegate: const SliverGridDelegateWithFixedHeight(
|
||||||
maxCrossAxisExtent: 200,
|
maxCrossAxisExtent: 250,
|
||||||
itemHeight: 48,
|
itemHeight: 48,
|
||||||
),
|
),
|
||||||
).sliverPadding(const EdgeInsets.symmetric(horizontal: 8)),
|
).sliverPadding(const EdgeInsets.symmetric(horizontal: 8)),
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
|
import 'dart:ui';
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:photo_view/photo_view.dart';
|
||||||
import 'package:shimmer_animation/shimmer_animation.dart';
|
import 'package:shimmer_animation/shimmer_animation.dart';
|
||||||
import 'package:sliver_tools/sliver_tools.dart';
|
import 'package:sliver_tools/sliver_tools.dart';
|
||||||
import 'package:url_launcher/url_launcher_string.dart';
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
@@ -17,12 +20,12 @@ import 'package:venera/foundation/image_provider/cached_image.dart';
|
|||||||
import 'package:venera/foundation/local.dart';
|
import 'package:venera/foundation/local.dart';
|
||||||
import 'package:venera/foundation/res.dart';
|
import 'package:venera/foundation/res.dart';
|
||||||
import 'package:venera/network/download.dart';
|
import 'package:venera/network/download.dart';
|
||||||
import 'package:venera/pages/category_comics_page.dart';
|
import 'package:venera/network/cache.dart';
|
||||||
import 'package:venera/pages/favorites/favorites_page.dart';
|
import 'package:venera/pages/favorites/favorites_page.dart';
|
||||||
import 'package:venera/pages/reader/reader.dart';
|
import 'package:venera/pages/reader/reader.dart';
|
||||||
import 'package:venera/pages/search_result_page.dart';
|
|
||||||
import 'package:venera/utils/app_links.dart';
|
import 'package:venera/utils/app_links.dart';
|
||||||
import 'package:venera/utils/ext.dart';
|
import 'package:venera/utils/ext.dart';
|
||||||
|
import 'package:venera/utils/file_type.dart';
|
||||||
import 'package:venera/utils/io.dart';
|
import 'package:venera/utils/io.dart';
|
||||||
import 'package:venera/utils/tags_translation.dart';
|
import 'package:venera/utils/tags_translation.dart';
|
||||||
import 'package:venera/utils/translations.dart';
|
import 'package:venera/utils/translations.dart';
|
||||||
@@ -40,6 +43,8 @@ part 'comments_preview.dart';
|
|||||||
|
|
||||||
part 'actions.dart';
|
part 'actions.dart';
|
||||||
|
|
||||||
|
part 'cover_viewer.dart';
|
||||||
|
|
||||||
class ComicPage extends StatefulWidget {
|
class ComicPage extends StatefulWidget {
|
||||||
const ComicPage({
|
const ComicPage({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -75,10 +80,14 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
|
|
||||||
bool isDownloaded = false;
|
bool isDownloaded = false;
|
||||||
|
|
||||||
|
bool showFAB = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onReadEnd() {
|
void onReadEnd() {
|
||||||
history ??=
|
history ??= HistoryManager().find(
|
||||||
HistoryManager().find(widget.id, ComicType(widget.sourceKey.hashCode));
|
widget.id,
|
||||||
|
ComicType(widget.sourceKey.hashCode),
|
||||||
|
);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,6 +102,32 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget buildError() {
|
||||||
|
final isDownloaded = LocalManager().isDownloaded(
|
||||||
|
widget.id,
|
||||||
|
ComicType.fromKey(widget.sourceKey),
|
||||||
|
);
|
||||||
|
Widget? action;
|
||||||
|
if (isDownloaded) {
|
||||||
|
action = FilledButton.tonal(
|
||||||
|
child: Text("Read".tl),
|
||||||
|
onPressed: () {
|
||||||
|
final localComic = LocalManager().find(
|
||||||
|
widget.id,
|
||||||
|
ComicType.fromKey(widget.sourceKey),
|
||||||
|
);
|
||||||
|
if (localComic == null) {
|
||||||
|
context.showMessage(message: "Local comic not found".tl);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
localComic.read();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return NetworkError(message: error!, retry: retry, action: action);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
scrollController.addListener(onScroll);
|
scrollController.addListener(onScroll);
|
||||||
@@ -114,7 +149,16 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
ComicDetails get comic => data!;
|
ComicDetails get comic => data!;
|
||||||
|
|
||||||
void onScroll() {
|
void onScroll() {
|
||||||
if (scrollController.offset > 100) {
|
var offset =
|
||||||
|
scrollController.position.pixels -
|
||||||
|
scrollController.position.minScrollExtent;
|
||||||
|
var showFAB = offset > 0;
|
||||||
|
if (showFAB != this.showFAB) {
|
||||||
|
setState(() {
|
||||||
|
this.showFAB = showFAB;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (offset > 100) {
|
||||||
if (!showAppbarTitle) {
|
if (!showAppbarTitle) {
|
||||||
setState(() {
|
setState(() {
|
||||||
showAppbarTitle = true;
|
showAppbarTitle = true;
|
||||||
@@ -133,19 +177,37 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildContent(BuildContext context, ComicDetails data) {
|
Widget buildContent(BuildContext context, ComicDetails data) {
|
||||||
return SmoothCustomScrollView(
|
return Scaffold(
|
||||||
controller: scrollController,
|
floatingActionButton: showFAB
|
||||||
slivers: [
|
? FloatingActionButton(
|
||||||
...buildTitle(),
|
onPressed: () {
|
||||||
buildActions(),
|
scrollController.animateTo(
|
||||||
buildDescription(),
|
0,
|
||||||
buildInfo(),
|
duration: const Duration(milliseconds: 200),
|
||||||
buildChapters(),
|
curve: Curves.ease,
|
||||||
buildComments(),
|
);
|
||||||
buildThumbnails(),
|
},
|
||||||
buildRecommend(),
|
child: const Icon(Icons.arrow_upward),
|
||||||
SliverPadding(padding: EdgeInsets.only(bottom: context.padding.bottom)),
|
)
|
||||||
],
|
: null,
|
||||||
|
body: SmoothCustomScrollView(
|
||||||
|
controller: scrollController,
|
||||||
|
slivers: [
|
||||||
|
...buildTitle(),
|
||||||
|
buildActions(),
|
||||||
|
buildDescription(),
|
||||||
|
buildInfo(),
|
||||||
|
buildChapters(),
|
||||||
|
buildComments(),
|
||||||
|
buildThumbnails(),
|
||||||
|
buildRecommend(),
|
||||||
|
SliverPadding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
bottom: context.padding.bottom + 80,
|
||||||
|
), // Add additional padding for FAB
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,12 +230,9 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
initialPage: history?.page,
|
initialPage: history?.page,
|
||||||
initialChapter: history?.ep,
|
initialChapter: history?.ep,
|
||||||
initialChapterGroup: history?.group,
|
initialChapterGroup: history?.group,
|
||||||
history: history ??
|
history:
|
||||||
History.fromModel(
|
history ??
|
||||||
model: localComic,
|
History.fromModel(model: localComic, ep: 0, page: 0),
|
||||||
ep: 0,
|
|
||||||
page: 0,
|
|
||||||
),
|
|
||||||
author: localComic.subTitle ?? '',
|
author: localComic.subTitle ?? '',
|
||||||
tags: localComic.tags,
|
tags: localComic.tags,
|
||||||
);
|
);
|
||||||
@@ -193,8 +252,10 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
widget.id,
|
widget.id,
|
||||||
ComicType(widget.sourceKey.hashCode),
|
ComicType(widget.sourceKey.hashCode),
|
||||||
);
|
);
|
||||||
history =
|
history = HistoryManager().find(
|
||||||
HistoryManager().find(widget.id, ComicType(widget.sourceKey.hashCode));
|
widget.id,
|
||||||
|
ComicType(widget.sourceKey.hashCode),
|
||||||
|
);
|
||||||
return comicSource.loadComicInfo!(widget.id);
|
return comicSource.loadComicInfo!(widget.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,12 +263,20 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
Future<void> onDataLoaded() async {
|
Future<void> onDataLoaded() async {
|
||||||
isLiked = comic.isLiked ?? false;
|
isLiked = comic.isLiked ?? false;
|
||||||
isFavorite = comic.isFavorite ?? false;
|
isFavorite = comic.isFavorite ?? false;
|
||||||
|
// For sources with multi-folder favorites, prefer querying folders to get accurate favorite status
|
||||||
|
// Some sources may not set isFavorite reliably when multi-folder is enabled
|
||||||
|
if (comicSource.favoriteData?.loadFolders != null && comicSource.isLogged) {
|
||||||
|
var res = await comicSource.favoriteData!.loadFolders!(comic.id);
|
||||||
|
if (!res.error) {
|
||||||
|
if (res.subData is List) {
|
||||||
|
var list = List<String>.from(res.subData);
|
||||||
|
isFavorite = list.isNotEmpty;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (comic.chapters == null) {
|
if (comic.chapters == null) {
|
||||||
isDownloaded = LocalManager().isDownloaded(
|
isDownloaded = LocalManager().isDownloaded(comic.id, comic.comicType, 0);
|
||||||
comic.id,
|
|
||||||
comic.comicType,
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +289,9 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: showMoreActions, icon: const Icon(Icons.more_horiz))
|
onPressed: showMoreActions,
|
||||||
|
icon: const Icon(Icons.more_horiz),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -231,31 +302,35 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(width: 16),
|
const SizedBox(width: 16),
|
||||||
Hero(
|
GestureDetector(
|
||||||
tag: "cover${widget.heroID}",
|
onTap: () => _viewCover(context),
|
||||||
child: Container(
|
onLongPress: () => _saveCover(context),
|
||||||
decoration: BoxDecoration(
|
child: Hero(
|
||||||
color: context.colorScheme.primaryContainer,
|
tag: "cover${widget.heroID}",
|
||||||
borderRadius: BorderRadius.circular(8),
|
child: Container(
|
||||||
boxShadow: [
|
decoration: BoxDecoration(
|
||||||
BoxShadow(
|
color: context.colorScheme.primaryContainer,
|
||||||
color: context.colorScheme.outlineVariant,
|
borderRadius: BorderRadius.circular(8),
|
||||||
blurRadius: 1,
|
boxShadow: [
|
||||||
offset: const Offset(0, 1),
|
BoxShadow(
|
||||||
),
|
color: context.colorScheme.outlineVariant,
|
||||||
],
|
blurRadius: 1,
|
||||||
),
|
offset: const Offset(0, 1),
|
||||||
height: 144,
|
),
|
||||||
width: 144 * 0.72,
|
],
|
||||||
clipBehavior: Clip.antiAlias,
|
),
|
||||||
child: AnimatedImage(
|
height: 144,
|
||||||
image: CachedImageProvider(
|
width: 144 * 0.72,
|
||||||
widget.cover ?? comic.cover,
|
clipBehavior: Clip.antiAlias,
|
||||||
sourceKey: comic.sourceKey,
|
child: AnimatedImage(
|
||||||
cid: comic.id,
|
image: CachedImageProvider(
|
||||||
|
widget.cover ?? comic.cover,
|
||||||
|
sourceKey: comic.sourceKey,
|
||||||
|
cid: comic.id,
|
||||||
|
),
|
||||||
|
width: double.infinity,
|
||||||
|
height: double.infinity,
|
||||||
),
|
),
|
||||||
width: double.infinity,
|
|
||||||
height: double.infinity,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -266,8 +341,10 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
children: [
|
children: [
|
||||||
SelectableText(comic.title, style: ts.s18),
|
SelectableText(comic.title, style: ts.s18),
|
||||||
if (comic.subTitle != null)
|
if (comic.subTitle != null)
|
||||||
SelectableText(comic.subTitle!, style: ts.s14)
|
SelectableText(
|
||||||
.paddingVertical(4),
|
comic.subTitle!,
|
||||||
|
style: ts.s14,
|
||||||
|
).paddingVertical(4),
|
||||||
Text(
|
Text(
|
||||||
(ComicSource.find(comic.sourceKey)?.name) ?? '',
|
(ComicSource.find(comic.sourceKey)?.name) ?? '',
|
||||||
style: ts.s12,
|
style: ts.s12,
|
||||||
@@ -316,10 +393,11 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
icon: const Icon(Icons.favorite_border),
|
icon: const Icon(Icons.favorite_border),
|
||||||
activeIcon: const Icon(Icons.favorite),
|
activeIcon: const Icon(Icons.favorite),
|
||||||
isActive: isLiked,
|
isActive: isLiked,
|
||||||
text: ((data!.likesCount != null)
|
text:
|
||||||
? (data!.likesCount! + (isLiked ? 1 : 0))
|
((data!.likesCount != null)
|
||||||
: (isLiked ? 'Liked'.tl : 'Like'.tl))
|
? (data!.likesCount! + (isLiked ? 1 : 0))
|
||||||
.toString(),
|
: (isLiked ? 'Liked'.tl : 'Like'.tl))
|
||||||
|
.toString(),
|
||||||
isLoading: isLiking,
|
isLoading: isLiking,
|
||||||
onPressed: likeOrUnlike,
|
onPressed: likeOrUnlike,
|
||||||
iconColor: context.useTextColor(Colors.red),
|
iconColor: context.useTextColor(Colors.red),
|
||||||
@@ -361,9 +439,11 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: hasHistory
|
child: hasHistory
|
||||||
? FilledButton(
|
? FilledButton(
|
||||||
onPressed: continueRead, child: Text("Continue".tl))
|
onPressed: continueRead,
|
||||||
|
child: Text("Continue".tl),
|
||||||
|
)
|
||||||
: FilledButton(onPressed: read, child: Text("Read".tl)),
|
: FilledButton(onPressed: read, child: Text("Read".tl)),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
).paddingHorizontal(16).paddingVertical(8),
|
).paddingHorizontal(16).paddingVertical(8),
|
||||||
if (history != null)
|
if (history != null)
|
||||||
@@ -387,15 +467,28 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
var group = history!.group;
|
var group = history!.group;
|
||||||
String text;
|
String text;
|
||||||
if (haveChapter) {
|
if (haveChapter) {
|
||||||
var epName = group == null
|
var epName = "E$ep";
|
||||||
? comic.chapters!.titles.elementAt(
|
String? groupName;
|
||||||
math.min(ep - 1, comic.chapters!.length - 1),
|
try {
|
||||||
)
|
if (group == null) {
|
||||||
: comic.chapters!
|
epName = comic.chapters!.titles.elementAt(
|
||||||
|
math.min(ep - 1, comic.chapters!.length - 1),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
groupName = comic.chapters!.groups.elementAt(
|
||||||
|
group - 1,
|
||||||
|
);
|
||||||
|
epName = comic.chapters!
|
||||||
.getGroupByIndex(group - 1)
|
.getGroupByIndex(group - 1)
|
||||||
.values
|
.values
|
||||||
.elementAt(ep - 1);
|
.elementAt(ep - 1);
|
||||||
text = "${"Last Reading".tl}: $epName P$page";
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
text = groupName == null
|
||||||
|
? "${"Last Reading".tl}: $epName P$page"
|
||||||
|
: "${"Last Reading".tl}: $groupName $epName P$page";
|
||||||
} else {
|
} else {
|
||||||
text = "${"Last Reading".tl}: P$page";
|
text = "${"Last Reading".tl}: P$page";
|
||||||
}
|
}
|
||||||
@@ -419,9 +512,7 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
return SliverLazyToBoxAdapter(
|
return SliverLazyToBoxAdapter(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
ListTile(
|
ListTile(title: Text("Description".tl)),
|
||||||
title: Text("Description".tl),
|
|
||||||
),
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||||
child: SelectableText(comic.description!).fixWidth(double.infinity),
|
child: SelectableText(comic.description!).fixWidth(double.infinity),
|
||||||
@@ -437,7 +528,8 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
if (comic.tags.isEmpty &&
|
if (comic.tags.isEmpty &&
|
||||||
comic.uploader == null &&
|
comic.uploader == null &&
|
||||||
comic.uploadTime == null &&
|
comic.uploadTime == null &&
|
||||||
comic.uploadTime == null) {
|
comic.uploadTime == null &&
|
||||||
|
comic.maxPage == null) {
|
||||||
return const SliverPadding(padding: EdgeInsets.zero);
|
return const SliverPadding(padding: EdgeInsets.zero);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -504,10 +596,7 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Container(
|
return Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(color: color, borderRadius: borderRadius),
|
||||||
color: color,
|
|
||||||
borderRadius: borderRadius,
|
|
||||||
),
|
|
||||||
child: Text(text).padding(padding),
|
child: Text(text).padding(padding),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -517,13 +606,13 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
if (int.tryParse(time) != null) {
|
if (int.tryParse(time) != null) {
|
||||||
var t = int.tryParse(time);
|
var t = int.tryParse(time);
|
||||||
if (t! > 1000000000000) {
|
if (t! > 1000000000000) {
|
||||||
return DateTime.fromMillisecondsSinceEpoch(t)
|
return DateTime.fromMillisecondsSinceEpoch(
|
||||||
.toString()
|
t,
|
||||||
.substring(0, 19);
|
).toString().substring(0, 19);
|
||||||
} else {
|
} else {
|
||||||
return DateTime.fromMillisecondsSinceEpoch(t * 1000)
|
return DateTime.fromMillisecondsSinceEpoch(
|
||||||
.toString()
|
t * 1000,
|
||||||
.substring(0, 19);
|
).toString().substring(0, 19);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (time.contains('T') || time.contains('Z')) {
|
if (time.contains('T') || time.contains('Z')) {
|
||||||
@@ -548,17 +637,11 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
ListTile(
|
ListTile(title: Text("Information".tl)),
|
||||||
title: Text("Information".tl),
|
|
||||||
),
|
|
||||||
if (comic.stars != null)
|
if (comic.stars != null)
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
StarRating(
|
StarRating(value: comic.stars!, size: 24, onTap: starRating),
|
||||||
value: comic.stars!,
|
|
||||||
size: 24,
|
|
||||||
onTap: starRating,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Text(comic.stars!.toStringAsFixed(2)),
|
Text(comic.stars!.toStringAsFixed(2)),
|
||||||
],
|
],
|
||||||
@@ -601,6 +684,13 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
buildTag(text: formatTime(comic.updateTime!)),
|
buildTag(text: formatTime(comic.updateTime!)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
if (comic.maxPage != null)
|
||||||
|
buildWrap(
|
||||||
|
children: [
|
||||||
|
buildTag(text: 'Pages'.tl, isTitle: true),
|
||||||
|
buildTag(text: comic.maxPage.toString()),
|
||||||
|
],
|
||||||
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
],
|
],
|
||||||
@@ -629,24 +719,67 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
|||||||
if (comic.recommend == null || comic.recommend!.isEmpty) {
|
if (comic.recommend == null || comic.recommend!.isEmpty) {
|
||||||
return const SliverPadding(padding: EdgeInsets.zero);
|
return const SliverPadding(padding: EdgeInsets.zero);
|
||||||
}
|
}
|
||||||
return SliverMainAxisGroup(slivers: [
|
return SliverMainAxisGroup(
|
||||||
SliverToBoxAdapter(
|
slivers: [
|
||||||
child: ListTile(
|
SliverToBoxAdapter(child: ListTile(title: Text("Related".tl))),
|
||||||
title: Text("Related".tl),
|
SliverGridComics(comics: comic.recommend!),
|
||||||
),
|
],
|
||||||
),
|
);
|
||||||
SliverGridComics(comics: comic.recommend!),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildComments() {
|
Widget buildComments() {
|
||||||
if (comic.comments == null || comic.comments!.isEmpty) {
|
if (comic.comments == null || comic.comments!.isEmpty) {
|
||||||
return const SliverPadding(padding: EdgeInsets.zero);
|
return const SliverPadding(padding: EdgeInsets.zero);
|
||||||
}
|
}
|
||||||
return _CommentsPart(
|
return _CommentsPart(comments: comic.comments!, showMore: showComments);
|
||||||
comments: comic.comments!,
|
}
|
||||||
showMore: showComments,
|
|
||||||
|
void _viewCover(BuildContext context) {
|
||||||
|
final imageProvider = CachedImageProvider(
|
||||||
|
widget.cover ?? comic.cover,
|
||||||
|
sourceKey: comic.sourceKey,
|
||||||
|
cid: comic.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
context.to(
|
||||||
|
() => _CoverViewer(
|
||||||
|
imageProvider: imageProvider,
|
||||||
|
title: comic.title,
|
||||||
|
heroTag: "cover${widget.heroID}",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _saveCover(BuildContext context) async {
|
||||||
|
try {
|
||||||
|
final imageProvider = CachedImageProvider(
|
||||||
|
widget.cover ?? comic.cover,
|
||||||
|
sourceKey: comic.sourceKey,
|
||||||
|
cid: comic.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
final imageStream = imageProvider.resolve(const ImageConfiguration());
|
||||||
|
final completer = Completer<Uint8List>();
|
||||||
|
|
||||||
|
imageStream.addListener(
|
||||||
|
ImageStreamListener((ImageInfo info, bool _) async {
|
||||||
|
final byteData = await info.image.toByteData(
|
||||||
|
format: ImageByteFormat.png,
|
||||||
|
);
|
||||||
|
if (byteData != null) {
|
||||||
|
completer.complete(byteData.buffer.asUint8List());
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
final data = await completer.future;
|
||||||
|
final fileType = detectFileType(data);
|
||||||
|
await saveFile(filename: "cover${fileType.ext}", data: data);
|
||||||
|
} catch (e) {
|
||||||
|
if (context.mounted) {
|
||||||
|
context.showMessage(message: "Error".tl);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -750,20 +883,21 @@ class _SelectDownloadChapterState extends State<_SelectDownloadChapter> {
|
|||||||
itemCount: widget.eps.length,
|
itemCount: widget.eps.length,
|
||||||
itemBuilder: (context, i) {
|
itemBuilder: (context, i) {
|
||||||
return CheckboxListTile(
|
return CheckboxListTile(
|
||||||
title: Text(widget.eps[i]),
|
title: Text(widget.eps[i]),
|
||||||
value: selected.contains(i) ||
|
value:
|
||||||
widget.downloadedEps.contains(i),
|
selected.contains(i) || widget.downloadedEps.contains(i),
|
||||||
onChanged: widget.downloadedEps.contains(i)
|
onChanged: widget.downloadedEps.contains(i)
|
||||||
? null
|
? null
|
||||||
: (v) {
|
: (v) {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (selected.contains(i)) {
|
if (selected.contains(i)) {
|
||||||
selected.remove(i);
|
selected.remove(i);
|
||||||
} else {
|
} else {
|
||||||
selected.add(i);
|
selected.add(i);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -771,9 +905,7 @@ class _SelectDownloadChapterState extends State<_SelectDownloadChapter> {
|
|||||||
height: 50,
|
height: 50,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: Border(
|
border: Border(
|
||||||
top: BorderSide(
|
top: BorderSide(color: context.colorScheme.outlineVariant),
|
||||||
color: context.colorScheme.outlineVariant,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
@@ -838,8 +970,12 @@ class _ComicPageLoadingPlaceHolder extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Widget buildContainer(double? width, double? height,
|
Widget buildContainer(
|
||||||
{Color? color, double? radius}) {
|
double? width,
|
||||||
|
double? height, {
|
||||||
|
Color? color,
|
||||||
|
double? radius,
|
||||||
|
}) {
|
||||||
return Container(
|
return Container(
|
||||||
height: height,
|
height: height,
|
||||||
width: width,
|
width: width,
|
||||||
@@ -881,13 +1017,9 @@ class _ComicPageLoadingPlaceHolder extends StatelessWidget {
|
|||||||
if (context.width < changePoint)
|
if (context.width < changePoint)
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(child: buildContainer(null, 36, radius: 18)),
|
||||||
child: buildContainer(null, 36, radius: 18),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 16),
|
const SizedBox(width: 16),
|
||||||
Expanded(
|
Expanded(child: buildContainer(null, 36, radius: 18)),
|
||||||
child: buildContainer(null, 36, radius: 18),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
).paddingHorizontal(16),
|
).paddingHorizontal(16),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
@@ -896,7 +1028,7 @@ class _ComicPageLoadingPlaceHolder extends StatelessWidget {
|
|||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(
|
||||||
strokeWidth: 2.4,
|
strokeWidth: 2.4,
|
||||||
).fixHeight(24).fixWidth(24),
|
).fixHeight(24).fixWidth(24),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -906,11 +1038,7 @@ class _ComicPageLoadingPlaceHolder extends StatelessWidget {
|
|||||||
Widget child;
|
Widget child;
|
||||||
if (cover != null) {
|
if (cover != null) {
|
||||||
child = AnimatedImage(
|
child = AnimatedImage(
|
||||||
image: CachedImageProvider(
|
image: CachedImageProvider(cover!, sourceKey: sourceKey, cid: cid),
|
||||||
cover!,
|
|
||||||
sourceKey: sourceKey,
|
|
||||||
cid: cid,
|
|
||||||
),
|
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
height: double.infinity,
|
height: double.infinity,
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
|
|||||||
@@ -99,61 +99,67 @@ class _CommentsPageState extends State<CommentsPage> {
|
|||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView.builder(
|
child: SmoothScrollProvider(
|
||||||
primary: false,
|
builder: (context, controller, physics) {
|
||||||
padding: EdgeInsets.zero,
|
return ListView.builder(
|
||||||
itemCount: _comments!.length + 2,
|
controller: controller,
|
||||||
itemBuilder: (context, index) {
|
physics: physics,
|
||||||
if (index == 0) {
|
primary: false,
|
||||||
if (widget.replyComment != null) {
|
padding: EdgeInsets.zero,
|
||||||
return Column(
|
itemCount: _comments!.length + 2,
|
||||||
children: [
|
itemBuilder: (context, index) {
|
||||||
_CommentTile(
|
if (index == 0) {
|
||||||
comment: widget.replyComment!,
|
if (widget.replyComment != null) {
|
||||||
source: widget.source,
|
return Column(
|
||||||
comic: widget.data,
|
children: [
|
||||||
showAvatar: showAvatar,
|
_CommentTile(
|
||||||
showActions: false,
|
comment: widget.replyComment!,
|
||||||
),
|
source: widget.source,
|
||||||
const SizedBox(height: 8),
|
comic: widget.data,
|
||||||
Container(
|
showAvatar: showAvatar,
|
||||||
alignment: Alignment.centerLeft,
|
showActions: false,
|
||||||
padding: const EdgeInsets.all(16),
|
),
|
||||||
decoration: BoxDecoration(
|
const SizedBox(height: 8),
|
||||||
border: Border(
|
Container(
|
||||||
top: BorderSide(
|
alignment: Alignment.centerLeft,
|
||||||
color: context.colorScheme.outlineVariant,
|
padding: const EdgeInsets.all(16),
|
||||||
width: 0.6,
|
decoration: BoxDecoration(
|
||||||
|
border: Border(
|
||||||
|
top: BorderSide(
|
||||||
|
color: context.colorScheme.outlineVariant,
|
||||||
|
width: 0.6,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
"Replies".tl,
|
||||||
|
style: ts.s18,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
child: Text(
|
);
|
||||||
"Replies".tl,
|
} else {
|
||||||
style: ts.s18,
|
return const SizedBox();
|
||||||
),
|
}
|
||||||
),
|
}
|
||||||
],
|
index--;
|
||||||
|
|
||||||
|
if (index == _comments!.length) {
|
||||||
|
if (_page < (maxPage ?? _page + 1)) {
|
||||||
|
loadMore();
|
||||||
|
return const ListLoadingIndicator();
|
||||||
|
} else {
|
||||||
|
return const SizedBox();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return _CommentTile(
|
||||||
|
comment: _comments![index],
|
||||||
|
source: widget.source,
|
||||||
|
comic: widget.data,
|
||||||
|
showAvatar: showAvatar,
|
||||||
);
|
);
|
||||||
} else {
|
},
|
||||||
return const SizedBox();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
index--;
|
|
||||||
|
|
||||||
if (index == _comments!.length) {
|
|
||||||
if (_page < (maxPage ?? _page + 1)) {
|
|
||||||
loadMore();
|
|
||||||
return const ListLoadingIndicator();
|
|
||||||
} else {
|
|
||||||
return const SizedBox();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return _CommentTile(
|
|
||||||
comment: _comments![index],
|
|
||||||
source: widget.source,
|
|
||||||
comic: widget.data,
|
|
||||||
showAvatar: showAvatar,
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
140
lib/pages/comic_details_page/cover_viewer.dart
Normal file
140
lib/pages/comic_details_page/cover_viewer.dart
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
part of 'comic_page.dart';
|
||||||
|
|
||||||
|
class _CoverViewer extends StatefulWidget {
|
||||||
|
const _CoverViewer({
|
||||||
|
required this.imageProvider,
|
||||||
|
required this.title,
|
||||||
|
required this.heroTag,
|
||||||
|
});
|
||||||
|
|
||||||
|
final ImageProvider imageProvider;
|
||||||
|
final String title;
|
||||||
|
final String heroTag;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_CoverViewer> createState() => _CoverViewerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CoverViewerState extends State<_CoverViewer> {
|
||||||
|
bool isAppBarShow = true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return PopScope(
|
||||||
|
canPop: true,
|
||||||
|
child: Scaffold(
|
||||||
|
backgroundColor: context.colorScheme.surface,
|
||||||
|
body: Stack(
|
||||||
|
children: [
|
||||||
|
Positioned.fill(
|
||||||
|
child: PhotoView(
|
||||||
|
imageProvider: widget.imageProvider,
|
||||||
|
minScale: PhotoViewComputedScale.contained * 1.0,
|
||||||
|
maxScale: PhotoViewComputedScale.covered * 3.0,
|
||||||
|
backgroundDecoration: BoxDecoration(
|
||||||
|
color: context.colorScheme.surface,
|
||||||
|
),
|
||||||
|
loadingBuilder: (context, event) => Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: 24.0,
|
||||||
|
height: 24.0,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
value: event == null || event.expectedTotalBytes == null
|
||||||
|
? null
|
||||||
|
: event.cumulativeBytesLoaded /
|
||||||
|
event.expectedTotalBytes!,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onTapUp: (context, details, controllerValue) {
|
||||||
|
setState(() {
|
||||||
|
isAppBarShow = !isAppBarShow;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
heroAttributes: PhotoViewHeroAttributes(tag: widget.heroTag),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
AnimatedPositioned(
|
||||||
|
top: isAppBarShow ? 0 : -(context.padding.top + 52),
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
duration: const Duration(milliseconds: 180),
|
||||||
|
child: _buildAppBar(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildAppBar() {
|
||||||
|
return Material(
|
||||||
|
color: context.colorScheme.surface.toOpacity(0.72),
|
||||||
|
child: BlurEffect(
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border(
|
||||||
|
bottom: BorderSide(
|
||||||
|
color: context.colorScheme.outlineVariant,
|
||||||
|
width: 0.5,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
height: 52,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.close),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
widget.title,
|
||||||
|
style: const TextStyle(fontSize: 18),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.save_alt),
|
||||||
|
onPressed: _saveCover,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
).paddingTop(context.padding.top),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _saveCover() async {
|
||||||
|
try {
|
||||||
|
final imageStream = widget.imageProvider.resolve(
|
||||||
|
const ImageConfiguration(),
|
||||||
|
);
|
||||||
|
final completer = Completer<Uint8List>();
|
||||||
|
|
||||||
|
imageStream.addListener(
|
||||||
|
ImageStreamListener((ImageInfo info, bool _) async {
|
||||||
|
final byteData = await info.image.toByteData(
|
||||||
|
format: ImageByteFormat.png,
|
||||||
|
);
|
||||||
|
if (byteData != null) {
|
||||||
|
completer.complete(byteData.buffer.asUint8List());
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
final data = await completer.future;
|
||||||
|
final fileType = detectFileType(data);
|
||||||
|
await saveFile(filename: "cover_${widget.title}${fileType.ext}", data: data);
|
||||||
|
} catch (e) {
|
||||||
|
if (mounted) {
|
||||||
|
context.showMessage(message: "Error".tl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,198 +33,122 @@ class _FavoritePanelState extends State<_FavoritePanel>
|
|||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
late ComicSource comicSource;
|
late ComicSource comicSource;
|
||||||
|
|
||||||
late TabController tabController;
|
|
||||||
|
|
||||||
late bool hasNetwork;
|
late bool hasNetwork;
|
||||||
|
|
||||||
|
late List<String> localFolders;
|
||||||
|
|
||||||
|
late List<String> added;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
comicSource = widget.type.comicSource!;
|
comicSource = widget.type.comicSource!;
|
||||||
localFolders = LocalFavoritesManager().folderNames;
|
localFolders = LocalFavoritesManager().folderNames;
|
||||||
added = LocalFavoritesManager().find(widget.cid, widget.type);
|
added = LocalFavoritesManager().find(widget.cid, widget.type);
|
||||||
hasNetwork = comicSource.favoriteData != null && comicSource.isLogged;
|
hasNetwork = comicSource.favoriteData != null && comicSource.isLogged;
|
||||||
var initIndex = 0;
|
|
||||||
if (appdata.implicitData['favoritePanelIndex'] is int) {
|
|
||||||
initIndex = appdata.implicitData['favoritePanelIndex'];
|
|
||||||
}
|
|
||||||
initIndex = initIndex.clamp(0, hasNetwork ? 1 : 0);
|
|
||||||
tabController = TabController(
|
|
||||||
initialIndex: initIndex,
|
|
||||||
length: hasNetwork ? 2 : 1,
|
|
||||||
vsync: this,
|
|
||||||
);
|
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
var currentIndex = tabController.index;
|
|
||||||
appdata.implicitData['favoritePanelIndex'] = currentIndex;
|
|
||||||
appdata.writeImplicitData();
|
|
||||||
tabController.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: Appbar(
|
appBar: Appbar(title: Text("Favorite".tl)),
|
||||||
title: Text("Favorite".tl),
|
body: _FavoriteList(
|
||||||
|
cid: widget.cid,
|
||||||
|
type: widget.type,
|
||||||
|
isFavorite: widget.isFavorite,
|
||||||
|
onFavorite: widget.onFavorite,
|
||||||
|
favoriteItem: widget.favoriteItem,
|
||||||
|
updateTime: widget.updateTime,
|
||||||
|
comicSource: comicSource,
|
||||||
|
hasNetwork: hasNetwork,
|
||||||
|
localFolders: localFolders,
|
||||||
|
added: added,
|
||||||
),
|
),
|
||||||
body: Column(
|
|
||||||
children: [
|
|
||||||
TabBar(
|
|
||||||
controller: tabController,
|
|
||||||
tabs: [
|
|
||||||
Tab(text: "Local".tl),
|
|
||||||
if (hasNetwork) Tab(text: "Network".tl),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: TabBarView(
|
|
||||||
controller: tabController,
|
|
||||||
children: [
|
|
||||||
buildLocal(),
|
|
||||||
if (hasNetwork) buildNetwork(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
late List<String> localFolders;
|
|
||||||
|
|
||||||
late List<String> added;
|
|
||||||
|
|
||||||
var selectedLocalFolders = <String>{};
|
|
||||||
|
|
||||||
Widget buildLocal() {
|
|
||||||
var isRemove = selectedLocalFolders.isNotEmpty &&
|
|
||||||
added.contains(selectedLocalFolders.first);
|
|
||||||
return Column(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: ListView.builder(
|
|
||||||
itemCount: localFolders.length + 1,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
if (index == localFolders.length) {
|
|
||||||
return SizedBox(
|
|
||||||
height: 36,
|
|
||||||
child: Center(
|
|
||||||
child: TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
newFolder().then((v) {
|
|
||||||
setState(() {
|
|
||||||
localFolders = LocalFavoritesManager().folderNames;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.add, size: 20),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Text("New Folder".tl)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
var folder = localFolders[index];
|
|
||||||
var disabled = false;
|
|
||||||
if (selectedLocalFolders.isNotEmpty) {
|
|
||||||
if (added.contains(folder) &&
|
|
||||||
!added.contains(selectedLocalFolders.first)) {
|
|
||||||
disabled = true;
|
|
||||||
} else if (!added.contains(folder) &&
|
|
||||||
added.contains(selectedLocalFolders.first)) {
|
|
||||||
disabled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return CheckboxListTile(
|
|
||||||
title: Row(
|
|
||||||
children: [
|
|
||||||
Text(folder),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
if (added.contains(folder))
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 8,
|
|
||||||
vertical: 4,
|
|
||||||
),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: context.colorScheme.primaryContainer,
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
child: Text("Added".tl, style: ts.s12),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
value: selectedLocalFolders.contains(folder),
|
|
||||||
onChanged: disabled
|
|
||||||
? null
|
|
||||||
: (v) {
|
|
||||||
setState(() {
|
|
||||||
if (v!) {
|
|
||||||
selectedLocalFolders.add(folder);
|
|
||||||
} else {
|
|
||||||
selectedLocalFolders.remove(folder);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Center(
|
|
||||||
child: FilledButton(
|
|
||||||
onPressed: () {
|
|
||||||
if (selectedLocalFolders.isEmpty) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (isRemove) {
|
|
||||||
for (var folder in selectedLocalFolders) {
|
|
||||||
LocalFavoritesManager()
|
|
||||||
.deleteComicWithId(folder, widget.cid, widget.type);
|
|
||||||
}
|
|
||||||
widget.onFavorite(false, null);
|
|
||||||
} else {
|
|
||||||
for (var folder in selectedLocalFolders) {
|
|
||||||
LocalFavoritesManager().addComic(
|
|
||||||
folder,
|
|
||||||
widget.favoriteItem,
|
|
||||||
null,
|
|
||||||
widget.updateTime,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
widget.onFavorite(true, null);
|
|
||||||
}
|
|
||||||
context.pop();
|
|
||||||
},
|
|
||||||
child: isRemove ? Text("Remove".tl) : Text("Add".tl),
|
|
||||||
).paddingVertical(8),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget buildNetwork() {
|
|
||||||
return _NetworkFavorites(
|
|
||||||
cid: widget.cid,
|
|
||||||
comicSource: comicSource,
|
|
||||||
isFavorite: widget.isFavorite,
|
|
||||||
onFavorite: (network) {
|
|
||||||
widget.onFavorite(null, network);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _NetworkFavorites extends StatefulWidget {
|
class _FavoriteList extends StatefulWidget {
|
||||||
const _NetworkFavorites({
|
const _FavoriteList({
|
||||||
|
required this.cid,
|
||||||
|
required this.type,
|
||||||
|
required this.isFavorite,
|
||||||
|
required this.onFavorite,
|
||||||
|
required this.favoriteItem,
|
||||||
|
this.updateTime,
|
||||||
|
required this.comicSource,
|
||||||
|
required this.hasNetwork,
|
||||||
|
required this.localFolders,
|
||||||
|
required this.added,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String cid;
|
||||||
|
final ComicType type;
|
||||||
|
final bool? isFavorite;
|
||||||
|
final void Function(bool?, bool?) onFavorite;
|
||||||
|
final FavoriteItem favoriteItem;
|
||||||
|
final String? updateTime;
|
||||||
|
final ComicSource comicSource;
|
||||||
|
final bool hasNetwork;
|
||||||
|
final List<String> localFolders;
|
||||||
|
final List<String> added;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_FavoriteList> createState() => _FavoriteListState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FavoriteListState extends State<_FavoriteList> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final localFavoritesFirst = appdata.settings['localFavoritesFirst'] ?? true;
|
||||||
|
|
||||||
|
final localSection = _LocalSection(
|
||||||
|
cid: widget.cid,
|
||||||
|
type: widget.type,
|
||||||
|
favoriteItem: widget.favoriteItem,
|
||||||
|
updateTime: widget.updateTime,
|
||||||
|
localFolders: widget.localFolders,
|
||||||
|
added: widget.added,
|
||||||
|
onFavorite: (local) {
|
||||||
|
widget.onFavorite(local, null);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
final networkSection = widget.hasNetwork
|
||||||
|
? _NetworkSection(
|
||||||
|
cid: widget.cid,
|
||||||
|
comicSource: widget.comicSource,
|
||||||
|
isFavorite: widget.isFavorite,
|
||||||
|
onFavorite: (network) {
|
||||||
|
widget.onFavorite(null, network);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
final divider = widget.hasNetwork
|
||||||
|
? Container(
|
||||||
|
height: 1,
|
||||||
|
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
|
color: context.colorScheme.outlineVariant.withValues(alpha: 0.3),
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return ListView(
|
||||||
|
children: [
|
||||||
|
if (localFavoritesFirst) ...[
|
||||||
|
localSection,
|
||||||
|
if (widget.hasNetwork) ...[divider!, networkSection!],
|
||||||
|
] else ...[
|
||||||
|
if (widget.hasNetwork) ...[networkSection!, divider!],
|
||||||
|
localSection,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _NetworkSection extends StatefulWidget {
|
||||||
|
const _NetworkSection({
|
||||||
required this.cid,
|
required this.cid,
|
||||||
required this.comicSource,
|
required this.comicSource,
|
||||||
required this.isFavorite,
|
required this.isFavorite,
|
||||||
@@ -232,82 +156,56 @@ class _NetworkFavorites extends StatefulWidget {
|
|||||||
});
|
});
|
||||||
|
|
||||||
final String cid;
|
final String cid;
|
||||||
|
|
||||||
final ComicSource comicSource;
|
final ComicSource comicSource;
|
||||||
|
|
||||||
final bool? isFavorite;
|
final bool? isFavorite;
|
||||||
|
|
||||||
final void Function(bool) onFavorite;
|
final void Function(bool) onFavorite;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_NetworkFavorites> createState() => _NetworkFavoritesState();
|
State<_NetworkSection> createState() => _NetworkSectionState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _NetworkFavoritesState extends State<_NetworkFavorites> {
|
class _NetworkSectionState extends State<_NetworkSection> {
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
bool isMultiFolder = widget.comicSource.favoriteData!.loadFolders != null;
|
|
||||||
|
|
||||||
return isMultiFolder ? buildMultiFolder() : buildSingleFolder();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isLoading = false;
|
bool isLoading = false;
|
||||||
|
|
||||||
Widget buildSingleFolder() {
|
|
||||||
var isFavorite = widget.isFavorite ?? false;
|
|
||||||
return Column(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Center(
|
|
||||||
child: Text(isFavorite ? "Added to favorites".tl : "Not added".tl),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Center(
|
|
||||||
child: Button.filled(
|
|
||||||
isLoading: isLoading,
|
|
||||||
onPressed: () async {
|
|
||||||
setState(() {
|
|
||||||
isLoading = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
var res = await widget.comicSource.favoriteData!
|
|
||||||
.addOrDelFavorite!(widget.cid, '', !isFavorite, null);
|
|
||||||
if (res.success) {
|
|
||||||
widget.onFavorite(!isFavorite);
|
|
||||||
context.pop();
|
|
||||||
App.rootContext.showMessage(
|
|
||||||
message: isFavorite ? "Removed".tl : "Added".tl);
|
|
||||||
} else {
|
|
||||||
setState(() {
|
|
||||||
isLoading = false;
|
|
||||||
});
|
|
||||||
context.showMessage(message: res.errorMessage!);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: isFavorite ? Text("Remove".tl) : Text("Add".tl),
|
|
||||||
).paddingVertical(8),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, String>? folders;
|
Map<String, String>? folders;
|
||||||
|
|
||||||
var addedFolders = <String>{};
|
var addedFolders = <String>{};
|
||||||
|
|
||||||
var isLoadingFolders = true;
|
var isLoadingFolders = true;
|
||||||
|
bool? localIsFavorite;
|
||||||
|
final Map<String, bool> _itemLoading = {};
|
||||||
|
late List<double> _skeletonWidths;
|
||||||
|
|
||||||
// for network favorites, only one selection is allowed
|
@override
|
||||||
String? selected;
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
localIsFavorite = widget.isFavorite;
|
||||||
|
_skeletonWidths = List.generate(3, (_) => 0.3 + math.Random().nextDouble() * 0.5);
|
||||||
|
if (widget.comicSource.favoriteData!.loadFolders != null) {
|
||||||
|
loadFolders();
|
||||||
|
} else {
|
||||||
|
isLoadingFolders = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void loadFolders() async {
|
void loadFolders() async {
|
||||||
var res = await widget.comicSource.favoriteData!.loadFolders!(widget.cid);
|
var res = await widget.comicSource.favoriteData!.loadFolders!(widget.cid);
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
context.showMessage(message: res.errorMessage!);
|
context.showMessage(message: res.errorMessage!);
|
||||||
|
setState(() {
|
||||||
|
isLoadingFolders = false;
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
folders = res.data;
|
folders = res.data;
|
||||||
if (res.subData is List) {
|
if (res.subData is List) {
|
||||||
addedFolders = List<String>.from(res.subData).toSet();
|
final list = List<String>.from(res.subData);
|
||||||
|
if (list.isNotEmpty) {
|
||||||
|
addedFolders = list.toSet();
|
||||||
|
localIsFavorite = true;
|
||||||
|
} else {
|
||||||
|
addedFolders.clear();
|
||||||
|
localIsFavorite = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
addedFolders.clear();
|
||||||
|
localIsFavorite = false;
|
||||||
}
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
isLoadingFolders = false;
|
isLoadingFolders = false;
|
||||||
@@ -315,118 +213,414 @@ class _NetworkFavoritesState extends State<_NetworkFavorites> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildMultiFolder() {
|
Widget _buildLoadingSkeleton() {
|
||||||
if (widget.isFavorite == true &&
|
return Column(
|
||||||
widget.comicSource.favoriteData!.singleFolderForSingleComic) {
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
return Column(
|
children: [
|
||||||
children: [
|
Padding(
|
||||||
Expanded(
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
|
||||||
child: Center(
|
child: Text(
|
||||||
child: Text("Added to favorites".tl),
|
"Network Favorites".tl,
|
||||||
|
style: ts.s14.copyWith(
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: context.colorScheme.primary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Center(
|
),
|
||||||
child: Button.filled(
|
Shimmer(
|
||||||
isLoading: isLoading,
|
child: Column(
|
||||||
onPressed: () async {
|
children: List.generate(3, (index) {
|
||||||
setState(() {
|
return ListTile(
|
||||||
isLoading = true;
|
title: Container(
|
||||||
});
|
height: 20,
|
||||||
|
width: double.infinity,
|
||||||
var res = await widget.comicSource.favoriteData!
|
margin: const EdgeInsets.only(right: 16),
|
||||||
.addOrDelFavorite!(widget.cid, '', false, null);
|
child: FractionallySizedBox(
|
||||||
if (res.success) {
|
widthFactor: _skeletonWidths[index],
|
||||||
widget.onFavorite(false);
|
alignment: Alignment.centerLeft,
|
||||||
context.pop();
|
child: Container(
|
||||||
App.rootContext.showMessage(message: "Removed".tl);
|
decoration: BoxDecoration(
|
||||||
} else {
|
color: context.colorScheme.surfaceContainerLow,
|
||||||
setState(() {
|
borderRadius: BorderRadius.circular(4),
|
||||||
isLoading = false;
|
),
|
||||||
});
|
),
|
||||||
context.showMessage(message: res.errorMessage!);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: Text("Remove".tl),
|
|
||||||
).paddingVertical(8),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (isLoadingFolders) {
|
|
||||||
loadFolders();
|
|
||||||
return const Center(child: CircularProgressIndicator());
|
|
||||||
} else {
|
|
||||||
return Column(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: ListView.builder(
|
|
||||||
itemCount: folders!.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
var name = folders!.values.elementAt(index);
|
|
||||||
var id = folders!.keys.elementAt(index);
|
|
||||||
return CheckboxListTile(
|
|
||||||
title: Row(
|
|
||||||
children: [
|
|
||||||
Text(name),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
if (addedFolders.contains(id))
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 8,
|
|
||||||
vertical: 4,
|
|
||||||
),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: context.colorScheme.primaryContainer,
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
),
|
|
||||||
child: Text("Added".tl, style: ts.s12),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
value: selected == id,
|
),
|
||||||
onChanged: (v) {
|
trailing: Container(
|
||||||
setState(() {
|
height: 28,
|
||||||
selected = id;
|
width: 60 + (index * 2),
|
||||||
});
|
decoration: BoxDecoration(
|
||||||
},
|
color: context.colorScheme.surfaceContainerLow,
|
||||||
);
|
borderRadius: BorderRadius.circular(12),
|
||||||
},
|
),
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
Center(
|
),
|
||||||
child: Button.filled(
|
],
|
||||||
isLoading: isLoading,
|
);
|
||||||
onPressed: () async {
|
}
|
||||||
if (selected == null) {
|
|
||||||
return;
|
@override
|
||||||
}
|
Widget build(BuildContext context) {
|
||||||
setState(() {
|
if (isLoadingFolders) {
|
||||||
isLoading = true;
|
return _buildLoadingSkeleton();
|
||||||
});
|
}
|
||||||
var res =
|
|
||||||
await widget.comicSource.favoriteData!.addOrDelFavorite!(
|
bool isMultiFolder = widget.comicSource.favoriteData!.loadFolders != null;
|
||||||
widget.cid,
|
|
||||||
selected!,
|
if (isMultiFolder) {
|
||||||
!addedFolders.contains(selected!),
|
return _buildMultiFolder();
|
||||||
null,
|
} else {
|
||||||
);
|
return _buildSingleFolder();
|
||||||
if (res.success) {
|
|
||||||
context.showMessage(message: "Success".tl);
|
|
||||||
context.pop();
|
|
||||||
} else {
|
|
||||||
context.showMessage(message: res.errorMessage!);
|
|
||||||
setState(() {
|
|
||||||
isLoading = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: selected != null && addedFolders.contains(selected!)
|
|
||||||
? Text("Remove".tl)
|
|
||||||
: Text("Add".tl),
|
|
||||||
).paddingVertical(8),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildSingleFolder() {
|
||||||
|
var isFavorite = localIsFavorite ?? false;
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
|
||||||
|
child: Text(
|
||||||
|
"Network Favorites".tl,
|
||||||
|
style: ts.s14.copyWith(
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: context.colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
title: Row(
|
||||||
|
children: [
|
||||||
|
Text("Network Favorites".tl),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
if (isFavorite)
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 8,
|
||||||
|
vertical: 4,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: context.colorScheme.primaryContainer,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Text("Added".tl, style: ts.s12),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
trailing: isLoading
|
||||||
|
? const SizedBox(
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
)
|
||||||
|
: _HoverButton(
|
||||||
|
isFavorite: isFavorite,
|
||||||
|
onTap: () async {
|
||||||
|
setState(() {
|
||||||
|
isLoading = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
var res = await widget
|
||||||
|
.comicSource
|
||||||
|
.favoriteData!
|
||||||
|
.addOrDelFavorite!(widget.cid, '', !isFavorite, null);
|
||||||
|
if (res.success) {
|
||||||
|
setState(() {
|
||||||
|
localIsFavorite = !isFavorite;
|
||||||
|
});
|
||||||
|
widget.onFavorite(!isFavorite);
|
||||||
|
App.rootContext.showMessage(
|
||||||
|
message: isFavorite ? "Removed".tl : "Added".tl,
|
||||||
|
);
|
||||||
|
if (appdata.settings['autoCloseFavoritePanel'] ?? false) {
|
||||||
|
context.pop();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
context.showMessage(message: res.errorMessage!);
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildMultiFolder() {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
|
||||||
|
child: Text(
|
||||||
|
"Network Favorites".tl,
|
||||||
|
style: ts.s14.copyWith(
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: context.colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
...folders!.entries.map((entry) {
|
||||||
|
var name = entry.value;
|
||||||
|
var id = entry.key;
|
||||||
|
var isAdded = addedFolders.contains(id);
|
||||||
|
// When `singleFolderForSingleComic` is `false`, all add and remove buttons are clickable.
|
||||||
|
// When `singleFolderForSingleComic` is `true`, the remove button is always clickable,
|
||||||
|
// while the add button is only clickable if the comic has not been added to any list.
|
||||||
|
var enabled = !(widget.comicSource.favoriteData!.singleFolderForSingleComic && addedFolders.isNotEmpty && !isAdded);
|
||||||
|
|
||||||
|
return ListTile(
|
||||||
|
title: Row(
|
||||||
|
children: [
|
||||||
|
Text(name),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
if (isAdded)
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 8,
|
||||||
|
vertical: 4,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: context.colorScheme.primaryContainer,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Text("Added".tl, style: ts.s12),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
trailing: (_itemLoading[id] ?? false)
|
||||||
|
? const SizedBox(
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
)
|
||||||
|
: _HoverButton(
|
||||||
|
isFavorite: isAdded,
|
||||||
|
enabled: enabled,
|
||||||
|
onTap: () async {
|
||||||
|
setState(() {
|
||||||
|
_itemLoading[id] = true;
|
||||||
|
});
|
||||||
|
var res = await widget
|
||||||
|
.comicSource
|
||||||
|
.favoriteData!
|
||||||
|
.addOrDelFavorite!(widget.cid, id, !isAdded, null);
|
||||||
|
if (res.success) {
|
||||||
|
// Invalidate network cache so folders/pages reload with fresh data
|
||||||
|
NetworkCacheManager().clear();
|
||||||
|
setState(() {
|
||||||
|
if (isAdded) {
|
||||||
|
addedFolders.remove(id);
|
||||||
|
} else {
|
||||||
|
addedFolders.add(id);
|
||||||
|
}
|
||||||
|
// sync local flag for single-folder-per-comic logic and parent
|
||||||
|
localIsFavorite = addedFolders.isNotEmpty;
|
||||||
|
});
|
||||||
|
// notify parent so page state updates when closing and reopening panel
|
||||||
|
widget.onFavorite(addedFolders.isNotEmpty);
|
||||||
|
context.showMessage(message: "Success".tl);
|
||||||
|
if (appdata.settings['autoCloseFavoritePanel'] ?? false) {
|
||||||
|
context.pop();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
context.showMessage(message: res.errorMessage!);
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
_itemLoading[id] = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LocalSection extends StatefulWidget {
|
||||||
|
const _LocalSection({
|
||||||
|
required this.cid,
|
||||||
|
required this.type,
|
||||||
|
required this.favoriteItem,
|
||||||
|
this.updateTime,
|
||||||
|
required this.localFolders,
|
||||||
|
required this.added,
|
||||||
|
required this.onFavorite,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String cid;
|
||||||
|
final ComicType type;
|
||||||
|
final FavoriteItem favoriteItem;
|
||||||
|
final String? updateTime;
|
||||||
|
final List<String> localFolders;
|
||||||
|
final List<String> added;
|
||||||
|
final void Function(bool) onFavorite;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_LocalSection> createState() => _LocalSectionState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LocalSectionState extends State<_LocalSection> {
|
||||||
|
late List<String> localFolders;
|
||||||
|
late Set<String> localAdded;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
localFolders = widget.localFolders;
|
||||||
|
localAdded = widget.added.toSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
|
||||||
|
child: Text(
|
||||||
|
"Local Favorites".tl,
|
||||||
|
style: ts.s14.copyWith(
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: context.colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
...localFolders.map((folder) {
|
||||||
|
var isAdded = localAdded.contains(folder);
|
||||||
|
|
||||||
|
return ListTile(
|
||||||
|
title: Row(
|
||||||
|
children: [
|
||||||
|
Text(folder),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
if (isAdded)
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 8,
|
||||||
|
vertical: 4,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: context.colorScheme.primaryContainer,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Text("Added".tl, style: ts.s12),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
trailing: _HoverButton(
|
||||||
|
isFavorite: isAdded,
|
||||||
|
onTap: () {
|
||||||
|
if (isAdded) {
|
||||||
|
LocalFavoritesManager().deleteComicWithId(
|
||||||
|
folder,
|
||||||
|
widget.cid,
|
||||||
|
widget.type,
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
localAdded.remove(folder);
|
||||||
|
});
|
||||||
|
widget.onFavorite(false);
|
||||||
|
} else {
|
||||||
|
LocalFavoritesManager().addComic(
|
||||||
|
folder,
|
||||||
|
widget.favoriteItem,
|
||||||
|
null,
|
||||||
|
widget.updateTime,
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
localAdded.add(folder);
|
||||||
|
});
|
||||||
|
widget.onFavorite(true);
|
||||||
|
}
|
||||||
|
if (appdata.settings['autoCloseFavoritePanel'] ?? false) {
|
||||||
|
context.pop();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
// New folder button
|
||||||
|
ListTile(
|
||||||
|
title: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.add, size: 20),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Text("New Folder".tl),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
newFolder().then((v) {
|
||||||
|
setState(() {
|
||||||
|
localFolders = LocalFavoritesManager().folderNames;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HoverButton extends StatefulWidget {
|
||||||
|
const _HoverButton({
|
||||||
|
required this.isFavorite,
|
||||||
|
required this.onTap,
|
||||||
|
this.enabled = true,
|
||||||
|
});
|
||||||
|
|
||||||
|
final bool isFavorite;
|
||||||
|
final VoidCallback onTap;
|
||||||
|
final bool enabled;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_HoverButton> createState() => _HoverButtonState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HoverButtonState extends State<_HoverButton> {
|
||||||
|
bool isHovered = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final removeColor = context.colorScheme.error;
|
||||||
|
final removeHoverColor = Color.lerp(removeColor, Colors.black, 0.2)!;
|
||||||
|
final addColor = context.colorScheme.primary;
|
||||||
|
final addHoverColor = Color.lerp(addColor, Colors.black, 0.2)!;
|
||||||
|
|
||||||
|
return MouseRegion(
|
||||||
|
onEnter: widget.enabled ? (_) => setState(() => isHovered = true) : null,
|
||||||
|
onExit: widget.enabled ? (_) => setState(() => isHovered = false) : null,
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: widget.enabled ? widget.onTap : null,
|
||||||
|
child: AnimatedContainer(
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: widget.enabled
|
||||||
|
? (widget.isFavorite
|
||||||
|
? (isHovered ? removeHoverColor : removeColor)
|
||||||
|
: (isHovered ? addHoverColor : addColor))
|
||||||
|
: context.colorScheme.surfaceContainerLow,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
widget.isFavorite ? "Remove".tl : "Add".tl,
|
||||||
|
style: ts.s12.copyWith(
|
||||||
|
color: widget.enabled
|
||||||
|
? context.colorScheme.onPrimary
|
||||||
|
: context.colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,57 @@ import 'package:venera/utils/translations.dart';
|
|||||||
class ComicSourcePage extends StatelessWidget {
|
class ComicSourcePage extends StatelessWidget {
|
||||||
const ComicSourcePage({super.key});
|
const ComicSourcePage({super.key});
|
||||||
|
|
||||||
|
static Future<void> update(
|
||||||
|
ComicSource source, [
|
||||||
|
bool showLoading = true,
|
||||||
|
]) async {
|
||||||
|
if (!source.url.isURL) {
|
||||||
|
if (showLoading) {
|
||||||
|
App.rootContext.showMessage(message: "Invalid url config");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
throw Exception("Invalid url config");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ComicSourceManager().remove(source.key);
|
||||||
|
bool cancel = false;
|
||||||
|
LoadingDialogController? controller;
|
||||||
|
if (showLoading) {
|
||||||
|
controller = showLoadingDialog(
|
||||||
|
App.rootContext,
|
||||||
|
onCancel: () => cancel = true,
|
||||||
|
barrierDismissible: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
var res = await AppDio().get<String>(
|
||||||
|
source.url,
|
||||||
|
options: Options(
|
||||||
|
responseType: ResponseType.plain,
|
||||||
|
headers: {"cache-time": "no"},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (cancel) return;
|
||||||
|
controller?.close();
|
||||||
|
await ComicSourceParser().parse(res.data!, source.filePath);
|
||||||
|
await io.File(source.filePath).writeAsString(res.data!);
|
||||||
|
if (ComicSourceManager().availableUpdates.containsKey(source.key)) {
|
||||||
|
ComicSourceManager().availableUpdates.remove(source.key);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (cancel) return;
|
||||||
|
if (showLoading) {
|
||||||
|
App.rootContext.showMessage(message: e.toString());
|
||||||
|
} else {
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await ComicSourceManager().reload();
|
||||||
|
if (showLoading) {
|
||||||
|
App.forceRebuild();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static Future<int> checkComicSourceUpdate() async {
|
static Future<int> checkComicSourceUpdate() async {
|
||||||
if (ComicSource.all().isEmpty) {
|
if (ComicSource.all().isEmpty) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -51,9 +102,7 @@ class ComicSourcePage extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(body: const _Body());
|
||||||
body: const _Body(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,10 +136,7 @@ class _BodyState extends State<_Body> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SmoothCustomScrollView(
|
return SmoothCustomScrollView(
|
||||||
slivers: [
|
slivers: [
|
||||||
SliverAppbar(
|
SliverAppbar(title: Text('Comic Source'.tl), style: AppbarStyle.shadow),
|
||||||
title: Text('Comic Source'.tl),
|
|
||||||
style: AppbarStyle.shadow,
|
|
||||||
),
|
|
||||||
buildCard(context),
|
buildCard(context),
|
||||||
for (var source in ComicSource.all())
|
for (var source in ComicSource.all())
|
||||||
_SliverComicSource(
|
_SliverComicSource(
|
||||||
@@ -109,9 +155,7 @@ class _BodyState extends State<_Body> {
|
|||||||
showConfirmDialog(
|
showConfirmDialog(
|
||||||
context: App.rootContext,
|
context: App.rootContext,
|
||||||
title: "Delete".tl,
|
title: "Delete".tl,
|
||||||
content: "Delete comic source '@n' ?".tlParams({
|
content: "Delete comic source '@n' ?".tlParams({"n": source.name}),
|
||||||
"n": source.name,
|
|
||||||
}),
|
|
||||||
btnColor: context.colorScheme.error,
|
btnColor: context.colorScheme.error,
|
||||||
onConfirm: () {
|
onConfirm: () {
|
||||||
var file = File(source.filePath);
|
var file = File(source.filePath);
|
||||||
@@ -133,14 +177,16 @@ class _BodyState extends State<_Body> {
|
|||||||
title: const Text("Reload Configs"),
|
title: const Text("Reload Configs"),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.pop(context),
|
onPressed: () => Navigator.pop(context),
|
||||||
child: const Text("cancel")),
|
child: const Text("cancel"),
|
||||||
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await ComicSourceManager().reload();
|
await ComicSourceManager().reload();
|
||||||
App.forceRebuild();
|
App.forceRebuild();
|
||||||
},
|
},
|
||||||
child: const Text("continue")),
|
child: const Text("continue"),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -157,49 +203,11 @@ class _BodyState extends State<_Body> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> update(ComicSource source,
|
void update(ComicSource source, [bool showLoading = true]) {
|
||||||
[bool showLoading = true]) async {
|
ComicSourcePage.update(source, showLoading);
|
||||||
if (!source.url.isURL) {
|
|
||||||
App.rootContext.showMessage(message: "Invalid url config");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ComicSourceManager().remove(source.key);
|
|
||||||
bool cancel = false;
|
|
||||||
LoadingDialogController? controller;
|
|
||||||
if (showLoading) {
|
|
||||||
controller = showLoadingDialog(
|
|
||||||
App.rootContext,
|
|
||||||
onCancel: () => cancel = true,
|
|
||||||
barrierDismissible: false,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
var res = await AppDio().get<String>(source.url,
|
|
||||||
options: Options(responseType: ResponseType.plain));
|
|
||||||
if (cancel) return;
|
|
||||||
controller?.close();
|
|
||||||
await ComicSourceParser().parse(res.data!, source.filePath);
|
|
||||||
await File(source.filePath).writeAsString(res.data!);
|
|
||||||
if (ComicSourceManager().availableUpdates.containsKey(source.key)) {
|
|
||||||
ComicSourceManager().availableUpdates.remove(source.key);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
if (cancel) return;
|
|
||||||
App.rootContext.showMessage(message: e.toString());
|
|
||||||
}
|
|
||||||
await ComicSourceManager().reload();
|
|
||||||
App.forceRebuild();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildCard(BuildContext context) {
|
Widget buildCard(BuildContext context) {
|
||||||
Widget buildButton(
|
|
||||||
{required Widget child, required VoidCallback onPressed}) {
|
|
||||||
return Button.normal(
|
|
||||||
onPressed: onPressed,
|
|
||||||
child: child,
|
|
||||||
).fixHeight(32);
|
|
||||||
}
|
|
||||||
|
|
||||||
return SliverToBoxAdapter(
|
return SliverToBoxAdapter(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
@@ -213,47 +221,46 @@ class _BodyState extends State<_Body> {
|
|||||||
),
|
),
|
||||||
TextField(
|
TextField(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: "URL",
|
hintText: "URL",
|
||||||
border: const UnderlineInputBorder(),
|
border: const UnderlineInputBorder(),
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12),
|
contentPadding: const EdgeInsets.symmetric(horizontal: 12),
|
||||||
suffix: IconButton(
|
suffix: IconButton(
|
||||||
onPressed: () => handleAddSource(url),
|
onPressed: () => handleAddSource(url),
|
||||||
icon: const Icon(Icons.check))),
|
icon: const Icon(Icons.check),
|
||||||
|
),
|
||||||
|
),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
url = value;
|
url = value;
|
||||||
},
|
},
|
||||||
onSubmitted: handleAddSource,
|
onSubmitted: handleAddSource,
|
||||||
).paddingHorizontal(16).paddingBottom(8),
|
).paddingHorizontal(16).paddingBottom(8),
|
||||||
ListTile(
|
Wrap(
|
||||||
title: Text("Comic Source list".tl),
|
spacing: 8,
|
||||||
trailing: buildButton(
|
runSpacing: 8,
|
||||||
child: Text("View".tl),
|
children: [
|
||||||
onPressed: () {
|
FilledButton.tonalIcon(
|
||||||
showPopUpWidget(
|
icon: Icon(Icons.article_outlined),
|
||||||
App.rootContext,
|
label: Text("Comic Source list".tl),
|
||||||
_ComicSourceList(handleAddSource),
|
onPressed: () {
|
||||||
);
|
showPopUpWidget(
|
||||||
},
|
App.rootContext,
|
||||||
),
|
_ComicSourceList(handleAddSource),
|
||||||
),
|
);
|
||||||
ListTile(
|
},
|
||||||
title: Text("Use a config file".tl),
|
),
|
||||||
trailing: buildButton(
|
FilledButton.tonalIcon(
|
||||||
onPressed: _selectFile,
|
icon: Icon(Icons.file_open_outlined),
|
||||||
child: Text("Select".tl),
|
label: Text("Use a config file".tl),
|
||||||
),
|
onPressed: _selectFile,
|
||||||
),
|
),
|
||||||
ListTile(
|
FilledButton.tonalIcon(
|
||||||
title: Text("Help".tl),
|
icon: Icon(Icons.help_outline),
|
||||||
trailing: buildButton(
|
label: Text("Help".tl),
|
||||||
onPressed: help,
|
onPressed: help,
|
||||||
child: Text("Open".tl),
|
),
|
||||||
),
|
_CheckUpdatesButton(),
|
||||||
),
|
],
|
||||||
ListTile(
|
).paddingHorizontal(12).paddingVertical(8),
|
||||||
title: Text("Check updates".tl),
|
|
||||||
trailing: _CheckUpdatesButton(),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -277,7 +284,8 @@ class _BodyState extends State<_Body> {
|
|||||||
|
|
||||||
void help() {
|
void help() {
|
||||||
launchUrlString(
|
launchUrlString(
|
||||||
"https://github.com/venera-app/venera/blob/master/doc/comic_source.md");
|
"https://github.com/venera-app/venera/blob/master/doc/comic_source.md",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> handleAddSource(String url) async {
|
Future<void> handleAddSource(String url) async {
|
||||||
@@ -288,11 +296,19 @@ class _BodyState extends State<_Body> {
|
|||||||
splits.removeWhere((element) => element == "");
|
splits.removeWhere((element) => element == "");
|
||||||
var fileName = splits.last;
|
var fileName = splits.last;
|
||||||
bool cancel = false;
|
bool cancel = false;
|
||||||
var controller = showLoadingDialog(App.rootContext,
|
var controller = showLoadingDialog(
|
||||||
onCancel: () => cancel = true, barrierDismissible: false);
|
App.rootContext,
|
||||||
|
onCancel: () => cancel = true,
|
||||||
|
barrierDismissible: false,
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
var res = await AppDio()
|
var res = await AppDio().get<String>(
|
||||||
.get<String>(url, options: Options(responseType: ResponseType.plain));
|
url,
|
||||||
|
options: Options(
|
||||||
|
responseType: ResponseType.plain,
|
||||||
|
headers: {"cache-time": "no"},
|
||||||
|
),
|
||||||
|
);
|
||||||
if (cancel) return;
|
if (cancel) return;
|
||||||
controller.close();
|
controller.close();
|
||||||
await addSource(res.data!, fileName);
|
await addSource(res.data!, fileName);
|
||||||
@@ -322,95 +338,178 @@ class _ComicSourceList extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ComicSourceListState extends State<_ComicSourceList> {
|
class _ComicSourceListState extends State<_ComicSourceList> {
|
||||||
bool loading = true;
|
|
||||||
List? json;
|
List? json;
|
||||||
|
bool changed = false;
|
||||||
|
var controller = TextEditingController();
|
||||||
|
|
||||||
void load() async {
|
void load() async {
|
||||||
var dio = AppDio();
|
if (json != null) {
|
||||||
var res = await dio.get<String>(appdata.settings['comicSourceListUrl']);
|
setState(() {
|
||||||
if (res.statusCode != 200) {
|
json = null;
|
||||||
context.showMessage(message: "Network error".tl);
|
});
|
||||||
|
}
|
||||||
|
if (controller.text.isEmpty) {
|
||||||
|
setState(() {
|
||||||
|
json = [];
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setState(() {
|
var dio = AppDio();
|
||||||
json = jsonDecode(res.data!);
|
try {
|
||||||
loading = false;
|
var res = await dio.get<String>(controller.text);
|
||||||
});
|
if (res.statusCode != 200) {
|
||||||
|
throw "error";
|
||||||
|
}
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
json = jsonDecode(res.data!);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
context.showMessage(message: "Network error".tl);
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
json = [];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
controller.text = appdata.settings['comicSourceListUrl'];
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
super.dispose();
|
||||||
|
if (changed) {
|
||||||
|
appdata.settings['comicSourceListUrl'] = controller.text;
|
||||||
|
appdata.saveData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return PopUpWidgetScaffold(
|
return PopUpWidgetScaffold(title: "Comic Source".tl, body: buildBody());
|
||||||
title: "Comic Source".tl,
|
|
||||||
tailing: [
|
|
||||||
IconButton(
|
|
||||||
icon: Icon(Icons.settings),
|
|
||||||
onPressed: () async {
|
|
||||||
await showInputDialog(
|
|
||||||
context: context,
|
|
||||||
title: "Set comic source list url".tl,
|
|
||||||
initialValue: appdata.settings['comicSourceListUrl'],
|
|
||||||
onConfirm: (value) {
|
|
||||||
appdata.settings['comicSourceListUrl'] = value;
|
|
||||||
appdata.saveData();
|
|
||||||
setState(() {
|
|
||||||
loading = true;
|
|
||||||
json = null;
|
|
||||||
});
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
|
||||||
body: buildBody(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildBody() {
|
Widget buildBody() {
|
||||||
if (loading) {
|
var currentKey = ComicSource.all().map((e) => e.key).toList();
|
||||||
load();
|
|
||||||
return const Center(child: CircularProgressIndicator());
|
|
||||||
} else {
|
|
||||||
var currentKey = ComicSource.all().map((e) => e.key).toList();
|
|
||||||
return ListView.builder(
|
|
||||||
itemCount: json!.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
var key = json![index]["key"];
|
|
||||||
var action = currentKey.contains(key)
|
|
||||||
? const Icon(Icons.check, size: 20).paddingRight(8)
|
|
||||||
: Button.filled(
|
|
||||||
child: Text("Add".tl),
|
|
||||||
onPressed: () async {
|
|
||||||
var fileName = json![index]["fileName"];
|
|
||||||
var url = json![index]["url"];
|
|
||||||
if (url == null || !(url.toString()).isURL) {
|
|
||||||
var listUrl =
|
|
||||||
appdata.settings['comicSourceListUrl'] as String;
|
|
||||||
if (listUrl
|
|
||||||
.replaceFirst("https://", "")
|
|
||||||
.replaceFirst("http://", "")
|
|
||||||
.contains("/")) {
|
|
||||||
url =
|
|
||||||
listUrl.substring(0, listUrl.lastIndexOf("/") + 1) +
|
|
||||||
fileName;
|
|
||||||
} else {
|
|
||||||
url = '$listUrl/$fileName';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await widget.onAdd(url);
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
).fixHeight(32);
|
|
||||||
|
|
||||||
return ListTile(
|
return ListView.builder(
|
||||||
title: Text(json![index]["name"]),
|
itemCount: (json?.length ?? 1) + 1,
|
||||||
subtitle: Text(json![index]["version"]),
|
itemBuilder: (context, index) {
|
||||||
trailing: action,
|
if (index == 0) {
|
||||||
|
return Container(
|
||||||
|
margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(
|
||||||
|
color: Theme.of(context).colorScheme.outlineVariant,
|
||||||
|
width: 0.6,
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
ListTile(
|
||||||
|
leading: Icon(Icons.source_outlined),
|
||||||
|
title: Text("Repo URL".tl),
|
||||||
|
),
|
||||||
|
TextField(
|
||||||
|
controller: controller,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: "URL",
|
||||||
|
border: const UnderlineInputBorder(),
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: 12),
|
||||||
|
),
|
||||||
|
onChanged: (value) {
|
||||||
|
changed = true;
|
||||||
|
},
|
||||||
|
).paddingHorizontal(16).paddingBottom(8),
|
||||||
|
Text(
|
||||||
|
"The URL should point to a 'index.json' file".tl,
|
||||||
|
).paddingLeft(16),
|
||||||
|
Text(
|
||||||
|
"Do not report any issues related to sources to App repo.".tl,
|
||||||
|
).paddingLeft(16),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
launchUrlString(
|
||||||
|
"https://github.com/venera-app/venera/blob/master/doc/comic_source.md",
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: Text("Help".tl),
|
||||||
|
),
|
||||||
|
FilledButton.tonal(
|
||||||
|
onPressed: load,
|
||||||
|
child: Text("Refresh".tl),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
);
|
|
||||||
}
|
if (index == 1 && json == null) {
|
||||||
|
return Center(
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 2,
|
||||||
|
).fixWidth(24).fixHeight(24),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
index--;
|
||||||
|
|
||||||
|
var key = json![index]["key"];
|
||||||
|
var action = currentKey.contains(key)
|
||||||
|
? const Icon(Icons.check, size: 20).paddingRight(8)
|
||||||
|
: Button.filled(
|
||||||
|
child: Text("Add".tl),
|
||||||
|
onPressed: () async {
|
||||||
|
var fileName = json![index]["fileName"];
|
||||||
|
var url = json![index]["url"];
|
||||||
|
if (url == null || !(url.toString()).isURL) {
|
||||||
|
var listUrl =
|
||||||
|
appdata.settings['comicSourceListUrl'] as String;
|
||||||
|
if (listUrl
|
||||||
|
.replaceFirst("https://", "")
|
||||||
|
.replaceFirst("http://", "")
|
||||||
|
.contains("/")) {
|
||||||
|
url =
|
||||||
|
listUrl.substring(0, listUrl.lastIndexOf("/") + 1) +
|
||||||
|
fileName;
|
||||||
|
} else {
|
||||||
|
url = '$listUrl/$fileName';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await widget.onAdd(url);
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
).fixHeight(32);
|
||||||
|
|
||||||
|
var description = json![index]["version"];
|
||||||
|
if (json![index]["description"] != null) {
|
||||||
|
description = "$description\n${json![index]["description"]}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return ListTile(
|
||||||
|
title: Text(json![index]["name"]),
|
||||||
|
subtitle: Text(description),
|
||||||
|
trailing: action,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,6 +560,7 @@ void _addAllPagesWithComicSource(ComicSource source) {
|
|||||||
var explorePages = appdata.settings['explore_pages'];
|
var explorePages = appdata.settings['explore_pages'];
|
||||||
var categoryPages = appdata.settings['categories'];
|
var categoryPages = appdata.settings['categories'];
|
||||||
var networkFavorites = appdata.settings['favorites'];
|
var networkFavorites = appdata.settings['favorites'];
|
||||||
|
var searchPages = appdata.settings['searchSources'];
|
||||||
|
|
||||||
if (source.explorePages.isNotEmpty) {
|
if (source.explorePages.isNotEmpty) {
|
||||||
for (var page in source.explorePages) {
|
for (var page in source.explorePages) {
|
||||||
@@ -477,10 +577,14 @@ void _addAllPagesWithComicSource(ComicSource source) {
|
|||||||
!networkFavorites.contains(source.favoriteData!.key)) {
|
!networkFavorites.contains(source.favoriteData!.key)) {
|
||||||
networkFavorites.add(source.favoriteData!.key);
|
networkFavorites.add(source.favoriteData!.key);
|
||||||
}
|
}
|
||||||
|
if (source.searchPageData != null && !searchPages.contains(source.key)) {
|
||||||
|
searchPages.add(source.key);
|
||||||
|
}
|
||||||
|
|
||||||
appdata.settings['explore_pages'] = explorePages.toSet().toList();
|
appdata.settings['explore_pages'] = explorePages.toSet().toList();
|
||||||
appdata.settings['categories'] = categoryPages.toSet().toList();
|
appdata.settings['categories'] = categoryPages.toSet().toList();
|
||||||
appdata.settings['favorites'] = networkFavorites.toSet().toList();
|
appdata.settings['favorites'] = networkFavorites.toSet().toList();
|
||||||
|
appdata.settings['searchSources'] = searchPages.toSet().toList();
|
||||||
|
|
||||||
appdata.saveData();
|
appdata.saveData();
|
||||||
}
|
}
|
||||||
@@ -515,15 +619,10 @@ class __EditFilePageState extends State<_EditFilePage> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: Appbar(
|
appBar: Appbar(title: Text("Edit".tl)),
|
||||||
title: Text("Edit".tl),
|
|
||||||
),
|
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(height: 0.6, color: context.colorScheme.outlineVariant),
|
||||||
height: 0.6,
|
|
||||||
color: context.colorScheme.outlineVariant,
|
|
||||||
),
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: CodeEditor(
|
child: CodeEditor(
|
||||||
initialValue: current,
|
initialValue: current,
|
||||||
@@ -564,9 +663,11 @@ class _CheckUpdatesButtonState extends State<_CheckUpdatesButton> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void showUpdateDialog() async {
|
void showUpdateDialog() async {
|
||||||
var text = ComicSourceManager().availableUpdates.entries.map((e) {
|
var text = ComicSourceManager().availableUpdates.entries
|
||||||
return "${ComicSource.find(e.key)!.name}: ${e.value}";
|
.map((e) {
|
||||||
}).join("\n");
|
return "${ComicSource.find(e.key)!.name}: ${e.value}";
|
||||||
|
})
|
||||||
|
.join("\n");
|
||||||
bool doUpdate = false;
|
bool doUpdate = false;
|
||||||
await showDialog(
|
await showDialog(
|
||||||
context: App.rootContext,
|
context: App.rootContext,
|
||||||
@@ -598,7 +699,7 @@ class _CheckUpdatesButtonState extends State<_CheckUpdatesButton> {
|
|||||||
var shouldUpdate = ComicSourceManager().availableUpdates.keys.toList();
|
var shouldUpdate = ComicSourceManager().availableUpdates.keys.toList();
|
||||||
for (var key in shouldUpdate) {
|
for (var key in shouldUpdate) {
|
||||||
var source = ComicSource.find(key)!;
|
var source = ComicSource.find(key)!;
|
||||||
await _BodyState.update(source, false);
|
await ComicSourcePage.update(source, false);
|
||||||
current++;
|
current++;
|
||||||
loadingController.setProgress(current / total);
|
loadingController.setProgress(current / total);
|
||||||
}
|
}
|
||||||
@@ -611,11 +712,17 @@ class _CheckUpdatesButtonState extends State<_CheckUpdatesButton> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Button.normal(
|
return FilledButton.tonalIcon(
|
||||||
|
icon: isLoading
|
||||||
|
? SizedBox(
|
||||||
|
width: 18,
|
||||||
|
height: 18,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
)
|
||||||
|
: Icon(Icons.update),
|
||||||
|
label: Text("Check updates".tl),
|
||||||
onPressed: check,
|
onPressed: check,
|
||||||
isLoading: isLoading,
|
);
|
||||||
child: Text("Check".tl),
|
|
||||||
).fixHeight(32);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -704,10 +811,7 @@ class _SliverComicSourceState extends State<_SliverComicSource> {
|
|||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Row(
|
title: Row(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(source.name, style: ts.s18),
|
||||||
source.name,
|
|
||||||
style: ts.s18,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 6),
|
const SizedBox(width: 6),
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
@@ -740,7 +844,7 @@ class _SliverComicSourceState extends State<_SliverComicSource> {
|
|||||||
style: const TextStyle(fontSize: 13),
|
style: const TextStyle(fontSize: 13),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
).paddingLeft(4)
|
).paddingLeft(4),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
trailing: Row(
|
trailing: Row(
|
||||||
@@ -785,15 +889,9 @@ class _SliverComicSourceState extends State<_SliverComicSource> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
SliverToBoxAdapter(
|
SliverToBoxAdapter(
|
||||||
child: Column(
|
child: Column(children: buildSourceSettings().toList()),
|
||||||
children: buildSourceSettings().toList(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SliverToBoxAdapter(
|
|
||||||
child: Column(
|
|
||||||
children: _buildAccount().toList(),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
SliverToBoxAdapter(child: Column(children: _buildAccount().toList())),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -819,8 +917,10 @@ class _SliverComicSourceState extends State<_SliverComicSource> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
current = item.value['options']
|
current =
|
||||||
.firstWhere((e) => e['value'] == current)['text'] ??
|
item.value['options'].firstWhere(
|
||||||
|
(e) => e['value'] == current,
|
||||||
|
)['text'] ??
|
||||||
current;
|
current;
|
||||||
}
|
}
|
||||||
yield ListTile(
|
yield ListTile(
|
||||||
@@ -828,8 +928,9 @@ class _SliverComicSourceState extends State<_SliverComicSource> {
|
|||||||
trailing: Select(
|
trailing: Select(
|
||||||
current: (current as String).ts(source.key),
|
current: (current as String).ts(source.key),
|
||||||
values: (item.value['options'] as List)
|
values: (item.value['options'] as List)
|
||||||
.map<String>((e) =>
|
.map<String>(
|
||||||
((e['text'] ?? e['value']) as String).ts(source.key))
|
(e) => ((e['text'] ?? e['value']) as String).ts(source.key),
|
||||||
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
onTap: (i) {
|
onTap: (i) {
|
||||||
source.data['settings'][key] =
|
source.data['settings'][key] =
|
||||||
@@ -857,8 +958,11 @@ class _SliverComicSourceState extends State<_SliverComicSource> {
|
|||||||
source.data['settings'][key] ?? item.value['default'] ?? '';
|
source.data['settings'][key] ?? item.value['default'] ?? '';
|
||||||
yield ListTile(
|
yield ListTile(
|
||||||
title: Text((item.value['title'] as String).ts(source.key)),
|
title: Text((item.value['title'] as String).ts(source.key)),
|
||||||
subtitle:
|
subtitle: Text(
|
||||||
Text(current, maxLines: 1, overflow: TextOverflow.ellipsis),
|
current,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
trailing: IconButton(
|
trailing: IconButton(
|
||||||
icon: const Icon(Icons.edit),
|
icon: const Icon(Icons.edit),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
@@ -899,10 +1003,7 @@ class _SliverComicSourceState extends State<_SliverComicSource> {
|
|||||||
trailing: const Icon(Icons.arrow_right),
|
trailing: const Icon(Icons.arrow_right),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
await context.to(
|
await context.to(
|
||||||
() => _LoginPage(
|
() => _LoginPage(config: source.account!, source: source),
|
||||||
config: source.account!,
|
|
||||||
source: source,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
source.saveData();
|
source.saveData();
|
||||||
setState(() {});
|
setState(() {});
|
||||||
@@ -948,9 +1049,7 @@ class _SliverComicSourceState extends State<_SliverComicSource> {
|
|||||||
trailing: loading
|
trailing: loading
|
||||||
? const SizedBox.square(
|
? const SizedBox.square(
|
||||||
dimension: 24,
|
dimension: 24,
|
||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
strokeWidth: 2,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
: const Icon(Icons.refresh),
|
: const Icon(Icons.refresh),
|
||||||
);
|
);
|
||||||
@@ -991,9 +1090,7 @@ class _LoginPageState extends State<_LoginPage> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: const Appbar(
|
appBar: const Appbar(title: Text('')),
|
||||||
title: Text(''),
|
|
||||||
),
|
|
||||||
body: Center(
|
body: Center(
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
@@ -1121,8 +1218,9 @@ class _LoginPageState extends State<_LoginPage> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
loading = true;
|
loading = true;
|
||||||
});
|
});
|
||||||
var cookies =
|
var cookies = widget.config.cookieFields!
|
||||||
widget.config.cookieFields!.map((e) => _cookies[e] ?? '').toList();
|
.map((e) => _cookies[e] ?? '')
|
||||||
|
.toList();
|
||||||
widget.config.validateCookies!(cookies).then((value) {
|
widget.config.validateCookies!(cookies).then((value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
widget.source.data['account'] = 'ok';
|
widget.source.data['account'] = 'ok';
|
||||||
|
|||||||
@@ -6,13 +6,10 @@ import 'package:venera/foundation/comic_source/comic_source.dart';
|
|||||||
import 'package:venera/foundation/global_state.dart';
|
import 'package:venera/foundation/global_state.dart';
|
||||||
import 'package:venera/foundation/res.dart';
|
import 'package:venera/foundation/res.dart';
|
||||||
import 'package:venera/pages/comic_source_page.dart';
|
import 'package:venera/pages/comic_source_page.dart';
|
||||||
import 'package:venera/pages/search_result_page.dart';
|
|
||||||
import 'package:venera/pages/settings/settings_page.dart';
|
import 'package:venera/pages/settings/settings_page.dart';
|
||||||
import 'package:venera/utils/ext.dart';
|
import 'package:venera/utils/ext.dart';
|
||||||
import 'package:venera/utils/translations.dart';
|
import 'package:venera/utils/translations.dart';
|
||||||
|
|
||||||
import 'category_comics_page.dart';
|
|
||||||
|
|
||||||
class ExplorePage extends StatefulWidget {
|
class ExplorePage extends StatefulWidget {
|
||||||
const ExplorePage({super.key});
|
const ExplorePage({super.key});
|
||||||
|
|
||||||
@@ -445,30 +442,7 @@ Iterable<Widget> _buildExplorePagePart(
|
|||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
var context = App.mainNavigatorKey!.currentContext!;
|
var context = App.mainNavigatorKey!.currentContext!;
|
||||||
if (part.viewMore!.startsWith("search:")) {
|
part.viewMore!.jump(context);
|
||||||
context.to(
|
|
||||||
() => SearchResultPage(
|
|
||||||
text: part.viewMore!.replaceFirst("search:", ""),
|
|
||||||
options: const [],
|
|
||||||
sourceKey: sourceKey,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else if (part.viewMore!.startsWith("category:")) {
|
|
||||||
var cp = part.viewMore!.replaceFirst("category:", "");
|
|
||||||
var c = cp.split('@').first;
|
|
||||||
String? p = cp.split('@').last;
|
|
||||||
if (p == c) {
|
|
||||||
p = null;
|
|
||||||
}
|
|
||||||
context.to(
|
|
||||||
() => CategoryComicsPage(
|
|
||||||
category: c,
|
|
||||||
categoryKey:
|
|
||||||
ComicSource.find(sourceKey)!.categoryData!.key,
|
|
||||||
param: p,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
child: Text("View more".tl),
|
child: Text("View more".tl),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ void addFavorite(List<Comic> comics) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<List<FavoriteItem>> updateComicsInfo(String folder) async {
|
Future<List<FavoriteItem>> updateComicsInfo(String folder) async {
|
||||||
var comics = LocalFavoritesManager().getAllComics(folder);
|
var comics = LocalFavoritesManager().getFolderComics(folder);
|
||||||
|
|
||||||
Future<void> updateSingleComic(int index) async {
|
Future<void> updateSingleComic(int index) async {
|
||||||
int retry = 3;
|
int retry = 3;
|
||||||
|
|||||||
@@ -15,17 +15,20 @@ import 'package:venera/foundation/local.dart';
|
|||||||
import 'package:venera/foundation/log.dart';
|
import 'package:venera/foundation/log.dart';
|
||||||
import 'package:venera/foundation/res.dart';
|
import 'package:venera/foundation/res.dart';
|
||||||
import 'package:venera/network/download.dart';
|
import 'package:venera/network/download.dart';
|
||||||
|
import 'package:venera/network/cache.dart';
|
||||||
import 'package:venera/pages/comic_details_page/comic_page.dart';
|
import 'package:venera/pages/comic_details_page/comic_page.dart';
|
||||||
import 'package:venera/pages/reader/reader.dart';
|
import 'package:venera/pages/reader/reader.dart';
|
||||||
import 'package:venera/pages/settings/settings_page.dart';
|
import 'package:venera/pages/settings/settings_page.dart';
|
||||||
|
import 'package:venera/utils/ext.dart';
|
||||||
import 'package:venera/utils/io.dart';
|
import 'package:venera/utils/io.dart';
|
||||||
|
import 'package:venera/utils/opencc.dart';
|
||||||
|
import 'package:venera/utils/tags_translation.dart';
|
||||||
import 'package:venera/utils/translations.dart';
|
import 'package:venera/utils/translations.dart';
|
||||||
|
|
||||||
part 'favorite_actions.dart';
|
part 'favorite_actions.dart';
|
||||||
part 'side_bar.dart';
|
part 'side_bar.dart';
|
||||||
part 'local_favorites_page.dart';
|
part 'local_favorites_page.dart';
|
||||||
part 'network_favorites_page.dart';
|
part 'network_favorites_page.dart';
|
||||||
part 'local_search_page.dart';
|
|
||||||
|
|
||||||
const _kLeftBarWidth = 256.0;
|
const _kLeftBarWidth = 256.0;
|
||||||
|
|
||||||
@@ -65,6 +68,11 @@ class _FavoritesPageState extends State<FavoritesPage> {
|
|||||||
folder = data['name'];
|
folder = data['name'];
|
||||||
isNetwork = data['isNetwork'] ?? false;
|
isNetwork = data['isNetwork'] ?? false;
|
||||||
}
|
}
|
||||||
|
if (folder != null
|
||||||
|
&& !isNetwork
|
||||||
|
&& !LocalFavoritesManager().existsFolder(folder!)) {
|
||||||
|
folder = null;
|
||||||
|
}
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
part of 'favorites_page.dart';
|
part of 'favorites_page.dart';
|
||||||
|
|
||||||
|
const _localAllFolderLabel = '^_^[%local_all%]^_^';
|
||||||
|
|
||||||
|
/// If the number of comics in a folder exceeds this limit, it will be
|
||||||
|
/// fetched asynchronously.
|
||||||
|
const _asyncDataFetchLimit = 500;
|
||||||
|
|
||||||
class _LocalFavoritesPage extends StatefulWidget {
|
class _LocalFavoritesPage extends StatefulWidget {
|
||||||
const _LocalFavoritesPage({required this.folder, super.key});
|
const _LocalFavoritesPage({required this.folder, super.key});
|
||||||
|
|
||||||
@@ -31,25 +37,132 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
|||||||
|
|
||||||
int? lastSelectedIndex;
|
int? lastSelectedIndex;
|
||||||
|
|
||||||
|
bool get isAllFolder => widget.folder == _localAllFolderLabel;
|
||||||
|
|
||||||
|
LocalFavoritesManager get manager => LocalFavoritesManager();
|
||||||
|
|
||||||
|
bool isLoading = false;
|
||||||
|
|
||||||
|
var searchResults = <FavoriteItem>[];
|
||||||
|
|
||||||
|
void updateSearchResult() {
|
||||||
|
setState(() {
|
||||||
|
if (keyword.trim().isEmpty) {
|
||||||
|
searchResults = comics;
|
||||||
|
} else {
|
||||||
|
searchResults = [];
|
||||||
|
for (var comic in comics) {
|
||||||
|
if (matchKeyword(keyword, comic) ||
|
||||||
|
matchKeywordT(keyword, comic) ||
|
||||||
|
matchKeywordS(keyword, comic)) {
|
||||||
|
searchResults.add(comic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void updateComics() {
|
void updateComics() {
|
||||||
if (keyword.isEmpty) {
|
if (isLoading) return;
|
||||||
setState(() {
|
if (isAllFolder) {
|
||||||
comics = LocalFavoritesManager().getAllComics(widget.folder);
|
var totalComics = manager.totalComics;
|
||||||
});
|
if (totalComics < _asyncDataFetchLimit) {
|
||||||
|
comics = manager.getAllComics();
|
||||||
|
} else {
|
||||||
|
isLoading = true;
|
||||||
|
manager
|
||||||
|
.getAllComicsAsync()
|
||||||
|
.minTime(const Duration(milliseconds: 200))
|
||||||
|
.then((value) {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
comics = value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setState(() {
|
var folderComics = manager.folderComics(widget.folder);
|
||||||
comics = LocalFavoritesManager().searchInFolder(widget.folder, keyword);
|
if (folderComics < _asyncDataFetchLimit) {
|
||||||
});
|
comics = manager.getFolderComics(widget.folder);
|
||||||
|
} else {
|
||||||
|
isLoading = true;
|
||||||
|
manager
|
||||||
|
.getFolderComicsAsync(widget.folder)
|
||||||
|
.minTime(const Duration(milliseconds: 200))
|
||||||
|
.then((value) {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
comics = value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool matchKeyword(String keyword, FavoriteItem comic) {
|
||||||
|
var list = keyword.split(" ");
|
||||||
|
for (var k in list) {
|
||||||
|
if (k.isEmpty) continue;
|
||||||
|
if (comic.title.contains(k)) {
|
||||||
|
continue;
|
||||||
|
} else if (comic.subtitle != null && comic.subtitle!.contains(k)) {
|
||||||
|
continue;
|
||||||
|
} else if (comic.tags.any((tag) {
|
||||||
|
if (tag == k) {
|
||||||
|
return true;
|
||||||
|
} else if (tag.contains(':') && tag.split(':')[1] == k) {
|
||||||
|
return true;
|
||||||
|
} else if (App.locale.languageCode != 'en' &&
|
||||||
|
tag.translateTagsToCN == k) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
})) {
|
||||||
|
continue;
|
||||||
|
} else if (comic.author == k) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert keyword to traditional Chinese to match comics
|
||||||
|
bool matchKeywordT(String keyword, FavoriteItem comic) {
|
||||||
|
if (!OpenCC.hasChineseSimplified(keyword)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
keyword = OpenCC.simplifiedToTraditional(keyword);
|
||||||
|
return matchKeyword(keyword, comic);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert keyword to simplified Chinese to match comics
|
||||||
|
bool matchKeywordS(String keyword, FavoriteItem comic) {
|
||||||
|
if (!OpenCC.hasChineseTraditional(keyword)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
keyword = OpenCC.traditionalToSimplified(keyword);
|
||||||
|
return matchKeyword(keyword, comic);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
favPage = context.findAncestorStateOfType<_FavoritesPageState>()!;
|
favPage = context.findAncestorStateOfType<_FavoritesPageState>()!;
|
||||||
comics = LocalFavoritesManager().getAllComics(widget.folder);
|
if (!isAllFolder) {
|
||||||
var (a, b) = LocalFavoritesManager().findLinked(widget.folder);
|
var (a, b) = LocalFavoritesManager().findLinked(widget.folder);
|
||||||
networkSource = a;
|
networkSource = a;
|
||||||
networkFolder = b;
|
networkFolder = b;
|
||||||
|
} else {
|
||||||
|
networkSource = null;
|
||||||
|
networkFolder = null;
|
||||||
|
}
|
||||||
|
comics = [];
|
||||||
|
updateComics();
|
||||||
LocalFavoritesManager().addListener(updateComics);
|
LocalFavoritesManager().addListener(updateComics);
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
@@ -62,16 +175,33 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
|||||||
|
|
||||||
void selectAll() {
|
void selectAll() {
|
||||||
setState(() {
|
setState(() {
|
||||||
selectedComics = comics.asMap().map((k, v) => MapEntry(v, true));
|
if (searchMode) {
|
||||||
|
selectedComics = searchResults.asMap().map((k, v) => MapEntry(v, true));
|
||||||
|
} else {
|
||||||
|
selectedComics = comics.asMap().map((k, v) => MapEntry(v, true));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void invertSelection() {
|
void invertSelection() {
|
||||||
setState(() {
|
setState(() {
|
||||||
comics.asMap().forEach((k, v) {
|
if (searchMode) {
|
||||||
selectedComics[v] = !selectedComics.putIfAbsent(v, () => false);
|
for (var c in searchResults) {
|
||||||
});
|
if (selectedComics.containsKey(c)) {
|
||||||
selectedComics.removeWhere((k, v) => !v);
|
selectedComics.remove(c);
|
||||||
|
} else {
|
||||||
|
selectedComics[c] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (var c in comics) {
|
||||||
|
if (selectedComics.containsKey(c)) {
|
||||||
|
selectedComics.remove(c);
|
||||||
|
} else {
|
||||||
|
selectedComics[c] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,6 +243,11 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var title = favPage.folder ?? "Unselected".tl;
|
||||||
|
if (title == _localAllFolderLabel) {
|
||||||
|
title = "All".tl;
|
||||||
|
}
|
||||||
|
|
||||||
Widget body = SmoothCustomScrollView(
|
Widget body = SmoothCustomScrollView(
|
||||||
controller: scrollController,
|
controller: scrollController,
|
||||||
slivers: [
|
slivers: [
|
||||||
@@ -135,10 +270,10 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
|||||||
onTap: context.width < _kTwoPanelChangeWidth
|
onTap: context.width < _kTwoPanelChangeWidth
|
||||||
? favPage.showFolderSelector
|
? favPage.showFolderSelector
|
||||||
: null,
|
: null,
|
||||||
child: Text(favPage.folder ?? "Unselected".tl),
|
child: Text(title),
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
if (networkSource != null)
|
if (networkSource != null && !isAllFolder)
|
||||||
Tooltip(
|
Tooltip(
|
||||||
message: "Sync".tl,
|
message: "Sync".tl,
|
||||||
child: Flyout(
|
child: Flyout(
|
||||||
@@ -191,14 +326,17 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
|||||||
icon: const Icon(Icons.search),
|
icon: const Icon(Icons.search),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
keyword = "";
|
||||||
searchMode = true;
|
searchMode = true;
|
||||||
|
updateSearchResult();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
MenuButton(
|
if (!isAllFolder)
|
||||||
entries: [
|
MenuButton(
|
||||||
MenuEntry(
|
entries: [
|
||||||
|
MenuEntry(
|
||||||
icon: Icons.edit_outlined,
|
icon: Icons.edit_outlined,
|
||||||
text: "Rename".tl,
|
text: "Rename".tl,
|
||||||
onClick: () {
|
onClick: () {
|
||||||
@@ -220,8 +358,9 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}),
|
},
|
||||||
MenuEntry(
|
),
|
||||||
|
MenuEntry(
|
||||||
icon: Icons.reorder,
|
icon: Icons.reorder,
|
||||||
text: "Reorder".tl,
|
text: "Reorder".tl,
|
||||||
onClick: () {
|
onClick: () {
|
||||||
@@ -241,8 +380,9 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}),
|
},
|
||||||
MenuEntry(
|
),
|
||||||
|
MenuEntry(
|
||||||
icon: Icons.upload_file,
|
icon: Icons.upload_file,
|
||||||
text: "Export".tl,
|
text: "Export".tl,
|
||||||
onClick: () {
|
onClick: () {
|
||||||
@@ -253,8 +393,9 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
|||||||
data: utf8.encode(json),
|
data: utf8.encode(json),
|
||||||
filename: "${widget.folder}.json",
|
filename: "${widget.folder}.json",
|
||||||
);
|
);
|
||||||
}),
|
},
|
||||||
MenuEntry(
|
),
|
||||||
|
MenuEntry(
|
||||||
icon: Icons.update,
|
icon: Icons.update,
|
||||||
text: "Update Comics Info".tl,
|
text: "Update Comics Info".tl,
|
||||||
onClick: () {
|
onClick: () {
|
||||||
@@ -265,8 +406,9 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}),
|
},
|
||||||
MenuEntry(
|
),
|
||||||
|
MenuEntry(
|
||||||
icon: Icons.delete_outline,
|
icon: Icons.delete_outline,
|
||||||
text: "Delete Folder".tl,
|
text: "Delete Folder".tl,
|
||||||
color: context.colorScheme.error,
|
color: context.colorScheme.error,
|
||||||
@@ -284,9 +426,10 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
|||||||
favPage.folderList?.updateFolders();
|
favPage.folderList?.updateFolders();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}),
|
},
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
else if (multiSelectMode)
|
else if (multiSelectMode)
|
||||||
@@ -310,10 +453,12 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
|||||||
"Selected @c comics".tlParams({"c": selectedComics.length})),
|
"Selected @c comics".tlParams({"c": selectedComics.length})),
|
||||||
actions: [
|
actions: [
|
||||||
MenuButton(entries: [
|
MenuButton(entries: [
|
||||||
|
if (!isAllFolder)
|
||||||
MenuEntry(
|
MenuEntry(
|
||||||
icon: Icons.drive_file_move,
|
icon: Icons.drive_file_move,
|
||||||
text: "Move to folder".tl,
|
text: "Move to folder".tl,
|
||||||
onClick: () => favoriteOption('move')),
|
onClick: () => favoriteOption('move')),
|
||||||
|
if (!isAllFolder)
|
||||||
MenuEntry(
|
MenuEntry(
|
||||||
icon: Icons.copy,
|
icon: Icons.copy,
|
||||||
text: "Copy to folder".tl,
|
text: "Copy to folder".tl,
|
||||||
@@ -330,22 +475,23 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
|||||||
icon: Icons.flip,
|
icon: Icons.flip,
|
||||||
text: "Invert Selection".tl,
|
text: "Invert Selection".tl,
|
||||||
onClick: invertSelection),
|
onClick: invertSelection),
|
||||||
MenuEntry(
|
if (!isAllFolder)
|
||||||
icon: Icons.delete_outline,
|
MenuEntry(
|
||||||
text: "Delete Comic".tl,
|
icon: Icons.delete_outline,
|
||||||
color: context.colorScheme.error,
|
text: "Delete Comic".tl,
|
||||||
onClick: () {
|
color: context.colorScheme.error,
|
||||||
showConfirmDialog(
|
onClick: () {
|
||||||
context: context,
|
showConfirmDialog(
|
||||||
title: "Delete".tl,
|
context: context,
|
||||||
content: "Delete @c comics?"
|
title: "Delete".tl,
|
||||||
.tlParams({"c": selectedComics.length}),
|
content: "Delete @c comics?"
|
||||||
btnColor: context.colorScheme.error,
|
.tlParams({"c": selectedComics.length}),
|
||||||
onConfirm: () {
|
btnColor: context.colorScheme.error,
|
||||||
_deleteComicWithId();
|
onConfirm: () {
|
||||||
},
|
_deleteComicWithId();
|
||||||
);
|
},
|
||||||
}),
|
);
|
||||||
|
}),
|
||||||
MenuEntry(
|
MenuEntry(
|
||||||
icon: Icons.download,
|
icon: Icons.download,
|
||||||
text: "Download".tl,
|
text: "Download".tl,
|
||||||
@@ -366,6 +512,18 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
if (selectedComics.length == 1)
|
||||||
|
MenuEntry(
|
||||||
|
icon: Icons.chrome_reader_mode_outlined,
|
||||||
|
text: "Read".tl,
|
||||||
|
onClick: () {
|
||||||
|
final c = selectedComics.keys.first as FavoriteItem;
|
||||||
|
App.rootContext.to(() => ReaderWithLoading(
|
||||||
|
id: c.id,
|
||||||
|
sourceKey: c.sourceKey,
|
||||||
|
));
|
||||||
|
},
|
||||||
|
),
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@@ -380,9 +538,9 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
|||||||
icon: const Icon(Icons.close),
|
icon: const Icon(Icons.close),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
searchMode = false;
|
setState(() {
|
||||||
keyword = "";
|
searchMode = false;
|
||||||
updateComics();
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -391,131 +549,142 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
|||||||
autofocus: true,
|
autofocus: true,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: "Search".tl,
|
hintText: "Search".tl,
|
||||||
border: InputBorder.none,
|
border: UnderlineInputBorder(),
|
||||||
),
|
),
|
||||||
onChanged: (v) {
|
onChanged: (v) {
|
||||||
keyword = v;
|
keyword = v;
|
||||||
updateComics();
|
updateSearchResult();
|
||||||
},
|
},
|
||||||
),
|
).paddingBottom(8).paddingRight(8),
|
||||||
),
|
),
|
||||||
SliverGridComics(
|
if (isLoading)
|
||||||
comics: comics,
|
SliverToBoxAdapter(
|
||||||
selections: selectedComics,
|
child: SizedBox(
|
||||||
menuBuilder: (c) {
|
height: 200,
|
||||||
return [
|
child: const Center(
|
||||||
MenuEntry(
|
child: CircularProgressIndicator(),
|
||||||
icon: Icons.delete,
|
|
||||||
text: "Delete".tl,
|
|
||||||
onClick: () {
|
|
||||||
LocalFavoritesManager().deleteComicWithId(
|
|
||||||
widget.folder,
|
|
||||||
c.id,
|
|
||||||
(c as FavoriteItem).type,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
MenuEntry(
|
),
|
||||||
icon: Icons.check,
|
)
|
||||||
text: "Select".tl,
|
else
|
||||||
onClick: () {
|
SliverGridComics(
|
||||||
setState(() {
|
comics: searchMode ? searchResults : comics,
|
||||||
if (!multiSelectMode) {
|
selections: selectedComics,
|
||||||
multiSelectMode = true;
|
menuBuilder: (c) {
|
||||||
}
|
return [
|
||||||
if (selectedComics.containsKey(c as FavoriteItem)) {
|
if (!isAllFolder)
|
||||||
selectedComics.remove(c);
|
MenuEntry(
|
||||||
_checkExitSelectMode();
|
icon: Icons.delete,
|
||||||
} else {
|
text: "Delete".tl,
|
||||||
selectedComics[c] = true;
|
onClick: () {
|
||||||
}
|
LocalFavoritesManager().deleteComicWithId(
|
||||||
lastSelectedIndex = comics.indexOf(c);
|
widget.folder,
|
||||||
});
|
c.id,
|
||||||
},
|
(c as FavoriteItem).type,
|
||||||
),
|
);
|
||||||
MenuEntry(
|
},
|
||||||
icon: Icons.download,
|
),
|
||||||
text: "Download".tl,
|
|
||||||
onClick: () {
|
|
||||||
downloadComic(c as FavoriteItem);
|
|
||||||
context.showMessage(
|
|
||||||
message: "Download started".tl,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
if (appdata.settings["onClickFavorite"] == "viewDetail")
|
|
||||||
MenuEntry(
|
MenuEntry(
|
||||||
icon: Icons.menu_book_outlined,
|
icon: Icons.check,
|
||||||
text: "Read".tl,
|
text: "Select".tl,
|
||||||
onClick: () {
|
onClick: () {
|
||||||
App.mainNavigatorKey?.currentContext?.to(
|
setState(() {
|
||||||
() => ReaderWithLoading(
|
if (!multiSelectMode) {
|
||||||
id: c.id,
|
multiSelectMode = true;
|
||||||
sourceKey: c.sourceKey,
|
}
|
||||||
),
|
if (selectedComics.containsKey(c as FavoriteItem)) {
|
||||||
|
selectedComics.remove(c);
|
||||||
|
_checkExitSelectMode();
|
||||||
|
} else {
|
||||||
|
selectedComics[c] = true;
|
||||||
|
}
|
||||||
|
lastSelectedIndex = comics.indexOf(c);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
MenuEntry(
|
||||||
|
icon: Icons.download,
|
||||||
|
text: "Download".tl,
|
||||||
|
onClick: () {
|
||||||
|
downloadComic(c as FavoriteItem);
|
||||||
|
context.showMessage(
|
||||||
|
message: "Download started".tl,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
];
|
if (appdata.settings["onClickFavorite"] == "viewDetail")
|
||||||
},
|
MenuEntry(
|
||||||
onTap: (c) {
|
icon: Icons.menu_book_outlined,
|
||||||
if (multiSelectMode) {
|
text: "Read".tl,
|
||||||
setState(() {
|
onClick: () {
|
||||||
if (selectedComics.containsKey(c as FavoriteItem)) {
|
App.mainNavigatorKey?.currentContext?.to(
|
||||||
selectedComics.remove(c);
|
() => ReaderWithLoading(
|
||||||
_checkExitSelectMode();
|
id: c.id,
|
||||||
} else {
|
sourceKey: c.sourceKey,
|
||||||
selectedComics[c] = true;
|
),
|
||||||
}
|
);
|
||||||
lastSelectedIndex = comics.indexOf(c);
|
},
|
||||||
});
|
),
|
||||||
} else if (appdata.settings["onClickFavorite"] == "viewDetail") {
|
];
|
||||||
App.mainNavigatorKey?.currentContext
|
},
|
||||||
?.to(() => ComicPage(id: c.id, sourceKey: c.sourceKey));
|
onTap: (c) {
|
||||||
} else {
|
if (multiSelectMode) {
|
||||||
App.mainNavigatorKey?.currentContext?.to(
|
setState(() {
|
||||||
() => ReaderWithLoading(
|
if (selectedComics.containsKey(c as FavoriteItem)) {
|
||||||
id: c.id,
|
selectedComics.remove(c);
|
||||||
sourceKey: c.sourceKey,
|
_checkExitSelectMode();
|
||||||
),
|
} else {
|
||||||
);
|
selectedComics[c] = true;
|
||||||
}
|
|
||||||
},
|
|
||||||
onLongPressed: (c) {
|
|
||||||
setState(() {
|
|
||||||
if (!multiSelectMode) {
|
|
||||||
multiSelectMode = true;
|
|
||||||
if (!selectedComics.containsKey(c as FavoriteItem)) {
|
|
||||||
selectedComics[c] = true;
|
|
||||||
}
|
|
||||||
lastSelectedIndex = comics.indexOf(c);
|
|
||||||
} else {
|
|
||||||
if (lastSelectedIndex != null) {
|
|
||||||
int start = lastSelectedIndex!;
|
|
||||||
int end = comics.indexOf(c as FavoriteItem);
|
|
||||||
if (start > end) {
|
|
||||||
int temp = start;
|
|
||||||
start = end;
|
|
||||||
end = temp;
|
|
||||||
}
|
}
|
||||||
|
lastSelectedIndex = comics.indexOf(c);
|
||||||
|
});
|
||||||
|
} else if (appdata.settings["onClickFavorite"] == "viewDetail") {
|
||||||
|
App.mainNavigatorKey?.currentContext
|
||||||
|
?.to(() => ComicPage(id: c.id, sourceKey: c.sourceKey));
|
||||||
|
} else {
|
||||||
|
App.mainNavigatorKey?.currentContext?.to(
|
||||||
|
() => ReaderWithLoading(
|
||||||
|
id: c.id,
|
||||||
|
sourceKey: c.sourceKey,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onLongPressed: (c) {
|
||||||
|
setState(() {
|
||||||
|
if (!multiSelectMode) {
|
||||||
|
multiSelectMode = true;
|
||||||
|
if (!selectedComics.containsKey(c as FavoriteItem)) {
|
||||||
|
selectedComics[c] = true;
|
||||||
|
}
|
||||||
|
lastSelectedIndex = comics.indexOf(c);
|
||||||
|
} else {
|
||||||
|
if (lastSelectedIndex != null) {
|
||||||
|
int start = lastSelectedIndex!;
|
||||||
|
int end = comics.indexOf(c as FavoriteItem);
|
||||||
|
if (start > end) {
|
||||||
|
int temp = start;
|
||||||
|
start = end;
|
||||||
|
end = temp;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = start; i <= end; i++) {
|
for (int i = start; i <= end; i++) {
|
||||||
if (i == lastSelectedIndex) continue;
|
if (i == lastSelectedIndex) continue;
|
||||||
|
|
||||||
var comic = comics[i];
|
var comic = comics[i];
|
||||||
if (selectedComics.containsKey(comic)) {
|
if (selectedComics.containsKey(comic)) {
|
||||||
selectedComics.remove(comic);
|
selectedComics.remove(comic);
|
||||||
} else {
|
} else {
|
||||||
selectedComics[comic] = true;
|
selectedComics[comic] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lastSelectedIndex = comics.indexOf(c as FavoriteItem);
|
||||||
}
|
}
|
||||||
lastSelectedIndex = comics.indexOf(c as FavoriteItem);
|
_checkExitSelectMode();
|
||||||
}
|
});
|
||||||
_checkExitSelectMode();
|
},
|
||||||
});
|
),
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
body = AppScrollBar(
|
body = AppScrollBar(
|
||||||
@@ -638,32 +807,26 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (option == 'move') {
|
if (option == 'move') {
|
||||||
for (var c in selectedComics.keys) {
|
var comics = selectedComics.keys
|
||||||
for (var s in selectedLocalFolders) {
|
.map((e) => e as FavoriteItem)
|
||||||
LocalFavoritesManager().moveFavorite(
|
.toList();
|
||||||
favPage.folder as String,
|
for (var f in selectedLocalFolders) {
|
||||||
s,
|
LocalFavoritesManager().batchMoveFavorites(
|
||||||
c.id,
|
favPage.folder as String,
|
||||||
(c as FavoriteItem).type);
|
f,
|
||||||
}
|
comics,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (var c in selectedComics.keys) {
|
var comics = selectedComics.keys
|
||||||
for (var s in selectedLocalFolders) {
|
.map((e) => e as FavoriteItem)
|
||||||
LocalFavoritesManager().addComic(
|
.toList();
|
||||||
s,
|
for (var f in selectedLocalFolders) {
|
||||||
FavoriteItem(
|
LocalFavoritesManager().batchCopyFavorites(
|
||||||
id: c.id,
|
favPage.folder as String,
|
||||||
name: c.title,
|
f,
|
||||||
coverPath: c.cover,
|
comics,
|
||||||
author: c.subtitle ?? '',
|
);
|
||||||
type: ComicType((c.sourceKey == 'local'
|
|
||||||
? 0
|
|
||||||
: c.sourceKey.hashCode)),
|
|
||||||
tags: c.tags ?? [],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
App.rootContext.pop();
|
App.rootContext.pop();
|
||||||
@@ -699,13 +862,8 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _deleteComicWithId() {
|
void _deleteComicWithId() {
|
||||||
for (var c in selectedComics.keys) {
|
var toBeDeleted = selectedComics.keys.map((e) => e as FavoriteItem).toList();
|
||||||
LocalFavoritesManager().deleteComicWithId(
|
LocalFavoritesManager().batchDeleteComics(widget.folder, toBeDeleted);
|
||||||
widget.folder,
|
|
||||||
c.id,
|
|
||||||
(c as FavoriteItem).type,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
_cancel();
|
_cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -725,7 +883,7 @@ class _ReorderComicsPageState extends State<_ReorderComicsPage> {
|
|||||||
final _key = GlobalKey();
|
final _key = GlobalKey();
|
||||||
var reorderWidgetKey = UniqueKey();
|
var reorderWidgetKey = UniqueKey();
|
||||||
final _scrollController = ScrollController();
|
final _scrollController = ScrollController();
|
||||||
late var comics = LocalFavoritesManager().getAllComics(widget.name);
|
late var comics = LocalFavoritesManager().getFolderComics(widget.name);
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
static int _floatToInt8(double x) {
|
static int _floatToInt8(double x) {
|
||||||
@@ -746,7 +904,10 @@ class _ReorderComicsPageState extends State<_ReorderComicsPage> {
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
if (changed) {
|
if (changed) {
|
||||||
LocalFavoritesManager().reorder(comics, widget.name);
|
// Delay to ensure navigation is completed
|
||||||
|
Future.delayed(const Duration(milliseconds: 200), () {
|
||||||
|
LocalFavoritesManager().reorder(comics, widget.name);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
@@ -781,27 +942,31 @@ class _ReorderComicsPageState extends State<_ReorderComicsPage> {
|
|||||||
appBar: Appbar(
|
appBar: Appbar(
|
||||||
title: Text("Reorder".tl),
|
title: Text("Reorder".tl),
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
Tooltip(
|
||||||
icon: const Icon(Icons.info_outline),
|
message: "Information".tl,
|
||||||
onPressed: () {
|
child: IconButton(
|
||||||
showInfoDialog(
|
icon: const Icon(Icons.info_outline),
|
||||||
context: context,
|
onPressed: () {
|
||||||
title: "Reorder".tl,
|
showInfoDialog(
|
||||||
content: "Long press and drag to reorder.".tl,
|
context: context,
|
||||||
);
|
title: "Reorder".tl,
|
||||||
},
|
content: "Long press and drag to reorder.".tl,
|
||||||
),
|
);
|
||||||
IconButton(
|
},
|
||||||
icon: const Icon(Icons.swap_vert),
|
),
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
comics = comics.reversed.toList();
|
|
||||||
changed = true;
|
|
||||||
showToast(
|
|
||||||
message: "Reversed successfully".tl, context: context);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
|
Tooltip(
|
||||||
|
message: "Reverse".tl,
|
||||||
|
child: IconButton(
|
||||||
|
icon: const Icon(Icons.swap_vert),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
comics = comics.reversed.toList();
|
||||||
|
changed = true;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: ReorderableBuilder<FavoriteItem>(
|
body: ReorderableBuilder<FavoriteItem>(
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
part of 'favorites_page.dart';
|
|
||||||
|
|
||||||
class LocalSearchPage extends StatefulWidget {
|
|
||||||
const LocalSearchPage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<LocalSearchPage> createState() => _LocalSearchPageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _LocalSearchPageState extends State<LocalSearchPage> {
|
|
||||||
String keyword = '';
|
|
||||||
|
|
||||||
var comics = <FavoriteItemWithFolderInfo>[];
|
|
||||||
|
|
||||||
late final SearchBarController controller;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
controller = SearchBarController(onSearch: (text) {
|
|
||||||
keyword = text;
|
|
||||||
comics = LocalFavoritesManager().search(keyword);
|
|
||||||
setState(() {});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
body: SmoothCustomScrollView(slivers: [
|
|
||||||
SliverSearchBar(controller: controller),
|
|
||||||
SliverGridComics(
|
|
||||||
comics: comics,
|
|
||||||
badgeBuilder: (c) {
|
|
||||||
return (c as FavoriteItemWithFolderInfo).folder;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -36,6 +36,8 @@ Future<bool> _deleteComic(
|
|||||||
favId,
|
favId,
|
||||||
);
|
);
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
|
// Invalidate network cache so next loads fetch fresh data
|
||||||
|
NetworkCacheManager().clear();
|
||||||
context.showMessage(message: "Deleted".tl);
|
context.showMessage(message: "Deleted".tl);
|
||||||
result = true;
|
result = true;
|
||||||
context.pop();
|
context.pop();
|
||||||
@@ -115,6 +117,8 @@ class _NormalFavoritePageState extends State<_NormalFavoritePage> {
|
|||||||
child: IconButton(
|
child: IconButton(
|
||||||
icon: const Icon(Icons.refresh),
|
icon: const Icon(Icons.refresh),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
// Force refresh bypassing cache
|
||||||
|
NetworkCacheManager().clear();
|
||||||
comicListKey.currentState!.refresh();
|
comicListKey.currentState!.refresh();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
|
|||||||
folders = LocalFavoritesManager().folderNames;
|
folders = LocalFavoritesManager().folderNames;
|
||||||
findNetworkFolders();
|
findNetworkFolders();
|
||||||
appdata.settings.addListener(updateFolders);
|
appdata.settings.addListener(updateFolders);
|
||||||
|
LocalFavoritesManager().addListener(updateFolders);
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +50,7 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
|
|||||||
void dispose() {
|
void dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
appdata.settings.removeListener(updateFolders);
|
appdata.settings.removeListener(updateFolders);
|
||||||
|
LocalFavoritesManager().removeListener(updateFolders);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -86,58 +88,14 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
|
|||||||
padding: widget.withAppbar
|
padding: widget.withAppbar
|
||||||
? EdgeInsets.zero
|
? EdgeInsets.zero
|
||||||
: EdgeInsets.only(top: context.padding.top),
|
: EdgeInsets.only(top: context.padding.top),
|
||||||
itemCount: folders.length + networkFolders.length + 2,
|
itemCount: folders.length + networkFolders.length + 3,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
return Container(
|
return buildLocalTitle();
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
}
|
||||||
child: Row(
|
index--;
|
||||||
children: [
|
if (index == 0) {
|
||||||
Icon(
|
return buildLocalFolder(_localAllFolderLabel);
|
||||||
Icons.local_activity,
|
|
||||||
color: context.colorScheme.secondary,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Text("Local".tl),
|
|
||||||
const Spacer(),
|
|
||||||
MenuButton(
|
|
||||||
entries: [
|
|
||||||
MenuEntry(
|
|
||||||
icon: Icons.search,
|
|
||||||
text: 'Search'.tl,
|
|
||||||
onClick: () {
|
|
||||||
context.to(() => const LocalSearchPage());
|
|
||||||
},
|
|
||||||
),
|
|
||||||
MenuEntry(
|
|
||||||
icon: Icons.add,
|
|
||||||
text: 'Create Folder'.tl,
|
|
||||||
onClick: () {
|
|
||||||
newFolder().then((value) {
|
|
||||||
setState(() {
|
|
||||||
folders =
|
|
||||||
LocalFavoritesManager().folderNames;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
MenuEntry(
|
|
||||||
icon: Icons.reorder,
|
|
||||||
text: 'Sort'.tl,
|
|
||||||
onClick: () {
|
|
||||||
sortFolders().then((value) {
|
|
||||||
setState(() {
|
|
||||||
folders =
|
|
||||||
LocalFavoritesManager().folderNames;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
).paddingHorizontal(16),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
index--;
|
index--;
|
||||||
if (index < folders.length) {
|
if (index < folders.length) {
|
||||||
@@ -145,38 +103,7 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
|
|||||||
}
|
}
|
||||||
index -= folders.length;
|
index -= folders.length;
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
return Container(
|
return buildNetworkTitle();
|
||||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
||||||
margin: const EdgeInsets.only(top: 8),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
border: Border(
|
|
||||||
top: BorderSide(
|
|
||||||
color: context.colorScheme.outlineVariant,
|
|
||||||
width: 0.6,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(
|
|
||||||
Icons.cloud,
|
|
||||||
color: context.colorScheme.secondary,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
Text("Network".tl),
|
|
||||||
const Spacer(),
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.settings),
|
|
||||||
onPressed: () {
|
|
||||||
showPopUpWidget(
|
|
||||||
App.rootContext,
|
|
||||||
setFavoritesPagesWidget(),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
).paddingHorizontal(16),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
index--;
|
index--;
|
||||||
return buildNetworkFolder(networkFolders[index]);
|
return buildNetworkFolder(networkFolders[index]);
|
||||||
@@ -188,8 +115,95 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget buildLocalTitle() {
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.local_activity,
|
||||||
|
color: context.colorScheme.secondary,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Text("Local".tl),
|
||||||
|
const Spacer(),
|
||||||
|
MenuButton(
|
||||||
|
entries: [
|
||||||
|
MenuEntry(
|
||||||
|
icon: Icons.add,
|
||||||
|
text: 'Create Folder'.tl,
|
||||||
|
onClick: () {
|
||||||
|
newFolder().then((value) {
|
||||||
|
setState(() {
|
||||||
|
folders = LocalFavoritesManager().folderNames;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
MenuEntry(
|
||||||
|
icon: Icons.reorder,
|
||||||
|
text: 'Sort'.tl,
|
||||||
|
onClick: () {
|
||||||
|
sortFolders().then((value) {
|
||||||
|
setState(() {
|
||||||
|
folders = LocalFavoritesManager().folderNames;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
).paddingHorizontal(16),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget buildNetworkTitle() {
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||||
|
margin: const EdgeInsets.only(top: 8),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border(
|
||||||
|
top: BorderSide(
|
||||||
|
color: context.colorScheme.outlineVariant,
|
||||||
|
width: 0.6,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.cloud,
|
||||||
|
color: context.colorScheme.secondary,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Text("Network".tl),
|
||||||
|
const Spacer(),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.settings),
|
||||||
|
onPressed: () {
|
||||||
|
showPopUpWidget(
|
||||||
|
App.rootContext,
|
||||||
|
setFavoritesPagesWidget(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
).paddingHorizontal(16),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Widget buildLocalFolder(String name) {
|
Widget buildLocalFolder(String name) {
|
||||||
bool isSelected = name == favPage.folder && !favPage.isNetwork;
|
bool isSelected = name == favPage.folder && !favPage.isNetwork;
|
||||||
|
int count = 0;
|
||||||
|
if (name == _localAllFolderLabel) {
|
||||||
|
count = LocalFavoritesManager().totalComics;
|
||||||
|
} else {
|
||||||
|
count = LocalFavoritesManager().folderComics(name);
|
||||||
|
}
|
||||||
|
var folderName = name == _localAllFolderLabel
|
||||||
|
? "All".tl
|
||||||
|
: getFavoriteDataOrNull(name)?.title ?? name;
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
@@ -214,7 +228,25 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.only(left: 16),
|
padding: const EdgeInsets.only(left: 16),
|
||||||
child: Text(name),
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(folderName),
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
margin: EdgeInsets.only(right: 8),
|
||||||
|
padding: EdgeInsets.symmetric(
|
||||||
|
horizontal: 8,
|
||||||
|
vertical: 2,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: context.colorScheme.surfaceContainer,
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
child: Text(count.toString()),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import 'package:venera/components/components.dart';
|
|||||||
import 'package:venera/foundation/app.dart';
|
import 'package:venera/foundation/app.dart';
|
||||||
import 'package:venera/foundation/appdata.dart';
|
import 'package:venera/foundation/appdata.dart';
|
||||||
import 'package:venera/foundation/favorites.dart';
|
import 'package:venera/foundation/favorites.dart';
|
||||||
import 'package:venera/foundation/log.dart';
|
|
||||||
import 'package:venera/utils/data_sync.dart';
|
import 'package:venera/utils/data_sync.dart';
|
||||||
import 'package:venera/utils/translations.dart';
|
import 'package:venera/utils/translations.dart';
|
||||||
import '../foundation/global_state.dart';
|
import '../foundation/global_state.dart';
|
||||||
|
import 'package:venera/foundation/follow_updates.dart';
|
||||||
|
|
||||||
class FollowUpdatesWidget extends StatefulWidget {
|
class FollowUpdatesWidget extends StatefulWidget {
|
||||||
const FollowUpdatesWidget({super.key});
|
const FollowUpdatesWidget({super.key});
|
||||||
@@ -460,7 +460,7 @@ class _FollowUpdatesPageState extends AutomaticGlobalState<FollowUpdatesPage> {
|
|||||||
message: "Updating comics...".tl,
|
message: "Updating comics...".tl,
|
||||||
);
|
);
|
||||||
|
|
||||||
await for (var progress in _updateFolder(folder, true)) {
|
await for (var progress in updateFolder(folder, true)) {
|
||||||
if (isCanceled) {
|
if (isCanceled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -497,7 +497,7 @@ class _FollowUpdatesPageState extends AutomaticGlobalState<FollowUpdatesPage> {
|
|||||||
|
|
||||||
int updated = 0;
|
int updated = 0;
|
||||||
|
|
||||||
await for (var progress in _updateFolder(folder!, true)) {
|
await for (var progress in updateFolder(folder!, true)) {
|
||||||
if (isCanceled) {
|
if (isCanceled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -532,128 +532,6 @@ class _FollowUpdatesPageState extends AutomaticGlobalState<FollowUpdatesPage> {
|
|||||||
Object? get key => 'FollowUpdatesPage';
|
Object? get key => 'FollowUpdatesPage';
|
||||||
}
|
}
|
||||||
|
|
||||||
class _UpdateProgress {
|
|
||||||
final int total;
|
|
||||||
final int current;
|
|
||||||
final int errors;
|
|
||||||
final int updated;
|
|
||||||
|
|
||||||
_UpdateProgress(this.total, this.current, this.errors, this.updated);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _updateFolderBase(
|
|
||||||
String folder,
|
|
||||||
StreamController<_UpdateProgress> stream,
|
|
||||||
bool ignoreCheckTime,
|
|
||||||
) async {
|
|
||||||
var comics = LocalFavoritesManager().getComicsWithUpdatesInfo(folder);
|
|
||||||
int current = 0;
|
|
||||||
int errors = 0;
|
|
||||||
int updated = 0;
|
|
||||||
var futures = <Future>[];
|
|
||||||
const maxConcurrent = 5;
|
|
||||||
|
|
||||||
for (int i = 0; i < comics.length; i++) {
|
|
||||||
if (stream.isClosed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!ignoreCheckTime) {
|
|
||||||
var lastCheckTime = comics[i].lastCheckTime;
|
|
||||||
if (lastCheckTime != null &&
|
|
||||||
DateTime.now().difference(lastCheckTime).inDays < 1) {
|
|
||||||
current++;
|
|
||||||
stream.add(_UpdateProgress(comics.length, current, errors, updated));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (futures.length >= maxConcurrent) {
|
|
||||||
await Future.any(futures);
|
|
||||||
}
|
|
||||||
|
|
||||||
var future = () async {
|
|
||||||
int retries = 3;
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
var c = comics[i];
|
|
||||||
var comicSource = c.type.comicSource;
|
|
||||||
if (comicSource == null) return;
|
|
||||||
var newInfo = (await comicSource.loadComicInfo!(c.id)).data;
|
|
||||||
|
|
||||||
var newTags = <String>[];
|
|
||||||
for (var entry in newInfo.tags.entries) {
|
|
||||||
const shouldIgnore = ['author', 'artist', 'time'];
|
|
||||||
var namespace = entry.key;
|
|
||||||
if (shouldIgnore.contains(namespace.toLowerCase())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (var tag in entry.value) {
|
|
||||||
newTags.add("$namespace:$tag");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var item = FavoriteItem(
|
|
||||||
id: c.id,
|
|
||||||
name: newInfo.title,
|
|
||||||
coverPath: newInfo.cover,
|
|
||||||
author: newInfo.subTitle ??
|
|
||||||
newInfo.tags['author']?.firstOrNull ??
|
|
||||||
c.author,
|
|
||||||
type: c.type,
|
|
||||||
tags: newTags,
|
|
||||||
);
|
|
||||||
|
|
||||||
LocalFavoritesManager().updateInfo(folder, item, false);
|
|
||||||
|
|
||||||
var updateTime = newInfo.findUpdateTime();
|
|
||||||
if (updateTime != null && updateTime != c.updateTime) {
|
|
||||||
LocalFavoritesManager().updateUpdateTime(
|
|
||||||
folder,
|
|
||||||
c.id,
|
|
||||||
c.type,
|
|
||||||
updateTime,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
LocalFavoritesManager().updateCheckTime(folder, c.id, c.type);
|
|
||||||
}
|
|
||||||
updated++;
|
|
||||||
return;
|
|
||||||
} catch (e, s) {
|
|
||||||
Log.error("Check Updates", e, s);
|
|
||||||
retries--;
|
|
||||||
if (retries == 0) {
|
|
||||||
errors++;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
current++;
|
|
||||||
stream.add(_UpdateProgress(comics.length, current, errors, updated));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}();
|
|
||||||
|
|
||||||
future.then((_) {
|
|
||||||
futures.remove(future);
|
|
||||||
});
|
|
||||||
|
|
||||||
futures.add(future);
|
|
||||||
}
|
|
||||||
|
|
||||||
await Future.wait(futures);
|
|
||||||
|
|
||||||
if (updated > 0) {
|
|
||||||
LocalFavoritesManager().notifyChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
stream.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
Stream<_UpdateProgress> _updateFolder(String folder, bool ignoreCheckTime) {
|
|
||||||
var stream = StreamController<_UpdateProgress>();
|
|
||||||
_updateFolderBase(folder, stream, ignoreCheckTime);
|
|
||||||
return stream.stream;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Background service for checking updates
|
/// Background service for checking updates
|
||||||
abstract class FollowUpdatesService {
|
abstract class FollowUpdatesService {
|
||||||
static bool _isChecking = false;
|
static bool _isChecking = false;
|
||||||
@@ -683,7 +561,7 @@ abstract class FollowUpdatesService {
|
|||||||
|
|
||||||
int updated = 0;
|
int updated = 0;
|
||||||
try {
|
try {
|
||||||
await for (var progress in _updateFolder(folder, false)) {
|
await for (var progress in updateFolder(folder, false)) {
|
||||||
if (isCanceled) {
|
if (isCanceled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,6 +140,14 @@ class _HistoryPageState extends State<HistoryPage> {
|
|||||||
title: 'Clear History'.tl,
|
title: 'Clear History'.tl,
|
||||||
content: Text('Are you sure you want to clear your history?'.tl),
|
content: Text('Are you sure you want to clear your history?'.tl),
|
||||||
actions: [
|
actions: [
|
||||||
|
Button.outlined(
|
||||||
|
onPressed: () {
|
||||||
|
HistoryManager().clearUnfavoritedHistory();
|
||||||
|
context.pop();
|
||||||
|
},
|
||||||
|
child: Text('Clear Unfavorited'.tl),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
Button.filled(
|
Button.filled(
|
||||||
color: context.colorScheme.error,
|
color: context.colorScheme.error,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class _SearchBar extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SliverToBoxAdapter(
|
return SliverToBoxAdapter(
|
||||||
child: Container(
|
child: Container(
|
||||||
height: 52,
|
height: App.isMobile ? 52 : 46,
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
||||||
child: Material(
|
child: Material(
|
||||||
@@ -514,51 +514,53 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
|
|||||||
child: CircularProgressIndicator(),
|
child: CircularProgressIndicator(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: Column(
|
: RadioGroup<int>(
|
||||||
key: key,
|
groupValue: type,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
onChanged: (value) {
|
||||||
children: [
|
setState(() {
|
||||||
const SizedBox(width: 600),
|
type = value ?? type;
|
||||||
...List.generate(importMethods.length, (index) {
|
});
|
||||||
return RadioListTile(
|
},
|
||||||
title: Text(importMethods[index]),
|
child: Column(
|
||||||
value: index,
|
key: key,
|
||||||
groupValue: type,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
onChanged: (value) {
|
children: [
|
||||||
setState(() {
|
const SizedBox(width: 600),
|
||||||
type = value as int;
|
...List.generate(importMethods.length, (index) {
|
||||||
});
|
return RadioListTile<int>(
|
||||||
},
|
title: Text(importMethods[index]),
|
||||||
);
|
value: index,
|
||||||
}),
|
);
|
||||||
if (type != 4)
|
}),
|
||||||
ListTile(
|
if (type != 4)
|
||||||
title: Text("Add to favorites".tl),
|
ListTile(
|
||||||
trailing: Select(
|
title: Text("Add to favorites".tl),
|
||||||
current: selectedFolder,
|
trailing: Select(
|
||||||
values: folders,
|
current: selectedFolder,
|
||||||
minWidth: 112,
|
values: folders,
|
||||||
onTap: (v) {
|
minWidth: 112,
|
||||||
setState(() {
|
onTap: (v) {
|
||||||
selectedFolder = folders[v];
|
setState(() {
|
||||||
});
|
selectedFolder = folders[v];
|
||||||
},
|
});
|
||||||
),
|
},
|
||||||
).paddingHorizontal(8),
|
),
|
||||||
if (!App.isIOS && !App.isMacOS && type != 2 && type != 3)
|
).paddingHorizontal(8),
|
||||||
CheckboxListTile(
|
if (!App.isIOS && !App.isMacOS && type != 2 && type != 3)
|
||||||
enabled: true,
|
CheckboxListTile(
|
||||||
title: Text("Copy to app local path".tl),
|
enabled: true,
|
||||||
value: copyToLocalFolder,
|
title: Text("Copy to app local path".tl),
|
||||||
onChanged: (v) {
|
value: copyToLocalFolder,
|
||||||
setState(() {
|
onChanged: (v) {
|
||||||
copyToLocalFolder = !copyToLocalFolder;
|
setState(() {
|
||||||
});
|
copyToLocalFolder = !copyToLocalFolder;
|
||||||
}).paddingHorizontal(8),
|
});
|
||||||
const SizedBox(height: 8),
|
}).paddingHorizontal(8),
|
||||||
Text(info).paddingHorizontal(24),
|
const SizedBox(height: 8),
|
||||||
],
|
Text(info).paddingHorizontal(24),
|
||||||
),
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
actions: [
|
actions: [
|
||||||
Button.text(
|
Button.text(
|
||||||
child: Row(
|
child: Row(
|
||||||
@@ -942,7 +944,7 @@ class _ImageFavoritesState extends State<ImageFavorites> {
|
|||||||
displayType = type;
|
displayType = type;
|
||||||
});
|
});
|
||||||
await Future.delayed(const Duration(milliseconds: 20));
|
await Future.delayed(const Duration(milliseconds: 20));
|
||||||
var scrollController = ScrollControllerProvider.of(context);
|
var scrollController = ScrollState.of(context).controller;
|
||||||
scrollController.animateTo(
|
scrollController.animateTo(
|
||||||
scrollController.position.maxScrollExtent,
|
scrollController.position.maxScrollExtent,
|
||||||
duration: const Duration(milliseconds: 200),
|
duration: const Duration(milliseconds: 200),
|
||||||
|
|||||||
@@ -404,21 +404,23 @@ class _ImageFavoritesDialogState extends State<_ImageFavoritesDialog> {
|
|||||||
children: [
|
children: [
|
||||||
tabBar,
|
tabBar,
|
||||||
TabViewBody(children: [
|
TabViewBody(children: [
|
||||||
Column(
|
RadioGroup<ImageFavoriteSortType>(
|
||||||
children: ImageFavoriteSortType.values
|
groupValue: sortType,
|
||||||
.map(
|
onChanged: (v) {
|
||||||
(e) => RadioListTile<ImageFavoriteSortType>(
|
setState(() {
|
||||||
title: Text(e.value.tl),
|
sortType = v ?? sortType;
|
||||||
value: e,
|
});
|
||||||
groupValue: sortType,
|
},
|
||||||
onChanged: (v) {
|
child: Column(
|
||||||
setState(() {
|
children: ImageFavoriteSortType.values
|
||||||
sortType = v!;
|
.map(
|
||||||
});
|
(e) => RadioListTile<ImageFavoriteSortType>(
|
||||||
},
|
title: Text(e.value.tl),
|
||||||
),
|
value: e,
|
||||||
)
|
),
|
||||||
.toList(),
|
)
|
||||||
|
.toList(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
Column(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import 'package:venera/utils/io.dart';
|
|||||||
import 'package:venera/utils/pdf.dart';
|
import 'package:venera/utils/pdf.dart';
|
||||||
import 'package:venera/utils/translations.dart';
|
import 'package:venera/utils/translations.dart';
|
||||||
import 'package:zip_flutter/zip_flutter.dart';
|
import 'package:zip_flutter/zip_flutter.dart';
|
||||||
|
import 'package:url_launcher/url_launcher_string.dart';
|
||||||
|
|
||||||
class LocalComicsPage extends StatefulWidget {
|
class LocalComicsPage extends StatefulWidget {
|
||||||
const LocalComicsPage({super.key});
|
const LocalComicsPage({super.key});
|
||||||
@@ -69,39 +70,29 @@ class _LocalComicsPageState extends State<LocalComicsPage> {
|
|||||||
return StatefulBuilder(builder: (context, setState) {
|
return StatefulBuilder(builder: (context, setState) {
|
||||||
return ContentDialog(
|
return ContentDialog(
|
||||||
title: "Sort".tl,
|
title: "Sort".tl,
|
||||||
content: Column(
|
content: RadioGroup<LocalSortType>(
|
||||||
children: [
|
groupValue: sortType,
|
||||||
RadioListTile<LocalSortType>(
|
onChanged: (v) {
|
||||||
title: Text("Name".tl),
|
setState(() {
|
||||||
value: LocalSortType.name,
|
sortType = v ?? sortType;
|
||||||
groupValue: sortType,
|
});
|
||||||
onChanged: (v) {
|
},
|
||||||
setState(() {
|
child: Column(
|
||||||
sortType = v!;
|
children: [
|
||||||
});
|
RadioListTile<LocalSortType>(
|
||||||
},
|
title: Text("Name".tl),
|
||||||
),
|
value: LocalSortType.name,
|
||||||
RadioListTile<LocalSortType>(
|
),
|
||||||
title: Text("Date".tl),
|
RadioListTile<LocalSortType>(
|
||||||
value: LocalSortType.timeAsc,
|
title: Text("Date".tl),
|
||||||
groupValue: sortType,
|
value: LocalSortType.timeAsc,
|
||||||
onChanged: (v) {
|
),
|
||||||
setState(() {
|
RadioListTile<LocalSortType>(
|
||||||
sortType = v!;
|
title: Text("Date Desc".tl),
|
||||||
});
|
value: LocalSortType.timeDesc,
|
||||||
},
|
),
|
||||||
),
|
],
|
||||||
RadioListTile<LocalSortType>(
|
),
|
||||||
title: Text("Date Desc".tl),
|
|
||||||
value: LocalSortType.timeDesc,
|
|
||||||
groupValue: sortType,
|
|
||||||
onChanged: (v) {
|
|
||||||
setState(() {
|
|
||||||
sortType = v!;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
FilledButton(
|
FilledButton(
|
||||||
@@ -143,6 +134,14 @@ class _LocalComicsPageState extends State<LocalComicsPage> {
|
|||||||
addFavorite(selectedComics.keys.toList());
|
addFavorite(selectedComics.keys.toList());
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
if (selectedComics.length == 1)
|
||||||
|
MenuEntry(
|
||||||
|
icon: Icons.folder_open,
|
||||||
|
text: "Open Folder".tl,
|
||||||
|
onClick: () {
|
||||||
|
openComicFolder(selectedComics.keys.first);
|
||||||
|
},
|
||||||
|
),
|
||||||
if (selectedComics.length == 1)
|
if (selectedComics.length == 1)
|
||||||
MenuEntry(
|
MenuEntry(
|
||||||
icon: Icons.chrome_reader_mode_outlined,
|
icon: Icons.chrome_reader_mode_outlined,
|
||||||
@@ -306,12 +305,20 @@ class _LocalComicsPageState extends State<LocalComicsPage> {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// prevent dirty data
|
// prevent dirty data
|
||||||
var comic = LocalManager().find(c.id, ComicType(c.sourceKey.hashCode))!;
|
var comic =
|
||||||
|
LocalManager().find(c.id, ComicType.fromKey(c.sourceKey))!;
|
||||||
comic.read();
|
comic.read();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
menuBuilder: (c) {
|
menuBuilder: (c) {
|
||||||
return [
|
return [
|
||||||
|
MenuEntry(
|
||||||
|
icon: Icons.folder_open,
|
||||||
|
text: "Open Folder".tl,
|
||||||
|
onClick: () {
|
||||||
|
openComicFolder(c as LocalComic);
|
||||||
|
},
|
||||||
|
),
|
||||||
MenuEntry(
|
MenuEntry(
|
||||||
icon: Icons.delete,
|
icon: Icons.delete,
|
||||||
text: "Delete".tl,
|
text: "Delete".tl,
|
||||||
@@ -360,28 +367,49 @@ class _LocalComicsPageState extends State<LocalComicsPage> {
|
|||||||
context: App.rootContext,
|
context: App.rootContext,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
bool removeComicFile = true;
|
bool removeComicFile = true;
|
||||||
|
bool removeFavoriteAndHistory = true;
|
||||||
return StatefulBuilder(builder: (context, state) {
|
return StatefulBuilder(builder: (context, state) {
|
||||||
return ContentDialog(
|
return ContentDialog(
|
||||||
title: "Delete".tl,
|
title: "Delete".tl,
|
||||||
content: CheckboxListTile(
|
content: Column(
|
||||||
title: Text("Also remove files on disk".tl),
|
children: [
|
||||||
value: removeComicFile,
|
CheckboxListTile(
|
||||||
onChanged: (v) {
|
title: Text("Remove local favorite and history".tl),
|
||||||
state(() {
|
value: removeFavoriteAndHistory,
|
||||||
removeComicFile = !removeComicFile;
|
onChanged: (v) {
|
||||||
});
|
state(() {
|
||||||
},
|
removeFavoriteAndHistory = !removeFavoriteAndHistory;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
CheckboxListTile(
|
||||||
|
title: Text("Also remove files on disk".tl),
|
||||||
|
value: removeComicFile,
|
||||||
|
onChanged: (v) {
|
||||||
|
state(() {
|
||||||
|
removeComicFile = !removeComicFile;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
|
if (comics.length == 1 && comics.first.hasChapters)
|
||||||
|
TextButton(
|
||||||
|
child: Text("Delete Chapters".tl),
|
||||||
|
onPressed: () {
|
||||||
|
context.pop();
|
||||||
|
showDeleteChaptersPopWindow(context, comics.first);
|
||||||
|
},
|
||||||
|
),
|
||||||
FilledButton(
|
FilledButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
context.pop();
|
context.pop();
|
||||||
for (var comic in comics) {
|
LocalManager().batchDeleteComics(
|
||||||
LocalManager().deleteComic(
|
comics,
|
||||||
comic,
|
removeComicFile,
|
||||||
removeComicFile,
|
removeFavoriteAndHistory,
|
||||||
);
|
);
|
||||||
}
|
|
||||||
isDeleted = true;
|
isDeleted = true;
|
||||||
},
|
},
|
||||||
child: Text("Confirm".tl),
|
child: Text("Confirm".tl),
|
||||||
@@ -444,7 +472,10 @@ class _LocalComicsPageState extends State<LocalComicsPage> {
|
|||||||
var fileName = "";
|
var fileName = "";
|
||||||
// For each comic, export it to a file
|
// For each comic, export it to a file
|
||||||
for (var comic in comics) {
|
for (var comic in comics) {
|
||||||
fileName = FilePath.join(cacheDir, sanitizeFileName(comic.title) + ext);
|
fileName = FilePath.join(
|
||||||
|
cacheDir,
|
||||||
|
sanitizeFileName(comic.title, maxLength: 100) + ext,
|
||||||
|
);
|
||||||
await export(comic, fileName);
|
await export(comic, fileName);
|
||||||
current++;
|
current++;
|
||||||
if (comics.length > 1) {
|
if (comics.length > 1) {
|
||||||
@@ -493,3 +524,102 @@ class _LocalComicsPageState extends State<LocalComicsPage> {
|
|||||||
|
|
||||||
typedef ExportComicFunc = Future<File> Function(
|
typedef ExportComicFunc = Future<File> Function(
|
||||||
LocalComic comic, String outFilePath);
|
LocalComic comic, String outFilePath);
|
||||||
|
|
||||||
|
/// Opens the folder containing the comic in the system file explorer
|
||||||
|
Future<void> openComicFolder(LocalComic comic) async {
|
||||||
|
try {
|
||||||
|
final folderPath = comic.baseDir;
|
||||||
|
|
||||||
|
if (App.isWindows) {
|
||||||
|
await Process.run('explorer', [folderPath]);
|
||||||
|
} else if (App.isMacOS) {
|
||||||
|
await Process.run('open', [folderPath]);
|
||||||
|
} else if (App.isLinux) {
|
||||||
|
// Try different file managers commonly found on Linux
|
||||||
|
try {
|
||||||
|
await Process.run('xdg-open', [folderPath]);
|
||||||
|
} catch (e) {
|
||||||
|
// Fallback to other common file managers
|
||||||
|
try {
|
||||||
|
await Process.run('nautilus', [folderPath]);
|
||||||
|
} catch (e) {
|
||||||
|
try {
|
||||||
|
await Process.run('dolphin', [folderPath]);
|
||||||
|
} catch (e) {
|
||||||
|
try {
|
||||||
|
await Process.run('thunar', [folderPath]);
|
||||||
|
} catch (e) {
|
||||||
|
// Last resort: use the URL launcher with file:// protocol
|
||||||
|
await launchUrlString('file://$folderPath');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// For mobile platforms, use the URL launcher with file:// protocol
|
||||||
|
await launchUrlString('file://$folderPath');
|
||||||
|
}
|
||||||
|
} catch (e, s) {
|
||||||
|
Log.error("Open Folder", "Failed to open comic folder: $e", s);
|
||||||
|
// Show error message to user
|
||||||
|
if (App.rootContext.mounted) {
|
||||||
|
App.rootContext.showMessage(message: "Failed to open folder: $e");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void showDeleteChaptersPopWindow(BuildContext context, LocalComic comic) {
|
||||||
|
var chapters = <String>[];
|
||||||
|
|
||||||
|
showPopUpWidget(
|
||||||
|
context,
|
||||||
|
PopUpWidgetScaffold(
|
||||||
|
title: "Delete Chapters".tl,
|
||||||
|
body: StatefulBuilder(builder: (context, setState) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: ListView.builder(
|
||||||
|
itemCount: comic.downloadedChapters.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
var id = comic.downloadedChapters[index];
|
||||||
|
var chapter = comic.chapters![id] ?? "Unknown Chapter";
|
||||||
|
return CheckboxListTile(
|
||||||
|
title: Text(chapter),
|
||||||
|
value: chapters.contains(id),
|
||||||
|
onChanged: (v) {
|
||||||
|
setState(() {
|
||||||
|
if (v == true) {
|
||||||
|
chapters.add(id);
|
||||||
|
} else {
|
||||||
|
chapters.remove(id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
FilledButton(
|
||||||
|
onPressed: () {
|
||||||
|
Future.delayed(const Duration(milliseconds: 200), () {
|
||||||
|
LocalManager().deleteComicChapters(comic, chapters);
|
||||||
|
});
|
||||||
|
App.rootContext.pop();
|
||||||
|
},
|
||||||
|
child: Text("Submit".tl),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ class ComicImage extends StatefulWidget {
|
|||||||
Map<String, String>? headers,
|
Map<String, String>? headers,
|
||||||
int? cacheWidth,
|
int? cacheWidth,
|
||||||
int? cacheHeight,
|
int? cacheHeight,
|
||||||
|
this.onInit,
|
||||||
|
this.onDispose,
|
||||||
}) : image = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, image),
|
}) : image = ResizeImage.resizeIfNeeded(cacheWidth, cacheHeight, image),
|
||||||
assert(cacheWidth == null || cacheWidth > 0),
|
assert(cacheWidth == null || cacheWidth > 0),
|
||||||
assert(cacheHeight == null || cacheHeight > 0);
|
assert(cacheHeight == null || cacheHeight > 0);
|
||||||
@@ -60,6 +62,10 @@ class ComicImage extends StatefulWidget {
|
|||||||
|
|
||||||
final bool isAntiAlias;
|
final bool isAntiAlias;
|
||||||
|
|
||||||
|
final void Function(State<ComicImage> state)? onInit;
|
||||||
|
|
||||||
|
final void Function(State<ComicImage> state)? onDispose;
|
||||||
|
|
||||||
static void clear() => _ComicImageState.clear();
|
static void clear() => _ComicImageState.clear();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -87,6 +93,7 @@ class _ComicImageState extends State<ComicImage> with WidgetsBindingObserver {
|
|||||||
super.initState();
|
super.initState();
|
||||||
WidgetsBinding.instance.addObserver(this);
|
WidgetsBinding.instance.addObserver(this);
|
||||||
_scrollAwareContext = DisposableBuildContext<State<ComicImage>>(this);
|
_scrollAwareContext = DisposableBuildContext<State<ComicImage>>(this);
|
||||||
|
widget.onInit?.call(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -97,6 +104,7 @@ class _ComicImageState extends State<ComicImage> with WidgetsBindingObserver {
|
|||||||
_completerHandle?.dispose();
|
_completerHandle?.dispose();
|
||||||
_scrollAwareContext.dispose();
|
_scrollAwareContext.dispose();
|
||||||
_replaceImage(info: null);
|
_replaceImage(info: null);
|
||||||
|
widget.onDispose?.call(this);
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,6 +144,15 @@ class _ComicImageState extends State<ComicImage> with WidgetsBindingObserver {
|
|||||||
super.reassemble();
|
super.reassemble();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool containsPoint(Offset point) {
|
||||||
|
if (!mounted) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var renderBox = context.findRenderObject() as RenderBox;
|
||||||
|
var localPoint = renderBox.globalToLocal(point);
|
||||||
|
return renderBox.paintBounds.contains(localPoint);
|
||||||
|
}
|
||||||
|
|
||||||
void _updateInvertColors() {
|
void _updateInvertColors() {
|
||||||
_invertColors = MediaQuery.maybeInvertColorsOf(context) ??
|
_invertColors = MediaQuery.maybeInvertColorsOf(context) ??
|
||||||
SemanticsBinding.instance.accessibilityFeatures.invertColors;
|
SemanticsBinding.instance.accessibilityFeatures.invertColors;
|
||||||
|
|||||||
@@ -152,12 +152,19 @@ class _ReaderGestureDetectorState extends AutomaticGlobalState<_ReaderGestureDet
|
|||||||
|
|
||||||
bool _dragInProgress = false;
|
bool _dragInProgress = false;
|
||||||
|
|
||||||
|
bool get _enableDoubleTapToZoom =>
|
||||||
|
appdata.settings.getReaderSetting(reader.cid, reader.type.sourceKey, 'enableDoubleTapToZoom');
|
||||||
|
|
||||||
void onTapUp(TapUpDetails event) {
|
void onTapUp(TapUpDetails event) {
|
||||||
if (_longPressInProgress) {
|
if (_longPressInProgress) {
|
||||||
_longPressInProgress = false;
|
_longPressInProgress = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final location = event.globalPosition;
|
final location = event.globalPosition;
|
||||||
|
if (!_enableDoubleTapToZoom) {
|
||||||
|
onTap(location);
|
||||||
|
return;
|
||||||
|
}
|
||||||
final previousLocation = _previousEvent?.globalPosition;
|
final previousLocation = _previousEvent?.globalPosition;
|
||||||
if (previousLocation != null) {
|
if (previousLocation != null) {
|
||||||
if ((location - previousLocation).distanceSquared <
|
if ((location - previousLocation).distanceSquared <
|
||||||
@@ -184,7 +191,8 @@ class _ReaderGestureDetectorState extends AutomaticGlobalState<_ReaderGestureDet
|
|||||||
} else if (context.readerScaffold.isOpen) {
|
} else if (context.readerScaffold.isOpen) {
|
||||||
context.readerScaffold.openOrClose();
|
context.readerScaffold.openOrClose();
|
||||||
} else {
|
} else {
|
||||||
if (appdata.settings['enableTapToTurnPages']) {
|
if (appdata.settings.getReaderSetting(
|
||||||
|
reader.cid, reader.type.sourceKey, 'enableTapToTurnPages')) {
|
||||||
bool isLeft = false, isRight = false, isTop = false, isBottom = false;
|
bool isLeft = false, isRight = false, isTop = false, isBottom = false;
|
||||||
final width = context.width;
|
final width = context.width;
|
||||||
final height = context.height;
|
final height = context.height;
|
||||||
@@ -201,11 +209,12 @@ class _ReaderGestureDetectorState extends AutomaticGlobalState<_ReaderGestureDet
|
|||||||
isBottom = true;
|
isBottom = true;
|
||||||
}
|
}
|
||||||
bool isCenter = false;
|
bool isCenter = false;
|
||||||
var prev = context.reader.toPrevPage;
|
var prev = () => context.reader.toPrevPage();
|
||||||
var next = context.reader.toNextPage;
|
var next = () => context.reader.toNextPage();
|
||||||
if (appdata.settings['reverseTapToTurnPages']) {
|
if (appdata.settings.getReaderSetting(
|
||||||
prev = context.reader.toNextPage;
|
reader.cid, reader.type.sourceKey, 'reverseTapToTurnPages')) {
|
||||||
next = context.reader.toPrevPage;
|
prev = () => context.reader.toNextPage();
|
||||||
|
next = () => context.reader.toPrevPage();
|
||||||
}
|
}
|
||||||
switch (context.reader.mode) {
|
switch (context.reader.mode) {
|
||||||
case ReaderMode.galleryLeftToRight:
|
case ReaderMode.galleryLeftToRight:
|
||||||
@@ -281,6 +290,18 @@ class _ReaderGestureDetectorState extends AutomaticGlobalState<_ReaderGestureDet
|
|||||||
context.pop();
|
context.pop();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
if (App.isDesktop && !reader.isLoading)
|
||||||
|
MenuEntry(
|
||||||
|
icon: Icons.copy,
|
||||||
|
text: "Copy Image".tl,
|
||||||
|
onClick: () => copyImage(location),
|
||||||
|
),
|
||||||
|
if (!reader.isLoading)
|
||||||
|
MenuEntry(
|
||||||
|
icon: Icons.download_outlined,
|
||||||
|
text: "Save Image".tl,
|
||||||
|
onClick: () => saveImage(location),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -303,6 +324,27 @@ class _ReaderGestureDetectorState extends AutomaticGlobalState<_ReaderGestureDet
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Object? get key => "reader_gesture";
|
Object? get key => "reader_gesture";
|
||||||
|
|
||||||
|
void copyImage(Offset location) async {
|
||||||
|
var controller = reader._imageViewController;
|
||||||
|
var image = await controller!.getImageByOffset(location);
|
||||||
|
if (image != null) {
|
||||||
|
writeImageToClipboard(image);
|
||||||
|
} else {
|
||||||
|
context.showMessage(message: "No Image");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveImage(Offset location) async {
|
||||||
|
var controller = reader._imageViewController;
|
||||||
|
var image = await controller!.getImageByOffset(location);
|
||||||
|
if (image != null) {
|
||||||
|
var filetype = detectFileType(image);
|
||||||
|
saveFile(filename: "image${filetype.ext}", data: image);
|
||||||
|
} else {
|
||||||
|
context.showMessage(message: "No Image");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _DragListener {
|
class _DragListener {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -29,7 +29,9 @@ import 'package:venera/foundation/image_provider/reader_image.dart';
|
|||||||
import 'package:venera/foundation/local.dart';
|
import 'package:venera/foundation/local.dart';
|
||||||
import 'package:venera/foundation/log.dart';
|
import 'package:venera/foundation/log.dart';
|
||||||
import 'package:venera/foundation/res.dart';
|
import 'package:venera/foundation/res.dart';
|
||||||
|
import 'package:venera/network/images.dart';
|
||||||
import 'package:venera/pages/settings/settings_page.dart';
|
import 'package:venera/pages/settings/settings_page.dart';
|
||||||
|
import 'package:venera/utils/clipboard_image.dart';
|
||||||
import 'package:venera/utils/data_sync.dart';
|
import 'package:venera/utils/data_sync.dart';
|
||||||
import 'package:venera/utils/ext.dart';
|
import 'package:venera/utils/ext.dart';
|
||||||
import 'package:venera/utils/file_type.dart';
|
import 'package:venera/utils/file_type.dart';
|
||||||
@@ -109,10 +111,21 @@ class _ReaderState extends State<Reader>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get maxPage => ((images?.length ?? 1) / imagesPerPage).ceil();
|
int get maxPage {
|
||||||
|
if (images == null) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!showSingleImageOnFirstPage()) {
|
||||||
|
return (images!.length / imagesPerPage).ceil();
|
||||||
|
} else {
|
||||||
|
return 1 + ((images!.length - 1) / imagesPerPage).ceil();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
ComicType get type => widget.type;
|
ComicType get type => widget.type;
|
||||||
|
|
||||||
|
@override
|
||||||
String get cid => widget.cid;
|
String get cid => widget.cid;
|
||||||
|
|
||||||
String get eid => widget.chapters?.ids.elementAtOrNull(chapter - 1) ?? '0';
|
String get eid => widget.chapters?.ids.elementAtOrNull(chapter - 1) ?? '0';
|
||||||
@@ -123,7 +136,8 @@ class _ReaderState extends State<Reader>
|
|||||||
late ReaderMode mode;
|
late ReaderMode mode;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get isPortrait => MediaQuery.of(context).orientation == Orientation.portrait;
|
bool get isPortrait =>
|
||||||
|
MediaQuery.of(context).orientation == Orientation.portrait;
|
||||||
|
|
||||||
History? history;
|
History? history;
|
||||||
|
|
||||||
@@ -150,13 +164,13 @@ class _ReaderState extends State<Reader>
|
|||||||
if (widget.initialPage != null) {
|
if (widget.initialPage != null) {
|
||||||
page = widget.initialPage!;
|
page = widget.initialPage!;
|
||||||
}
|
}
|
||||||
mode = ReaderMode.fromKey(appdata.settings['readerMode']);
|
// mode = ReaderMode.fromKey(appdata.settings['readerMode']);
|
||||||
|
mode = ReaderMode.fromKey(appdata.settings.getReaderSetting(cid, type.sourceKey, 'readerMode'));
|
||||||
history = widget.history;
|
history = widget.history;
|
||||||
Future.microtask(() {
|
if (!appdata.settings.getReaderSetting(cid, type.sourceKey, 'showSystemStatusBar')) {
|
||||||
updateHistory();
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
|
||||||
});
|
}
|
||||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
|
if (appdata.settings.getReaderSetting(cid, type.sourceKey, 'enableTurnPageByVolumeKey')) {
|
||||||
if (appdata.settings['enableTurnPageByVolumeKey']) {
|
|
||||||
handleVolumeEvent();
|
handleVolumeEvent();
|
||||||
}
|
}
|
||||||
setImageCacheSize();
|
setImageCacheSize();
|
||||||
@@ -166,10 +180,18 @@ class _ReaderState extends State<Reader>
|
|||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _isInitialized = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
initImagesPerPage(widget.initialPage ?? 1);
|
if (!_isInitialized) {
|
||||||
|
initImagesPerPage(widget.initialPage ?? 1);
|
||||||
|
_isInitialized = true;
|
||||||
|
} else {
|
||||||
|
// For orientation changed
|
||||||
|
_checkImagesPerPageChange();
|
||||||
|
}
|
||||||
initReaderWindow();
|
initReaderWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,10 +237,16 @@ class _ReaderState extends State<Reader>
|
|||||||
focusNode: focusNode,
|
focusNode: focusNode,
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
onKeyEvent: onKeyEvent,
|
onKeyEvent: onKeyEvent,
|
||||||
child: _ReaderScaffold(
|
child: Overlay(
|
||||||
child: _ReaderGestureDetector(
|
initialEntries: [
|
||||||
child: _ReaderImages(key: Key(chapter.toString())),
|
OverlayEntry(builder: (context) {
|
||||||
),
|
return _ReaderScaffold(
|
||||||
|
child: _ReaderGestureDetector(
|
||||||
|
child: _ReaderImages(key: Key(chapter.toString())),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
})
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -249,7 +277,15 @@ class _ReaderState extends State<Reader>
|
|||||||
history!.page = images?.length ?? 1;
|
history!.page = images?.length ?? 1;
|
||||||
} else {
|
} else {
|
||||||
/// Record the first image of the page
|
/// Record the first image of the page
|
||||||
history!.page = (page - 1) * imagesPerPage + 1;
|
if (!showSingleImageOnFirstPage() || imagesPerPage == 1) {
|
||||||
|
history!.page = (page - 1) * imagesPerPage + 1;
|
||||||
|
} else {
|
||||||
|
if (page == 1) {
|
||||||
|
history!.page = 1;
|
||||||
|
} else {
|
||||||
|
history!.page = (page - 2) * imagesPerPage + 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
history!.maxPage = images?.length ?? 1;
|
history!.maxPage = images?.length ?? 1;
|
||||||
if (widget.chapters?.isGrouped ?? false) {
|
if (widget.chapters?.isGrouped ?? false) {
|
||||||
@@ -308,11 +344,20 @@ class _ReaderState extends State<Reader>
|
|||||||
}
|
}
|
||||||
return chapter == maxChapter;
|
return chapter == maxChapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the size of the reader.
|
||||||
|
/// The size is not always the same as the size of the screen.
|
||||||
|
Size get size {
|
||||||
|
var renderBox = context.findRenderObject() as RenderBox;
|
||||||
|
return renderBox.size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract mixin class _ImagePerPageHandler {
|
abstract mixin class _ImagePerPageHandler {
|
||||||
late int _lastImagesPerPage;
|
late int _lastImagesPerPage;
|
||||||
|
|
||||||
|
late bool _lastOrientation;
|
||||||
|
|
||||||
bool get isPortrait;
|
bool get isPortrait;
|
||||||
|
|
||||||
int get page;
|
int get page;
|
||||||
@@ -321,39 +366,72 @@ abstract mixin class _ImagePerPageHandler {
|
|||||||
|
|
||||||
ReaderMode get mode;
|
ReaderMode get mode;
|
||||||
|
|
||||||
|
String get cid;
|
||||||
|
|
||||||
|
ComicType get type;
|
||||||
|
|
||||||
void initImagesPerPage(int initialPage) {
|
void initImagesPerPage(int initialPage) {
|
||||||
_lastImagesPerPage = imagesPerPage;
|
_lastImagesPerPage = imagesPerPage;
|
||||||
|
_lastOrientation = isPortrait;
|
||||||
if (imagesPerPage != 1) {
|
if (imagesPerPage != 1) {
|
||||||
page = (initialPage / imagesPerPage).ceil();
|
if (showSingleImageOnFirstPage()) {
|
||||||
|
page = ((initialPage - 1) / imagesPerPage).ceil() + 1;
|
||||||
|
} else {
|
||||||
|
page = (initialPage / imagesPerPage).ceil();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool showSingleImageOnFirstPage() =>
|
||||||
|
appdata.settings.getReaderSetting(cid, type.sourceKey, 'showSingleImageOnFirstPage');
|
||||||
|
|
||||||
/// The number of images displayed on one screen
|
/// The number of images displayed on one screen
|
||||||
int get imagesPerPage {
|
int get imagesPerPage {
|
||||||
if (mode.isContinuous) return 1;
|
if (mode.isContinuous) return 1;
|
||||||
if (isPortrait) {
|
if (isPortrait) {
|
||||||
return appdata.settings['readerScreenPicNumberForPortrait'] ?? 1;
|
return appdata.settings.getReaderSetting(cid, type.sourceKey, 'readerScreenPicNumberForPortrait') ?? 1;
|
||||||
} else {
|
} else {
|
||||||
return appdata.settings['readerScreenPicNumberForLandscape'] ?? 1;
|
return appdata.settings.getReaderSetting(cid, type.sourceKey, 'readerScreenPicNumberForLandscape') ?? 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if the number of images per page has changed
|
/// Check if the number of images per page has changed
|
||||||
void _checkImagesPerPageChange() {
|
void _checkImagesPerPageChange() {
|
||||||
int currentImagesPerPage = imagesPerPage;
|
int currentImagesPerPage = imagesPerPage;
|
||||||
if (_lastImagesPerPage != currentImagesPerPage) {
|
bool currentOrientation = isPortrait;
|
||||||
_adjustPageForImagesPerPageChange(
|
|
||||||
_lastImagesPerPage, currentImagesPerPage);
|
if (_lastImagesPerPage != currentImagesPerPage || _lastOrientation != currentOrientation) {
|
||||||
|
_adjustPageForImagesPerPageChange(_lastImagesPerPage, currentImagesPerPage);
|
||||||
_lastImagesPerPage = currentImagesPerPage;
|
_lastImagesPerPage = currentImagesPerPage;
|
||||||
|
_lastOrientation = currentOrientation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adjust the page number when the number of images per page changes
|
/// Adjust the page number when the number of images per page changes
|
||||||
void _adjustPageForImagesPerPageChange(
|
void _adjustPageForImagesPerPageChange(int oldImagesPerPage, int newImagesPerPage) {
|
||||||
int oldImagesPerPage, int newImagesPerPage) {
|
int previousImageIndex = 1;
|
||||||
int previousImageIndex = (page - 1) * oldImagesPerPage;
|
if (!showSingleImageOnFirstPage() || oldImagesPerPage == 1) {
|
||||||
int newPage = (previousImageIndex ~/ newImagesPerPage) + 1;
|
previousImageIndex = (page - 1) * oldImagesPerPage + 1;
|
||||||
page = newPage;
|
} else {
|
||||||
|
if (page == 1) {
|
||||||
|
previousImageIndex = 1;
|
||||||
|
} else {
|
||||||
|
previousImageIndex = (page - 2) * oldImagesPerPage + 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int newPage;
|
||||||
|
if (newImagesPerPage != 1) {
|
||||||
|
if (showSingleImageOnFirstPage()) {
|
||||||
|
newPage = ((previousImageIndex - 1) / newImagesPerPage).ceil() + 1;
|
||||||
|
} else {
|
||||||
|
newPage = (previousImageIndex / newImagesPerPage).ceil();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newPage = previousImageIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
page = newPage>0 ? newPage : 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,8 +440,24 @@ abstract mixin class _VolumeListener {
|
|||||||
|
|
||||||
bool toPrevPage();
|
bool toPrevPage();
|
||||||
|
|
||||||
|
bool toNextChapter();
|
||||||
|
|
||||||
|
bool toPrevChapter();
|
||||||
|
|
||||||
VolumeListener? volumeListener;
|
VolumeListener? volumeListener;
|
||||||
|
|
||||||
|
void onDown() {
|
||||||
|
if (!toNextPage()) {
|
||||||
|
toNextChapter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void onUp() {
|
||||||
|
if (!toPrevPage()) {
|
||||||
|
toPrevChapter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void handleVolumeEvent() {
|
void handleVolumeEvent() {
|
||||||
if (!App.isAndroid) {
|
if (!App.isAndroid) {
|
||||||
// Currently only support Android
|
// Currently only support Android
|
||||||
@@ -373,8 +467,8 @@ abstract mixin class _VolumeListener {
|
|||||||
volumeListener?.cancel();
|
volumeListener?.cancel();
|
||||||
}
|
}
|
||||||
volumeListener = VolumeListener(
|
volumeListener = VolumeListener(
|
||||||
onDown: toNextPage,
|
onDown: onDown,
|
||||||
onUp: toPrevPage,
|
onUp: onUp,
|
||||||
)..listen();
|
)..listen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,9 +498,13 @@ abstract mixin class _ReaderLocation {
|
|||||||
|
|
||||||
bool get isLoading;
|
bool get isLoading;
|
||||||
|
|
||||||
|
String get cid;
|
||||||
|
|
||||||
|
ComicType get type;
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
bool get enablePageAnimation => appdata.settings['enablePageAnimation'];
|
bool enablePageAnimation(String cid, ComicType type) => appdata.settings.getReaderSetting(cid, type.sourceKey, 'enablePageAnimation');
|
||||||
|
|
||||||
_ImageViewController? _imageViewController;
|
_ImageViewController? _imageViewController;
|
||||||
|
|
||||||
@@ -443,7 +541,7 @@ abstract mixin class _ReaderLocation {
|
|||||||
}
|
}
|
||||||
this.page = page;
|
this.page = page;
|
||||||
update();
|
update();
|
||||||
if (enablePageAnimation) {
|
if (enablePageAnimation(cid, type)) {
|
||||||
_animationCount++;
|
_animationCount++;
|
||||||
_imageViewController!.animateToPage(page).then((_) {
|
_imageViewController!.animateToPage(page).then((_) {
|
||||||
_animationCount--;
|
_animationCount--;
|
||||||
@@ -482,12 +580,12 @@ abstract mixin class _ReaderLocation {
|
|||||||
|
|
||||||
Timer? autoPageTurningTimer;
|
Timer? autoPageTurningTimer;
|
||||||
|
|
||||||
void autoPageTurning() {
|
void autoPageTurning(String cid, ComicType type) {
|
||||||
if (autoPageTurningTimer != null) {
|
if (autoPageTurningTimer != null) {
|
||||||
autoPageTurningTimer!.cancel();
|
autoPageTurningTimer!.cancel();
|
||||||
autoPageTurningTimer = null;
|
autoPageTurningTimer = null;
|
||||||
} else {
|
} else {
|
||||||
int interval = appdata.settings['autoPageTurningInterval'];
|
int interval = appdata.settings.getReaderSetting(cid, type.sourceKey, 'autoPageTurningInterval');
|
||||||
autoPageTurningTimer = Timer.periodic(Duration(seconds: interval), (_) {
|
autoPageTurningTimer = Timer.periodic(Duration(seconds: interval), (_) {
|
||||||
if (page == maxPage) {
|
if (page == maxPage) {
|
||||||
autoPageTurningTimer!.cancel();
|
autoPageTurningTimer!.cancel();
|
||||||
@@ -577,4 +675,8 @@ abstract interface class _ImageViewController {
|
|||||||
|
|
||||||
/// Returns true if the event is handled.
|
/// Returns true if the event is handled.
|
||||||
bool handleOnTap(Offset location);
|
bool handleOnTap(Offset location);
|
||||||
|
|
||||||
|
Future<Uint8List?> getImageByOffset(Offset offset);
|
||||||
|
|
||||||
|
String? getImageKeyByOffset(Offset offset);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,11 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
if (!_isOpen) {
|
if (!_isOpen) {
|
||||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||||
} else {
|
} else {
|
||||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
|
if (!appdata.settings['showSystemStatusBar']) {
|
||||||
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
|
||||||
|
} else {
|
||||||
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
_isOpen = !_isOpen;
|
_isOpen = !_isOpen;
|
||||||
@@ -124,10 +128,9 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Stack(
|
return Stack(
|
||||||
children: [
|
children: [
|
||||||
Positioned.fill(
|
Positioned.fill(child: widget.child),
|
||||||
child: widget.child,
|
if (appdata.settings['showPageNumberInReader'] == true)
|
||||||
),
|
buildPageInfoText(),
|
||||||
buildPageInfoText(),
|
|
||||||
buildStatusInfo(),
|
buildStatusInfo(),
|
||||||
AnimatedPositioned(
|
AnimatedPositioned(
|
||||||
duration: const Duration(milliseconds: 180),
|
duration: const Duration(milliseconds: 180),
|
||||||
@@ -161,12 +164,9 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
child: Container(
|
child: Container(
|
||||||
padding: EdgeInsets.only(top: context.padding.top),
|
padding: EdgeInsets.only(top: context.padding.top),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: context.colorScheme.surface.toOpacity(0.82),
|
color: context.colorScheme.surface.toOpacity(0.92),
|
||||||
border: Border(
|
border: Border(
|
||||||
bottom: BorderSide(
|
bottom: BorderSide(color: Colors.grey.toOpacity(0.5), width: 0.5),
|
||||||
color: Colors.grey.toOpacity(0.5),
|
|
||||||
width: 0.5,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
@@ -207,12 +207,13 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addImageFavorite() {
|
void addImageFavorite() async {
|
||||||
try {
|
try {
|
||||||
if (context.reader.images![0].contains('file://')) {
|
if (context.reader.images![0].contains('file://')) {
|
||||||
showToast(
|
showToast(
|
||||||
message: "Local comic collection is not supported at present".tl,
|
message: "Local comic collection is not supported at present".tl,
|
||||||
context: context);
|
context: context,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String id = context.reader.cid;
|
String id = context.reader.cid;
|
||||||
@@ -221,14 +222,18 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
String title = context.reader.history!.title;
|
String title = context.reader.history!.title;
|
||||||
String subTitle = context.reader.history!.subtitle;
|
String subTitle = context.reader.history!.subtitle;
|
||||||
int maxPage = context.reader.images!.length;
|
int maxPage = context.reader.images!.length;
|
||||||
int page = context.reader.page;
|
int? page = await selectImage();
|
||||||
|
if (page == null) return;
|
||||||
|
page += 1;
|
||||||
String sourceKey = context.reader.type.sourceKey;
|
String sourceKey = context.reader.type.sourceKey;
|
||||||
String imageKey = context.reader.images![page - 1];
|
String imageKey = context.reader.images![page - 1];
|
||||||
List<String> tags = context.reader.widget.tags;
|
List<String> tags = context.reader.widget.tags;
|
||||||
String author = context.reader.widget.author;
|
String author = context.reader.widget.author;
|
||||||
|
|
||||||
var epName = context.reader.widget.chapters?.titles
|
var epName =
|
||||||
.elementAtOrNull(context.reader.chapter - 1) ??
|
context.reader.widget.chapters?.titles.elementAtOrNull(
|
||||||
|
context.reader.chapter - 1,
|
||||||
|
) ??
|
||||||
"E${context.reader.chapter}";
|
"E${context.reader.chapter}";
|
||||||
var translatedTags = tags.map((e) => e.translateTagsToCN).toList();
|
var translatedTags = tags.map((e) => e.translateTagsToCN).toList();
|
||||||
|
|
||||||
@@ -241,7 +246,7 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ImageFavoriteManager().deleteImageFavorite([
|
ImageFavoriteManager().deleteImageFavorite([
|
||||||
ImageFavorite(page, imageKey, null, eid, id, ep, sourceKey, epName)
|
ImageFavorite(page, imageKey, null, eid, id, ep, sourceKey, epName),
|
||||||
]);
|
]);
|
||||||
showToast(
|
showToast(
|
||||||
message: "Uncollected the image".tl,
|
message: "Uncollected the image".tl,
|
||||||
@@ -249,7 +254,8 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
seconds: 1,
|
seconds: 1,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
var imageFavoritesComic = ImageFavoriteManager().find(id, sourceKey) ??
|
var imageFavoritesComic =
|
||||||
|
ImageFavoriteManager().find(id, sourceKey) ??
|
||||||
ImageFavoritesComic(
|
ImageFavoritesComic(
|
||||||
id,
|
id,
|
||||||
[],
|
[],
|
||||||
@@ -263,12 +269,21 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
subTitle,
|
subTitle,
|
||||||
maxPage,
|
maxPage,
|
||||||
);
|
);
|
||||||
ImageFavorite imageFavorite =
|
ImageFavorite imageFavorite = ImageFavorite(
|
||||||
ImageFavorite(page, imageKey, null, eid, id, ep, sourceKey, epName);
|
page,
|
||||||
ImageFavoritesEp? imageFavoritesEp =
|
imageKey,
|
||||||
imageFavoritesComic.imageFavoritesEp.firstWhereOrNull((e) {
|
null,
|
||||||
return e.ep == ep;
|
eid,
|
||||||
});
|
id,
|
||||||
|
ep,
|
||||||
|
sourceKey,
|
||||||
|
epName,
|
||||||
|
);
|
||||||
|
ImageFavoritesEp? imageFavoritesEp = imageFavoritesComic
|
||||||
|
.imageFavoritesEp
|
||||||
|
.firstWhereOrNull((e) {
|
||||||
|
return e.ep == ep;
|
||||||
|
});
|
||||||
if (imageFavoritesEp == null) {
|
if (imageFavoritesEp == null) {
|
||||||
if (page != firstPage) {
|
if (page != firstPage) {
|
||||||
var copy = imageFavorite.copyWith(
|
var copy = imageFavorite.copyWith(
|
||||||
@@ -278,10 +293,20 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
);
|
);
|
||||||
// 不是第一页的话, 自动塞一个封面进去
|
// 不是第一页的话, 自动塞一个封面进去
|
||||||
imageFavoritesEp = ImageFavoritesEp(
|
imageFavoritesEp = ImageFavoritesEp(
|
||||||
eid, ep, [copy, imageFavorite], epName, maxPage);
|
eid,
|
||||||
|
ep,
|
||||||
|
[copy, imageFavorite],
|
||||||
|
epName,
|
||||||
|
maxPage,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
imageFavoritesEp =
|
imageFavoritesEp = ImageFavoritesEp(
|
||||||
ImageFavoritesEp(eid, ep, [imageFavorite], epName, maxPage);
|
eid,
|
||||||
|
ep,
|
||||||
|
[imageFavorite],
|
||||||
|
epName,
|
||||||
|
maxPage,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
imageFavoritesComic.imageFavoritesEp.add(imageFavoritesEp);
|
imageFavoritesComic.imageFavoritesEp.add(imageFavoritesEp);
|
||||||
} else {
|
} else {
|
||||||
@@ -305,7 +330,10 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
|
|
||||||
ImageFavoriteManager().addOrUpdateOrDelete(imageFavoritesComic);
|
ImageFavoriteManager().addOrUpdateOrDelete(imageFavoritesComic);
|
||||||
showToast(
|
showToast(
|
||||||
message: "Successfully collected".tl, context: context, seconds: 1);
|
message: "Successfully collected".tl,
|
||||||
|
context: context,
|
||||||
|
seconds: 1,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
} catch (e, stackTrace) {
|
} catch (e, stackTrace) {
|
||||||
@@ -320,154 +348,152 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
text = "P${context.reader.page}";
|
text = "P${context.reader.page}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final buttons = [
|
||||||
|
Tooltip(
|
||||||
|
message: "Collect the image".tl,
|
||||||
|
child: IconButton(
|
||||||
|
icon: Icon(isLiked() ? Icons.favorite : Icons.favorite_border),
|
||||||
|
onPressed: addImageFavorite,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (App.isDesktop)
|
||||||
|
Tooltip(
|
||||||
|
message: "${"Full Screen".tl}(F12)",
|
||||||
|
child: IconButton(
|
||||||
|
icon: const Icon(Icons.fullscreen),
|
||||||
|
onPressed: () {
|
||||||
|
context.reader.fullscreen();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (App.isAndroid)
|
||||||
|
Tooltip(
|
||||||
|
message: "Screen Rotation".tl,
|
||||||
|
child: IconButton(
|
||||||
|
icon: () {
|
||||||
|
if (rotation == null) {
|
||||||
|
return const Icon(Icons.screen_rotation);
|
||||||
|
} else if (rotation == false) {
|
||||||
|
return const Icon(Icons.screen_lock_portrait);
|
||||||
|
} else {
|
||||||
|
return const Icon(Icons.screen_lock_landscape);
|
||||||
|
}
|
||||||
|
}.call(),
|
||||||
|
onPressed: () {
|
||||||
|
if (rotation == null) {
|
||||||
|
setState(() {
|
||||||
|
rotation = false;
|
||||||
|
});
|
||||||
|
SystemChrome.setPreferredOrientations([
|
||||||
|
DeviceOrientation.portraitUp,
|
||||||
|
DeviceOrientation.portraitDown,
|
||||||
|
]);
|
||||||
|
} else if (rotation == false) {
|
||||||
|
setState(() {
|
||||||
|
rotation = true;
|
||||||
|
});
|
||||||
|
SystemChrome.setPreferredOrientations([
|
||||||
|
DeviceOrientation.landscapeLeft,
|
||||||
|
DeviceOrientation.landscapeRight,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
rotation = null;
|
||||||
|
});
|
||||||
|
SystemChrome.setPreferredOrientations(DeviceOrientation.values);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Tooltip(
|
||||||
|
message: "Auto Page Turning".tl,
|
||||||
|
child: IconButton(
|
||||||
|
icon: context.reader.autoPageTurningTimer != null
|
||||||
|
? const Icon(Icons.timer)
|
||||||
|
: const Icon(Icons.timer_sharp),
|
||||||
|
onPressed: () {
|
||||||
|
context.reader.autoPageTurning(
|
||||||
|
context.reader.cid,
|
||||||
|
context.reader.type,
|
||||||
|
);
|
||||||
|
update();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (context.reader.widget.chapters != null)
|
||||||
|
Tooltip(
|
||||||
|
message: "Chapters".tl,
|
||||||
|
child: IconButton(
|
||||||
|
icon: const Icon(Icons.library_books),
|
||||||
|
onPressed: openChapterDrawer,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Tooltip(
|
||||||
|
message: "Save Image".tl,
|
||||||
|
child: IconButton(
|
||||||
|
icon: const Icon(Icons.download),
|
||||||
|
onPressed: saveCurrentImage,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Tooltip(
|
||||||
|
message: "Share".tl,
|
||||||
|
child: IconButton(icon: const Icon(Icons.share), onPressed: share),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
Widget child = SizedBox(
|
Widget child = SizedBox(
|
||||||
height: kBottomBarHeight,
|
height: kBottomBarHeight,
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(
|
const SizedBox(height: 8),
|
||||||
height: 8,
|
|
||||||
),
|
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
IconButton.filledTonal(
|
IconButton.filledTonal(
|
||||||
onPressed: () => !isReversed
|
onPressed: () => !isReversed
|
||||||
? context.reader.chapter > 1
|
? context.reader.chapter > 1
|
||||||
? context.reader.toPrevChapter()
|
? context.reader.toPrevChapter()
|
||||||
: context.reader.toPage(1)
|
: context.reader.toPage(1)
|
||||||
: context.reader.chapter < context.reader.maxChapter
|
: context.reader.chapter < context.reader.maxChapter
|
||||||
? context.reader.toNextChapter()
|
? context.reader.toNextChapter()
|
||||||
: context.reader.toPage(context.reader.maxPage),
|
: context.reader.toPage(context.reader.maxPage),
|
||||||
icon: const Icon(Icons.first_page),
|
icon: const Icon(Icons.first_page),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(child: buildSlider()),
|
||||||
child: buildSlider(),
|
|
||||||
),
|
|
||||||
IconButton.filledTonal(
|
IconButton.filledTonal(
|
||||||
onPressed: () => !isReversed
|
onPressed: () => !isReversed
|
||||||
? context.reader.chapter < context.reader.maxChapter
|
? context.reader.chapter < context.reader.maxChapter
|
||||||
? context.reader.toNextChapter()
|
? context.reader.toNextChapter()
|
||||||
: context.reader.toPage(context.reader.maxPage)
|
: context.reader.toPage(context.reader.maxPage)
|
||||||
: context.reader.chapter > 1
|
: context.reader.chapter > 1
|
||||||
? context.reader.toPrevChapter()
|
? context.reader.toPrevChapter()
|
||||||
: context.reader.toPage(1),
|
: context.reader.toPage(1),
|
||||||
icon: const Icon(Icons.last_page)),
|
icon: const Icon(Icons.last_page),
|
||||||
const SizedBox(
|
|
||||||
width: 8,
|
|
||||||
),
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Row(
|
LayoutBuilder(
|
||||||
children: [
|
builder: (context, constrains) {
|
||||||
const SizedBox(
|
return Row(
|
||||||
width: 16,
|
children: [
|
||||||
),
|
if ((constrains.maxWidth - buttons.length * 42) > 80)
|
||||||
Container(
|
Container(
|
||||||
height: 24,
|
height: 24,
|
||||||
padding: const EdgeInsets.fromLTRB(6, 2, 6, 0),
|
padding: const EdgeInsets.fromLTRB(6, 2, 6, 0),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).colorScheme.tertiaryContainer,
|
color: Theme.of(context).colorScheme.tertiaryContainer,
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(child: Text(text)),
|
||||||
child: Text(text),
|
).paddingLeft(16),
|
||||||
),
|
const Spacer(),
|
||||||
),
|
...buttons,
|
||||||
const Spacer(),
|
const SizedBox(width: 4),
|
||||||
Tooltip(
|
],
|
||||||
message: "Collect the image".tl,
|
);
|
||||||
child: IconButton(
|
},
|
||||||
icon: Icon(
|
),
|
||||||
isLiked() ? Icons.favorite : Icons.favorite_border),
|
|
||||||
onPressed: addImageFavorite),
|
|
||||||
),
|
|
||||||
if (App.isWindows)
|
|
||||||
Tooltip(
|
|
||||||
message: "${"Full Screen".tl}(F12)",
|
|
||||||
child: IconButton(
|
|
||||||
icon: const Icon(Icons.fullscreen),
|
|
||||||
onPressed: () {
|
|
||||||
context.reader.fullscreen();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (App.isAndroid)
|
|
||||||
Tooltip(
|
|
||||||
message: "Screen Rotation".tl,
|
|
||||||
child: IconButton(
|
|
||||||
icon: () {
|
|
||||||
if (rotation == null) {
|
|
||||||
return const Icon(Icons.screen_rotation);
|
|
||||||
} else if (rotation == false) {
|
|
||||||
return const Icon(Icons.screen_lock_portrait);
|
|
||||||
} else {
|
|
||||||
return const Icon(Icons.screen_lock_landscape);
|
|
||||||
}
|
|
||||||
}.call(),
|
|
||||||
onPressed: () {
|
|
||||||
if (rotation == null) {
|
|
||||||
setState(() {
|
|
||||||
rotation = false;
|
|
||||||
});
|
|
||||||
SystemChrome.setPreferredOrientations([
|
|
||||||
DeviceOrientation.portraitUp,
|
|
||||||
DeviceOrientation.portraitDown,
|
|
||||||
]);
|
|
||||||
} else if (rotation == false) {
|
|
||||||
setState(() {
|
|
||||||
rotation = true;
|
|
||||||
});
|
|
||||||
SystemChrome.setPreferredOrientations([
|
|
||||||
DeviceOrientation.landscapeLeft,
|
|
||||||
DeviceOrientation.landscapeRight
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
setState(() {
|
|
||||||
rotation = null;
|
|
||||||
});
|
|
||||||
SystemChrome.setPreferredOrientations(
|
|
||||||
DeviceOrientation.values);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Tooltip(
|
|
||||||
message: "Auto Page Turning".tl,
|
|
||||||
child: IconButton(
|
|
||||||
icon: context.reader.autoPageTurningTimer != null
|
|
||||||
? const Icon(Icons.timer)
|
|
||||||
: const Icon(Icons.timer_sharp),
|
|
||||||
onPressed: () {
|
|
||||||
context.reader.autoPageTurning();
|
|
||||||
update();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (context.reader.widget.chapters != null)
|
|
||||||
Tooltip(
|
|
||||||
message: "Chapters".tl,
|
|
||||||
child: IconButton(
|
|
||||||
icon: const Icon(Icons.library_books),
|
|
||||||
onPressed: openChapterDrawer,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Tooltip(
|
|
||||||
message: "Save Image".tl,
|
|
||||||
child: IconButton(
|
|
||||||
icon: const Icon(Icons.download),
|
|
||||||
onPressed: saveCurrentImage,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Tooltip(
|
|
||||||
message: "Share".tl,
|
|
||||||
child: IconButton(
|
|
||||||
icon: const Icon(Icons.share),
|
|
||||||
onPressed: share,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 4)
|
|
||||||
],
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -475,7 +501,7 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
return BlurEffect(
|
return BlurEffect(
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: context.colorScheme.surface.toOpacity(0.82),
|
color: context.colorScheme.surface.toOpacity(0.92),
|
||||||
border: isOpen
|
border: isOpen
|
||||||
? Border(
|
? Border(
|
||||||
top: BorderSide(
|
top: BorderSide(
|
||||||
@@ -498,8 +524,9 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
focusNode: sliderFocus,
|
focusNode: sliderFocus,
|
||||||
value: context.reader.page.toDouble(),
|
value: context.reader.page.toDouble(),
|
||||||
min: 1,
|
min: 1,
|
||||||
max:
|
max: context.reader.maxPage
|
||||||
context.reader.maxPage.clamp(context.reader.page, 1 << 16).toDouble(),
|
.clamp(context.reader.page, 1 << 16)
|
||||||
|
.toDouble(),
|
||||||
reversed: isReversed,
|
reversed: isReversed,
|
||||||
divisions: (context.reader.maxPage - 1).clamp(2, 1 << 16),
|
divisions: (context.reader.maxPage - 1).clamp(2, 1 << 16),
|
||||||
onChanged: (i) {
|
onChanged: (i) {
|
||||||
@@ -509,8 +536,10 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget buildPageInfoText() {
|
Widget buildPageInfoText() {
|
||||||
var epName = context.reader.widget.chapters?.titles
|
var epName =
|
||||||
.elementAtOrNull(context.reader.chapter - 1) ??
|
context.reader.widget.chapters?.titles.elementAtOrNull(
|
||||||
|
context.reader.chapter - 1,
|
||||||
|
) ??
|
||||||
"E${context.reader.chapter}";
|
"E${context.reader.chapter}";
|
||||||
if (epName.length > 8) {
|
if (epName.length > 8) {
|
||||||
epName = "${epName.substring(0, 8)}...";
|
epName = "${epName.substring(0, 8)}...";
|
||||||
@@ -569,126 +598,50 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Uint8List?> _getCurrentImageData() async {
|
|
||||||
var imageKey = context.reader.images![context.reader.page - 1];
|
|
||||||
var reader = context.reader;
|
|
||||||
if (context.reader.mode.isContinuous) {
|
|
||||||
var continuesState =
|
|
||||||
context.reader._imageViewController as _ContinuousModeState;
|
|
||||||
var imagesOnScreen =
|
|
||||||
continuesState.itemPositionsListener.itemPositions.value;
|
|
||||||
var images = imagesOnScreen
|
|
||||||
.map((e) => context.reader.images!.elementAtOrNull(e.index - 1))
|
|
||||||
.whereType<String>()
|
|
||||||
.toList();
|
|
||||||
String? selected;
|
|
||||||
if (images.length > 1) {
|
|
||||||
await showPopUpWidget(
|
|
||||||
context,
|
|
||||||
PopUpWidgetScaffold(
|
|
||||||
title: "Select an image on screen".tl,
|
|
||||||
body: GridView.builder(
|
|
||||||
itemCount: images.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
ImageProvider image;
|
|
||||||
var imageKey = images[index];
|
|
||||||
if (imageKey.startsWith('file://')) {
|
|
||||||
image = FileImage(File(imageKey.replaceFirst("file://", '')));
|
|
||||||
} else {
|
|
||||||
image = ReaderImageProvider(
|
|
||||||
imageKey,
|
|
||||||
reader.type.comicSource!.key,
|
|
||||||
reader.cid,
|
|
||||||
reader.eid,
|
|
||||||
reader.page,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return InkWell(
|
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(16)),
|
|
||||||
onTap: () {
|
|
||||||
selected = images[index];
|
|
||||||
App.rootContext.pop();
|
|
||||||
},
|
|
||||||
child: Container(
|
|
||||||
foregroundDecoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(16),
|
|
||||||
border: Border.all(
|
|
||||||
color: Theme.of(context).colorScheme.outline,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
clipBehavior: Clip.antiAlias,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: BorderRadius.circular(16),
|
|
||||||
),
|
|
||||||
width: double.infinity,
|
|
||||||
height: double.infinity,
|
|
||||||
child: Image(
|
|
||||||
width: double.infinity,
|
|
||||||
height: double.infinity,
|
|
||||||
image: image,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
).padding(const EdgeInsets.all(8));
|
|
||||||
},
|
|
||||||
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
|
||||||
maxCrossAxisExtent: 200,
|
|
||||||
childAspectRatio: 0.7,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
selected = images.first;
|
|
||||||
}
|
|
||||||
if (selected == null) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
imageKey = selected!;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (imageKey.startsWith("file://")) {
|
|
||||||
return await File(imageKey.substring(7)).readAsBytes();
|
|
||||||
} else {
|
|
||||||
return (await CacheManager().findCache(
|
|
||||||
"$imageKey@${context.reader.type.sourceKey}@${context.reader.cid}@${context.reader.eid}"))!
|
|
||||||
.readAsBytes();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void saveCurrentImage() async {
|
void saveCurrentImage() async {
|
||||||
var data = await _getCurrentImageData();
|
var result = await selectImageToData();
|
||||||
if (data == null) {
|
if (result == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var (imageIndex, data) = result;
|
||||||
var fileType = detectFileType(data);
|
var fileType = detectFileType(data);
|
||||||
var filename = "${context.reader.page}${fileType.ext}";
|
var filename = "${context.reader.widget.name}_${imageIndex + 1}${fileType.ext}";
|
||||||
saveFile(data: data, filename: filename);
|
saveFile(data: data, filename: filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void share() async {
|
void share() async {
|
||||||
var data = await _getCurrentImageData();
|
var result = await selectImageToData();
|
||||||
if (data == null) {
|
if (result == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var (imageIndex, data) = result;
|
||||||
var fileType = detectFileType(data);
|
var fileType = detectFileType(data);
|
||||||
var filename = "${context.reader.page}${fileType.ext}";
|
var filename = "${context.reader.widget.name}_${imageIndex + 1}${fileType.ext}";
|
||||||
Share.shareFile(
|
Share.shareFile(data: data, filename: filename, mime: fileType.mime);
|
||||||
data: data,
|
|
||||||
filename: filename,
|
|
||||||
mime: fileType.mime,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void openSetting() {
|
void openSetting() {
|
||||||
showSideBar(
|
showSideBar(
|
||||||
context,
|
context,
|
||||||
ReaderSettings(
|
ReaderSettings(
|
||||||
|
comicId: context.reader.cid,
|
||||||
|
comicSource: context.reader.type.sourceKey,
|
||||||
onChanged: (key) {
|
onChanged: (key) {
|
||||||
if (key == "readerMode") {
|
if (key == "readerMode") {
|
||||||
context.reader.mode = ReaderMode.fromKey(appdata.settings[key]);
|
context.reader.mode = ReaderMode.fromKey(
|
||||||
|
appdata.settings.getReaderSetting(
|
||||||
|
context.reader.cid,
|
||||||
|
context.reader.type.sourceKey,
|
||||||
|
key,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (key == "enableTurnPageByVolumeKey") {
|
if (key == "enableTurnPageByVolumeKey") {
|
||||||
if (appdata.settings[key]) {
|
if (appdata.settings.getReaderSetting(
|
||||||
|
context.reader.cid,
|
||||||
|
context.reader.type.sourceKey,
|
||||||
|
key,
|
||||||
|
)) {
|
||||||
context.reader.handleVolumeEvent();
|
context.reader.handleVolumeEvent();
|
||||||
} else {
|
} else {
|
||||||
context.reader.stopVolumeEvent();
|
context.reader.stopVolumeEvent();
|
||||||
@@ -749,9 +702,7 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
? Icons.arrow_forward_ios
|
? Icons.arrow_forward_ios
|
||||||
: Icons.arrow_back_ios_outlined,
|
: Icons.arrow_back_ios_outlined,
|
||||||
size: 24,
|
size: 24,
|
||||||
color: Theme.of(context)
|
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||||
.colorScheme
|
|
||||||
.onPrimaryContainer,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -760,6 +711,101 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
|||||||
}
|
}
|
||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// If there is only one image on screen, return it.
|
||||||
|
///
|
||||||
|
/// If there are multiple images on screen,
|
||||||
|
/// show an overlay to let the user select an image.
|
||||||
|
///
|
||||||
|
/// The return value is the index of the selected image.
|
||||||
|
Future<int?> selectImage() async {
|
||||||
|
var reader = context.reader;
|
||||||
|
var imageViewController = context.reader._imageViewController;
|
||||||
|
|
||||||
|
bool needsSelection = false;
|
||||||
|
int? singleImageIndex;
|
||||||
|
|
||||||
|
if (imageViewController is _GalleryModeState) {
|
||||||
|
var range = imageViewController.getCurrentPageImageRange();
|
||||||
|
if (range != null) {
|
||||||
|
var (startIndex, endIndex) = range;
|
||||||
|
int actualImageCount = endIndex - startIndex;
|
||||||
|
if (actualImageCount == 1) {
|
||||||
|
needsSelection = false;
|
||||||
|
singleImageIndex = startIndex;
|
||||||
|
} else {
|
||||||
|
needsSelection = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (imageViewController is _ContinuousModeState) {
|
||||||
|
needsSelection = false;
|
||||||
|
singleImageIndex = reader.page - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!needsSelection && singleImageIndex != null) {
|
||||||
|
return singleImageIndex;
|
||||||
|
} else {
|
||||||
|
var location = await _showSelectImageOverlay();
|
||||||
|
if (location == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var imageKey = imageViewController!.getImageKeyByOffset(location);
|
||||||
|
if (imageKey == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return reader.images!.indexOf(imageKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Same as [selectImage], but return the image data with its index.
|
||||||
|
/// Returns (imageIndex, imageData) or null if cancelled.
|
||||||
|
Future<(int, Uint8List)?> selectImageToData() async {
|
||||||
|
var i = await selectImage();
|
||||||
|
if (i == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var imageKey = context.reader.images![i];
|
||||||
|
Uint8List data;
|
||||||
|
if (imageKey.startsWith("file://")) {
|
||||||
|
data = await File(imageKey.substring(7)).readAsBytes();
|
||||||
|
} else {
|
||||||
|
data = await (await CacheManager().findCache(
|
||||||
|
"$imageKey@${context.reader.type.sourceKey}@${context.reader.cid}@${context.reader.eid}",
|
||||||
|
))!.readAsBytes();
|
||||||
|
}
|
||||||
|
return (i, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Offset?> _showSelectImageOverlay() {
|
||||||
|
if (_isOpen) {
|
||||||
|
openOrClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
var completer = Completer<Offset?>();
|
||||||
|
|
||||||
|
var overlay = Overlay.of(context);
|
||||||
|
OverlayEntry? entry;
|
||||||
|
entry = OverlayEntry(
|
||||||
|
builder: (context) {
|
||||||
|
return Positioned.fill(
|
||||||
|
child: _SelectImageOverlayContent(
|
||||||
|
onTap: (offset) {
|
||||||
|
completer.complete(offset);
|
||||||
|
entry!.remove();
|
||||||
|
},
|
||||||
|
onDispose: () {
|
||||||
|
if (!completer.isCompleted) {
|
||||||
|
completer.complete(null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
overlay.insert(entry);
|
||||||
|
|
||||||
|
return completer.future;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _BatteryWidget extends StatefulWidget {
|
class _BatteryWidget extends StatefulWidget {
|
||||||
@@ -852,20 +898,17 @@ class _BatteryWidgetState extends State<_BatteryWidget> {
|
|||||||
size: 16,
|
size: 16,
|
||||||
color: batteryColor,
|
color: batteryColor,
|
||||||
// Stroke
|
// Stroke
|
||||||
shadows: List.generate(
|
shadows: List.generate(9, (index) {
|
||||||
9,
|
if (index == 4) {
|
||||||
(index) {
|
return null;
|
||||||
if (index == 4) {
|
}
|
||||||
return null;
|
double offsetX = (index % 3 - 1) * 0.8;
|
||||||
}
|
double offsetY = ((index / 3).floor() - 1) * 0.8;
|
||||||
double offsetX = (index % 3 - 1) * 0.8;
|
return Shadow(
|
||||||
double offsetY = ((index / 3).floor() - 1) * 0.8;
|
color: context.colorScheme.onInverseSurface,
|
||||||
return Shadow(
|
offset: Offset(offsetX, offsetY),
|
||||||
color: context.colorScheme.onInverseSurface,
|
);
|
||||||
offset: Offset(offsetX, offsetY),
|
}).whereType<Shadow>().toList(),
|
||||||
);
|
|
||||||
},
|
|
||||||
).whereType<Shadow>().toList(),
|
|
||||||
),
|
),
|
||||||
Stack(
|
Stack(
|
||||||
children: [
|
children: [
|
||||||
@@ -940,3 +983,66 @@ class _ClockWidgetState extends State<_ClockWidget> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _SelectImageOverlayContent extends StatefulWidget {
|
||||||
|
const _SelectImageOverlayContent({
|
||||||
|
required this.onTap,
|
||||||
|
required this.onDispose,
|
||||||
|
});
|
||||||
|
|
||||||
|
final void Function(Offset) onTap;
|
||||||
|
|
||||||
|
final void Function() onDispose;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_SelectImageOverlayContent> createState() =>
|
||||||
|
_SelectImageOverlayContentState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SelectImageOverlayContentState
|
||||||
|
extends State<_SelectImageOverlayContent> {
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
widget.onDispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTapUp: (details) {
|
||||||
|
widget.onTap(details.globalPosition);
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
color: Colors.black.withAlpha(50),
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment(0, -0.8),
|
||||||
|
child: Container(
|
||||||
|
width: 232,
|
||||||
|
height: 42,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: context.colorScheme.surface,
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
border: Border.all(color: context.colorScheme.outlineVariant),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
const Icon(Icons.info_outline),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
Text(
|
||||||
|
"Click to select an image".tl,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
color: context.colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -376,11 +376,16 @@ class _SearchPageState extends State<SearchPage> {
|
|||||||
controller.text =
|
controller.text =
|
||||||
controller.text.replaceLast(words[words.length - 1], "");
|
controller.text.replaceLast(words[words.length - 1], "");
|
||||||
}
|
}
|
||||||
if (type != null) {
|
final source = ComicSource.find(searchTarget);
|
||||||
controller.text += "${type.name}:$text ";
|
String insert;
|
||||||
|
if (source?.onTagSuggestionSelected != null) {
|
||||||
|
insert = source!.onTagSuggestionSelected!(type?.name ?? '', text);
|
||||||
} else {
|
} else {
|
||||||
controller.text += "$text ";
|
var t = text;
|
||||||
|
if (t.contains(' ')) t = "'$t'";
|
||||||
|
insert = type != null ? "${type.name}:$t" : t;
|
||||||
}
|
}
|
||||||
|
controller.text += "$insert ";
|
||||||
suggestions.clear();
|
suggestions.clear();
|
||||||
update();
|
update();
|
||||||
focusNode.requestFocus();
|
focusNode.requestFocus();
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ class _SearchResultPageState extends State<SearchResultPage> {
|
|||||||
options = widget.options ?? const [];
|
options = widget.options ?? const [];
|
||||||
validateOptions();
|
validateOptions();
|
||||||
appdata.addSearchHistory(text);
|
appdata.addSearchHistory(text);
|
||||||
suggestionsController = _SuggestionsController(controller);
|
suggestionsController = _SuggestionsController(controller, sourceKey);
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,6 +213,8 @@ class _SuggestionsController {
|
|||||||
|
|
||||||
final SearchBarController controller;
|
final SearchBarController controller;
|
||||||
|
|
||||||
|
final String sourceKey;
|
||||||
|
|
||||||
OverlayEntry? entry;
|
OverlayEntry? entry;
|
||||||
|
|
||||||
void updateWidget() {
|
void updateWidget() {
|
||||||
@@ -270,7 +272,7 @@ class _SuggestionsController {
|
|||||||
find(TagsTranslation.cosplayerTags, TranslationType.cosplayer);
|
find(TagsTranslation.cosplayerTags, TranslationType.cosplayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
_SuggestionsController(this.controller);
|
_SuggestionsController(this.controller, this.sourceKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
class _Suggestions extends StatefulWidget {
|
class _Suggestions extends StatefulWidget {
|
||||||
@@ -400,14 +402,16 @@ class _SuggestionsState extends State<_Suggestions> {
|
|||||||
controller.text =
|
controller.text =
|
||||||
controller.text.replaceLast(words[words.length - 1], "");
|
controller.text.replaceLast(words[words.length - 1], "");
|
||||||
}
|
}
|
||||||
if (text.contains(' ')) {
|
final source = ComicSource.find(widget.controller.sourceKey);
|
||||||
text = "'$text'";
|
String insert;
|
||||||
}
|
if (source?.onTagSuggestionSelected != null) {
|
||||||
if (type != null) {
|
insert = source!.onTagSuggestionSelected!(type?.name ?? '', text);
|
||||||
controller.text += "${type.name}:$text ";
|
|
||||||
} else {
|
} else {
|
||||||
controller.text += "$text ";
|
var t = text;
|
||||||
|
if (t.contains(' ')) t = "'$t'";
|
||||||
|
insert = type != null ? "${type.name}:$t" : t;
|
||||||
}
|
}
|
||||||
|
controller.text += "$insert ";
|
||||||
widget.controller.suggestions.clear();
|
widget.controller.suggestions.clear();
|
||||||
widget.controller.remove();
|
widget.controller.remove();
|
||||||
}
|
}
|
||||||
@@ -441,6 +445,11 @@ class _SearchSettingsDialogState extends State<_SearchSettingsDialog> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var sources = ComicSource.all();
|
||||||
|
var enabled = appdata.settings['searchSources'] as List;
|
||||||
|
sources.removeWhere((e) {
|
||||||
|
return !enabled.contains(e.key);
|
||||||
|
});
|
||||||
return ContentDialog(
|
return ContentDialog(
|
||||||
title: "Settings".tl,
|
title: "Settings".tl,
|
||||||
content: Column(
|
content: Column(
|
||||||
@@ -452,7 +461,7 @@ class _SearchSettingsDialogState extends State<_SearchSettingsDialog> {
|
|||||||
Wrap(
|
Wrap(
|
||||||
spacing: 8,
|
spacing: 8,
|
||||||
runSpacing: 8,
|
runSpacing: 8,
|
||||||
children: ComicSource.all().map((e) {
|
children: sources.map((e) {
|
||||||
return OptionChip(
|
return OptionChip(
|
||||||
text: e.name.tl,
|
text: e.name.tl,
|
||||||
isSelected: searchTarget == e.key,
|
isSelected: searchTarget == e.key,
|
||||||
|
|||||||
@@ -96,10 +96,13 @@ Future<bool> checkUpdate() async {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> checkUpdateUi([bool showMessageIfNoUpdate = true]) async {
|
Future<void> checkUpdateUi([bool showMessageIfNoUpdate = true, bool delay = false]) async {
|
||||||
try {
|
try {
|
||||||
var value = await checkUpdate();
|
var value = await checkUpdate();
|
||||||
if (value) {
|
if (value) {
|
||||||
|
if (delay) {
|
||||||
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
|
}
|
||||||
showDialog(
|
showDialog(
|
||||||
context: App.rootContext,
|
context: App.rootContext,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
|
|||||||
@@ -140,17 +140,6 @@ class _AppSettingsState extends State<AppSettings> {
|
|||||||
},
|
},
|
||||||
actionTitle: 'Set'.tl,
|
actionTitle: 'Set'.tl,
|
||||||
).toSliver(),
|
).toSliver(),
|
||||||
_SettingPartTitle(
|
|
||||||
title: "Log".tl,
|
|
||||||
icon: Icons.error_outline,
|
|
||||||
),
|
|
||||||
_CallbackSetting(
|
|
||||||
title: "Open Log".tl,
|
|
||||||
callback: () {
|
|
||||||
context.to(() => const LogsPage());
|
|
||||||
},
|
|
||||||
actionTitle: 'Open'.tl,
|
|
||||||
).toSliver(),
|
|
||||||
_SettingPartTitle(
|
_SettingPartTitle(
|
||||||
title: "User".tl,
|
title: "User".tl,
|
||||||
icon: Icons.person_outline,
|
icon: Icons.person_outline,
|
||||||
@@ -204,12 +193,46 @@ class LogsPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _LogsPageState extends State<LogsPage> {
|
class _LogsPageState extends State<LogsPage> {
|
||||||
|
String logLevelToShow = "all";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var logToShow = logLevelToShow == "all"
|
||||||
|
? Log.logs
|
||||||
|
: Log.logs.where((log) => log.level.name == logLevelToShow).toList();
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: Appbar(
|
appBar: Appbar(
|
||||||
title: const Text("Logs"),
|
title: Text("Logs".tl),
|
||||||
actions: [
|
actions: [
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => setState(() {
|
||||||
|
final RelativeRect position = RelativeRect.fromLTRB(
|
||||||
|
MediaQuery.of(context).size.width,
|
||||||
|
MediaQuery.of(context).padding.top + kToolbarHeight,
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
);
|
||||||
|
showMenu(context: context, position: position, items: [
|
||||||
|
PopupMenuItem(
|
||||||
|
child: Text("all"),
|
||||||
|
onTap: () => setState(() => logLevelToShow = "all")
|
||||||
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
child: Text("info"),
|
||||||
|
onTap: () => setState(() => logLevelToShow = "info")
|
||||||
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
child: Text("warning"),
|
||||||
|
onTap: () => setState(() => logLevelToShow = "warning")
|
||||||
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
child: Text("error"),
|
||||||
|
onTap: () => setState(() => logLevelToShow = "error")
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
}),
|
||||||
|
icon: const Icon(Icons.filter_list_outlined)
|
||||||
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => setState(() {
|
onPressed: () => setState(() {
|
||||||
final RelativeRect position = RelativeRect.fromLTRB(
|
final RelativeRect position = RelativeRect.fromLTRB(
|
||||||
@@ -228,7 +251,7 @@ class _LogsPageState extends State<LogsPage> {
|
|||||||
onTap: () {
|
onTap: () {
|
||||||
Log.ignoreLimitation = true;
|
Log.ignoreLimitation = true;
|
||||||
context.showMessage(
|
context.showMessage(
|
||||||
message: "Only valid for this run");
|
message: "Only valid for this run".tl);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
@@ -243,9 +266,9 @@ class _LogsPageState extends State<LogsPage> {
|
|||||||
body: ListView.builder(
|
body: ListView.builder(
|
||||||
reverse: true,
|
reverse: true,
|
||||||
controller: ScrollController(),
|
controller: ScrollController(),
|
||||||
itemCount: Log.logs.length,
|
itemCount: logToShow.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
index = Log.logs.length - index - 1;
|
index = logToShow.length - index - 1;
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
||||||
child: SelectionArea(
|
child: SelectionArea(
|
||||||
@@ -264,7 +287,7 @@ class _LogsPageState extends State<LogsPage> {
|
|||||||
),
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(5, 0, 5, 1),
|
padding: const EdgeInsets.fromLTRB(5, 0, 5, 1),
|
||||||
child: Text(Log.logs[index].title),
|
child: Text(logToShow[index].title),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
@@ -276,16 +299,16 @@ class _LogsPageState extends State<LogsPage> {
|
|||||||
Theme.of(context).colorScheme.error,
|
Theme.of(context).colorScheme.error,
|
||||||
Theme.of(context).colorScheme.errorContainer,
|
Theme.of(context).colorScheme.errorContainer,
|
||||||
Theme.of(context).colorScheme.primaryContainer
|
Theme.of(context).colorScheme.primaryContainer
|
||||||
][Log.logs[index].level.index],
|
][logToShow[index].level.index],
|
||||||
borderRadius:
|
borderRadius:
|
||||||
const BorderRadius.all(Radius.circular(16)),
|
const BorderRadius.all(Radius.circular(16)),
|
||||||
),
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(5, 0, 5, 1),
|
padding: const EdgeInsets.fromLTRB(5, 0, 5, 1),
|
||||||
child: Text(
|
child: Text(
|
||||||
Log.logs[index].level.name,
|
logToShow[index].level.name,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Log.logs[index].level.index == 0
|
color: logToShow[index].level.index == 0
|
||||||
? Colors.white
|
? Colors.white
|
||||||
: Colors.black),
|
: Colors.black),
|
||||||
),
|
),
|
||||||
@@ -293,14 +316,14 @@ class _LogsPageState extends State<LogsPage> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Text(Log.logs[index].content),
|
Text(logToShow[index].content),
|
||||||
Text(Log.logs[index].time
|
Text(logToShow[index].time
|
||||||
.toString()
|
.toString()
|
||||||
.replaceAll(RegExp(r"\.\w+"), "")),
|
.replaceAll(RegExp(r"\.\w+"), "")),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Clipboard.setData(
|
Clipboard.setData(
|
||||||
ClipboardData(text: Log.logs[index].content));
|
ClipboardData(text: logToShow[index].content));
|
||||||
},
|
},
|
||||||
child: Text("Copy".tl),
|
child: Text("Copy".tl),
|
||||||
),
|
),
|
||||||
@@ -330,11 +353,10 @@ class _WebdavSettingState extends State<_WebdavSetting> {
|
|||||||
String url = "";
|
String url = "";
|
||||||
String user = "";
|
String user = "";
|
||||||
String pass = "";
|
String pass = "";
|
||||||
bool autoSync = false;
|
bool autoSync = true;
|
||||||
|
|
||||||
bool isTesting = false;
|
bool isTesting = false;
|
||||||
bool upload = true;
|
bool upload = true;
|
||||||
bool isEnabled = false;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -349,8 +371,7 @@ class _WebdavSettingState extends State<_WebdavSetting> {
|
|||||||
url = configs[0];
|
url = configs[0];
|
||||||
user = configs[1];
|
user = configs[1];
|
||||||
pass = configs[2];
|
pass = configs[2];
|
||||||
isEnabled = true;
|
autoSync = appdata.implicitData['webdavAutoSync'] ?? true;
|
||||||
autoSync = appdata.implicitData['webdavAutoSync'] ?? false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onAutoSyncChanged(bool value) {
|
void onAutoSyncChanged(bool value) {
|
||||||
@@ -368,16 +389,11 @@ class _WebdavSettingState extends State<_WebdavSetting> {
|
|||||||
body: SingleChildScrollView(
|
body: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 12),
|
|
||||||
SwitchListTile(
|
|
||||||
title: Text("WebDAV Auto Sync".tl),
|
|
||||||
value: autoSync,
|
|
||||||
onChanged: onAutoSyncChanged,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
TextField(
|
TextField(
|
||||||
decoration: const InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: "URL",
|
labelText: "URL",
|
||||||
|
hintText: "A valid WebDav directory URL".tl,
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
),
|
),
|
||||||
controller: TextEditingController(text: url),
|
controller: TextEditingController(text: url),
|
||||||
@@ -402,49 +418,62 @@ class _WebdavSettingState extends State<_WebdavSetting> {
|
|||||||
onChanged: (value) => pass = value,
|
onChanged: (value) => pass = value,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Row(
|
ListTile(
|
||||||
children: [
|
leading: Icon(Icons.sync),
|
||||||
Text("Operation".tl),
|
title: Text("Auto Sync Data".tl),
|
||||||
Radio<bool>(
|
contentPadding: EdgeInsets.zero,
|
||||||
groupValue: upload,
|
trailing: Switch(
|
||||||
value: true,
|
value: autoSync,
|
||||||
onChanged: (value) {
|
onChanged: onAutoSyncChanged,
|
||||||
setState(() {
|
|
||||||
upload = value!;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Text("Upload".tl),
|
|
||||||
Radio<bool>(
|
|
||||||
groupValue: upload,
|
|
||||||
value: false,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
upload = value!;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Text("Download".tl),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.all(8),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Theme.of(context).colorScheme.primaryContainer,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
RadioGroup<bool>(
|
||||||
|
groupValue: upload,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
upload = value ?? upload;
|
||||||
|
});
|
||||||
|
},
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.info_outline, size: 20),
|
Text("Operation".tl),
|
||||||
const SizedBox(width: 8),
|
Radio<bool>(
|
||||||
Expanded(
|
value: true,
|
||||||
child: Text("Once the operation is successful, app will automatically sync data with the server.".tl),
|
|
||||||
),
|
),
|
||||||
|
Text("Upload".tl),
|
||||||
|
Radio<bool>(
|
||||||
|
value: false,
|
||||||
|
),
|
||||||
|
Text("Download".tl),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
|
AnimatedSize(
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
child: autoSync
|
||||||
|
? Container(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context).colorScheme.primaryContainer,
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.info_outline, size: 20),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
"Once the operation is successful, app will automatically sync data with the server."
|
||||||
|
.tl),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: const SizedBox.shrink(),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
Center(
|
Center(
|
||||||
child: Button.filled(
|
child: Button.filled(
|
||||||
isLoading: isTesting,
|
isLoading: isTesting,
|
||||||
|
|||||||
99
lib/pages/settings/debug.dart
Normal file
99
lib/pages/settings/debug.dart
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
part of 'settings_page.dart';
|
||||||
|
|
||||||
|
class DebugPage extends StatefulWidget {
|
||||||
|
const DebugPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<DebugPage> createState() => DebugPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class DebugPageState extends State<DebugPage> {
|
||||||
|
final controller = TextEditingController();
|
||||||
|
|
||||||
|
var result = "";
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SmoothCustomScrollView(
|
||||||
|
slivers: [
|
||||||
|
SliverAppbar(title: Text("Debug".tl)),
|
||||||
|
_CallbackSetting(
|
||||||
|
title: "Reload Configs".tl,
|
||||||
|
actionTitle: "Reload".tl,
|
||||||
|
callback: () {
|
||||||
|
ComicSourceManager().reload();
|
||||||
|
},
|
||||||
|
).toSliver(),
|
||||||
|
_CallbackSetting(
|
||||||
|
title: "Open Log".tl,
|
||||||
|
callback: () {
|
||||||
|
context.to(() => const LogsPage());
|
||||||
|
},
|
||||||
|
actionTitle: 'Open'.tl,
|
||||||
|
).toSliver(),
|
||||||
|
_SwitchSetting(
|
||||||
|
title: "Ignore Certificate Errors".tl,
|
||||||
|
settingKey: "ignoreBadCertificate",
|
||||||
|
).toSliver(),
|
||||||
|
SliverToBoxAdapter(
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
const Text(
|
||||||
|
"JS Evaluator",
|
||||||
|
style: TextStyle(fontSize: 16),
|
||||||
|
).toAlign(Alignment.centerLeft).paddingLeft(16),
|
||||||
|
Container(
|
||||||
|
width: double.infinity,
|
||||||
|
height: 200,
|
||||||
|
margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
||||||
|
child: TextField(
|
||||||
|
controller: controller,
|
||||||
|
maxLines: null,
|
||||||
|
expands: true,
|
||||||
|
textAlign: TextAlign.start,
|
||||||
|
textAlignVertical: TextAlignVertical.top,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: const OutlineInputBorder(),
|
||||||
|
contentPadding: const EdgeInsets.all(8),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
try {
|
||||||
|
var res = JsEngine().runCode(controller.text, "<debug>");
|
||||||
|
setState(() {
|
||||||
|
result = res.toString();
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
setState(() {
|
||||||
|
result = e.toString();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: const Text("Run"),
|
||||||
|
).toAlign(Alignment.centerRight).paddingRight(16),
|
||||||
|
const Text(
|
||||||
|
"Result",
|
||||||
|
style: TextStyle(fontSize: 16),
|
||||||
|
).toAlign(Alignment.centerLeft).paddingLeft(16),
|
||||||
|
Container(
|
||||||
|
width: double.infinity,
|
||||||
|
height: 200,
|
||||||
|
margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(color: context.colorScheme.outline),
|
||||||
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
),
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Text(result).paddingAll(4),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,8 +25,8 @@ class _ExploreSettingsState extends State<ExploreSettings> {
|
|||||||
title: "Size of comic tile".tl,
|
title: "Size of comic tile".tl,
|
||||||
settingsIndex: "comicTileScale",
|
settingsIndex: "comicTileScale",
|
||||||
interval: 0.05,
|
interval: 0.05,
|
||||||
min: 0.75,
|
min: 0.5,
|
||||||
max: 1.25,
|
max: 1.5,
|
||||||
).toSliver(),
|
).toSliver(),
|
||||||
_PopupWindowSetting(
|
_PopupWindowSetting(
|
||||||
title: "Explore Pages".tl,
|
title: "Explore Pages".tl,
|
||||||
@@ -52,6 +52,10 @@ class _ExploreSettingsState extends State<ExploreSettings> {
|
|||||||
title: "Show history on comic tile".tl,
|
title: "Show history on comic tile".tl,
|
||||||
settingKey: "showHistoryStatusOnTile",
|
settingKey: "showHistoryStatusOnTile",
|
||||||
).toSliver(),
|
).toSliver(),
|
||||||
|
_SwitchSetting(
|
||||||
|
title: "Reverse default chapter order".tl,
|
||||||
|
settingKey: "reverseChapterOrder",
|
||||||
|
).toSliver(),
|
||||||
_PopupWindowSetting(
|
_PopupWindowSetting(
|
||||||
title: "Keyword blocking".tl,
|
title: "Keyword blocking".tl,
|
||||||
builder: () => const _ManageBlockingWordView(),
|
builder: () => const _ManageBlockingWordView(),
|
||||||
|
|||||||
@@ -13,6 +13,14 @@ class _LocalFavoritesSettingsState extends State<LocalFavoritesSettings> {
|
|||||||
return SmoothCustomScrollView(
|
return SmoothCustomScrollView(
|
||||||
slivers: [
|
slivers: [
|
||||||
SliverAppbar(title: Text("Local Favorites".tl)),
|
SliverAppbar(title: Text("Local Favorites".tl)),
|
||||||
|
_SwitchSetting(
|
||||||
|
title: "Show local favorites before network favorites".tl,
|
||||||
|
settingKey: "localFavoritesFirst",
|
||||||
|
).toSliver(),
|
||||||
|
_SwitchSetting(
|
||||||
|
title: "Auto close favorite panel after operation".tl,
|
||||||
|
settingKey: "autoCloseFavoritePanel",
|
||||||
|
).toSliver(),
|
||||||
SelectSetting(
|
SelectSetting(
|
||||||
title: "Add new favorite to".tl,
|
title: "Add new favorite to".tl,
|
||||||
settingKey: "newFavoriteAddTo",
|
settingKey: "newFavoriteAddTo",
|
||||||
|
|||||||
@@ -111,44 +111,34 @@ class _ProxySettingViewState extends State<_ProxySettingView> {
|
|||||||
return PopUpWidgetScaffold(
|
return PopUpWidgetScaffold(
|
||||||
title: "Proxy".tl,
|
title: "Proxy".tl,
|
||||||
body: SingleChildScrollView(
|
body: SingleChildScrollView(
|
||||||
child: Column(
|
child: RadioGroup<String>(
|
||||||
children: [
|
groupValue: type,
|
||||||
RadioListTile<String>(
|
onChanged: (v) {
|
||||||
title: Text("Direct".tl),
|
setState(() {
|
||||||
value: 'direct',
|
type = v ?? type;
|
||||||
groupValue: type,
|
});
|
||||||
onChanged: (v) {
|
if (type != 'manual') {
|
||||||
setState(() {
|
appdata.settings['proxy'] = toProxyStr();
|
||||||
type = v!;
|
appdata.saveData();
|
||||||
});
|
}
|
||||||
appdata.settings['proxy'] = toProxyStr();
|
},
|
||||||
appdata.saveData();
|
child: Column(
|
||||||
},
|
children: [
|
||||||
),
|
RadioListTile<String>(
|
||||||
RadioListTile<String>(
|
title: Text("Direct".tl),
|
||||||
title: Text("System".tl),
|
value: 'direct',
|
||||||
value: 'system',
|
),
|
||||||
groupValue: type,
|
RadioListTile<String>(
|
||||||
onChanged: (v) {
|
title: Text("System".tl),
|
||||||
setState(() {
|
value: 'system',
|
||||||
type = v!;
|
),
|
||||||
});
|
RadioListTile(
|
||||||
appdata.settings['proxy'] = toProxyStr();
|
title: Text("Manual".tl),
|
||||||
appdata.saveData();
|
value: 'manual',
|
||||||
},
|
),
|
||||||
),
|
if (type == 'manual') buildManualProxy(),
|
||||||
RadioListTile(
|
],
|
||||||
title: Text("Manual".tl),
|
),
|
||||||
value: 'manual',
|
|
||||||
groupValue: type,
|
|
||||||
onChanged: (v) {
|
|
||||||
setState(() {
|
|
||||||
type = v!;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
if (type == 'manual') buildManualProxy(),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
part of 'settings_page.dart';
|
part of 'settings_page.dart';
|
||||||
|
|
||||||
class ReaderSettings extends StatefulWidget {
|
class ReaderSettings extends StatefulWidget {
|
||||||
const ReaderSettings({super.key, this.onChanged});
|
const ReaderSettings({
|
||||||
|
super.key,
|
||||||
|
this.onChanged,
|
||||||
|
this.comicId,
|
||||||
|
this.comicSource,
|
||||||
|
});
|
||||||
|
|
||||||
final void Function(String key)? onChanged;
|
final void Function(String key)? onChanged;
|
||||||
|
final String? comicId;
|
||||||
|
final String? comicSource;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<ReaderSettings> createState() => _ReaderSettingsState();
|
State<ReaderSettings> createState() => _ReaderSettingsState();
|
||||||
@@ -12,15 +19,57 @@ class ReaderSettings extends StatefulWidget {
|
|||||||
class _ReaderSettingsState extends State<ReaderSettings> {
|
class _ReaderSettingsState extends State<ReaderSettings> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final comicId = widget.comicId;
|
||||||
|
final sourceKey = widget.comicSource;
|
||||||
|
final key = "$comicId@$sourceKey";
|
||||||
|
|
||||||
|
bool isEnabledSpecificSettings =
|
||||||
|
comicId != null &&
|
||||||
|
appdata.settings.isComicSpecificSettingsEnabled(comicId, sourceKey);
|
||||||
|
|
||||||
return SmoothCustomScrollView(
|
return SmoothCustomScrollView(
|
||||||
slivers: [
|
slivers: [
|
||||||
SliverAppbar(title: Text("Reading".tl)),
|
SliverAppbar(title: Text("Reading".tl)),
|
||||||
|
if (comicId != null && sourceKey != null)
|
||||||
|
SliverMainAxisGroup(
|
||||||
|
slivers: [
|
||||||
|
SwitchListTile(
|
||||||
|
title: Text("Enable comic specific settings".tl),
|
||||||
|
value: isEnabledSpecificSettings,
|
||||||
|
onChanged: (b) {
|
||||||
|
setState(() {
|
||||||
|
appdata.settings.setEnabledComicSpecificSettings(
|
||||||
|
comicId,
|
||||||
|
sourceKey,
|
||||||
|
b,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
).toSliver(),
|
||||||
|
if (isEnabledSpecificSettings)
|
||||||
|
Center(
|
||||||
|
child: TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
appdata.settings.resetComicReaderSettings(key);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: Text(
|
||||||
|
"Clear specific reader settings for this comic".tl,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
).toSliver(),
|
||||||
|
Divider().toSliver(),
|
||||||
|
],
|
||||||
|
),
|
||||||
_SwitchSetting(
|
_SwitchSetting(
|
||||||
title: "Tap to turn Pages".tl,
|
title: "Tap to turn Pages".tl,
|
||||||
settingKey: "enableTapToTurnPages",
|
settingKey: "enableTapToTurnPages",
|
||||||
onChanged: () {
|
onChanged: () {
|
||||||
widget.onChanged?.call("enableTapToTurnPages");
|
widget.onChanged?.call("enableTapToTurnPages");
|
||||||
},
|
},
|
||||||
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
).toSliver(),
|
).toSliver(),
|
||||||
_SwitchSetting(
|
_SwitchSetting(
|
||||||
title: "Reverse tap to turn Pages".tl,
|
title: "Reverse tap to turn Pages".tl,
|
||||||
@@ -28,6 +77,8 @@ class _ReaderSettingsState extends State<ReaderSettings> {
|
|||||||
onChanged: () {
|
onChanged: () {
|
||||||
widget.onChanged?.call("reverseTapToTurnPages");
|
widget.onChanged?.call("reverseTapToTurnPages");
|
||||||
},
|
},
|
||||||
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
).toSliver(),
|
).toSliver(),
|
||||||
_SwitchSetting(
|
_SwitchSetting(
|
||||||
title: "Page animation".tl,
|
title: "Page animation".tl,
|
||||||
@@ -35,6 +86,8 @@ class _ReaderSettingsState extends State<ReaderSettings> {
|
|||||||
onChanged: () {
|
onChanged: () {
|
||||||
widget.onChanged?.call("enablePageAnimation");
|
widget.onChanged?.call("enablePageAnimation");
|
||||||
},
|
},
|
||||||
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
).toSliver(),
|
).toSliver(),
|
||||||
SelectSetting(
|
SelectSetting(
|
||||||
title: "Reading mode".tl,
|
title: "Reading mode".tl,
|
||||||
@@ -48,6 +101,7 @@ class _ReaderSettingsState extends State<ReaderSettings> {
|
|||||||
"continuousTopToBottom": "Continuous (Top to Bottom)".tl,
|
"continuousTopToBottom": "Continuous (Top to Bottom)".tl,
|
||||||
},
|
},
|
||||||
onChanged: () {
|
onChanged: () {
|
||||||
|
setState(() {});
|
||||||
var readerMode = appdata.settings['readerMode'];
|
var readerMode = appdata.settings['readerMode'];
|
||||||
if (readerMode?.toLowerCase().startsWith('continuous') ?? false) {
|
if (readerMode?.toLowerCase().startsWith('continuous') ?? false) {
|
||||||
appdata.settings['readerScreenPicNumberForLandscape'] = 1;
|
appdata.settings['readerScreenPicNumberForLandscape'] = 1;
|
||||||
@@ -57,6 +111,8 @@ class _ReaderSettingsState extends State<ReaderSettings> {
|
|||||||
}
|
}
|
||||||
widget.onChanged?.call("readerMode");
|
widget.onChanged?.call("readerMode");
|
||||||
},
|
},
|
||||||
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
).toSliver(),
|
).toSliver(),
|
||||||
_SliderSetting(
|
_SliderSetting(
|
||||||
title: "Auto page turning interval".tl,
|
title: "Auto page turning interval".tl,
|
||||||
@@ -65,70 +121,110 @@ class _ReaderSettingsState extends State<ReaderSettings> {
|
|||||||
min: 1,
|
min: 1,
|
||||||
max: 20,
|
max: 20,
|
||||||
onChanged: () {
|
onChanged: () {
|
||||||
|
setState(() {});
|
||||||
widget.onChanged?.call("autoPageTurningInterval");
|
widget.onChanged?.call("autoPageTurningInterval");
|
||||||
},
|
},
|
||||||
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
).toSliver(),
|
).toSliver(),
|
||||||
SliverToBoxAdapter(
|
SliverAnimatedVisibility(
|
||||||
child: AbsorbPointer(
|
visible: appdata.settings['readerMode']!.startsWith('gallery'),
|
||||||
absorbing: (appdata.settings['readerMode']
|
child: _SliderSetting(
|
||||||
?.toLowerCase()
|
title:
|
||||||
.startsWith('continuous') ??
|
"The number of pic in screen for landscape (Only Gallery Mode)"
|
||||||
false),
|
.tl,
|
||||||
child: AnimatedOpacity(
|
settingsIndex: "readerScreenPicNumberForLandscape",
|
||||||
opacity: (appdata.settings['readerMode']
|
interval: 1,
|
||||||
?.toLowerCase()
|
min: 1,
|
||||||
.startsWith('continuous') ??
|
max: 5,
|
||||||
false)
|
onChanged: () {
|
||||||
? 0.5
|
setState(() {});
|
||||||
: 1.0,
|
widget.onChanged?.call("readerScreenPicNumberForLandscape");
|
||||||
duration: Duration(milliseconds: 300),
|
},
|
||||||
child: _SliderSetting(
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
title: "The number of pic in screen for landscape (Only Gallery Mode)".tl,
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
settingsIndex: "readerScreenPicNumberForLandscape",
|
|
||||||
interval: 1,
|
|
||||||
min: 1,
|
|
||||||
max: 5,
|
|
||||||
onChanged: () {
|
|
||||||
widget.onChanged?.call("readerScreenPicNumberForLandscape");
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SliverToBoxAdapter(
|
SliverAnimatedVisibility(
|
||||||
child: AbsorbPointer(
|
visible: appdata.settings['readerMode']!.startsWith('gallery'),
|
||||||
absorbing: (appdata.settings['readerMode']
|
child: _SliderSetting(
|
||||||
?.toLowerCase()
|
title:
|
||||||
.startsWith('continuous') ??
|
"The number of pic in screen for portrait (Only Gallery Mode)"
|
||||||
false),
|
.tl,
|
||||||
child: AnimatedOpacity(
|
settingsIndex: "readerScreenPicNumberForPortrait",
|
||||||
opacity: (appdata.settings['readerMode']
|
interval: 1,
|
||||||
?.toLowerCase()
|
min: 1,
|
||||||
.startsWith('continuous') ??
|
max: 5,
|
||||||
false)
|
onChanged: () {
|
||||||
? 0.5
|
widget.onChanged?.call("readerScreenPicNumberForPortrait");
|
||||||
: 1.0,
|
},
|
||||||
duration: Duration(milliseconds: 300),
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
child: _SliderSetting(
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
title: "The number of pic in screen for portrait (Only Gallery Mode)".tl,
|
|
||||||
settingsIndex: "readerScreenPicNumberForPortrait",
|
|
||||||
interval: 1,
|
|
||||||
min: 1,
|
|
||||||
max: 5,
|
|
||||||
onChanged: () {
|
|
||||||
widget.onChanged?.call("readerScreenPicNumberForPortrait");
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
SliverAnimatedVisibility(
|
||||||
|
visible:
|
||||||
|
appdata.settings['readerMode']!.startsWith('gallery') &&
|
||||||
|
(appdata.settings['readerScreenPicNumberForLandscape'] > 1 ||
|
||||||
|
appdata.settings['readerScreenPicNumberForPortrait'] > 1),
|
||||||
|
child: _SwitchSetting(
|
||||||
|
title: "Show single image on first page".tl,
|
||||||
|
settingKey: "showSingleImageOnFirstPage",
|
||||||
|
onChanged: () {
|
||||||
|
widget.onChanged?.call("showSingleImageOnFirstPage");
|
||||||
|
},
|
||||||
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SliverAnimatedVisibility(
|
||||||
|
visible: appdata.settings['readerMode']!.startsWith('continuous'),
|
||||||
|
child: _SliderSetting(
|
||||||
|
title: "Mouse scroll speed".tl,
|
||||||
|
settingsIndex: "readerScrollSpeed",
|
||||||
|
interval: 0.1,
|
||||||
|
min: 0.5,
|
||||||
|
max: 3,
|
||||||
|
onChanged: () {
|
||||||
|
widget.onChanged?.call("readerScrollSpeed");
|
||||||
|
},
|
||||||
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
_SwitchSetting(
|
||||||
|
title: 'Double tap to zoom'.tl,
|
||||||
|
settingKey: 'enableDoubleTapToZoom',
|
||||||
|
onChanged: () {
|
||||||
|
setState(() {});
|
||||||
|
widget.onChanged?.call('enableDoubleTapToZoom');
|
||||||
|
},
|
||||||
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
|
).toSliver(),
|
||||||
_SwitchSetting(
|
_SwitchSetting(
|
||||||
title: 'Long press to zoom'.tl,
|
title: 'Long press to zoom'.tl,
|
||||||
settingKey: 'enableLongPressToZoom',
|
settingKey: 'enableLongPressToZoom',
|
||||||
onChanged: () {
|
onChanged: () {
|
||||||
|
setState(() {});
|
||||||
widget.onChanged?.call('enableLongPressToZoom');
|
widget.onChanged?.call('enableLongPressToZoom');
|
||||||
},
|
},
|
||||||
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
).toSliver(),
|
).toSliver(),
|
||||||
|
SliverAnimatedVisibility(
|
||||||
|
visible: appdata.settings['enableLongPressToZoom'] == true,
|
||||||
|
child: SelectSetting(
|
||||||
|
title: "Long press zoom position".tl,
|
||||||
|
settingKey: "longPressZoomPosition",
|
||||||
|
optionTranslation: {
|
||||||
|
"press": "Press position".tl,
|
||||||
|
"center": "Screen center".tl,
|
||||||
|
},
|
||||||
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
|
),
|
||||||
|
),
|
||||||
_SwitchSetting(
|
_SwitchSetting(
|
||||||
title: 'Limit image width'.tl,
|
title: 'Limit image width'.tl,
|
||||||
subtitle: 'When using Continuous(Top to Bottom) mode'.tl,
|
subtitle: 'When using Continuous(Top to Bottom) mode'.tl,
|
||||||
@@ -136,6 +232,8 @@ class _ReaderSettingsState extends State<ReaderSettings> {
|
|||||||
onChanged: () {
|
onChanged: () {
|
||||||
widget.onChanged?.call('limitImageWidth');
|
widget.onChanged?.call('limitImageWidth');
|
||||||
},
|
},
|
||||||
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
).toSliver(),
|
).toSliver(),
|
||||||
if (App.isAndroid)
|
if (App.isAndroid)
|
||||||
_SwitchSetting(
|
_SwitchSetting(
|
||||||
@@ -144,6 +242,8 @@ class _ReaderSettingsState extends State<ReaderSettings> {
|
|||||||
onChanged: () {
|
onChanged: () {
|
||||||
widget.onChanged?.call('enableTurnPageByVolumeKey');
|
widget.onChanged?.call('enableTurnPageByVolumeKey');
|
||||||
},
|
},
|
||||||
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
).toSliver(),
|
).toSliver(),
|
||||||
_SwitchSetting(
|
_SwitchSetting(
|
||||||
title: "Display time & battery info in reader".tl,
|
title: "Display time & battery info in reader".tl,
|
||||||
@@ -151,6 +251,17 @@ class _ReaderSettingsState extends State<ReaderSettings> {
|
|||||||
onChanged: () {
|
onChanged: () {
|
||||||
widget.onChanged?.call("enableClockAndBatteryInfoInReader");
|
widget.onChanged?.call("enableClockAndBatteryInfoInReader");
|
||||||
},
|
},
|
||||||
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
|
).toSliver(),
|
||||||
|
_SwitchSetting(
|
||||||
|
title: "Show system status bar".tl,
|
||||||
|
settingKey: "showSystemStatusBar",
|
||||||
|
onChanged: () {
|
||||||
|
widget.onChanged?.call("showSystemStatusBar");
|
||||||
|
},
|
||||||
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
).toSliver(),
|
).toSliver(),
|
||||||
SelectSetting(
|
SelectSetting(
|
||||||
title: "Quick collect image".tl,
|
title: "Quick collect image".tl,
|
||||||
@@ -166,6 +277,8 @@ class _ReaderSettingsState extends State<ReaderSettings> {
|
|||||||
help:
|
help:
|
||||||
"On the image browsing page, you can quickly collect images by sliding horizontally or vertically according to your reading mode"
|
"On the image browsing page, you can quickly collect images by sliding horizontally or vertically according to your reading mode"
|
||||||
.tl,
|
.tl,
|
||||||
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
).toSliver(),
|
).toSliver(),
|
||||||
_CallbackSetting(
|
_CallbackSetting(
|
||||||
title: "Custom Image Processing".tl,
|
title: "Custom Image Processing".tl,
|
||||||
@@ -178,6 +291,17 @@ class _ReaderSettingsState extends State<ReaderSettings> {
|
|||||||
interval: 1,
|
interval: 1,
|
||||||
min: 1,
|
min: 1,
|
||||||
max: 16,
|
max: 16,
|
||||||
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
|
).toSliver(),
|
||||||
|
_SwitchSetting(
|
||||||
|
title: "Show Page Number".tl,
|
||||||
|
settingKey: "showPageNumberInReader",
|
||||||
|
onChanged: () {
|
||||||
|
widget.onChanged?.call("showPageNumberInReader");
|
||||||
|
},
|
||||||
|
comicId: isEnabledSpecificSettings ? widget.comicId : null,
|
||||||
|
comicSource: isEnabledSpecificSettings ? widget.comicSource : null,
|
||||||
).toSliver(),
|
).toSliver(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@@ -223,7 +347,7 @@ class __CustomImageProcessingState extends State<_CustomImageProcessing> {
|
|||||||
setState(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
child: Text("Reset".tl),
|
child: Text("Reset".tl),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: Column(
|
body: Column(
|
||||||
@@ -249,7 +373,7 @@ class __CustomImageProcessingState extends State<_CustomImageProcessing> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ class _SwitchSetting extends StatefulWidget {
|
|||||||
required this.settingKey,
|
required this.settingKey,
|
||||||
this.onChanged,
|
this.onChanged,
|
||||||
this.subtitle,
|
this.subtitle,
|
||||||
|
this.comicId,
|
||||||
|
this.comicSource,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
@@ -16,6 +18,10 @@ class _SwitchSetting extends StatefulWidget {
|
|||||||
|
|
||||||
final String? subtitle;
|
final String? subtitle;
|
||||||
|
|
||||||
|
final String? comicId;
|
||||||
|
|
||||||
|
final String? comicSource;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_SwitchSetting> createState() => _SwitchSettingState();
|
State<_SwitchSetting> createState() => _SwitchSettingState();
|
||||||
}
|
}
|
||||||
@@ -23,16 +29,33 @@ class _SwitchSetting extends StatefulWidget {
|
|||||||
class _SwitchSettingState extends State<_SwitchSetting> {
|
class _SwitchSettingState extends State<_SwitchSetting> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
assert(appdata.settings[widget.settingKey] is bool);
|
var value = widget.comicId == null
|
||||||
|
? appdata.settings[widget.settingKey]
|
||||||
|
: appdata.settings.getReaderSetting(
|
||||||
|
widget.comicId!,
|
||||||
|
widget.comicSource!,
|
||||||
|
widget.settingKey,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert(value is bool);
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(widget.title),
|
title: Text(widget.title),
|
||||||
subtitle: widget.subtitle == null ? null : Text(widget.subtitle!),
|
subtitle: widget.subtitle == null ? null : Text(widget.subtitle!),
|
||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: appdata.settings[widget.settingKey],
|
value: value,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
appdata.settings[widget.settingKey] = value;
|
if (widget.comicId == null) {
|
||||||
|
appdata.settings[widget.settingKey] = value;
|
||||||
|
} else {
|
||||||
|
appdata.settings.setReaderSetting(
|
||||||
|
widget.comicId!,
|
||||||
|
widget.comicSource!,
|
||||||
|
widget.settingKey,
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
appdata.saveData().then((_) {
|
appdata.saveData().then((_) {
|
||||||
widget.onChanged?.call();
|
widget.onChanged?.call();
|
||||||
@@ -51,6 +74,8 @@ class SelectSetting extends StatelessWidget {
|
|||||||
required this.optionTranslation,
|
required this.optionTranslation,
|
||||||
this.onChanged,
|
this.onChanged,
|
||||||
this.help,
|
this.help,
|
||||||
|
this.comicId,
|
||||||
|
this.comicSource,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
@@ -63,6 +88,10 @@ class SelectSetting extends StatelessWidget {
|
|||||||
|
|
||||||
final String? help;
|
final String? help;
|
||||||
|
|
||||||
|
final String? comicId;
|
||||||
|
|
||||||
|
final String? comicSource;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
@@ -76,6 +105,8 @@ class SelectSetting extends StatelessWidget {
|
|||||||
optionTranslation: optionTranslation,
|
optionTranslation: optionTranslation,
|
||||||
onChanged: onChanged,
|
onChanged: onChanged,
|
||||||
help: help,
|
help: help,
|
||||||
|
comicId: comicId,
|
||||||
|
comicSource: comicSource,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return _EndSelectorSelectSetting(
|
return _EndSelectorSelectSetting(
|
||||||
@@ -84,6 +115,8 @@ class SelectSetting extends StatelessWidget {
|
|||||||
optionTranslation: optionTranslation,
|
optionTranslation: optionTranslation,
|
||||||
onChanged: onChanged,
|
onChanged: onChanged,
|
||||||
help: help,
|
help: help,
|
||||||
|
comicId: comicId,
|
||||||
|
comicSource: comicSource,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -99,6 +132,8 @@ class _DoubleLineSelectSettings extends StatefulWidget {
|
|||||||
required this.optionTranslation,
|
required this.optionTranslation,
|
||||||
this.onChanged,
|
this.onChanged,
|
||||||
this.help,
|
this.help,
|
||||||
|
this.comicId,
|
||||||
|
this.comicSource,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
@@ -111,6 +146,10 @@ class _DoubleLineSelectSettings extends StatefulWidget {
|
|||||||
|
|
||||||
final String? help;
|
final String? help;
|
||||||
|
|
||||||
|
final String? comicId;
|
||||||
|
|
||||||
|
final String? comicSource;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_DoubleLineSelectSettings> createState() =>
|
State<_DoubleLineSelectSettings> createState() =>
|
||||||
_DoubleLineSelectSettingsState();
|
_DoubleLineSelectSettingsState();
|
||||||
@@ -119,6 +158,14 @@ class _DoubleLineSelectSettings extends StatefulWidget {
|
|||||||
class _DoubleLineSelectSettingsState extends State<_DoubleLineSelectSettings> {
|
class _DoubleLineSelectSettingsState extends State<_DoubleLineSelectSettings> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var value = widget.comicId == null
|
||||||
|
? appdata.settings[widget.settingKey]
|
||||||
|
: appdata.settings.getReaderSetting(
|
||||||
|
widget.comicId!,
|
||||||
|
widget.comicSource!,
|
||||||
|
widget.settingKey,
|
||||||
|
);
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Row(
|
title: Row(
|
||||||
children: [
|
children: [
|
||||||
@@ -134,9 +181,9 @@ class _DoubleLineSelectSettingsState extends State<_DoubleLineSelectSettings> {
|
|||||||
builder: (context) {
|
builder: (context) {
|
||||||
return ContentDialog(
|
return ContentDialog(
|
||||||
title: "Help".tl,
|
title: "Help".tl,
|
||||||
content: Text(widget.help!)
|
content: Text(
|
||||||
.paddingHorizontal(16)
|
widget.help!,
|
||||||
.fixWidth(double.infinity),
|
).paddingHorizontal(16).fixWidth(double.infinity),
|
||||||
actions: [
|
actions: [
|
||||||
Button.filled(
|
Button.filled(
|
||||||
onPressed: context.pop,
|
onPressed: context.pop,
|
||||||
@@ -150,9 +197,7 @@ class _DoubleLineSelectSettingsState extends State<_DoubleLineSelectSettings> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
subtitle: Text(
|
subtitle: Text(widget.optionTranslation[value] ?? "None"),
|
||||||
widget.optionTranslation[appdata.settings[widget.settingKey]] ??
|
|
||||||
"None"),
|
|
||||||
trailing: const Icon(Icons.arrow_drop_down),
|
trailing: const Icon(Icons.arrow_drop_down),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
var renderBox = context.findRenderObject() as RenderBox;
|
var renderBox = context.findRenderObject() as RenderBox;
|
||||||
@@ -170,16 +215,27 @@ class _DoubleLineSelectSettingsState extends State<_DoubleLineSelectSettings> {
|
|||||||
Offset.zero & MediaQuery.of(context).size,
|
Offset.zero & MediaQuery.of(context).size,
|
||||||
),
|
),
|
||||||
items: widget.optionTranslation.keys
|
items: widget.optionTranslation.keys
|
||||||
.map((key) => PopupMenuItem(
|
.map(
|
||||||
value: key,
|
(key) => PopupMenuItem(
|
||||||
height: App.isMobile ? 46 : 40,
|
value: key,
|
||||||
child: Text(widget.optionTranslation[key]!),
|
height: App.isMobile ? 46 : 40,
|
||||||
))
|
child: Text(widget.optionTranslation[key]!),
|
||||||
|
),
|
||||||
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
).then((value) {
|
).then((value) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
appdata.settings[widget.settingKey] = value;
|
if (widget.comicId == null) {
|
||||||
|
appdata.settings[widget.settingKey] = value;
|
||||||
|
} else {
|
||||||
|
appdata.settings.setReaderSetting(
|
||||||
|
widget.comicId!,
|
||||||
|
widget.comicSource!,
|
||||||
|
widget.settingKey,
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
appdata.saveData();
|
appdata.saveData();
|
||||||
widget.onChanged?.call();
|
widget.onChanged?.call();
|
||||||
@@ -197,6 +253,8 @@ class _EndSelectorSelectSetting extends StatefulWidget {
|
|||||||
required this.optionTranslation,
|
required this.optionTranslation,
|
||||||
this.onChanged,
|
this.onChanged,
|
||||||
this.help,
|
this.help,
|
||||||
|
this.comicId,
|
||||||
|
this.comicSource,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
@@ -209,6 +267,10 @@ class _EndSelectorSelectSetting extends StatefulWidget {
|
|||||||
|
|
||||||
final String? help;
|
final String? help;
|
||||||
|
|
||||||
|
final String? comicId;
|
||||||
|
|
||||||
|
final String? comicSource;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_EndSelectorSelectSetting> createState() =>
|
State<_EndSelectorSelectSetting> createState() =>
|
||||||
_EndSelectorSelectSettingState();
|
_EndSelectorSelectSettingState();
|
||||||
@@ -218,6 +280,13 @@ class _EndSelectorSelectSettingState extends State<_EndSelectorSelectSetting> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var options = widget.optionTranslation;
|
var options = widget.optionTranslation;
|
||||||
|
var value = widget.comicId == null
|
||||||
|
? appdata.settings[widget.settingKey]
|
||||||
|
: appdata.settings.getReaderSetting(
|
||||||
|
widget.comicId!,
|
||||||
|
widget.comicSource!,
|
||||||
|
widget.settingKey,
|
||||||
|
);
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Row(
|
title: Row(
|
||||||
children: [
|
children: [
|
||||||
@@ -233,9 +302,9 @@ class _EndSelectorSelectSettingState extends State<_EndSelectorSelectSetting> {
|
|||||||
builder: (context) {
|
builder: (context) {
|
||||||
return ContentDialog(
|
return ContentDialog(
|
||||||
title: "Help".tl,
|
title: "Help".tl,
|
||||||
content: Text(widget.help!)
|
content: Text(
|
||||||
.paddingHorizontal(16)
|
widget.help!,
|
||||||
.fixWidth(double.infinity),
|
).paddingHorizontal(16).fixWidth(double.infinity),
|
||||||
actions: [
|
actions: [
|
||||||
Button.filled(
|
Button.filled(
|
||||||
onPressed: context.pop,
|
onPressed: context.pop,
|
||||||
@@ -250,12 +319,22 @@ class _EndSelectorSelectSettingState extends State<_EndSelectorSelectSetting> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
trailing: Select(
|
trailing: Select(
|
||||||
current: options[appdata.settings[widget.settingKey]],
|
current: options[value],
|
||||||
values: options.values.toList(),
|
values: options.values.toList(),
|
||||||
minWidth: 64,
|
minWidth: 64,
|
||||||
onTap: (index) {
|
onTap: (index) {
|
||||||
setState(() {
|
setState(() {
|
||||||
appdata.settings[widget.settingKey] = options.keys.elementAt(index);
|
var value = options.keys.elementAt(index);
|
||||||
|
if (widget.comicId == null) {
|
||||||
|
appdata.settings[widget.settingKey] = value;
|
||||||
|
} else {
|
||||||
|
appdata.settings.setReaderSetting(
|
||||||
|
widget.comicId!,
|
||||||
|
widget.comicSource!,
|
||||||
|
widget.settingKey,
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
appdata.saveData();
|
appdata.saveData();
|
||||||
widget.onChanged?.call();
|
widget.onChanged?.call();
|
||||||
@@ -273,6 +352,8 @@ class _SliderSetting extends StatefulWidget {
|
|||||||
required this.min,
|
required this.min,
|
||||||
required this.max,
|
required this.max,
|
||||||
this.onChanged,
|
this.onChanged,
|
||||||
|
this.comicId,
|
||||||
|
this.comicSource,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
@@ -287,6 +368,10 @@ class _SliderSetting extends StatefulWidget {
|
|||||||
|
|
||||||
final VoidCallback? onChanged;
|
final VoidCallback? onChanged;
|
||||||
|
|
||||||
|
final String? comicId;
|
||||||
|
|
||||||
|
final String? comicSource;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_SliderSetting> createState() => _SliderSettingState();
|
State<_SliderSetting> createState() => _SliderSettingState();
|
||||||
}
|
}
|
||||||
@@ -294,28 +379,52 @@ class _SliderSetting extends StatefulWidget {
|
|||||||
class _SliderSettingState extends State<_SliderSetting> {
|
class _SliderSettingState extends State<_SliderSetting> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var value =
|
||||||
|
(widget.comicId == null
|
||||||
|
? appdata.settings[widget.settingsIndex]
|
||||||
|
: appdata.settings.getReaderSetting(
|
||||||
|
widget.comicId!,
|
||||||
|
widget.comicSource!,
|
||||||
|
widget.settingsIndex,
|
||||||
|
))
|
||||||
|
.toDouble();
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Row(
|
title: Row(
|
||||||
children: [
|
children: [
|
||||||
Text(widget.title),
|
Text(widget.title),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
Text(
|
Text(value.toString(), style: ts.s12),
|
||||||
appdata.settings[widget.settingsIndex].toString(),
|
|
||||||
style: ts.s12,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
subtitle: Slider(
|
subtitle: Slider(
|
||||||
value: appdata.settings[widget.settingsIndex].toDouble(),
|
value: value,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
if (value.toInt() == value) {
|
if (value.toInt() == value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
appdata.settings[widget.settingsIndex] = value.toInt();
|
if (widget.comicId == null) {
|
||||||
|
appdata.settings[widget.settingsIndex] = value.toInt();
|
||||||
|
} else {
|
||||||
|
appdata.settings.setReaderSetting(
|
||||||
|
widget.comicId!,
|
||||||
|
widget.comicSource!,
|
||||||
|
widget.settingsIndex,
|
||||||
|
value.toInt(),
|
||||||
|
);
|
||||||
|
}
|
||||||
appdata.saveData();
|
appdata.saveData();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
setState(() {
|
setState(() {
|
||||||
appdata.settings[widget.settingsIndex] = value;
|
if (widget.comicId == null) {
|
||||||
|
appdata.settings[widget.settingsIndex] = value;
|
||||||
|
} else {
|
||||||
|
appdata.settings.setReaderSetting(
|
||||||
|
widget.comicId!,
|
||||||
|
widget.comicSource!,
|
||||||
|
widget.settingsIndex,
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
}
|
||||||
appdata.saveData();
|
appdata.saveData();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -402,10 +511,11 @@ class _MultiPagesFilterState extends State<_MultiPagesFilter> {
|
|||||||
color: Theme.of(context).colorScheme.surfaceContainer,
|
color: Theme.of(context).colorScheme.surfaceContainer,
|
||||||
boxShadow: const [
|
boxShadow: const [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: Colors.black12,
|
color: Colors.black12,
|
||||||
blurRadius: 5,
|
blurRadius: 5,
|
||||||
offset: Offset(0, 2),
|
offset: Offset(0, 2),
|
||||||
spreadRadius: 2)
|
spreadRadius: 2,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
onReorder: (reorderFunc) {
|
onReorder: (reorderFunc) {
|
||||||
@@ -435,7 +545,7 @@ class _MultiPagesFilterState extends State<_MultiPagesFilter> {
|
|||||||
label: Text("Add".tl),
|
label: Text("Add".tl),
|
||||||
icon: const Icon(Icons.add),
|
icon: const Icon(Icons.add),
|
||||||
onPressed: showAddDialog,
|
onPressed: showAddDialog,
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
body: view,
|
body: view,
|
||||||
);
|
);
|
||||||
@@ -445,12 +555,13 @@ class _MultiPagesFilterState extends State<_MultiPagesFilter> {
|
|||||||
Widget removeButton = Padding(
|
Widget removeButton = Padding(
|
||||||
padding: const EdgeInsets.only(right: 8),
|
padding: const EdgeInsets.only(right: 8),
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
keys.remove(key);
|
keys.remove(key);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.delete_outline)),
|
icon: const Icon(Icons.delete_outline),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
@@ -458,10 +569,7 @@ class _MultiPagesFilterState extends State<_MultiPagesFilter> {
|
|||||||
key: Key(key),
|
key: Key(key),
|
||||||
trailing: Row(
|
trailing: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [removeButton, const Icon(Icons.drag_handle)],
|
||||||
removeButton,
|
|
||||||
const Icon(Icons.drag_handle),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -477,64 +585,66 @@ class _MultiPagesFilterState extends State<_MultiPagesFilter> {
|
|||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return StatefulBuilder(builder: (context, setState) {
|
return StatefulBuilder(
|
||||||
return ContentDialog(
|
builder: (context, setState) {
|
||||||
title: "Add".tl,
|
return ContentDialog(
|
||||||
content: Column(
|
title: "Add".tl,
|
||||||
mainAxisSize: MainAxisSize.min,
|
content: Column(
|
||||||
children: canAdd.entries
|
mainAxisSize: MainAxisSize.min,
|
||||||
.map(
|
children: canAdd.entries
|
||||||
(e) => CheckboxListTile(
|
.map(
|
||||||
value: selected.contains(e.key),
|
(e) => CheckboxListTile(
|
||||||
title: Text(e.value),
|
value: selected.contains(e.key),
|
||||||
key: Key(e.key),
|
title: Text(e.value),
|
||||||
onChanged: (value) {
|
key: Key(e.key),
|
||||||
setState(() {
|
onChanged: (value) {
|
||||||
if (value!) {
|
setState(() {
|
||||||
selected.add(e.key);
|
if (value!) {
|
||||||
} else {
|
selected.add(e.key);
|
||||||
selected.remove(e.key);
|
} else {
|
||||||
}
|
selected.remove(e.key);
|
||||||
});
|
}
|
||||||
},
|
});
|
||||||
),
|
},
|
||||||
)
|
),
|
||||||
.toList(),
|
)
|
||||||
),
|
.toList(),
|
||||||
actions: [
|
|
||||||
if (selected.length < canAdd.length)
|
|
||||||
TextButton(
|
|
||||||
child: Text("Select All".tl),
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
selected = canAdd.keys.toList();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
)
|
|
||||||
else
|
|
||||||
TextButton(
|
|
||||||
child: Text("Deselect All".tl),
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
selected.clear();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
FilledButton(
|
|
||||||
onPressed: selected.isNotEmpty
|
|
||||||
? () {
|
|
||||||
this.setState(() {
|
|
||||||
keys.addAll(selected);
|
|
||||||
});
|
|
||||||
Navigator.pop(context);
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
child: Text("Add".tl),
|
|
||||||
),
|
),
|
||||||
],
|
actions: [
|
||||||
);
|
if (selected.length < canAdd.length)
|
||||||
});
|
TextButton(
|
||||||
|
child: Text("Select All".tl),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
selected = canAdd.keys.toList();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
)
|
||||||
|
else
|
||||||
|
TextButton(
|
||||||
|
child: Text("Deselect All".tl),
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
selected.clear();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
FilledButton(
|
||||||
|
onPressed: selected.isNotEmpty
|
||||||
|
? () {
|
||||||
|
this.setState(() {
|
||||||
|
keys.addAll(selected);
|
||||||
|
});
|
||||||
|
Navigator.pop(context);
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
child: Text("Add".tl),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ part 'local_favorites.dart';
|
|||||||
part 'app.dart';
|
part 'app.dart';
|
||||||
part 'about.dart';
|
part 'about.dart';
|
||||||
part 'network.dart';
|
part 'network.dart';
|
||||||
|
part 'debug.dart';
|
||||||
|
|
||||||
class SettingsPage extends StatefulWidget {
|
class SettingsPage extends StatefulWidget {
|
||||||
const SettingsPage({this.initialPage = -1, super.key});
|
const SettingsPage({this.initialPage = -1, super.key});
|
||||||
@@ -55,6 +56,7 @@ class _SettingsPageState extends State<SettingsPage> implements PopEntry {
|
|||||||
"APP",
|
"APP",
|
||||||
"Network",
|
"Network",
|
||||||
"About",
|
"About",
|
||||||
|
"Debug"
|
||||||
];
|
];
|
||||||
|
|
||||||
final icons = <IconData>[
|
final icons = <IconData>[
|
||||||
@@ -64,7 +66,8 @@ class _SettingsPageState extends State<SettingsPage> implements PopEntry {
|
|||||||
Icons.collections_bookmark_rounded,
|
Icons.collections_bookmark_rounded,
|
||||||
Icons.apps,
|
Icons.apps,
|
||||||
Icons.public,
|
Icons.public,
|
||||||
Icons.info
|
Icons.info,
|
||||||
|
Icons.bug_report,
|
||||||
];
|
];
|
||||||
|
|
||||||
double offset = 0;
|
double offset = 0;
|
||||||
@@ -246,6 +249,9 @@ class _SettingsPageState extends State<SettingsPage> implements PopEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void handlePointerDown(PointerDownEvent event) {
|
void handlePointerDown(PointerDownEvent event) {
|
||||||
|
if (!App.isIOS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (event.position.dx < 20) {
|
if (event.position.dx < 20) {
|
||||||
gestureRecognizer.addPointer(event);
|
gestureRecognizer.addPointer(event);
|
||||||
}
|
}
|
||||||
@@ -350,6 +356,7 @@ class _SettingsPageState extends State<SettingsPage> implements PopEntry {
|
|||||||
4 => const AppSettings(),
|
4 => const AppSettings(),
|
||||||
5 => const NetworkSettings(),
|
5 => const NetworkSettings(),
|
||||||
6 => const AboutSettings(),
|
6 => const AboutSettings(),
|
||||||
|
7 => const DebugPage(),
|
||||||
_ => throw UnimplementedError()
|
_ => throw UnimplementedError()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import 'package:url_launcher/url_launcher_string.dart';
|
|||||||
import 'package:venera/components/components.dart';
|
import 'package:venera/components/components.dart';
|
||||||
import 'package:venera/foundation/app.dart';
|
import 'package:venera/foundation/app.dart';
|
||||||
import 'package:venera/foundation/appdata.dart';
|
import 'package:venera/foundation/appdata.dart';
|
||||||
import 'package:venera/network/app_dio.dart';
|
import 'package:venera/network/proxy.dart';
|
||||||
import 'package:venera/utils/ext.dart';
|
import 'package:venera/utils/ext.dart';
|
||||||
import 'package:venera/utils/translations.dart';
|
import 'package:venera/utils/translations.dart';
|
||||||
import 'dart:io' as io;
|
import 'dart:io' as io;
|
||||||
@@ -308,7 +308,7 @@ class DesktopWebview {
|
|||||||
useWindowPositionAndSize: true,
|
useWindowPositionAndSize: true,
|
||||||
userDataFolderWindows: "${App.dataPath}\\webview",
|
userDataFolderWindows: "${App.dataPath}\\webview",
|
||||||
title: "webview",
|
title: "webview",
|
||||||
proxy: AppDio.proxy,
|
proxy: await getProxy(),
|
||||||
));
|
));
|
||||||
_webview!.addOnWebMessageReceivedCallback(onMessage);
|
_webview!.addOnWebMessageReceivedCallback(onMessage);
|
||||||
_webview!.setOnNavigation((s) {
|
_webview!.setOnNavigation((s) {
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ abstract class CBZ {
|
|||||||
var ext = e.path.split('.').last;
|
var ext = e.path.split('.').last;
|
||||||
return !['jpg', 'jpeg', 'png', 'webp', 'gif', 'jpe'].contains(ext);
|
return !['jpg', 'jpeg', 'png', 'webp', 'gif', 'jpe'].contains(ext);
|
||||||
});
|
});
|
||||||
if(files.isEmpty) {
|
if (files.isEmpty) {
|
||||||
cache.deleteSync(recursive: true);
|
cache.deleteSync(recursive: true);
|
||||||
throw Exception('No images found in the archive');
|
throw Exception('No images found in the archive');
|
||||||
}
|
}
|
||||||
@@ -141,8 +141,7 @@ abstract class CBZ {
|
|||||||
FilePath.join(LocalManager().path, sanitizeFileName(metaData.title)),
|
FilePath.join(LocalManager().path, sanitizeFileName(metaData.title)),
|
||||||
);
|
);
|
||||||
dest.createSync();
|
dest.createSync();
|
||||||
coverFile.copyMem(
|
coverFile.copyMem(FilePath.join(dest.path, 'cover.${coverFile.extension}'));
|
||||||
FilePath.join(dest.path, 'cover.${coverFile.extension}'));
|
|
||||||
if (metaData.chapters == null) {
|
if (metaData.chapters == null) {
|
||||||
for (var i = 0; i < files.length; i++) {
|
for (var i = 0; i < files.length; i++) {
|
||||||
var src = files[i];
|
var src = files[i];
|
||||||
@@ -233,17 +232,19 @@ abstract class CBZ {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var cover = comic.coverFile;
|
var cover = comic.coverFile;
|
||||||
await cover
|
await cover.copyMem(
|
||||||
.copyMem(FilePath.join(cache.path, 'cover.${cover.path.split('.').last}'));
|
FilePath.join(cache.path, 'cover.${cover.path.split('.').last}'));
|
||||||
|
final metaData = ComicMetaData(
|
||||||
|
title: comic.title,
|
||||||
|
author: comic.subtitle,
|
||||||
|
tags: comic.tags,
|
||||||
|
chapters: chapters,
|
||||||
|
);
|
||||||
await File(FilePath.join(cache.path, 'metadata.json')).writeAsString(
|
await File(FilePath.join(cache.path, 'metadata.json')).writeAsString(
|
||||||
jsonEncode(
|
jsonEncode(metaData),
|
||||||
ComicMetaData(
|
);
|
||||||
title: comic.title,
|
await File(FilePath.join(cache.path, 'ComicInfo.xml')).writeAsString(
|
||||||
author: comic.subtitle,
|
_buildComicInfoXml(metaData),
|
||||||
tags: comic.tags,
|
|
||||||
chapters: chapters,
|
|
||||||
).toJson(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
var cbz = File(outFilePath);
|
var cbz = File(outFilePath);
|
||||||
if (cbz.existsSync()) cbz.deleteSync();
|
if (cbz.existsSync()) cbz.deleteSync();
|
||||||
@@ -252,7 +253,54 @@ abstract class CBZ {
|
|||||||
return cbz;
|
return cbz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String _buildComicInfoXml(ComicMetaData data) {
|
||||||
|
final buffer = StringBuffer();
|
||||||
|
buffer.writeln('<?xml version="1.0" encoding="utf-8"?>');
|
||||||
|
buffer.writeln('<ComicInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">');
|
||||||
|
|
||||||
|
buffer.writeln(' <Title>${_escapeXml(data.title)}</Title>');
|
||||||
|
buffer.writeln(' <Series>${_escapeXml(data.title)}</Series>');
|
||||||
|
|
||||||
|
if (data.author.isNotEmpty) {
|
||||||
|
buffer.writeln(' <Writer>${_escapeXml(data.author)}</Writer>');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.tags.isNotEmpty) {
|
||||||
|
var tags = data.tags;
|
||||||
|
if (tags.length > 5) {
|
||||||
|
tags = tags.sublist(0, 5);
|
||||||
|
}
|
||||||
|
buffer.writeln(' <Genre>${_escapeXml(tags.join(', '))}</Genre>');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.chapters != null && data.chapters!.isNotEmpty) {
|
||||||
|
final chaptersInfo = data.chapters!.map((chapter) =>
|
||||||
|
'${_escapeXml(chapter.title)}: ${chapter.start}-${chapter.end}'
|
||||||
|
).join('; ');
|
||||||
|
buffer.writeln(' <Notes>Chapters: $chaptersInfo</Notes>');
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.writeln(' <Manga>Unknown</Manga>');
|
||||||
|
buffer.writeln(' <BlackAndWhite>Unknown</BlackAndWhite>');
|
||||||
|
|
||||||
|
final now = DateTime.now();
|
||||||
|
buffer.writeln(' <Year>${now.year}</Year>');
|
||||||
|
|
||||||
|
buffer.writeln('</ComicInfo>');
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
static String _escapeXml(String text) {
|
||||||
|
return text
|
||||||
|
.replaceAll('&', '&')
|
||||||
|
.replaceAll('<', '<')
|
||||||
|
.replaceAll('>', '>')
|
||||||
|
.replaceAll('"', '"')
|
||||||
|
.replaceAll("'", ''');
|
||||||
|
}
|
||||||
|
|
||||||
static _compress(String src, String dst) async {
|
static _compress(String src, String dst) async {
|
||||||
await ZipFile.compressFolderAsync(src, dst, 4);
|
await ZipFile.compressFolderAsync(src, dst, 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
58
lib/utils/channel.dart
Normal file
58
lib/utils/channel.dart
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:collection';
|
||||||
|
|
||||||
|
class Channel<T> {
|
||||||
|
final Queue<T> _queue;
|
||||||
|
|
||||||
|
final int size;
|
||||||
|
|
||||||
|
Channel(this.size) : _queue = Queue<T>();
|
||||||
|
|
||||||
|
Completer? _releaseCompleter;
|
||||||
|
|
||||||
|
Completer? _pushCompleter;
|
||||||
|
|
||||||
|
var currentSize = 0;
|
||||||
|
|
||||||
|
var isClosed = false;
|
||||||
|
|
||||||
|
Future<void> push(T item) async {
|
||||||
|
if (currentSize >= size) {
|
||||||
|
_releaseCompleter ??= Completer();
|
||||||
|
return _releaseCompleter!.future.then((_) {
|
||||||
|
if (isClosed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_queue.addLast(item);
|
||||||
|
currentSize++;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_queue.addLast(item);
|
||||||
|
currentSize++;
|
||||||
|
_pushCompleter?.complete();
|
||||||
|
_pushCompleter = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<T?> pop() async {
|
||||||
|
while (_queue.isEmpty) {
|
||||||
|
if (isClosed) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_pushCompleter ??= Completer();
|
||||||
|
await _pushCompleter!.future;
|
||||||
|
}
|
||||||
|
var item = _queue.removeFirst();
|
||||||
|
currentSize--;
|
||||||
|
if (_releaseCompleter != null && currentSize < size) {
|
||||||
|
_releaseCompleter!.complete();
|
||||||
|
_releaseCompleter = null;
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
void close() {
|
||||||
|
isClosed = true;
|
||||||
|
_pushCompleter?.complete();
|
||||||
|
_releaseCompleter?.complete();
|
||||||
|
}
|
||||||
|
}
|
||||||
25
lib/utils/clipboard_image.dart
Normal file
25
lib/utils/clipboard_image.dart
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
import 'dart:ui';
|
||||||
|
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
Future<void> writeImageToClipboard(Uint8List imageBytes) async {
|
||||||
|
const channel = MethodChannel("venera/clipboard");
|
||||||
|
if (Platform.isWindows || Platform.isLinux) {
|
||||||
|
var image = await instantiateImageCodec(imageBytes);
|
||||||
|
var frame = await image.getNextFrame();
|
||||||
|
var data = await frame.image.toByteData(format: ImageByteFormat.rawRgba);
|
||||||
|
await channel.invokeMethod("writeImageToClipboard", {
|
||||||
|
"width": frame.image.width,
|
||||||
|
"height": frame.image.height,
|
||||||
|
"data": Uint8List.view(data!.buffer)
|
||||||
|
});
|
||||||
|
image.dispose();
|
||||||
|
} else if (Platform.isMacOS) {
|
||||||
|
await channel.invokeMethod("writeImageToClipboard", {
|
||||||
|
"data": imageBytes,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw UnsupportedError("Clipboard image is not supported on this platform");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:venera/components/components.dart';
|
||||||
|
import 'package:venera/components/window_frame.dart';
|
||||||
import 'package:venera/foundation/app.dart';
|
import 'package:venera/foundation/app.dart';
|
||||||
import 'package:venera/foundation/appdata.dart';
|
import 'package:venera/foundation/appdata.dart';
|
||||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||||
@@ -9,7 +11,7 @@ import 'package:venera/network/app_dio.dart';
|
|||||||
import 'package:venera/utils/data.dart';
|
import 'package:venera/utils/data.dart';
|
||||||
import 'package:venera/utils/ext.dart';
|
import 'package:venera/utils/ext.dart';
|
||||||
import 'package:webdav_client/webdav_client.dart' hide File;
|
import 'package:webdav_client/webdav_client.dart' hide File;
|
||||||
import 'package:rhttp/rhttp.dart' as rhttp;
|
import 'package:venera/utils/translations.dart';
|
||||||
|
|
||||||
import 'io.dart';
|
import 'io.dart';
|
||||||
|
|
||||||
@@ -20,6 +22,12 @@ class DataSync with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
LocalFavoritesManager().addListener(onDataChanged);
|
LocalFavoritesManager().addListener(onDataChanged);
|
||||||
ComicSourceManager().addListener(onDataChanged);
|
ComicSourceManager().addListener(onDataChanged);
|
||||||
|
if (App.isDesktop) {
|
||||||
|
Future.delayed(const Duration(seconds: 1), () {
|
||||||
|
var controller = WindowFrame.of(App.rootContext);
|
||||||
|
controller.addCloseListener(_handleWindowClose);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onDataChanged() {
|
void onDataChanged() {
|
||||||
@@ -28,6 +36,28 @@ class DataSync with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _handleWindowClose() {
|
||||||
|
if (_isUploading) {
|
||||||
|
_showWindowCloseDialog();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _showWindowCloseDialog() async {
|
||||||
|
showLoadingDialog(
|
||||||
|
App.rootContext,
|
||||||
|
cancelButtonText: "Shut Down".tl,
|
||||||
|
onCancel: () => exit(0),
|
||||||
|
barrierDismissible: false,
|
||||||
|
message: "Uploading data...".tl,
|
||||||
|
);
|
||||||
|
while (_isUploading) {
|
||||||
|
await Future.delayed(const Duration(milliseconds: 50));
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
static DataSync? instance;
|
static DataSync? instance;
|
||||||
|
|
||||||
factory DataSync() => instance ?? (instance = DataSync._());
|
factory DataSync() => instance ?? (instance = DataSync._());
|
||||||
@@ -90,18 +120,11 @@ class DataSync with ChangeNotifier {
|
|||||||
String user = config[1];
|
String user = config[1];
|
||||||
String pass = config[2];
|
String pass = config[2];
|
||||||
|
|
||||||
var proxy = await AppDio.getProxy();
|
|
||||||
|
|
||||||
var client = newClient(
|
var client = newClient(
|
||||||
url,
|
url,
|
||||||
user: user,
|
user: user,
|
||||||
password: pass,
|
password: pass,
|
||||||
adapter: RHttpAdapter(
|
adapter: RHttpAdapter(),
|
||||||
rhttp.ClientSettings(
|
|
||||||
proxySettings:
|
|
||||||
proxy == null ? null : rhttp.ProxySettings.proxy(proxy),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -162,18 +185,11 @@ class DataSync with ChangeNotifier {
|
|||||||
String user = config[1];
|
String user = config[1];
|
||||||
String pass = config[2];
|
String pass = config[2];
|
||||||
|
|
||||||
var proxy = await AppDio.getProxy();
|
|
||||||
|
|
||||||
var client = newClient(
|
var client = newClient(
|
||||||
url,
|
url,
|
||||||
user: user,
|
user: user,
|
||||||
password: pass,
|
password: pass,
|
||||||
adapter: RHttpAdapter(
|
adapter: RHttpAdapter(),
|
||||||
rhttp.ClientSettings(
|
|
||||||
proxySettings:
|
|
||||||
proxy == null ? null : rhttp.ProxySettings.proxy(proxy),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -107,4 +107,15 @@ abstract class MapOrNull{
|
|||||||
static Map<K, V>? from<K, V>(Map<dynamic, dynamic>? i){
|
static Map<K, V>? from<K, V>(Map<dynamic, dynamic>? i){
|
||||||
return i == null ? null : Map<K, V>.from(i);
|
return i == null ? null : Map<K, V>.from(i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension FutureExt<T> on Future<T>{
|
||||||
|
/// Wrap the future to make sure it will return at least the duration.
|
||||||
|
Future<T> minTime(Duration duration) async {
|
||||||
|
var res = await Future.wait([
|
||||||
|
this,
|
||||||
|
Future.delayed(duration),
|
||||||
|
]);
|
||||||
|
return res[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -28,6 +28,8 @@ final _resolver = MimeTypeResolver()
|
|||||||
..addMagicNumber([0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C], 'application/x-7z-compressed')
|
..addMagicNumber([0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C], 'application/x-7z-compressed')
|
||||||
// rar
|
// rar
|
||||||
..addMagicNumber([0x52, 0x61, 0x72, 0x21, 0x1A, 0x07], 'application/vnd.rar')
|
..addMagicNumber([0x52, 0x61, 0x72, 0x21, 0x1A, 0x07], 'application/vnd.rar')
|
||||||
|
// avif
|
||||||
|
..addMagicNumber([0x00, 0x00, 0x00, 0x18, 0x66, 0x74, 0x79, 0x70, 0x61, 0x76, 0x69, 0x66], 'image/avif')
|
||||||
;
|
;
|
||||||
|
|
||||||
FileType detectFileType(List<int> data) {
|
FileType detectFileType(List<int> data) {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:isolate';
|
import 'dart:isolate';
|
||||||
|
|
||||||
@@ -132,25 +131,28 @@ extension DirectoryExtension on Directory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sanitize the file name. Remove invalid characters and trim the file name.
|
/// Sanitize the file name. Remove invalid characters and trim the file name.
|
||||||
String sanitizeFileName(String fileName) {
|
String sanitizeFileName(String fileName, {String? dir, int? maxLength}) {
|
||||||
if (fileName.endsWith('.')) {
|
while (fileName.endsWith('.')) {
|
||||||
fileName = fileName.substring(0, fileName.length - 1);
|
fileName = fileName.substring(0, fileName.length - 1);
|
||||||
}
|
}
|
||||||
const maxLength = 255;
|
var length = maxLength ?? 255;
|
||||||
|
if (dir != null) {
|
||||||
|
if (!dir.endsWith('/') && !dir.endsWith('\\')) {
|
||||||
|
dir = "$dir/";
|
||||||
|
}
|
||||||
|
length -= dir.length;
|
||||||
|
}
|
||||||
final invalidChars = RegExp(r'[<>:"/\\|?*]');
|
final invalidChars = RegExp(r'[<>:"/\\|?*]');
|
||||||
final sanitizedFileName = fileName.replaceAll(invalidChars, ' ');
|
final sanitizedFileName = fileName.replaceAll(invalidChars, ' ');
|
||||||
var trimmedFileName = sanitizedFileName.trim();
|
var trimmedFileName = sanitizedFileName.trim();
|
||||||
if (trimmedFileName.isEmpty) {
|
if (trimmedFileName.isEmpty) {
|
||||||
throw Exception('Invalid File Name: Empty length.');
|
throw Exception('Invalid File Name: Empty length.');
|
||||||
}
|
}
|
||||||
while (true) {
|
if (length <= 0) {
|
||||||
final bytes = utf8.encode(trimmedFileName);
|
throw Exception('Invalid File Name: Max length is less than 0.');
|
||||||
if (bytes.length > maxLength) {
|
}
|
||||||
trimmedFileName =
|
if (trimmedFileName.length > length) {
|
||||||
trimmedFileName.substring(0, trimmedFileName.length - 1);
|
trimmedFileName = trimmedFileName.substring(0, length);
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return trimmedFileName;
|
return trimmedFileName;
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user