mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
Compare commits
138 Commits
v1.0.0-bet
...
v1.0.5
Author | SHA1 | Date | |
---|---|---|---|
dd7154830b | |||
![]() |
194abb82de | ||
a8bc097541 | |||
d34c7c3806 | |||
![]() |
926437b967 | ||
![]() |
856ad82c55 | ||
81baf53ad4 | |||
71b03d744a | |||
6f2bac52e4 | |||
9fcc306ee0 | |||
5d4e8f5b84 | |||
9bdcba1270 | |||
8e99e94620 | |||
![]() |
00bcbaa2eb | ||
![]() |
acb9c47657 | ||
1636c959d0 | |||
![]() |
4ff1140bf6 | ||
![]() |
057d6a2f54 | ||
![]() |
601ef68ad3 | ||
![]() |
c94438d7c4 | ||
![]() |
5825f88e78 | ||
![]() |
389403c11d | ||
![]() |
abd9afad6b | ||
![]() |
5119beb1fe | ||
9b98075153 | |||
775ab471f5 | |||
293040f374 | |||
a427bcdf84 | |||
c4f531a463 | |||
![]() |
6c076bfc7a | ||
![]() |
93bf99daa5 | ||
![]() |
b3e95d7162 | ||
![]() |
c35bf9fb7f | ||
![]() |
189dfe5a43 | ||
![]() |
53b9bc79dd | ||
![]() |
bc4e0f79a5 | ||
05bbef0b8a | |||
e1df69e785 | |||
a0e3cc720a | |||
6ae3e50a5b | |||
![]() |
7cf55fcb8e | ||
![]() |
d875681c4b | ||
193ecdb765 | |||
ea3cc8cc58 | |||
f8eace4c31 | |||
db2c2395de | |||
![]() |
fe266dcade | ||
![]() |
ecb657d20d | ||
b8492b3adc | |||
![]() |
0f37feb318 | ||
6e2c5c6e07 | |||
64d8bcba9a | |||
160d0df935 | |||
6a60194ffb | |||
93193bddc0 | |||
aa415f201e | |||
4f4411fcc3 | |||
![]() |
afd690ed07 | ||
![]() |
a3936f64da | ||
![]() |
7bf8cf569f | ||
![]() |
856ec23586 | ||
![]() |
d910b8a35d | ||
![]() |
234bf218a9 | ||
![]() |
0226477256 | ||
![]() |
42ded1221a | ||
a9a22ace14 | |||
99bbea80dc | |||
26fa41f503 | |||
082aa36316 | |||
5a14ea48c1 | |||
5d43f5c556 | |||
e51a58ba4f | |||
5234de434a | |||
22f2ac99ad | |||
b08b5d0abe | |||
![]() |
96c6323c07 | ||
ae80715db1 | |||
3d7f30af00 | |||
f12cb55bbc | |||
![]() |
1cc30c5748 | ||
af371df2a4 | |||
98b9e6e9d9 | |||
96c75300d0 | |||
a6608b6fa2 | |||
b09e2e6f12 | |||
7991f1a385 | |||
afa320e863 | |||
adb6cdd0c1 | |||
b49e528ff4 | |||
07f8f2a4af | |||
0fbe9677b9 | |||
45e7f0dfc2 | |||
![]() |
9e0e318107 | ||
![]() |
03727d114c | ||
![]() |
6cf5c7b27b | ||
![]() |
173689b57e | ||
![]() |
8fb39b1ec8 | ||
![]() |
679462f272 | ||
![]() |
ee944a2869 | ||
![]() |
bbb414757d | ||
![]() |
f2335894a4 | ||
![]() |
77ef0fb404 | ||
![]() |
28913adc86 | ||
![]() |
cd607ff337 | ||
![]() |
eecd30f77d | ||
![]() |
49174a7d8e | ||
![]() |
c4d867db89 | ||
![]() |
19a93cbbce | ||
![]() |
877e2d5e63 | ||
![]() |
98ae67a6a5 | ||
![]() |
2db3f5a72e | ||
![]() |
2d628ec9b1 | ||
![]() |
b1b516381d | ||
![]() |
048a68f76a | ||
![]() |
11bbbdca0e | ||
![]() |
d48edc6331 | ||
![]() |
13c775b7ce | ||
![]() |
d0e76dd3a0 | ||
![]() |
37997af173 | ||
![]() |
82478fa247 | ||
![]() |
a508d85ce6 | ||
![]() |
a09fb0e81c | ||
![]() |
1883c3ee5b | ||
![]() |
3518949f99 | ||
![]() |
0589e63be7 | ||
![]() |
c2d3f3e56d | ||
![]() |
3e1bb5ef5c | ||
![]() |
7ce84d095e | ||
![]() |
373411e49d | ||
![]() |
0fba86d6a0 | ||
![]() |
97a6e456a5 | ||
![]() |
363f3641fb | ||
![]() |
02bda275b1 | ||
![]() |
093a772dff | ||
![]() |
5280f26981 | ||
![]() |
cc29ff0c33 | ||
![]() |
0db633a9d9 | ||
![]() |
c4dc12e050 |
22
.github/workflows/main.yml
vendored
22
.github/workflows/main.yml
vendored
@@ -4,7 +4,7 @@ on:
|
||||
workflow_dispatch: {}
|
||||
jobs:
|
||||
Build_MacOS:
|
||||
runs-on: macos-13
|
||||
runs-on: macos-15
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: subosito/flutter-action@v2
|
||||
@@ -12,7 +12,7 @@ jobs:
|
||||
channel: "stable"
|
||||
flutter-version-file: pubspec.yaml
|
||||
architecture: x64
|
||||
- run: sudo xcode-select --switch /Applications/Xcode_14.3.1.app
|
||||
- run: sudo xcode-select --switch /Applications/Xcode_16.0.app
|
||||
- run: flutter pub get
|
||||
# Step 1: Decode and install the certificate
|
||||
- name: Decode and install certificate
|
||||
@@ -27,23 +27,23 @@ jobs:
|
||||
- name: Build Flutter macOS App
|
||||
run: flutter build macos --release
|
||||
|
||||
|
||||
# Step 4: Create the DMG file
|
||||
# Step 3: Create the DMG file
|
||||
- name: Create DMG
|
||||
run: |
|
||||
mkdir -p dist
|
||||
hdiutil create -volname "venera" -srcfolder build/macos/Build/Products/Release/venera.app -ov -format UDZO "dist/venera.dmg"
|
||||
mkdir -p dist/dmg_contents
|
||||
cp -R build/macos/Build/Products/Release/venera.app dist/dmg_contents/
|
||||
ln -s /Applications dist/dmg_contents/Applications
|
||||
hdiutil create -volname "venera" -srcfolder dist/dmg_contents -ov -format UDZO "dist/venera.dmg"
|
||||
|
||||
|
||||
|
||||
# Step 8: Attach and upload artifacts (optional)
|
||||
# Step 4: Attach and upload artifacts (optional)
|
||||
- name: Upload DMG
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: venera.dmg
|
||||
path: dist/venera.dmg
|
||||
Build_IOS:
|
||||
runs-on: macos-13
|
||||
runs-on: macos-15
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: subosito/flutter-action@v2
|
||||
@@ -51,7 +51,7 @@ jobs:
|
||||
channel: "stable"
|
||||
flutter-version-file: pubspec.yaml
|
||||
architecture: x64
|
||||
- run: sudo xcode-select --switch /Applications/Xcode_14.3.1.app
|
||||
- run: sudo xcode-select --switch /Applications/Xcode_16.0.app
|
||||
- run: flutter pub get
|
||||
- run: flutter build ios --release --no-codesign
|
||||
- run: |
|
||||
|
5
.gitignore
vendored
5
.gitignore
vendored
@@ -41,3 +41,8 @@ app.*.map.json
|
||||
/android/app/debug
|
||||
/android/app/profile
|
||||
/android/app/release
|
||||
|
||||
add_translation.py
|
||||
|
||||
*/*/generated_*
|
||||
*/*/Generated*
|
39
README.md
39
README.md
@@ -1,16 +1,37 @@
|
||||
# venera
|
||||
|
||||
A comic app.
|
||||
[](https://flutter.dev/)
|
||||
[](https://github.com/venera-app/venera/blob/master/LICENSE)
|
||||
[](https://github.com/venera-app/venera/releases)
|
||||
[](https://github.com/venera-app/venera/stargazers)
|
||||
[](https://t.me/+Ws-IpmUutzkxMjhl)
|
||||
|
||||
## Getting Started
|
||||
A comic reader that support reading local and network comics.
|
||||
|
||||
This project is a starting point for a Flutter application.
|
||||
## Features
|
||||
|
||||
A few resources to get you started if this is your first Flutter project:
|
||||
- Read local comics
|
||||
- Use javascript to create comic sources
|
||||
- Read comics from network sources
|
||||
- Manage favorite comics
|
||||
- Download comics
|
||||
- View comments, tags, and other information of comics if the source supports
|
||||
- Login to comment, rate, and other operations if the source supports
|
||||
|
||||
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
|
||||
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
|
||||
## Build from source
|
||||
|
||||
For help getting started with Flutter development, view the
|
||||
[online documentation](https://docs.flutter.dev/), which offers tutorials,
|
||||
samples, guidance on mobile development, and a full API reference.
|
||||
1. Clone the repository
|
||||
2. Install flutter, see [flutter.dev](https://flutter.dev/docs/get-started/install)
|
||||
3. Install rust, see [rustup.rs](https://rustup.rs/)
|
||||
4. Build for your platform: e.g. `flutter build apk`
|
||||
|
||||
## Create a new comic source
|
||||
|
||||
See [venera-configs](https://github.com/venera-app/venera-configs)
|
||||
|
||||
## Thanks
|
||||
|
||||
### Tags Translation
|
||||
[](https://github.com/EhTagTranslation/Database)
|
||||
|
||||
The Chinese translation of the manga tags is from this project.
|
||||
|
@@ -75,6 +75,9 @@ android {
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
ndk {
|
||||
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
|
||||
}
|
||||
signingConfig signingConfigs.release
|
||||
applicationVariants.all { variant ->
|
||||
variant.outputs.all { output ->
|
||||
|
@@ -1,5 +1,8 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<application
|
||||
android:label="venera"
|
||||
android:name="${applicationName}"
|
||||
|
@@ -3,8 +3,15 @@ package com.github.wgh136.venera
|
||||
import android.app.Activity
|
||||
import android.content.ContentResolver
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.view.KeyEvent
|
||||
import android.Manifest
|
||||
import android.os.Environment
|
||||
import android.provider.Settings
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
@@ -23,6 +30,11 @@ class MainActivity : FlutterActivity() {
|
||||
|
||||
private lateinit var result: MethodChannel.Result
|
||||
|
||||
private val storageRequestCode = 0x10
|
||||
private var storagePermissionRequest: ((Boolean) -> Unit)? = null
|
||||
|
||||
private val selectFileCode = 0x11
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (requestCode == pickDirectoryCode) {
|
||||
@@ -43,6 +55,46 @@ class MainActivity : FlutterActivity() {
|
||||
result.error("Failed to Copy Files", e.toString(), null)
|
||||
}
|
||||
}.start()
|
||||
} else if (requestCode == storageRequestCode) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
storagePermissionRequest?.invoke(Environment.isExternalStorageManager())
|
||||
}
|
||||
storagePermissionRequest = null
|
||||
} else if (requestCode == selectFileCode) {
|
||||
if (resultCode != Activity.RESULT_OK) {
|
||||
result.success(null)
|
||||
return
|
||||
}
|
||||
val uri = data?.data
|
||||
if (uri == null) {
|
||||
result.success(null)
|
||||
return
|
||||
}
|
||||
val contentResolver = context.contentResolver
|
||||
val file = DocumentFile.fromSingleUri(context, uri)
|
||||
if (file == null) {
|
||||
result.success(null)
|
||||
return
|
||||
}
|
||||
val fileName = file.name
|
||||
if (fileName == null) {
|
||||
result.success(null)
|
||||
return
|
||||
}
|
||||
// copy file to cache directory
|
||||
val cacheDir = context.cacheDir
|
||||
val newFile = File(cacheDir, fileName)
|
||||
val inputStream = contentResolver.openInputStream(uri)
|
||||
if (inputStream == null) {
|
||||
result.success(null)
|
||||
return
|
||||
}
|
||||
val outputStream = FileOutputStream(newFile)
|
||||
inputStream.copyTo(outputStream)
|
||||
inputStream.close()
|
||||
outputStream.close()
|
||||
// send file path to flutter
|
||||
result.success(newFile.absolutePath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +141,19 @@ class MainActivity : FlutterActivity() {
|
||||
listening = false
|
||||
}
|
||||
})
|
||||
|
||||
val storageChannel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "venera/storage")
|
||||
storageChannel.setMethodCallHandler { _, res ->
|
||||
requestStoragePermission {result ->
|
||||
res.success(result)
|
||||
}
|
||||
}
|
||||
|
||||
val selectFileChannel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "venera/select_file")
|
||||
selectFileChannel.setMethodCallHandler { _, res ->
|
||||
openFile()
|
||||
result = res
|
||||
}
|
||||
}
|
||||
|
||||
private fun getProxy(): String {
|
||||
@@ -145,6 +210,68 @@ class MainActivity : FlutterActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestStoragePermission(result: (Boolean) -> Unit) {
|
||||
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
||||
val readPermission = ContextCompat.checkSelfPermission(
|
||||
this,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE
|
||||
) == PackageManager.PERMISSION_GRANTED
|
||||
|
||||
val writePermission = ContextCompat.checkSelfPermission(
|
||||
this,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
) == PackageManager.PERMISSION_GRANTED
|
||||
|
||||
if (!readPermission || !writePermission) {
|
||||
storagePermissionRequest = result
|
||||
ActivityCompat.requestPermissions(
|
||||
this,
|
||||
arrayOf(
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
),
|
||||
storageRequestCode
|
||||
)
|
||||
} else {
|
||||
result(true)
|
||||
}
|
||||
} else {
|
||||
if (!Environment.isExternalStorageManager()) {
|
||||
try {
|
||||
val intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
|
||||
intent.addCategory("android.intent.category.DEFAULT")
|
||||
intent.data = Uri.parse("package:" + context.packageName)
|
||||
startActivityForResult(intent, storageRequestCode)
|
||||
} catch (e: Exception) {
|
||||
result(false)
|
||||
}
|
||||
} else {
|
||||
result(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(
|
||||
requestCode: Int,
|
||||
permissions: Array<out String>,
|
||||
grantResults: IntArray
|
||||
) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
if(requestCode == storageRequestCode) {
|
||||
storagePermissionRequest?.invoke(grantResults.all {
|
||||
it == PackageManager.PERMISSION_GRANTED
|
||||
})
|
||||
storagePermissionRequest = null
|
||||
}
|
||||
}
|
||||
|
||||
fun openFile() {
|
||||
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
||||
intent.type = "*/*"
|
||||
startActivityForResult(intent, selectFileCode)
|
||||
}
|
||||
}
|
||||
|
||||
class VolumeListen{
|
||||
|
169
assets/init.js
169
assets/init.js
@@ -224,7 +224,25 @@ let Convert = {
|
||||
key: key,
|
||||
isEncode: false
|
||||
});
|
||||
}
|
||||
},
|
||||
/** Encode bytes to hex string
|
||||
* @param bytes {ArrayBuffer}
|
||||
* @return {string}
|
||||
*/
|
||||
hexEncode: (bytes) => {
|
||||
const hexDigits = '0123456789abcdef';
|
||||
const view = new Uint8Array(bytes);
|
||||
let charCodes = new Uint8Array(view.length * 2);
|
||||
let j = 0;
|
||||
|
||||
for (let i = 0; i < view.length; i++) {
|
||||
let byte = view[i];
|
||||
charCodes[j++] = hexDigits.charCodeAt((byte >> 4) & 0xF);
|
||||
charCodes[j++] = hexDigits.charCodeAt(byte & 0xF);
|
||||
}
|
||||
|
||||
return String.fromCharCode(...charCodes);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -681,7 +699,7 @@ class HtmlElement {
|
||||
doc: this.doc,
|
||||
})
|
||||
if(k == null) return null;
|
||||
return new HtmlElement(k);
|
||||
return new HtmlElement(k, this.doc);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -832,6 +850,7 @@ let console = {
|
||||
* @param id {string}
|
||||
* @param title {string}
|
||||
* @param subtitle {string}
|
||||
* @param subTitle {string} - equal to subtitle
|
||||
* @param cover {string}
|
||||
* @param tags {string[]}
|
||||
* @param description {string}
|
||||
@@ -841,10 +860,11 @@ let console = {
|
||||
* @param stars {number?} - 0-5, double
|
||||
* @constructor
|
||||
*/
|
||||
function Comic({id, title, subtitle, cover, tags, description, maxPage, language, favoriteId, stars}) {
|
||||
function Comic({id, title, subtitle, subTitle, cover, tags, description, maxPage, language, favoriteId, stars}) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.subtitle = subtitle;
|
||||
this.subTitle = subTitle;
|
||||
this.cover = cover;
|
||||
this.tags = tags;
|
||||
this.description = description;
|
||||
@@ -922,6 +942,33 @@ function Comment({userName, avatar, content, time, replyCount, id, isLiked, scor
|
||||
this.voteStatus = voteStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create image loading config
|
||||
* @param url {string?}
|
||||
* @param method {string?} - http method, uppercase
|
||||
* @param data {any} - request data, may be null
|
||||
* @param headers {Object?} - request headers
|
||||
* @param onResponse {((ArrayBuffer) => ArrayBuffer)?} - modify response data
|
||||
* @param modifyImage {string?}
|
||||
* A js script string.
|
||||
* The script will be executed in a new Isolate.
|
||||
* A function named `modifyImage` should be defined in the script, which receives an [Image] as the only argument, and returns an [Image]..
|
||||
* @param onLoadFailed {(() => ImageLoadingConfig)?} - called when the image loading failed
|
||||
* @constructor
|
||||
* @since 1.0.5
|
||||
*
|
||||
* To keep the compatibility with the old version, do not use the constructor. Consider creating a new object with the properties directly.
|
||||
*/
|
||||
function ImageLoadingConfig({url, method, data, headers, onResponse, modifyImage, onLoadFailed}) {
|
||||
this.url = url;
|
||||
this.method = method;
|
||||
this.data = data;
|
||||
this.headers = headers;
|
||||
this.onResponse = onResponse;
|
||||
this.modifyImage = modifyImage;
|
||||
this.onLoadFailed = onLoadFailed;
|
||||
}
|
||||
|
||||
class ComicSource {
|
||||
name = ""
|
||||
|
||||
@@ -999,4 +1046,118 @@ class ComicSource {
|
||||
init() { }
|
||||
|
||||
static sources = {}
|
||||
}
|
||||
}
|
||||
|
||||
/// A reference to dart object.
|
||||
/// The api can only be used in the comic.onImageLoad.modifyImage function
|
||||
class Image {
|
||||
key = 0;
|
||||
|
||||
constructor(key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the specified range of the image
|
||||
* @param x
|
||||
* @param y
|
||||
* @param width
|
||||
* @param height
|
||||
* @returns {Image|null}
|
||||
*/
|
||||
copyRange(x, y, width, height) {
|
||||
let key = sendMessage({
|
||||
method: "image",
|
||||
function: "copyRange",
|
||||
key: this.key,
|
||||
x: x,
|
||||
y: y,
|
||||
width: width,
|
||||
height: height
|
||||
})
|
||||
if(key == null) return null;
|
||||
return new Image(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the image and rotate 90 degrees
|
||||
* @returns {Image|null}
|
||||
*/
|
||||
copyAndRotate90() {
|
||||
let key = sendMessage({
|
||||
method: "image",
|
||||
function: "copyAndRotate90",
|
||||
key: this.key
|
||||
})
|
||||
if(key == null) return null;
|
||||
return new Image(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* fill [image] to this image at (x, y)
|
||||
* @param x
|
||||
* @param y
|
||||
* @param image
|
||||
*/
|
||||
fillImageAt(x, y, image) {
|
||||
sendMessage({
|
||||
method: "image",
|
||||
function: "fillImageAt",
|
||||
key: this.key,
|
||||
x: x,
|
||||
y: y,
|
||||
image: image.key
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* fill [image] with range(srcX, srcY, width, height) to this image at (x, y)
|
||||
* @param x
|
||||
* @param y
|
||||
* @param image
|
||||
* @param srcX
|
||||
* @param srcY
|
||||
* @param width
|
||||
* @param height
|
||||
*/
|
||||
fillImageRangeAt(x, y, image, srcX, srcY, width, height) {
|
||||
sendMessage({
|
||||
method: "image",
|
||||
function: "fillImageRangeAt",
|
||||
key: this.key,
|
||||
x: x,
|
||||
y: y,
|
||||
image: image.key,
|
||||
srcX: srcX,
|
||||
srcY: srcY,
|
||||
width: width,
|
||||
height: height
|
||||
})
|
||||
}
|
||||
|
||||
get width() {
|
||||
return sendMessage({
|
||||
method: "image",
|
||||
function: "getWidth",
|
||||
key: this.key
|
||||
})
|
||||
}
|
||||
|
||||
get height() {
|
||||
return sendMessage({
|
||||
method: "image",
|
||||
function: "getHeight",
|
||||
key: this.key
|
||||
})
|
||||
}
|
||||
|
||||
static empty(width, height) {
|
||||
let key = sendMessage({
|
||||
method: "image",
|
||||
function: "emptyImage",
|
||||
width: width,
|
||||
height: height
|
||||
})
|
||||
return new Image(key);
|
||||
}
|
||||
}
|
||||
|
@@ -17,9 +17,10 @@
|
||||
"Multiple Comics": "多个漫画",
|
||||
"help": "帮助",
|
||||
"Select": "选择",
|
||||
"Selected @a comics": "已选择 @a 部漫画",
|
||||
"Imported @a comics": "已导入 @a 部漫画",
|
||||
"Downloading": "下载中",
|
||||
"Back": "返回",
|
||||
"Back": "后退",
|
||||
"Delete": "删除",
|
||||
"Full Screen": "全屏",
|
||||
"Auto Page Turning": "自动翻页",
|
||||
@@ -41,6 +42,7 @@
|
||||
"Folder": "文件夹",
|
||||
"Confirm": "确认",
|
||||
"Are you sure you want to delete this comic?": "您确定要删除这部漫画吗?",
|
||||
"Are you sure you want to delete @a selected comics?": "您确定要删除 @a 部漫画吗?",
|
||||
"Add comic source": "添加漫画来源",
|
||||
"Select file": "选择文件",
|
||||
"View list": "查看列表",
|
||||
@@ -141,10 +143,73 @@
|
||||
"1. The directory only contains image files." : "1. 目录只包含图片文件。",
|
||||
"2. The directory contains directories which contain image files. Each directory is considered as a chapter." : "2. 目录包含多个包含图片文件的目录。每个目录被视为一个章节。",
|
||||
"If the directory contains a file named 'cover.*', it will be used as the cover image. Otherwise the first image will be used." : "如果目录包含一个名为'cover.*'的文件,它将被用作封面图片。否则将使用第一张图片。",
|
||||
"The directory name will be used as the comic title. And the name of chapter directories will be used as the chapter titles." : "目录名称将被用作漫画标题。章节目录的名称将被用作章节标题。",
|
||||
"The directory name will be used as the comic title. And the name of chapter directories will be used as the chapter titles.\n" : "目录名称将被用作漫画标题。章节目录的名称将被用作章节标题。\n",
|
||||
"Export as cbz": "导出为cbz",
|
||||
"Select a cbz file." : "选择一个cbz文件",
|
||||
"A cbz file" : "一个cbz文件"
|
||||
"A cbz file" : "一个cbz文件",
|
||||
"Fullscreen": "全屏",
|
||||
"Exit": "退出",
|
||||
"View more": "查看更多",
|
||||
"Sort": "排序",
|
||||
"Name": "名称",
|
||||
"Date": "日期",
|
||||
"Date Desc": "日期降序",
|
||||
"Start": "开始",
|
||||
"Export App Data": "导出应用数据",
|
||||
"Import App Data": "导入应用数据",
|
||||
"Export": "导出",
|
||||
"Download Threads": "下载线程数",
|
||||
"Update Time": "更新时间",
|
||||
"Copy ID": "复制ID",
|
||||
"Copy URL": "复制URL",
|
||||
"Create": "创建",
|
||||
"Folder Name": "文件夹名称",
|
||||
"Ranking": "排行",
|
||||
"Download Selected": "下载选中",
|
||||
"Download All": "下载全部",
|
||||
"Order": "顺序",
|
||||
"minAppVersion @version is required": "需要最低App版本 @version",
|
||||
"Remove": "移除",
|
||||
"Long press to zoom": "长按缩放",
|
||||
"Updates Available": "更新可用",
|
||||
"Unselected": "未选择",
|
||||
"Long press and drag to reorder.": "长按并拖动以重新排序。",
|
||||
"Limit image width": "限制图片宽度",
|
||||
"When using Continuous(Top to Bottom) mode": "当使用连续(从上到下)模式",
|
||||
"Open link": "打开链接",
|
||||
"Open comic": "打开漫画",
|
||||
"Move To First": "移动到最前",
|
||||
"Cancel": "取消",
|
||||
"Paused": "已暂停",
|
||||
"Pause": "暂停",
|
||||
"Operation": "操作",
|
||||
"Upload": "上传",
|
||||
"Saved": "已保存",
|
||||
"Sync Data": "同步数据",
|
||||
"Syncing Data": "正在同步数据",
|
||||
"Data Sync": "数据同步",
|
||||
"Quick Favorite": "快速收藏",
|
||||
"Long press on the favorite button to quickly add to this folder": "长按收藏按钮快速添加到这个文件夹",
|
||||
"Added": "已添加",
|
||||
"Turn page by volume keys": "使用音量键翻页",
|
||||
"Display time & battery info in reader":"在阅读器中显示时间和电量信息",
|
||||
"EhViewer downloads":"EhViewer下载",
|
||||
"Select an EhViewer database and a download folder.":"选择EhViewer的下载数据(导出的db文件)与存放下载内容的目录",
|
||||
"(EhViewer)Default": "(EhViewer)默认",
|
||||
"If you import an EhViewer's database, program will automatically create folders according to the download label in that database.": "若通过EhViewer数据库导入漫画,程序将会按其中的下载标签自动创建收藏文件夹。",
|
||||
"Multi-Select": "进入多选模式",
|
||||
"Exit Multi-Select": "退出多选模式",
|
||||
"Selected @c comics": "已选择 @c 本漫画",
|
||||
"Select All": "全选",
|
||||
"Deselect": "取消选择",
|
||||
"Invert Selection": "反选",
|
||||
"Select in range": "区间选择",
|
||||
"Finished": "已完成",
|
||||
"Updating": "更新中",
|
||||
"Update Comics Info": "更新漫画信息",
|
||||
"Create Folder": "新建文件夹",
|
||||
"Select an image on screen": "选择屏幕上的图片",
|
||||
"Added @count comics to download queue.": "已添加 @count 本漫画到下载队列"
|
||||
},
|
||||
"zh_TW": {
|
||||
"Home": "首頁",
|
||||
@@ -165,9 +230,10 @@
|
||||
"Multiple Comics": "多部漫畫",
|
||||
"help": "幫助",
|
||||
"Select": "選擇",
|
||||
"Selected @a comics": "已選擇 @a 部漫畫",
|
||||
"Imported @a comics": "已匯入 @a 部漫畫",
|
||||
"Downloading": "下載中",
|
||||
"Back": "返回",
|
||||
"Back": "後退",
|
||||
"Delete": "刪除",
|
||||
"Full Screen": "全螢幕",
|
||||
"Auto Page Turning": "自動翻頁",
|
||||
@@ -190,6 +256,7 @@
|
||||
"Folder": "文件夾",
|
||||
"Confirm": "確認",
|
||||
"Are you sure you want to delete this comic?": "您確定要刪除這部漫畫嗎?",
|
||||
"Are you sure you want to delete @a selected comics?": "您確定要刪除 @a 部漫畫嗎?",
|
||||
"Add comic source": "添加漫畫來源",
|
||||
"Select file": "選擇文件",
|
||||
"View list": "查看列表",
|
||||
@@ -288,9 +355,72 @@
|
||||
"1. The directory only contains image files." : "1. 目錄只包含圖片文件。",
|
||||
"2. The directory contains directories which contain image files. Each directory is considered as a chapter." : "2. 目錄包含多個包含圖片文件的目錄。每個目錄被視為一個章節。",
|
||||
"If the directory contains a file named 'cover.*', it will be used as the cover image. Otherwise the first image will be used." : "如果目錄包含一個名為'cover.*'的文件,它將被用作封面圖片。否則將使用第一張圖片。",
|
||||
"The directory name will be used as the comic title. And the name of chapter directories will be used as the chapter titles." : "目錄名稱將被用作漫畫標題。章節目錄的名稱將被用作章節標題。",
|
||||
"The directory name will be used as the comic title. And the name of chapter directories will be used as the chapter titles.\n" : "目錄名稱將被用作漫畫標題。章節目錄的名稱將被用作章節標題。\n",
|
||||
"Export as cbz": "匯出為cbz",
|
||||
"Select a cbz file." : "選擇一個cbz文件",
|
||||
"A cbz file" : "一個cbz文件"
|
||||
"A cbz file" : "一個cbz文件",
|
||||
"Fullscreen": "全螢幕",
|
||||
"Exit": "退出",
|
||||
"View more": "查看更多",
|
||||
"Sort": "排序",
|
||||
"Name": "名稱",
|
||||
"Date": "日期",
|
||||
"Date Desc": "日期降序",
|
||||
"Start": "開始",
|
||||
"Export App Data": "匯出應用數據",
|
||||
"Import App Data": "匯入應用數據",
|
||||
"Export": "匯出",
|
||||
"Download Threads": "下載線程數",
|
||||
"Update Time": "更新時間",
|
||||
"Copy ID": "複製ID",
|
||||
"Copy URL": "複製URL",
|
||||
"Create": "創建",
|
||||
"Folder Name": "文件夾名稱",
|
||||
"Ranking": "排行",
|
||||
"Download Selected": "下載選中",
|
||||
"Download All": "下載全部",
|
||||
"Order": "順序",
|
||||
"minAppVersion @version is required": "需要最低App版本 @version",
|
||||
"Remove": "移除",
|
||||
"Long press to zoom": "長按縮放",
|
||||
"Updates Available": "更新可用",
|
||||
"Unselected": "未選擇",
|
||||
"Long press and drag to reorder.": "長按並拖動以重新排序。",
|
||||
"Limit image width": "限制圖片寬度",
|
||||
"When using Continuous(Top to Bottom) mode": "當使用連續(從上到下)模式",
|
||||
"Open link": "打開鏈接",
|
||||
"Open comic": "打開漫畫",
|
||||
"Move To First": "移動到最前",
|
||||
"Cancel": "取消",
|
||||
"Paused": "已暫停",
|
||||
"Pause": "暫停",
|
||||
"Operation": "操作",
|
||||
"Upload": "上傳",
|
||||
"Saved": "已保存",
|
||||
"Sync Data": "同步數據",
|
||||
"Syncing Data": "正在同步數據",
|
||||
"Data Sync": "數據同步",
|
||||
"Quick Favorite": "快速收藏",
|
||||
"Long press on the favorite button to quickly add to this folder": "長按收藏按鈕快速添加到這個文件夾",
|
||||
"Added": "已添加",
|
||||
"Turn page by volume keys": "使用音量鍵翻頁",
|
||||
"Display time & battery info in reader": "在閱讀器中顯示時間和電量信息",
|
||||
"EhViewer downloads": "EhViewer下載",
|
||||
"Select an EhViewer database and a download folder.": "選擇EhViewer的下載資料(匯出的db檔案)與存放下載內容的目錄",
|
||||
"(EhViewer)Default": "(EhViewer)預設",
|
||||
"If you import an EhViewer's database, program will automatically create folders according to the download label in that database.": "若透過EhViewer資料庫匯入漫畫,程式將會按其中的下載標籤自動建立收藏資料夾。",
|
||||
"Multi-Select": "進入多選模式",
|
||||
"Exit Multi-Select": "退出多選模式",
|
||||
"Selected @c comics": "已選擇 @c 本漫畫",
|
||||
"Select All": "全選",
|
||||
"Deselect": "取消選擇",
|
||||
"Invert Selection": "反選",
|
||||
"Select in range": "區間選擇",
|
||||
"Finished": "已完成",
|
||||
"Updating": "更新中",
|
||||
"Update Comics Info": "更新漫畫信息",
|
||||
"Create Folder": "新建文件夾",
|
||||
"Select an image on screen": "選擇屏幕上的圖片",
|
||||
"Added @count comics to download queue.": "已添加 @count 本漫畫到下載隊列"
|
||||
}
|
||||
}
|
@@ -15,6 +15,7 @@
|
||||
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
|
||||
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
|
||||
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
|
||||
C0086D072CDEFE6E004596D9 /* DirectoryPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0086D062CDEFE64004596D9 /* DirectoryPicker.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@@ -59,6 +60,7 @@
|
||||
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
|
||||
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
C0086D062CDEFE64004596D9 /* DirectoryPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DirectoryPicker.swift; sourceTree = "<group>"; };
|
||||
C22B8A9F3177D4A68EB8F66B /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
@@ -133,6 +135,7 @@
|
||||
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */,
|
||||
74858FAE1ED2DC5600515810 /* AppDelegate.swift */,
|
||||
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */,
|
||||
C0086D062CDEFE64004596D9 /* DirectoryPicker.swift */,
|
||||
);
|
||||
path = Runner;
|
||||
sourceTree = "<group>";
|
||||
@@ -144,7 +147,6 @@
|
||||
730F73FE38E23FCF3E461640 /* Pods-Runner.release.xcconfig */,
|
||||
29B89F848F26E839605E1D88 /* Pods-Runner.profile.xcconfig */,
|
||||
);
|
||||
name = Pods;
|
||||
path = Pods;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
@@ -336,6 +338,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
C0086D072CDEFE6E004596D9 /* DirectoryPicker.swift in Sources */,
|
||||
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */,
|
||||
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */,
|
||||
);
|
||||
|
@@ -1,12 +1,16 @@
|
||||
import Flutter
|
||||
import UIKit
|
||||
import UniformTypeIdentifiers
|
||||
import Foundation // 添加此行
|
||||
|
||||
@main
|
||||
@objc class AppDelegate: FlutterAppDelegate, UIDocumentPickerDelegate {
|
||||
var flutterResult: FlutterResult?
|
||||
var directoryPath: URL!
|
||||
|
||||
// 定义插件通道名称
|
||||
private var directoryPicker: DirectoryPicker?
|
||||
|
||||
override func application(
|
||||
_ application: UIApplication,
|
||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
||||
@@ -42,6 +46,9 @@ import UniformTypeIdentifiers
|
||||
self.directoryPath?.stopAccessingSecurityScopedResource()
|
||||
self.directoryPath = nil
|
||||
result(nil)
|
||||
} else if call.method == "selectDirectory" {
|
||||
self.directoryPicker = DirectoryPicker()
|
||||
self.directoryPicker?.selectDirectory(result: result)
|
||||
} else {
|
||||
result(FlutterMethodNotImplemented)
|
||||
}
|
||||
|
36
ios/Runner/DirectoryPicker.swift
Normal file
36
ios/Runner/DirectoryPicker.swift
Normal file
@@ -0,0 +1,36 @@
|
||||
import UIKit
|
||||
import Flutter
|
||||
|
||||
class DirectoryPicker: NSObject, UIDocumentPickerDelegate {
|
||||
private var result: FlutterResult?
|
||||
|
||||
// 初始化选择目录方法
|
||||
func selectDirectory(result: @escaping FlutterResult) {
|
||||
self.result = result
|
||||
|
||||
// 配置 UIDocumentPicker 为目录选择模式
|
||||
let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [.folder])
|
||||
documentPicker.delegate = self
|
||||
documentPicker.allowsMultipleSelection = false
|
||||
|
||||
// 获取根视图控制器并显示选择器
|
||||
if let rootViewController = UIApplication.shared.keyWindow?.rootViewController {
|
||||
rootViewController.present(documentPicker, animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
// 处理选择完成后的结果
|
||||
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
|
||||
// 获取选中的路径
|
||||
if let url = urls.first {
|
||||
result?(url.path)
|
||||
} else {
|
||||
result?(nil)
|
||||
}
|
||||
}
|
||||
|
||||
// 处理取消选择情况
|
||||
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
|
||||
result?(nil)
|
||||
}
|
||||
}
|
@@ -46,6 +46,10 @@
|
||||
<key>UIApplicationSupportsIndirectInputEvents</key>
|
||||
<true/>
|
||||
<key>NSPhotoLibraryUsageDescription</key>
|
||||
<string>Choose images</string>
|
||||
<string>Choose images</string>
|
||||
<key>UIFileSharingEnabled</key>
|
||||
<true/>
|
||||
<key>LSSupportsOpeningDocumentsInPlace</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
@@ -156,7 +156,7 @@ class _ButtonState extends State<Button> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var padding = widget.padding ??
|
||||
const EdgeInsets.symmetric(horizontal: 16, vertical: 6);
|
||||
const EdgeInsets.symmetric(horizontal: 16);
|
||||
var width = widget.width;
|
||||
if (width != null) {
|
||||
width = width - padding.horizontal;
|
||||
@@ -172,7 +172,7 @@ class _ButtonState extends State<Button> {
|
||||
child: DefaultTextStyle(
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
fontSize: 16,
|
||||
fontSize: 14,
|
||||
),
|
||||
child: isLoading
|
||||
? CircularProgressIndicator(
|
||||
@@ -206,15 +206,16 @@ class _ButtonState extends State<Button> {
|
||||
padding: padding,
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 76,
|
||||
minHeight: 32,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: buttonColor,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: (isHover && !isLoading && widget.type == ButtonType.filled)
|
||||
boxShadow: (isHover && !isLoading && (widget.type == ButtonType.filled || widget.type == ButtonType.normal))
|
||||
? [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.1),
|
||||
blurRadius: 4,
|
||||
blurRadius: 2,
|
||||
offset: const Offset(0, 1),
|
||||
)
|
||||
]
|
||||
@@ -252,6 +253,14 @@ class _ButtonState extends State<Button> {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
if (widget.type == ButtonType.normal) {
|
||||
var color = widget.color ?? context.colorScheme.surfaceContainer;
|
||||
if (isHover) {
|
||||
return color.withOpacity(0.9);
|
||||
} else {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
if (isHover) {
|
||||
return context.colorScheme.outline.withOpacity(0.2);
|
||||
}
|
||||
|
@@ -158,9 +158,16 @@ class ComicTile extends StatelessWidget {
|
||||
image = FileImage(File(comic.cover.substring(7)));
|
||||
} else if (comic.sourceKey == 'local') {
|
||||
var localComic = LocalManager().find(comic.id, ComicType.local);
|
||||
image = FileImage(localComic!.coverFile);
|
||||
if (localComic == null) {
|
||||
return const SizedBox();
|
||||
}
|
||||
image = FileImage(localComic.coverFile);
|
||||
} else {
|
||||
image = CachedImageProvider(comic.cover, sourceKey: comic.sourceKey);
|
||||
image = CachedImageProvider(
|
||||
comic.cover,
|
||||
sourceKey: comic.sourceKey,
|
||||
cid: comic.id,
|
||||
);
|
||||
}
|
||||
return AnimatedImage(
|
||||
image: image,
|
||||
@@ -382,7 +389,7 @@ class _ComicDescription extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
title,
|
||||
title.trim(),
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 14.0,
|
||||
@@ -405,47 +412,58 @@ class _ComicDescription extends StatelessWidget {
|
||||
height: 4,
|
||||
),
|
||||
if (tags != null)
|
||||
LayoutBuilder(builder: (context, constraints) {
|
||||
return Container(
|
||||
constraints: const BoxConstraints(maxHeight: 47),
|
||||
child: Wrap(
|
||||
runAlignment: WrapAlignment.start,
|
||||
Expanded(
|
||||
child: LayoutBuilder(builder: (context, constraints) {
|
||||
if (constraints.maxHeight < 22) {
|
||||
return Container();
|
||||
}
|
||||
int cnt = (constraints.maxHeight - 22).toInt() ~/ 25;
|
||||
return Container(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
crossAxisAlignment: WrapCrossAlignment.end,
|
||||
spacing: 4,
|
||||
runSpacing: 3,
|
||||
children: [
|
||||
for (var s in tags!)
|
||||
Container(
|
||||
height: 22,
|
||||
padding: const EdgeInsets.fromLTRB(3,2,3,2),
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: constraints.maxWidth * 0.45,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: s == "Unavailable"
|
||||
? Theme.of(context).colorScheme.errorContainer
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
.secondaryContainer,
|
||||
borderRadius:
|
||||
const BorderRadius.all(Radius.circular(8)),
|
||||
),
|
||||
child: Text(
|
||||
enableTranslate
|
||||
? TagsTranslation.translateTag(s)
|
||||
: s,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
softWrap: true,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
const Spacer(),
|
||||
if (rating != null) StarRating(value: rating!, size: 18),
|
||||
height: 22 + cnt * 25,
|
||||
width: double.infinity,
|
||||
decoration: const BoxDecoration(),
|
||||
child: Wrap(
|
||||
runAlignment: WrapAlignment.start,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
crossAxisAlignment: WrapCrossAlignment.end,
|
||||
spacing: 4,
|
||||
runSpacing: 3,
|
||||
children: [
|
||||
for (var s in tags!)
|
||||
Container(
|
||||
height: 22,
|
||||
padding: const EdgeInsets.fromLTRB(3, 2, 3, 2),
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: constraints.maxWidth * 0.45,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: s == "Unavailable"
|
||||
? Theme.of(context).colorScheme.errorContainer
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
.secondaryContainer,
|
||||
borderRadius:
|
||||
const BorderRadius.all(Radius.circular(8)),
|
||||
),
|
||||
child: Center(
|
||||
widthFactor: 1,
|
||||
child: Text(
|
||||
enableTranslate
|
||||
? TagsTranslation.translateTag(s)
|
||||
: s.split(':').last,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
softWrap: true,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
))),
|
||||
],
|
||||
),
|
||||
).toAlign(Alignment.topCenter);
|
||||
}),
|
||||
)
|
||||
else
|
||||
const Spacer(),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
@@ -453,6 +471,7 @@ class _ComicDescription extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (rating != null) StarRating(value: rating!, size: 18),
|
||||
Text(
|
||||
description,
|
||||
style: const TextStyle(
|
||||
@@ -464,16 +483,17 @@ class _ComicDescription extends StatelessWidget {
|
||||
),
|
||||
if (badge != null)
|
||||
Container(
|
||||
padding: const EdgeInsets.fromLTRB(6, 4, 6, 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.tertiaryContainer,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||
),
|
||||
child: Text(
|
||||
badge!,
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.fromLTRB(6, 4, 6, 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.tertiaryContainer,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
"${badge![0].toUpperCase()}${badge!.substring(1).toLowerCase()}",
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
)),
|
||||
],
|
||||
)
|
||||
],
|
||||
@@ -557,17 +577,19 @@ class _ReadingHistoryPainter extends CustomPainter {
|
||||
}
|
||||
|
||||
class SliverGridComics extends StatefulWidget {
|
||||
const SliverGridComics({
|
||||
super.key,
|
||||
required this.comics,
|
||||
this.onLastItemBuild,
|
||||
this.badgeBuilder,
|
||||
this.menuBuilder,
|
||||
this.onTap,
|
||||
});
|
||||
const SliverGridComics(
|
||||
{super.key,
|
||||
required this.comics,
|
||||
this.onLastItemBuild,
|
||||
this.badgeBuilder,
|
||||
this.menuBuilder,
|
||||
this.onTap,
|
||||
this.selections});
|
||||
|
||||
final List<Comic> comics;
|
||||
|
||||
final Map<Comic, bool>? selections;
|
||||
|
||||
final void Function()? onLastItemBuild;
|
||||
|
||||
final String? Function(Comic)? badgeBuilder;
|
||||
@@ -621,6 +643,7 @@ class _SliverGridComicsState extends State<SliverGridComics> {
|
||||
Widget build(BuildContext context) {
|
||||
return _SliverGridComics(
|
||||
comics: comics,
|
||||
selection: widget.selections,
|
||||
onLastItemBuild: widget.onLastItemBuild,
|
||||
badgeBuilder: widget.badgeBuilder,
|
||||
menuBuilder: widget.menuBuilder,
|
||||
@@ -636,10 +659,13 @@ class _SliverGridComics extends StatelessWidget {
|
||||
this.badgeBuilder,
|
||||
this.menuBuilder,
|
||||
this.onTap,
|
||||
this.selection,
|
||||
});
|
||||
|
||||
final List<Comic> comics;
|
||||
|
||||
final Map<Comic, bool>? selection;
|
||||
|
||||
final void Function()? onLastItemBuild;
|
||||
|
||||
final String? Function(Comic)? badgeBuilder;
|
||||
@@ -657,12 +683,24 @@ class _SliverGridComics extends StatelessWidget {
|
||||
onLastItemBuild?.call();
|
||||
}
|
||||
var badge = badgeBuilder?.call(comics[index]);
|
||||
return ComicTile(
|
||||
var isSelected =
|
||||
selection == null ? false : selection![comics[index]] ?? false;
|
||||
var comic = ComicTile(
|
||||
comic: comics[index],
|
||||
badge: badge,
|
||||
menuOptions: menuBuilder?.call(comics[index]),
|
||||
onTap: onTap != null ? () => onTap!(comics[index]) : null,
|
||||
);
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? Theme.of(context).colorScheme.surfaceContainer
|
||||
: null,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
margin: const EdgeInsets.all(4),
|
||||
child: comic,
|
||||
);
|
||||
},
|
||||
childCount: comics.length,
|
||||
),
|
||||
@@ -860,6 +898,7 @@ class ComicListState extends State<ComicList> {
|
||||
try {
|
||||
if (widget.loadPage != null) {
|
||||
var res = await widget.loadPage!(page);
|
||||
if (!mounted) return;
|
||||
if (res.success) {
|
||||
if (res.data.isEmpty) {
|
||||
_data[page] = const [];
|
||||
|
@@ -21,7 +21,6 @@ import 'package:venera/foundation/history.dart';
|
||||
import 'package:venera/foundation/image_provider/cached_image.dart';
|
||||
import 'package:venera/foundation/local.dart';
|
||||
import 'package:venera/foundation/res.dart';
|
||||
import 'package:venera/foundation/state_controller.dart';
|
||||
import 'package:venera/network/cloudflare.dart';
|
||||
import 'package:venera/pages/comic_page.dart';
|
||||
import 'package:venera/pages/favorites/favorites_page.dart';
|
||||
@@ -45,4 +44,5 @@ part 'scroll.dart';
|
||||
part 'select.dart';
|
||||
part 'side_bar.dart';
|
||||
part 'comic.dart';
|
||||
part 'effects.dart';
|
||||
part 'effects.dart';
|
||||
part 'gesture.dart';
|
22
lib/components/gesture.dart
Normal file
22
lib/components/gesture.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
part of 'components.dart';
|
||||
|
||||
class MouseBackDetector extends StatelessWidget {
|
||||
const MouseBackDetector({super.key, required this.onTapDown, required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
final void Function() onTapDown;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Listener(
|
||||
onPointerDown: (event) {
|
||||
if (event.buttons == kBackMouseButton) {
|
||||
onTapDown();
|
||||
}
|
||||
},
|
||||
behavior: HitTestBehavior.translucent,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
@@ -129,13 +129,14 @@ void showDialogMessage(BuildContext context, String title, String message) {
|
||||
);
|
||||
}
|
||||
|
||||
void showConfirmDialog({
|
||||
Future<void> showConfirmDialog({
|
||||
required BuildContext context,
|
||||
required String title,
|
||||
required String content,
|
||||
required void Function() onConfirm,
|
||||
String confirmText = "Confirm",
|
||||
}) {
|
||||
showDialog(
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (context) => ContentDialog(
|
||||
title: title,
|
||||
@@ -146,7 +147,7 @@ void showConfirmDialog({
|
||||
context.pop();
|
||||
onConfirm();
|
||||
},
|
||||
child: Text("Confirm".tl),
|
||||
child: Text(confirmText.tl),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@@ -27,7 +27,7 @@ class NaviPane extends StatefulWidget {
|
||||
required this.paneActions,
|
||||
required this.pageBuilder,
|
||||
this.initialPage = 0,
|
||||
this.onPageChange,
|
||||
this.onPageChanged,
|
||||
required this.observer,
|
||||
required this.navigatorKey,
|
||||
super.key});
|
||||
@@ -38,7 +38,7 @@ class NaviPane extends StatefulWidget {
|
||||
|
||||
final Widget Function(int page) pageBuilder;
|
||||
|
||||
final void Function(int index)? onPageChange;
|
||||
final void Function(int index)? onPageChanged;
|
||||
|
||||
final int initialPage;
|
||||
|
||||
@@ -59,7 +59,7 @@ class _NaviPaneState extends State<NaviPane>
|
||||
set currentPage(int value) {
|
||||
if (value == _currentPage) return;
|
||||
_currentPage = value;
|
||||
widget.onPageChange?.call(value);
|
||||
widget.onPageChanged?.call(value);
|
||||
}
|
||||
|
||||
void Function()? mainViewUpdateHandler;
|
||||
|
@@ -16,7 +16,14 @@ class SmoothCustomScrollView extends StatelessWidget {
|
||||
return CustomScrollView(
|
||||
controller: controller,
|
||||
physics: physics,
|
||||
slivers: slivers,
|
||||
slivers: [
|
||||
...slivers,
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: context.padding.bottom,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -87,7 +94,7 @@ class _SmoothScrollProviderState extends State<SmoothScrollProvider> {
|
||||
_controller.position.minScrollExtent,
|
||||
_controller.position.maxScrollExtent,
|
||||
);
|
||||
if(_futurePosition == old) return;
|
||||
if (_futurePosition == old) return;
|
||||
_controller.animateTo(_futurePosition!,
|
||||
duration: _fastAnimationDuration, curve: Curves.linear);
|
||||
}
|
||||
|
@@ -485,8 +485,15 @@ class WindowPlacement {
|
||||
}
|
||||
}
|
||||
|
||||
static Rect? lastValidRect;
|
||||
|
||||
static Future<WindowPlacement> get current async {
|
||||
var rect = await windowManager.getBounds();
|
||||
if(validate(rect)) {
|
||||
lastValidRect = rect;
|
||||
} else {
|
||||
rect = lastValidRect ?? defaultPlacement.rect;
|
||||
}
|
||||
var isMaximized = await windowManager.isMaximized();
|
||||
return WindowPlacement(rect, isMaximized);
|
||||
}
|
||||
@@ -501,9 +508,6 @@ class WindowPlacement {
|
||||
static void loop() async {
|
||||
timer ??= Timer.periodic(const Duration(milliseconds: 100), (timer) async {
|
||||
var placement = await WindowPlacement.current;
|
||||
if (!validate(placement.rect)) {
|
||||
return;
|
||||
}
|
||||
if (placement.rect != cache.rect ||
|
||||
placement.isMaximized != cache.isMaximized) {
|
||||
cache = placement;
|
||||
|
@@ -10,7 +10,7 @@ export "widget_utils.dart";
|
||||
export "context.dart";
|
||||
|
||||
class _App {
|
||||
final version = "1.0.0-beta";
|
||||
final version = "1.0.5";
|
||||
|
||||
bool get isAndroid => Platform.isAndroid;
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:venera/foundation/app.dart';
|
||||
import 'package:venera/utils/io.dart';
|
||||
@@ -85,7 +86,7 @@ class _Appdata {
|
||||
|
||||
final appdata = _Appdata();
|
||||
|
||||
class _Settings {
|
||||
class _Settings with ChangeNotifier {
|
||||
_Settings();
|
||||
|
||||
final _data = <String, dynamic>{
|
||||
@@ -109,6 +110,15 @@ class _Settings {
|
||||
'enablePageAnimation': true,
|
||||
'language': 'system', // system, zh-CN, zh-TW, en-US
|
||||
'cacheSize': 2048, // in MB
|
||||
'downloadThreads': 5,
|
||||
'enableLongPressToZoom': true,
|
||||
'checkUpdateOnStart': true,
|
||||
'limitImageWidth': true,
|
||||
'webdav': [], // empty means not configured
|
||||
'dataVersion': 0,
|
||||
'quickFavorite': null,
|
||||
'enableTurnPageByVolumeKey': true,
|
||||
'enableClockAndBatteryInfoInReader': true,
|
||||
};
|
||||
|
||||
operator [](String key) {
|
||||
@@ -117,6 +127,7 @@ class _Settings {
|
||||
|
||||
operator []=(String key, dynamic value) {
|
||||
_data[key] = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@@ -10,8 +10,10 @@ import 'package:venera/foundation/app.dart';
|
||||
import 'package:venera/foundation/comic_type.dart';
|
||||
import 'package:venera/foundation/history.dart';
|
||||
import 'package:venera/foundation/res.dart';
|
||||
import 'package:venera/utils/data_sync.dart';
|
||||
import 'package:venera/utils/ext.dart';
|
||||
import 'package:venera/utils/io.dart';
|
||||
import 'package:venera/utils/translations.dart';
|
||||
|
||||
import '../js_engine.dart';
|
||||
import '../log.dart';
|
||||
@@ -235,6 +237,7 @@ class ComicSource {
|
||||
}
|
||||
await file.writeAsString(jsonEncode(data));
|
||||
_isSaving = false;
|
||||
DataSync().uploadData();
|
||||
}
|
||||
|
||||
Future<bool> reLogin() async {
|
||||
|
@@ -92,7 +92,7 @@ class Comic {
|
||||
|
||||
Comic.fromJson(Map<String, dynamic> json, this.sourceKey)
|
||||
: title = json["title"],
|
||||
subtitle = json["subTitle"] ?? "",
|
||||
subtitle = json["subtitle"] ?? json["subTitle"] ?? "",
|
||||
cover = json["cover"],
|
||||
id = json["id"],
|
||||
tags = List<String>.from(json["tags"] ?? []),
|
||||
|
@@ -106,7 +106,9 @@ class ComicSourceParser {
|
||||
if (minAppVersion != null) {
|
||||
if (compareSemVer(minAppVersion, App.version.split('-').first)) {
|
||||
throw ComicSourceParseException(
|
||||
"minAppVersion $minAppVersion is required");
|
||||
"minAppVersion @version is required"
|
||||
.tlParams({"version": minAppVersion}),
|
||||
);
|
||||
}
|
||||
}
|
||||
for (var source in ComicSource.all()) {
|
||||
@@ -728,7 +730,7 @@ class ComicSourceParser {
|
||||
|
||||
return retryZone(func);
|
||||
};
|
||||
if(_checkExists("favorites.addFolder")) {
|
||||
if (_checkExists("favorites.addFolder")) {
|
||||
addFolder = (name) async {
|
||||
try {
|
||||
await JsEngine().runCode("""
|
||||
@@ -741,7 +743,7 @@ class ComicSourceParser {
|
||||
}
|
||||
};
|
||||
}
|
||||
if(_checkExists("favorites.deleteFolder")) {
|
||||
if (_checkExists("favorites.deleteFolder")) {
|
||||
deleteFolder = (key) async {
|
||||
try {
|
||||
await JsEngine().runCode("""
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:sqlite3/sqlite3.dart';
|
||||
import 'package:venera/foundation/appdata.dart';
|
||||
import 'package:venera/foundation/image_provider/local_favorite_image.dart';
|
||||
@@ -10,8 +11,8 @@ import 'app.dart';
|
||||
import 'comic_source/comic_source.dart';
|
||||
import 'comic_type.dart';
|
||||
|
||||
String _getCurTime() {
|
||||
return DateTime.now()
|
||||
String _getTimeString(DateTime time) {
|
||||
return time
|
||||
.toIso8601String()
|
||||
.replaceFirst("T", " ")
|
||||
.substring(0, 19);
|
||||
@@ -26,7 +27,7 @@ class FavoriteItem implements Comic {
|
||||
@override
|
||||
String id;
|
||||
String coverPath;
|
||||
String time = _getCurTime();
|
||||
late String time;
|
||||
|
||||
FavoriteItem({
|
||||
required this.id,
|
||||
@@ -35,7 +36,11 @@ class FavoriteItem implements Comic {
|
||||
required this.author,
|
||||
required this.type,
|
||||
required this.tags,
|
||||
});
|
||||
DateTime? favoriteTime
|
||||
}) {
|
||||
var t = favoriteTime ?? DateTime.now();
|
||||
time = _getTimeString(t);
|
||||
}
|
||||
|
||||
FavoriteItem.fromRow(Row row)
|
||||
: name = row["name"],
|
||||
@@ -83,7 +88,9 @@ class FavoriteItem implements Comic {
|
||||
int? get maxPage => null;
|
||||
|
||||
@override
|
||||
String get sourceKey => type == ComicType.local ? 'local' : type.comicSource?.key ?? "Unknown:${type.value}";
|
||||
String get sourceKey => type == ComicType.local
|
||||
? 'local'
|
||||
: type.comicSource?.key ?? "Unknown:${type.value}";
|
||||
|
||||
@override
|
||||
double? get stars => null;
|
||||
@@ -108,17 +115,17 @@ class FavoriteItem implements Comic {
|
||||
|
||||
static FavoriteItem fromJson(Map<String, dynamic> json) {
|
||||
var type = json["type"] as int;
|
||||
if(type == 0 && json['coverPath'].toString().startsWith('http')) {
|
||||
if (type == 0 && json['coverPath'].toString().startsWith('http')) {
|
||||
type = 'picacg'.hashCode;
|
||||
} else if(type == 1) {
|
||||
} else if (type == 1) {
|
||||
type = 'ehentai'.hashCode;
|
||||
} else if(type == 2) {
|
||||
} else if (type == 2) {
|
||||
type = 'jm'.hashCode;
|
||||
} else if(type == 3) {
|
||||
} else if (type == 3) {
|
||||
type = 'hitomi'.hashCode;
|
||||
} else if(type == 4) {
|
||||
} else if (type == 4) {
|
||||
type = 'wnacg'.hashCode;
|
||||
} else if(type == 6) {
|
||||
} else if (type == 6) {
|
||||
type = 'nhentai'.hashCode;
|
||||
}
|
||||
return FavoriteItem(
|
||||
@@ -132,24 +139,21 @@ class FavoriteItem implements Comic {
|
||||
}
|
||||
}
|
||||
|
||||
class FavoriteItemWithFolderInfo {
|
||||
FavoriteItem comic;
|
||||
class FavoriteItemWithFolderInfo extends FavoriteItem {
|
||||
String folder;
|
||||
|
||||
FavoriteItemWithFolderInfo(this.comic, this.folder);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is FavoriteItemWithFolderInfo &&
|
||||
other.comic == comic &&
|
||||
other.folder == folder;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => comic.hashCode ^ folder.hashCode;
|
||||
FavoriteItemWithFolderInfo(FavoriteItem item, this.folder)
|
||||
: super(
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
coverPath: item.coverPath,
|
||||
author: item.author,
|
||||
type: item.type,
|
||||
tags: item.tags,
|
||||
);
|
||||
}
|
||||
|
||||
class LocalFavoritesManager {
|
||||
class LocalFavoritesManager with ChangeNotifier {
|
||||
factory LocalFavoritesManager() =>
|
||||
cache ?? (cache = LocalFavoritesManager._create());
|
||||
|
||||
@@ -167,6 +171,13 @@ class LocalFavoritesManager {
|
||||
order_value int
|
||||
);
|
||||
""");
|
||||
_db.execute("""
|
||||
create table if not exists folder_sync (
|
||||
folder_name text primary key,
|
||||
source_key text,
|
||||
source_folder text
|
||||
);
|
||||
""");
|
||||
}
|
||||
|
||||
List<String> find(String id, ComicType type) {
|
||||
@@ -227,13 +238,14 @@ class LocalFavoritesManager {
|
||||
return folders;
|
||||
}
|
||||
|
||||
void updateOrder(Map<String, int> order) {
|
||||
for (var folder in order.keys) {
|
||||
void updateOrder(List<String> folders) {
|
||||
for (int i = 0; i < folders.length; i++) {
|
||||
_db.execute("""
|
||||
insert or replace into folder_order (folder_name, order_value)
|
||||
values (?, ?);
|
||||
""", [folder, order[folder]]);
|
||||
""", [folders[i], i]);
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
int count(String folderName) {
|
||||
@@ -273,6 +285,7 @@ class LocalFavoritesManager {
|
||||
set tags = '$tag,' || tags
|
||||
where id == ?
|
||||
""", [id]);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
List<FavoriteItemWithFolderInfo> allComics() {
|
||||
@@ -287,12 +300,16 @@ class LocalFavoritesManager {
|
||||
return res;
|
||||
}
|
||||
|
||||
bool existsFolder(String name) {
|
||||
return folderNames.contains(name);
|
||||
}
|
||||
|
||||
/// create a folder
|
||||
String createFolder(String name, [bool renameWhenInvalidName = false]) {
|
||||
if (name.isEmpty) {
|
||||
if (renameWhenInvalidName) {
|
||||
int i = 0;
|
||||
while (folderNames.contains(i.toString())) {
|
||||
while (existsFolder(i.toString())) {
|
||||
i++;
|
||||
}
|
||||
name = i.toString();
|
||||
@@ -300,11 +317,11 @@ class LocalFavoritesManager {
|
||||
throw "name is empty!";
|
||||
}
|
||||
}
|
||||
if (folderNames.contains(name)) {
|
||||
if (existsFolder(name)) {
|
||||
if (renameWhenInvalidName) {
|
||||
var prevName = name;
|
||||
int i = 0;
|
||||
while (folderNames.contains(i.toString())) {
|
||||
while (existsFolder(i.toString())) {
|
||||
i++;
|
||||
}
|
||||
name = prevName + i.toString();
|
||||
@@ -325,6 +342,7 @@ class LocalFavoritesManager {
|
||||
primary key (id, type)
|
||||
);
|
||||
""");
|
||||
notifyListeners();
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -352,7 +370,7 @@ class LocalFavoritesManager {
|
||||
/// This method will download cover to local, to avoid problems like changing url
|
||||
void addComic(String folder, FavoriteItem comic, [int? order]) async {
|
||||
_modifiedAfterLastCache = true;
|
||||
if (!folderNames.contains(folder)) {
|
||||
if (!existsFolder(folder)) {
|
||||
throw Exception("Folder does not exists");
|
||||
}
|
||||
var res = _db.select("""
|
||||
@@ -387,6 +405,7 @@ class LocalFavoritesManager {
|
||||
values (?, ?, ?, ?, ?, ?, ?, ?);
|
||||
""", [...params, minValue(folder) - 1]);
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// delete a folder
|
||||
@@ -395,6 +414,7 @@ class LocalFavoritesManager {
|
||||
_db.execute("""
|
||||
drop table "$name";
|
||||
""");
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void deleteComic(String folder, FavoriteItem comic) {
|
||||
@@ -409,6 +429,7 @@ class LocalFavoritesManager {
|
||||
delete from "$folder"
|
||||
where id == ? and type == ?;
|
||||
""", [id, type.value]);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> clearAll() async {
|
||||
@@ -418,7 +439,7 @@ class LocalFavoritesManager {
|
||||
}
|
||||
|
||||
void reorder(List<FavoriteItem> newFolder, String folder) async {
|
||||
if (!folderNames.contains(folder)) {
|
||||
if (!existsFolder(folder)) {
|
||||
throw Exception("Failed to reorder: folder not found");
|
||||
}
|
||||
deleteFolder(folder);
|
||||
@@ -426,10 +447,11 @@ class LocalFavoritesManager {
|
||||
for (int i = 0; i < newFolder.length; i++) {
|
||||
addComic(folder, newFolder[i], i);
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void rename(String before, String after) {
|
||||
if (folderNames.contains(after)) {
|
||||
if (existsFolder(after)) {
|
||||
throw "Name already exists!";
|
||||
}
|
||||
if (after.contains('"')) {
|
||||
@@ -439,6 +461,7 @@ class LocalFavoritesManager {
|
||||
ALTER TABLE "$before"
|
||||
RENAME TO "$after";
|
||||
""");
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void onReadEnd(String id, ComicType type) async {
|
||||
@@ -476,6 +499,7 @@ class LocalFavoritesManager {
|
||||
""", [newTime, id]);
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
List<FavoriteItemWithFolderInfo> search(String keyword) {
|
||||
@@ -498,11 +522,11 @@ class LocalFavoritesManager {
|
||||
}
|
||||
|
||||
bool test(FavoriteItemWithFolderInfo comic, String keyword) {
|
||||
if (comic.comic.name.contains(keyword)) {
|
||||
if (comic.name.contains(keyword)) {
|
||||
return true;
|
||||
} else if (comic.comic.author.contains(keyword)) {
|
||||
} else if (comic.author.contains(keyword)) {
|
||||
return true;
|
||||
} else if (comic.comic.tags.any((element) => element.contains(keyword))) {
|
||||
} else if (comic.tags.any((element) => element.contains(keyword))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -522,6 +546,7 @@ class LocalFavoritesManager {
|
||||
set tags = ?
|
||||
where id == ?;
|
||||
""", [tags.join(","), id]);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
final _cachedFavoritedIds = <String, bool>{};
|
||||
@@ -561,6 +586,7 @@ class LocalFavoritesManager {
|
||||
comic.id,
|
||||
comic.type.value
|
||||
]);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
String folderToJson(String folder) {
|
||||
@@ -577,12 +603,12 @@ class LocalFavoritesManager {
|
||||
void fromJson(String json) {
|
||||
var data = jsonDecode(json);
|
||||
var folder = data["name"];
|
||||
if(folder == null || folder is! String) {
|
||||
if (folder == null || folder is! String) {
|
||||
throw "Invalid data";
|
||||
}
|
||||
if (folderNames.contains(folder)) {
|
||||
if (existsFolder(folder)) {
|
||||
int i = 0;
|
||||
while (folderNames.contains("$folder($i)")) {
|
||||
while (existsFolder("$folder($i)")) {
|
||||
i++;
|
||||
}
|
||||
folder = "$folder($i)";
|
||||
@@ -591,10 +617,13 @@ class LocalFavoritesManager {
|
||||
for (var comic in data["comics"]) {
|
||||
try {
|
||||
addComic(folder, FavoriteItem.fromJson(comic));
|
||||
}
|
||||
catch(e) {
|
||||
} catch (e) {
|
||||
Log.error("Import Data", e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void close() {
|
||||
_db.dispose();
|
||||
}
|
||||
}
|
||||
|
@@ -172,6 +172,8 @@ class HistoryManager with ChangeNotifier {
|
||||
max_page int
|
||||
);
|
||||
""");
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// add history. if exists, update time.
|
||||
@@ -275,4 +277,8 @@ class HistoryManager with ChangeNotifier {
|
||||
""");
|
||||
return res.first[0] as int;
|
||||
}
|
||||
|
||||
void close() {
|
||||
_db.dispose();
|
||||
}
|
||||
}
|
||||
|
@@ -87,17 +87,16 @@ abstract class BaseImageProvider<T extends BaseImageProvider<T>>
|
||||
return await decode(buffer);
|
||||
} catch (e) {
|
||||
await CacheManager().delete(this.key);
|
||||
Object error = e;
|
||||
if (data.length < 2 * 1024) {
|
||||
// data is too short, it's likely that the data is text, not image
|
||||
try {
|
||||
var text = const Utf8Codec(allowMalformed: false).decoder.convert(data);
|
||||
error = Exception("Expected image data, but got text: $text");
|
||||
throw Exception("Expected image data, but got text: $text");
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
rethrow;
|
||||
}
|
||||
} catch (e) {
|
||||
scheduleMicrotask(() {
|
||||
|
@@ -8,7 +8,7 @@ import 'cached_image.dart' as image_provider;
|
||||
class CachedImageProvider
|
||||
extends BaseImageProvider<image_provider.CachedImageProvider> {
|
||||
/// Image provider for normal image.
|
||||
const CachedImageProvider(this.url, {this.headers, this.sourceKey});
|
||||
const CachedImageProvider(this.url, {this.headers, this.sourceKey, this.cid});
|
||||
|
||||
final String url;
|
||||
|
||||
@@ -16,9 +16,11 @@ class CachedImageProvider
|
||||
|
||||
final String? sourceKey;
|
||||
|
||||
final String? cid;
|
||||
|
||||
@override
|
||||
Future<Uint8List> load(StreamController<ImageChunkEvent> chunkEvents) async {
|
||||
await for (var progress in ImageDownloader.loadThumbnail(url, sourceKey)) {
|
||||
await for (var progress in ImageDownloader.loadThumbnail(url, sourceKey, cid)) {
|
||||
chunkEvents.add(ImageChunkEvent(
|
||||
cumulativeBytesLoaded: progress.currentBytes,
|
||||
expectedTotalBytes: progress.totalBytes,
|
||||
@@ -36,5 +38,5 @@ class CachedImageProvider
|
||||
}
|
||||
|
||||
@override
|
||||
String get key => url;
|
||||
String get key => url + (sourceKey ?? "") + (cid ?? "");
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:html/parser.dart' as html;
|
||||
@@ -238,7 +237,7 @@ mixin class _JSEngineApi {
|
||||
Log.warning(
|
||||
"JS Engine",
|
||||
"Too many documents, deleting the oldest: $shouldDelete\n"
|
||||
"Current documents: ${_documents.keys}",
|
||||
"Current documents: ${_documents.keys}",
|
||||
);
|
||||
_documents.remove(shouldDelete);
|
||||
}
|
||||
@@ -350,9 +349,6 @@ mixin class _JSEngineApi {
|
||||
case "utf8":
|
||||
return isEncode ? utf8.encode(value) : utf8.decode(value);
|
||||
case "base64":
|
||||
if (value is String) {
|
||||
value = utf8.encode(value);
|
||||
}
|
||||
return isEncode ? base64Encode(value) : base64Decode(value);
|
||||
case "md5":
|
||||
return Uint8List.fromList(md5.convert(value).bytes);
|
||||
@@ -383,8 +379,21 @@ mixin class _JSEngineApi {
|
||||
if (!isEncode) {
|
||||
var key = data["key"];
|
||||
var cipher = ECBBlockCipher(AESEngine());
|
||||
cipher.init(false, KeyParameter(key));
|
||||
return cipher.process(value);
|
||||
cipher.init(
|
||||
false,
|
||||
KeyParameter(key),
|
||||
);
|
||||
var offset = 0;
|
||||
var result = Uint8List(value.length);
|
||||
while (offset < value.length) {
|
||||
offset += cipher.processBlock(
|
||||
value,
|
||||
offset,
|
||||
result,
|
||||
offset,
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
case "aes-cbc":
|
||||
@@ -393,7 +402,17 @@ mixin class _JSEngineApi {
|
||||
var iv = data["iv"];
|
||||
var cipher = CBCBlockCipher(AESEngine());
|
||||
cipher.init(false, ParametersWithIV(KeyParameter(key), iv));
|
||||
return cipher.process(value);
|
||||
var offset = 0;
|
||||
var result = Uint8List(value.length);
|
||||
while (offset < value.length) {
|
||||
offset += cipher.processBlock(
|
||||
value,
|
||||
offset,
|
||||
result,
|
||||
offset,
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
case "aes-cfb":
|
||||
@@ -402,7 +421,17 @@ mixin class _JSEngineApi {
|
||||
var blockSize = data["blockSize"];
|
||||
var cipher = CFBBlockCipher(AESEngine(), blockSize);
|
||||
cipher.init(false, KeyParameter(key));
|
||||
return cipher.process(value);
|
||||
var offset = 0;
|
||||
var result = Uint8List(value.length);
|
||||
while (offset < value.length) {
|
||||
offset += cipher.processBlock(
|
||||
value,
|
||||
offset,
|
||||
result,
|
||||
offset,
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
case "aes-ofb":
|
||||
@@ -411,7 +440,17 @@ mixin class _JSEngineApi {
|
||||
var blockSize = data["blockSize"];
|
||||
var cipher = OFBBlockCipher(AESEngine(), blockSize);
|
||||
cipher.init(false, KeyParameter(key));
|
||||
return cipher.process(value);
|
||||
var offset = 0;
|
||||
var result = Uint8List(value.length);
|
||||
while (offset < value.length) {
|
||||
offset += cipher.processBlock(
|
||||
value,
|
||||
offset,
|
||||
result,
|
||||
offset,
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
case "rsa":
|
||||
@@ -426,8 +465,8 @@ mixin class _JSEngineApi {
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
} catch (e) {
|
||||
Log.error("JS Engine", "Failed to convert $type: $e");
|
||||
} catch (e, s) {
|
||||
Log.error("JS Engine", "Failed to convert $type: $e", s);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -5,6 +5,8 @@ import 'package:path_provider/path_provider.dart';
|
||||
import 'package:sqlite3/sqlite3.dart';
|
||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||
import 'package:venera/foundation/comic_type.dart';
|
||||
import 'package:venera/foundation/favorites.dart';
|
||||
import 'package:venera/foundation/log.dart';
|
||||
import 'package:venera/network/download.dart';
|
||||
import 'package:venera/pages/reader/reader.dart';
|
||||
import 'package:venera/utils/ext.dart';
|
||||
@@ -158,15 +160,16 @@ class LocalManager with ChangeNotifier {
|
||||
return "Directory is not empty";
|
||||
}
|
||||
try {
|
||||
await copyDirectory(
|
||||
await copyDirectoryIsolate(
|
||||
Directory(path),
|
||||
newDir,
|
||||
);
|
||||
await File(FilePath.join(App.dataPath, 'local_path')).writeAsString(path);
|
||||
} catch (e) {
|
||||
await File(FilePath.join(App.dataPath, 'local_path')).writeAsString(newPath);
|
||||
} catch (e, s) {
|
||||
Log.error("IO", e, s);
|
||||
return e.toString();
|
||||
}
|
||||
await Directory(path).deleteIgnoreError();
|
||||
await Directory(path).deleteIgnoreError(recursive:true);
|
||||
path = newPath;
|
||||
return null;
|
||||
}
|
||||
@@ -261,8 +264,14 @@ class LocalManager with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
List<LocalComic> getComics() {
|
||||
final res = _db.select('SELECT * FROM comics;');
|
||||
List<LocalComic> getComics(LocalSortType sortType) {
|
||||
var res = _db.select('''
|
||||
SELECT * FROM comics
|
||||
ORDER BY
|
||||
${sortType.value == 'name' ? 'title' : 'created_at'}
|
||||
${sortType.value == 'time_asc' ? 'ASC' : 'DESC'}
|
||||
;
|
||||
''');
|
||||
return res.map((row) => LocalComic.fromRow(row)).toList();
|
||||
}
|
||||
|
||||
@@ -310,6 +319,15 @@ class LocalManager with ChangeNotifier {
|
||||
return LocalComic.fromRow(res.first);
|
||||
}
|
||||
|
||||
List<LocalComic> search(String keyword) {
|
||||
final res = _db.select('''
|
||||
SELECT * FROM comics
|
||||
WHERE title LIKE ? OR tags LIKE ? OR subtitle LIKE ?
|
||||
ORDER BY created_at DESC;
|
||||
''', ['%$keyword%', '%$keyword%', '%$keyword%']);
|
||||
return res.map((row) => LocalComic.fromRow(row)).toList();
|
||||
}
|
||||
|
||||
Future<List<String>> getImages(String id, ComicType type, Object ep) async {
|
||||
if(ep is! String && ep is! int) {
|
||||
throw "Invalid ep";
|
||||
@@ -329,6 +347,10 @@ class LocalManager with ChangeNotifier {
|
||||
comic.cover) {
|
||||
continue;
|
||||
}
|
||||
//Hidden file in some file system
|
||||
if(entity.name.startsWith('.')) {
|
||||
continue;
|
||||
}
|
||||
files.add(entity);
|
||||
}
|
||||
}
|
||||
@@ -343,10 +365,10 @@ class LocalManager with ChangeNotifier {
|
||||
return files.map((e) => "file://${e.path}").toList();
|
||||
}
|
||||
|
||||
Future<bool> isDownloaded(String id, ComicType type, int ep) async {
|
||||
Future<bool> isDownloaded(String id, ComicType type, [int? ep]) async {
|
||||
var comic = find(id, type);
|
||||
if (comic == null) return false;
|
||||
if (comic.chapters == null) return true;
|
||||
if (comic.chapters == null || ep == null) return true;
|
||||
return comic.downloadedChapters
|
||||
.contains(comic.chapters!.keys.elementAt(ep-1));
|
||||
}
|
||||
@@ -422,10 +444,40 @@ class LocalManager with ChangeNotifier {
|
||||
downloadingTasks.first.resume();
|
||||
}
|
||||
|
||||
void deleteComic(LocalComic c) {
|
||||
var dir = Directory(FilePath.join(path, c.directory));
|
||||
dir.deleteIgnoreError(recursive: true);
|
||||
void deleteComic(LocalComic c, [bool removeFileOnDisk = true]) {
|
||||
if(removeFileOnDisk) {
|
||||
var dir = Directory(FilePath.join(path, c.directory));
|
||||
dir.deleteIgnoreError(recursive: true);
|
||||
}
|
||||
//Deleting a local comic means that it's nolonger available, thus both favorite and history should be deleted.
|
||||
if(HistoryManager().findSync(c.id, c.comicType) != null) {
|
||||
HistoryManager().remove(c.id, c.comicType);
|
||||
}
|
||||
assert(c.comicType == ComicType.local);
|
||||
var folders = LocalFavoritesManager().find(c.id, c.comicType);
|
||||
for (var f in folders) {
|
||||
LocalFavoritesManager().deleteComicWithId(f, c.id, c.comicType);
|
||||
}
|
||||
remove(c.id, c.comicType);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
enum LocalSortType {
|
||||
name("name"),
|
||||
timeAsc("time_asc"),
|
||||
timeDesc("time_desc");
|
||||
|
||||
final String value;
|
||||
|
||||
const LocalSortType(this.value);
|
||||
|
||||
static LocalSortType fromString(String value) {
|
||||
for (var type in values) {
|
||||
if (type.value == value) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
@@ -82,11 +82,12 @@ class Log {
|
||||
addLog(LogLevel.warning, title, content);
|
||||
}
|
||||
|
||||
static error(String title, String content, [Object? stackTrace]) {
|
||||
static error(String title, Object content, [Object? stackTrace]) {
|
||||
var info = content.toString();
|
||||
if(stackTrace != null) {
|
||||
content += "\n${stackTrace.toString()}";
|
||||
info += "\n${stackTrace.toString()}";
|
||||
}
|
||||
addLog(LogLevel.error, title, content);
|
||||
addLog(LogLevel.error, title, info);
|
||||
}
|
||||
|
||||
static void clear() => _logs.clear();
|
||||
|
@@ -3,8 +3,12 @@ import 'package:desktop_webview_window/desktop_webview_window.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:rhttp/rhttp.dart';
|
||||
import 'package:venera/foundation/log.dart';
|
||||
import 'package:venera/network/app_dio.dart';
|
||||
import 'package:venera/pages/comic_source_page.dart';
|
||||
import 'package:venera/pages/main_page.dart';
|
||||
import 'package:venera/pages/settings/settings_page.dart';
|
||||
import 'package:venera/utils/app_links.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
import 'components/components.dart';
|
||||
@@ -18,9 +22,10 @@ void main(List<String> args) {
|
||||
return;
|
||||
}
|
||||
runZonedGuarded(() async {
|
||||
await Rhttp.init();
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await init();
|
||||
if(App.isAndroid) {
|
||||
if (App.isAndroid) {
|
||||
handleLinks();
|
||||
}
|
||||
FlutterError.onError = (details) {
|
||||
@@ -63,6 +68,7 @@ class MyApp extends StatefulWidget {
|
||||
class _MyAppState extends State<MyApp> {
|
||||
@override
|
||||
void initState() {
|
||||
checkUpdates();
|
||||
App.registerForceRebuild(forceRebuild);
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
super.initState();
|
||||
@@ -73,6 +79,7 @@ class _MyAppState extends State<MyApp> {
|
||||
el.markNeedsBuild();
|
||||
el.visitChildren(rebuild);
|
||||
}
|
||||
|
||||
(context as Element).visitChildren(rebuild);
|
||||
setState(() {});
|
||||
}
|
||||
@@ -114,10 +121,10 @@ class _MyAppState extends State<MyApp> {
|
||||
],
|
||||
locale: () {
|
||||
var lang = appdata.settings['language'];
|
||||
if(lang == 'system') {
|
||||
if (lang == 'system') {
|
||||
return null;
|
||||
}
|
||||
return switch(lang) {
|
||||
return switch (lang) {
|
||||
'zh-CN' => const Locale('zh', 'CN'),
|
||||
'zh-TW' => const Locale('zh', 'TW'),
|
||||
'en-US' => const Locale('en'),
|
||||
@@ -148,7 +155,10 @@ class _MyAppState extends State<MyApp> {
|
||||
App.pop,
|
||||
),
|
||||
},
|
||||
child: WindowFrame(widget),
|
||||
child: MouseBackDetector(
|
||||
onTapDown: App.pop,
|
||||
child: WindowFrame(widget),
|
||||
),
|
||||
);
|
||||
}
|
||||
return _SystemUiProvider(Material(
|
||||
@@ -159,6 +169,22 @@ class _MyAppState extends State<MyApp> {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void checkUpdates() async {
|
||||
if(!appdata.settings['checkUpdateOnStart']) {
|
||||
return;
|
||||
}
|
||||
var lastCheck = appdata.implicitData['lastCheckUpdate'] ?? 0;
|
||||
var now = DateTime.now().millisecondsSinceEpoch;
|
||||
if(now - lastCheck < 24 * 60 * 60 * 1000) {
|
||||
return;
|
||||
}
|
||||
appdata.implicitData['lastCheckUpdate'] = now;
|
||||
appdata.writeImplicitData();
|
||||
await Future.delayed(const Duration(milliseconds: 300));
|
||||
await checkUpdateUi(false);
|
||||
await ComicSourcePage.checkComicSourceUpdate(true);
|
||||
}
|
||||
}
|
||||
|
||||
class _SystemUiProvider extends StatelessWidget {
|
||||
@@ -174,11 +200,13 @@ class _SystemUiProvider extends StatelessWidget {
|
||||
systemUiStyle = SystemUiOverlayStyle.dark.copyWith(
|
||||
statusBarColor: Colors.transparent,
|
||||
systemNavigationBarColor: Colors.transparent,
|
||||
systemNavigationBarIconBrightness: Brightness.dark,
|
||||
);
|
||||
} else {
|
||||
systemUiStyle = SystemUiOverlayStyle.light.copyWith(
|
||||
statusBarColor: Colors.transparent,
|
||||
systemNavigationBarColor: Colors.transparent,
|
||||
systemNavigationBarIconBrightness: Brightness.light,
|
||||
);
|
||||
}
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
|
@@ -1,9 +1,10 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:dio/io.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:rhttp/rhttp.dart' as rhttp;
|
||||
import 'package:venera/foundation/appdata.dart';
|
||||
import 'package:venera/foundation/log.dart';
|
||||
import 'package:venera/network/cache.dart';
|
||||
@@ -108,11 +109,11 @@ class AppDio with DioMixin {
|
||||
|
||||
AppDio([BaseOptions? options]) {
|
||||
this.options = options ?? BaseOptions();
|
||||
interceptors.add(MyLogInterceptor());
|
||||
httpClientAdapter = IOHttpClientAdapter(createHttpClient: createHttpClient);
|
||||
httpClientAdapter = RHttpAdapter(const rhttp.ClientSettings());
|
||||
interceptors.add(CookieManagerSql(SingleInstanceCookieJar.instance!));
|
||||
interceptors.add(NetworkCacheManager());
|
||||
interceptors.add(CloudflareInterceptor());
|
||||
interceptors.add(MyLogInterceptor());
|
||||
}
|
||||
|
||||
static HttpClient createHttpClient() {
|
||||
@@ -136,8 +137,9 @@ class AppDio with DioMixin {
|
||||
static String? proxy;
|
||||
|
||||
static Future<String?> getProxy() async {
|
||||
if ((appdata.settings['proxy'] as String).removeAllBlank == "direct")
|
||||
if ((appdata.settings['proxy'] as String).removeAllBlank == "direct") {
|
||||
return null;
|
||||
}
|
||||
if (appdata.settings['proxy'] != "system") return appdata.settings['proxy'];
|
||||
|
||||
String res;
|
||||
@@ -175,6 +177,8 @@ class AppDio with DioMixin {
|
||||
return res;
|
||||
}
|
||||
|
||||
static final Map<String, bool> _requests = {};
|
||||
|
||||
@override
|
||||
Future<Response<T>> request<T>(
|
||||
String path, {
|
||||
@@ -185,27 +189,111 @@ class AppDio with DioMixin {
|
||||
ProgressCallback? onSendProgress,
|
||||
ProgressCallback? onReceiveProgress,
|
||||
}) async {
|
||||
if(options?.headers?['prevent-parallel'] == 'true') {
|
||||
while(_requests.containsKey(path)) {
|
||||
await Future.delayed(const Duration(milliseconds: 20));
|
||||
}
|
||||
_requests[path] = true;
|
||||
options!.headers!.remove('prevent-parallel');
|
||||
}
|
||||
proxy = await getProxy();
|
||||
if (_proxy != proxy) {
|
||||
Log.info("Network", "Proxy changed to $proxy");
|
||||
_proxy = proxy;
|
||||
(httpClientAdapter as IOHttpClientAdapter).close();
|
||||
httpClientAdapter =
|
||||
IOHttpClientAdapter(createHttpClient: createHttpClient);
|
||||
httpClientAdapter = RHttpAdapter(rhttp.ClientSettings(
|
||||
proxySettings: proxy == null
|
||||
? const rhttp.ProxySettings.noProxy()
|
||||
: rhttp.ProxySettings.proxy(proxy!),
|
||||
));
|
||||
}
|
||||
Log.info(
|
||||
"Network",
|
||||
"${options?.method ?? 'GET'} $path\n"
|
||||
"Headers: ${options?.headers}\n"
|
||||
"Data: $data\n",
|
||||
try {
|
||||
return super.request<T>(
|
||||
path,
|
||||
data: data,
|
||||
queryParameters: queryParameters,
|
||||
cancelToken: cancelToken,
|
||||
options: options,
|
||||
onSendProgress: onSendProgress,
|
||||
onReceiveProgress: onReceiveProgress,
|
||||
);
|
||||
}
|
||||
finally {
|
||||
if(_requests.containsKey(path)) {
|
||||
_requests.remove(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RHttpAdapter implements HttpClientAdapter {
|
||||
rhttp.ClientSettings settings;
|
||||
|
||||
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,
|
||||
);
|
||||
return super.request(
|
||||
path,
|
||||
data: data,
|
||||
queryParameters: queryParameters,
|
||||
cancelToken: cancelToken,
|
||||
options: options,
|
||||
onSendProgress: onSendProgress,
|
||||
onReceiveProgress: onReceiveProgress,
|
||||
}
|
||||
|
||||
@override
|
||||
void close({bool force = false}) {}
|
||||
|
||||
@override
|
||||
Future<ResponseBody> fetch(
|
||||
RequestOptions options,
|
||||
Stream<Uint8List>? requestStream,
|
||||
Future<void>? cancelFuture,
|
||||
) async {
|
||||
var res = await rhttp.Rhttp.request(
|
||||
method: switch (options.method) {
|
||||
'GET' => rhttp.HttpMethod.get,
|
||||
'POST' => rhttp.HttpMethod.post,
|
||||
'PUT' => rhttp.HttpMethod.put,
|
||||
'PATCH' => rhttp.HttpMethod.patch,
|
||||
'DELETE' => rhttp.HttpMethod.delete,
|
||||
'HEAD' => rhttp.HttpMethod.head,
|
||||
'OPTIONS' => rhttp.HttpMethod.options,
|
||||
'TRACE' => rhttp.HttpMethod.trace,
|
||||
'CONNECT' => rhttp.HttpMethod.connect,
|
||||
_ => throw ArgumentError('Unsupported method: ${options.method}'),
|
||||
},
|
||||
url: options.uri.toString(),
|
||||
settings: settings,
|
||||
expectBody: rhttp.HttpExpectBody.stream,
|
||||
body: requestStream == null ? null : rhttp.HttpBody.stream(requestStream),
|
||||
headers: rhttp.HttpHeaders.rawMap(
|
||||
Map.fromEntries(
|
||||
options.headers.entries.map(
|
||||
(e) => MapEntry(e.key, e.value.toString().trim()),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (res is! rhttp.HttpStreamResponse) {
|
||||
throw Exception("Invalid response type: ${res.runtimeType}");
|
||||
}
|
||||
var headers = <String, List<String>>{};
|
||||
for (var entry in res.headers) {
|
||||
var key = entry.$1.toLowerCase();
|
||||
headers[key] ??= [];
|
||||
headers[key]!.add(entry.$2);
|
||||
}
|
||||
var data = res.body;
|
||||
if(headers['content-encoding']?.contains('gzip') ?? false) {
|
||||
// rhttp does not support gzip decoding
|
||||
data = gzip.decoder.bind(data).map((data) => Uint8List.fromList(data));
|
||||
}
|
||||
return ResponseBody(
|
||||
data,
|
||||
res.statusCode,
|
||||
statusMessage: null,
|
||||
isRedirect: false,
|
||||
headers: headers,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'dart:typed_data';
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
class NetworkCache {
|
||||
@@ -43,7 +42,7 @@ class NetworkCacheManager implements Interceptor {
|
||||
static const _maxCacheSize = 10 * 1024 * 1024;
|
||||
|
||||
void setCache(NetworkCache cache) {
|
||||
while(size > _maxCacheSize){
|
||||
while (size > _maxCacheSize) {
|
||||
size -= _cache.values.first.size;
|
||||
_cache.remove(_cache.keys.first);
|
||||
}
|
||||
@@ -53,7 +52,7 @@ class NetworkCacheManager implements Interceptor {
|
||||
|
||||
void removeCache(Uri uri) {
|
||||
var cache = _cache[uri];
|
||||
if(cache != null){
|
||||
if (cache != null) {
|
||||
size -= cache.size;
|
||||
}
|
||||
_cache.remove(uri);
|
||||
@@ -64,41 +63,29 @@ class NetworkCacheManager implements Interceptor {
|
||||
size = 0;
|
||||
}
|
||||
|
||||
var preventParallel = <Uri, Completer>{};
|
||||
|
||||
@override
|
||||
void onError(DioException err, ErrorInterceptorHandler handler) {
|
||||
if(err.requestOptions.method != "GET"){
|
||||
if (err.requestOptions.method != "GET") {
|
||||
return handler.next(err);
|
||||
}
|
||||
if(preventParallel[err.requestOptions.uri] != null){
|
||||
preventParallel[err.requestOptions.uri]!.complete();
|
||||
preventParallel.remove(err.requestOptions.uri);
|
||||
}
|
||||
return handler.next(err);
|
||||
}
|
||||
|
||||
@override
|
||||
void onRequest(
|
||||
RequestOptions options, RequestInterceptorHandler handler) async {
|
||||
if(options.method != "GET"){
|
||||
if (options.method != "GET") {
|
||||
return handler.next(options);
|
||||
}
|
||||
if(preventParallel[options.uri] != null){
|
||||
await preventParallel[options.uri]!.future;
|
||||
}
|
||||
var cache = getCache(options.uri);
|
||||
if (cache == null || !compareHeaders(options.headers, cache.requestHeaders)) {
|
||||
if(options.headers['cache-time'] != null){
|
||||
if (cache == null ||
|
||||
!compareHeaders(options.headers, cache.requestHeaders)) {
|
||||
if (options.headers['cache-time'] != null) {
|
||||
options.headers.remove('cache-time');
|
||||
}
|
||||
if(options.headers['prevent-parallel'] != null){
|
||||
options.headers.remove('prevent-parallel');
|
||||
preventParallel[options.uri] = Completer();
|
||||
}
|
||||
return handler.next(options);
|
||||
} else {
|
||||
if(options.headers['cache-time'] == 'no'){
|
||||
if (options.headers['cache-time'] == 'no') {
|
||||
options.headers.remove('cache-time');
|
||||
removeCache(options.uri);
|
||||
return handler.next(options);
|
||||
@@ -106,20 +93,21 @@ class NetworkCacheManager implements Interceptor {
|
||||
}
|
||||
var time = DateTime.now();
|
||||
var diff = time.difference(cache.time);
|
||||
if (options.headers['cache-time'] == 'long'
|
||||
&& diff < const Duration(hours: 2)) {
|
||||
if (options.headers['cache-time'] == 'long' &&
|
||||
diff < const Duration(hours: 2)) {
|
||||
return handler.resolve(Response(
|
||||
requestOptions: options,
|
||||
data: cache.data,
|
||||
headers: Headers.fromMap(cache.responseHeaders),
|
||||
headers: Headers.fromMap(cache.responseHeaders)
|
||||
..set('venera-cache', 'true'),
|
||||
statusCode: 200,
|
||||
));
|
||||
}
|
||||
else if (diff < const Duration(seconds: 5)) {
|
||||
} else if (diff < const Duration(seconds: 5)) {
|
||||
return handler.resolve(Response(
|
||||
requestOptions: options,
|
||||
data: cache.data,
|
||||
headers: Headers.fromMap(cache.responseHeaders),
|
||||
headers: Headers.fromMap(cache.responseHeaders)
|
||||
..set('venera-cache', 'true'),
|
||||
statusCode: 200,
|
||||
));
|
||||
} else if (diff < const Duration(hours: 1)) {
|
||||
@@ -133,7 +121,8 @@ class NetworkCacheManager implements Interceptor {
|
||||
return handler.resolve(Response(
|
||||
requestOptions: options,
|
||||
data: cache.data,
|
||||
headers: Headers.fromMap(cache.responseHeaders),
|
||||
headers: Headers.fromMap(cache.responseHeaders)
|
||||
..set('venera-cache', 'true'),
|
||||
statusCode: 200,
|
||||
));
|
||||
}
|
||||
@@ -143,6 +132,10 @@ class NetworkCacheManager implements Interceptor {
|
||||
}
|
||||
|
||||
static bool compareHeaders(Map<String, dynamic> a, Map<String, dynamic> b) {
|
||||
a.remove('cache-time');
|
||||
a.remove('prevent-parallel');
|
||||
b.remove('cache-time');
|
||||
b.remove('prevent-parallel');
|
||||
if (a.length != b.length) {
|
||||
return false;
|
||||
}
|
||||
@@ -160,11 +153,11 @@ class NetworkCacheManager implements Interceptor {
|
||||
if (response.requestOptions.method != "GET") {
|
||||
return handler.next(response);
|
||||
}
|
||||
if(response.statusCode != null && response.statusCode! >= 400){
|
||||
if (response.statusCode != null && response.statusCode! >= 400) {
|
||||
return handler.next(response);
|
||||
}
|
||||
var size = _calculateSize(response.data);
|
||||
if(size != null && size < 1024 * 1024 && size > 0) {
|
||||
if (size != null && size < 1024 * 1024 && size > 0) {
|
||||
var cache = NetworkCache(
|
||||
uri: response.requestOptions.uri,
|
||||
requestHeaders: response.requestOptions.headers,
|
||||
@@ -175,30 +168,29 @@ class NetworkCacheManager implements Interceptor {
|
||||
);
|
||||
setCache(cache);
|
||||
}
|
||||
if(preventParallel[response.requestOptions.uri] != null){
|
||||
preventParallel[response.requestOptions.uri]!.complete();
|
||||
preventParallel.remove(response.requestOptions.uri);
|
||||
}
|
||||
handler.next(response);
|
||||
}
|
||||
|
||||
static int? _calculateSize(Object? data){
|
||||
if(data == null){
|
||||
static int? _calculateSize(Object? data) {
|
||||
if (data == null) {
|
||||
return 0;
|
||||
}
|
||||
if(data is List<int>) {
|
||||
if (data is List<int>) {
|
||||
return data.length;
|
||||
}
|
||||
if(data is String) {
|
||||
if(data.trim().isEmpty){
|
||||
if (data is Uint8List) {
|
||||
return data.length;
|
||||
}
|
||||
if (data is String) {
|
||||
if (data.trim().isEmpty) {
|
||||
return 0;
|
||||
}
|
||||
if(data.length < 512 && data.contains("IP address")){
|
||||
if (data.length < 512 && data.contains("IP address")) {
|
||||
return 0;
|
||||
}
|
||||
return data.length * 4;
|
||||
}
|
||||
if(data is Map) {
|
||||
if (data is Map) {
|
||||
return data.toString().length * 4;
|
||||
}
|
||||
return null;
|
||||
|
@@ -2,6 +2,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:sqlite3/sqlite3.dart';
|
||||
import 'package:venera/foundation/log.dart';
|
||||
import 'package:venera/utils/ext.dart';
|
||||
|
||||
class CookieJarSql {
|
||||
@@ -130,9 +131,17 @@ class CookieJarSql {
|
||||
}
|
||||
|
||||
void saveFromResponseCookieHeader(Uri uri, List<String> cookieHeader) {
|
||||
var cookies = cookieHeader
|
||||
.map((header) => Cookie.fromSetCookieValue(header))
|
||||
.toList();
|
||||
var cookies = <Cookie>[];
|
||||
for (var header in cookieHeader) {
|
||||
try{
|
||||
var cookie = Cookie.fromSetCookieValue(header);
|
||||
cookies.add(cookie);
|
||||
}
|
||||
catch(_) {
|
||||
Log.warning("Network", "Invalid cookie header: $header");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
saveFromResponse(uri, cookies);
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/widgets.dart' show ChangeNotifier;
|
||||
import 'package:venera/foundation/appdata.dart';
|
||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||
import 'package:venera/foundation/comic_type.dart';
|
||||
import 'package:venera/foundation/local.dart';
|
||||
@@ -75,11 +76,14 @@ class ImagesDownloadTask extends DownloadTask with _TransferSpeedMixin {
|
||||
@override
|
||||
ComicType get comicType => ComicType(source.key.hashCode);
|
||||
|
||||
String? comicTitle;
|
||||
|
||||
ImagesDownloadTask({
|
||||
required this.source,
|
||||
required this.comicId,
|
||||
this.comic,
|
||||
this.chapters,
|
||||
this.comicTitle,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -89,7 +93,7 @@ class ImagesDownloadTask extends DownloadTask with _TransferSpeedMixin {
|
||||
var local = LocalManager().find(id, comicType);
|
||||
if (path != null) {
|
||||
if (local == null) {
|
||||
Directory(path!).deleteIgnoreError();
|
||||
Directory(path!).deleteIgnoreError(recursive: true);
|
||||
} else if (chapters != null) {
|
||||
for (var c in chapters!) {
|
||||
var dir = Directory(FilePath.join(path!, c));
|
||||
@@ -155,7 +159,7 @@ class ImagesDownloadTask extends DownloadTask with _TransferSpeedMixin {
|
||||
|
||||
var tasks = <int, _ImageDownloadWrapper>{};
|
||||
|
||||
int get _maxConcurrentTasks => 5;
|
||||
int get _maxConcurrentTasks => (appdata.settings["downloadThreads"] as num).toInt();
|
||||
|
||||
void _scheduleTasks() {
|
||||
var images = _images![_images!.keys.elementAt(_chapter)]!;
|
||||
@@ -197,6 +201,7 @@ class ImagesDownloadTask extends DownloadTask with _TransferSpeedMixin {
|
||||
_scheduleTasks();
|
||||
}
|
||||
});
|
||||
downloading++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,6 +360,7 @@ class ImagesDownloadTask extends DownloadTask with _TransferSpeedMixin {
|
||||
}
|
||||
|
||||
LocalManager().completeTask(this);
|
||||
stopRecorder();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -376,7 +382,7 @@ class ImagesDownloadTask extends DownloadTask with _TransferSpeedMixin {
|
||||
int get speed => currentSpeed;
|
||||
|
||||
@override
|
||||
String get title => comic?.title ?? "Loading...";
|
||||
String get title => comic?.title ?? comicTitle ?? "Loading...";
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
@@ -532,6 +538,9 @@ class _ImageDownloadWrapper {
|
||||
}
|
||||
}
|
||||
} catch (e, s) {
|
||||
if (isCancelled) {
|
||||
return;
|
||||
}
|
||||
Log.error("Download", e.toString(), s);
|
||||
retry--;
|
||||
if (retry > 0) {
|
||||
@@ -590,5 +599,7 @@ abstract mixin class _TransferSpeedMixin {
|
||||
void stopRecorder() {
|
||||
timer?.cancel();
|
||||
timer = null;
|
||||
_currentSpeed = 0;
|
||||
_bytesSinceLastSecond = 0;
|
||||
}
|
||||
}
|
||||
|
@@ -1,15 +1,18 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter_qjs/flutter_qjs.dart';
|
||||
import 'package:venera/foundation/cache_manager.dart';
|
||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||
import 'package:venera/foundation/consts.dart';
|
||||
import 'package:venera/utils/image.dart';
|
||||
|
||||
import 'app_dio.dart';
|
||||
|
||||
class ImageDownloader {
|
||||
static Stream<ImageDownloadProgress> loadThumbnail(
|
||||
String url, String? sourceKey) async* {
|
||||
final cacheKey = "$url@$sourceKey";
|
||||
String url, String? sourceKey,
|
||||
[String? cid]) async* {
|
||||
final cacheKey = "$url@$sourceKey${cid != null ? '@$cid' : ''}";
|
||||
final cache = await CacheManager().findCache(cacheKey);
|
||||
|
||||
if (cache != null) {
|
||||
@@ -27,11 +30,21 @@ class ImageDownloader {
|
||||
configs = comicSource?.getThumbnailLoadingConfig?.call(url) ?? {};
|
||||
}
|
||||
configs['headers'] ??= {};
|
||||
if(configs['headers']['user-agent'] == null
|
||||
&& configs['headers']['User-Agent'] == null) {
|
||||
if (configs['headers']['user-agent'] == null &&
|
||||
configs['headers']['User-Agent'] == null) {
|
||||
configs['headers']['user-agent'] = webUA;
|
||||
}
|
||||
|
||||
if (((configs['url'] as String?) ?? url).startsWith('cover.') &&
|
||||
sourceKey != null) {
|
||||
var comicSource = ComicSource.find(sourceKey);
|
||||
if(comicSource != null) {
|
||||
var comicInfo = await comicSource.loadComicInfo!(cid!);
|
||||
yield* loadThumbnail(comicInfo.data.cover, sourceKey);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var dio = AppDio(BaseOptions(
|
||||
headers: Map<String, dynamic>.from(configs['headers']),
|
||||
method: configs['method'] ?? 'GET',
|
||||
@@ -56,8 +69,9 @@ class ImageDownloader {
|
||||
}
|
||||
}
|
||||
|
||||
if (configs['onResponse'] != null) {
|
||||
buffer = configs['onResponse'](buffer);
|
||||
if (configs['onResponse'] is JSInvokable) {
|
||||
buffer = (configs['onResponse'] as JSInvokable)([buffer]);
|
||||
(configs['onResponse'] as JSInvokable).free();
|
||||
}
|
||||
|
||||
await CacheManager().writeCache(cacheKey, buffer);
|
||||
@@ -82,50 +96,98 @@ class ImageDownloader {
|
||||
);
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>?> Function()? onLoadFailed;
|
||||
|
||||
var configs = <String, dynamic>{};
|
||||
if (sourceKey != null) {
|
||||
var comicSource = ComicSource.find(sourceKey);
|
||||
configs = (await comicSource!.getImageLoadingConfig
|
||||
?.call(imageKey, cid, eid)) ?? {};
|
||||
?.call(imageKey, cid, eid)) ??
|
||||
{};
|
||||
}
|
||||
configs['headers'] ??= {
|
||||
'user-agent': webUA,
|
||||
};
|
||||
var retryLimit = 5;
|
||||
while (true) {
|
||||
try {
|
||||
configs['headers'] ??= {
|
||||
'user-agent': webUA,
|
||||
};
|
||||
|
||||
var dio = AppDio(BaseOptions(
|
||||
headers: configs['headers'],
|
||||
method: configs['method'] ?? 'GET',
|
||||
responseType: ResponseType.stream,
|
||||
));
|
||||
if (configs['onLoadFailed'] is JSInvokable) {
|
||||
onLoadFailed = () async {
|
||||
dynamic result = (configs['onLoadFailed'] as JSInvokable)([]);
|
||||
if (result is Future) {
|
||||
result = await result;
|
||||
}
|
||||
if (result is! Map<String, dynamic>) return null;
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
var req = await dio.request<ResponseBody>(configs['url'] ?? imageKey,
|
||||
data: configs['data']);
|
||||
var stream = req.data?.stream ?? (throw "Error: Empty response body.");
|
||||
int? expectedBytes = req.data!.contentLength;
|
||||
if (expectedBytes == -1) {
|
||||
expectedBytes = null;
|
||||
}
|
||||
var buffer = <int>[];
|
||||
await for (var data in stream) {
|
||||
buffer.addAll(data);
|
||||
if (expectedBytes != null) {
|
||||
var dio = AppDio(BaseOptions(
|
||||
headers: configs['headers'],
|
||||
method: configs['method'] ?? 'GET',
|
||||
responseType: ResponseType.stream,
|
||||
));
|
||||
|
||||
var req = await dio.request<ResponseBody>(configs['url'] ?? imageKey,
|
||||
data: configs['data']);
|
||||
var stream = req.data?.stream ?? (throw "Error: Empty response body.");
|
||||
int? expectedBytes = req.data!.contentLength;
|
||||
if (expectedBytes == -1) {
|
||||
expectedBytes = null;
|
||||
}
|
||||
var buffer = <int>[];
|
||||
await for (var data in stream) {
|
||||
buffer.addAll(data);
|
||||
if (expectedBytes != null) {
|
||||
yield ImageDownloadProgress(
|
||||
currentBytes: buffer.length,
|
||||
totalBytes: expectedBytes,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (configs['onResponse'] is JSInvokable) {
|
||||
buffer = (configs['onResponse'] as JSInvokable)([buffer]);
|
||||
(configs['onResponse'] as JSInvokable).free();
|
||||
}
|
||||
|
||||
var data = Uint8List.fromList(buffer);
|
||||
buffer.clear();
|
||||
|
||||
if (configs['modifyImage'] != null) {
|
||||
var newData = await modifyImageWithScript(
|
||||
data,
|
||||
configs['modifyImage'],
|
||||
);
|
||||
data = newData;
|
||||
}
|
||||
|
||||
await CacheManager().writeCache(cacheKey, data);
|
||||
yield ImageDownloadProgress(
|
||||
currentBytes: buffer.length,
|
||||
totalBytes: expectedBytes,
|
||||
currentBytes: data.length,
|
||||
totalBytes: data.length,
|
||||
imageBytes: data,
|
||||
);
|
||||
return;
|
||||
} catch (e) {
|
||||
if (retryLimit < 0 || onLoadFailed == null) {
|
||||
rethrow;
|
||||
}
|
||||
var newConfig = await onLoadFailed();
|
||||
(configs['onLoadFailed'] as JSInvokable).free();
|
||||
onLoadFailed = null;
|
||||
if (newConfig == null) {
|
||||
rethrow;
|
||||
}
|
||||
configs = newConfig;
|
||||
retryLimit--;
|
||||
} finally {
|
||||
if (onLoadFailed != null) {
|
||||
(configs['onLoadFailed'] as JSInvokable).free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (configs['onResponse'] != null) {
|
||||
buffer = configs['onResponse'](buffer);
|
||||
}
|
||||
|
||||
await CacheManager().writeCache(cacheKey, buffer);
|
||||
yield ImageDownloadProgress(
|
||||
currentBytes: buffer.length,
|
||||
totalBytes: buffer.length,
|
||||
imageBytes: Uint8List.fromList(buffer),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -70,6 +70,7 @@ class AccountsPage extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
element.saveData();
|
||||
ComicSource.notifyListeners();
|
||||
logic.update();
|
||||
},
|
||||
);
|
||||
@@ -124,6 +125,7 @@ class AccountsPage extends StatelessWidget {
|
||||
element.data["account"] = null;
|
||||
element.account?.logout();
|
||||
element.saveData();
|
||||
ComicSource.notifyListeners();
|
||||
logic.update();
|
||||
},
|
||||
trailing: const Icon(Icons.logout),
|
||||
@@ -171,84 +173,88 @@ class _LoginPageState extends State<_LoginPage> {
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
constraints: const BoxConstraints(maxWidth: 400),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text("Login".tl, style: const TextStyle(fontSize: 24)),
|
||||
const SizedBox(height: 32),
|
||||
if (widget.config.cookieFields == null)
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Username".tl,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
enabled: widget.config.login != null,
|
||||
onChanged: (s) {
|
||||
username = s;
|
||||
},
|
||||
).paddingBottom(16),
|
||||
if (widget.config.cookieFields == null)
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Password".tl,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
obscureText: true,
|
||||
enabled: widget.config.login != null,
|
||||
onChanged: (s) {
|
||||
password = s;
|
||||
},
|
||||
onSubmitted: (s) => login(),
|
||||
).paddingBottom(16),
|
||||
for (var field in widget.config.cookieFields ?? <String>[])
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: field,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
obscureText: true,
|
||||
enabled: widget.config.validateCookies != null,
|
||||
onChanged: (s) {
|
||||
_cookies[field] = s;
|
||||
},
|
||||
).paddingBottom(16),
|
||||
if (widget.config.login == null &&
|
||||
widget.config.cookieFields == null)
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.error_outline),
|
||||
const SizedBox(width: 8),
|
||||
Text("Login with password is disabled".tl),
|
||||
],
|
||||
)
|
||||
else
|
||||
Button.filled(
|
||||
isLoading: loading,
|
||||
onPressed: login,
|
||||
child: Text("Continue".tl),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
if (widget.config.loginWebsite != null)
|
||||
TextButton(
|
||||
onPressed: loginWithWebview,
|
||||
child: Text("Login with webview".tl),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (widget.config.registerWebsite != null)
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
launchUrlString(widget.config.registerWebsite!),
|
||||
child: Row(
|
||||
child: AutofillGroup(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text("Login".tl, style: const TextStyle(fontSize: 24)),
|
||||
const SizedBox(height: 32),
|
||||
if (widget.config.cookieFields == null)
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Username".tl,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
enabled: widget.config.login != null,
|
||||
onChanged: (s) {
|
||||
username = s;
|
||||
},
|
||||
autofillHints: const [AutofillHints.username],
|
||||
).paddingBottom(16),
|
||||
if (widget.config.cookieFields == null)
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Password".tl,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
obscureText: true,
|
||||
enabled: widget.config.login != null,
|
||||
onChanged: (s) {
|
||||
password = s;
|
||||
},
|
||||
onSubmitted: (s) => login(),
|
||||
autofillHints: const [AutofillHints.password],
|
||||
).paddingBottom(16),
|
||||
for (var field in widget.config.cookieFields ?? <String>[])
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: field,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
obscureText: true,
|
||||
enabled: widget.config.validateCookies != null,
|
||||
onChanged: (s) {
|
||||
_cookies[field] = s;
|
||||
},
|
||||
).paddingBottom(16),
|
||||
if (widget.config.login == null &&
|
||||
widget.config.cookieFields == null)
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.link),
|
||||
const Icon(Icons.error_outline),
|
||||
const SizedBox(width: 8),
|
||||
Text("Create Account".tl),
|
||||
Text("Login with password is disabled".tl),
|
||||
],
|
||||
)
|
||||
else
|
||||
Button.filled(
|
||||
isLoading: loading,
|
||||
onPressed: login,
|
||||
child: Text("Continue".tl),
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 24),
|
||||
if (widget.config.loginWebsite != null)
|
||||
TextButton(
|
||||
onPressed: loginWithWebview,
|
||||
child: Text("Login with webview".tl),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (widget.config.registerWebsite != null)
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
launchUrlString(widget.config.registerWebsite!),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.link),
|
||||
const SizedBox(width: 8),
|
||||
Text("Create Account".tl),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@@ -1,8 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:sliver_tools/sliver_tools.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
import 'package:venera/components/components.dart';
|
||||
import 'package:venera/foundation/app.dart';
|
||||
import 'package:venera/foundation/appdata.dart';
|
||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||
import 'package:venera/foundation/comic_type.dart';
|
||||
import 'package:venera/foundation/consts.dart';
|
||||
@@ -42,12 +44,41 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
||||
|
||||
bool isDownloaded = false;
|
||||
|
||||
void updateHistory() async {
|
||||
var newHistory = await HistoryManager()
|
||||
.find(widget.id, ComicType(widget.sourceKey.hashCode));
|
||||
if (newHistory?.ep != history?.ep || newHistory?.page != history?.page) {
|
||||
history = newHistory;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildLoading() {
|
||||
return Column(
|
||||
children: [
|
||||
const Appbar(title: Text("")),
|
||||
Expanded(
|
||||
child: super.buildLoading(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
scrollController.addListener(onScroll);
|
||||
HistoryManager().addListener(updateHistory);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
scrollController.removeListener(onScroll);
|
||||
HistoryManager().removeListener(updateHistory);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void update() {
|
||||
setState(() {});
|
||||
@@ -205,6 +236,7 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
||||
|
||||
Widget buildActions() {
|
||||
bool isMobile = context.width < changePoint;
|
||||
bool hasHistory = history != null && (history!.ep > 1 || history!.page > 1);
|
||||
return SliverToBoxAdapter(
|
||||
child: Column(
|
||||
children: [
|
||||
@@ -212,17 +244,17 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
children: [
|
||||
if (history != null && (history!.ep > 1 || history!.page > 1))
|
||||
if (hasHistory && !isMobile)
|
||||
_ActionButton(
|
||||
icon: const Icon(Icons.menu_book),
|
||||
text: 'Continue'.tl,
|
||||
onPressed: continueRead,
|
||||
iconColor: context.useTextColor(Colors.yellow),
|
||||
),
|
||||
if (!isMobile)
|
||||
if (!isMobile || hasHistory)
|
||||
_ActionButton(
|
||||
icon: const Icon(Icons.play_circle_outline),
|
||||
text: 'Read'.tl,
|
||||
text: 'Start'.tl,
|
||||
onPressed: read,
|
||||
iconColor: context.useTextColor(Colors.orange),
|
||||
),
|
||||
@@ -238,7 +270,9 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
||||
icon: const Icon(Icons.favorite_border),
|
||||
activeIcon: const Icon(Icons.favorite),
|
||||
isActive: isLiked,
|
||||
text: (data!.likesCount ?? (isLiked ? 'Liked'.tl : 'Like'.tl))
|
||||
text: ((data!.likesCount != null)
|
||||
? (data!.likesCount! + (isLiked ? 1 : 0))
|
||||
: (isLiked ? 'Liked'.tl : 'Like'.tl))
|
||||
.toString(),
|
||||
isLoading: isLiking,
|
||||
onPressed: likeOrUnlike,
|
||||
@@ -250,6 +284,7 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
||||
isActive: isFavorite || isAddToLocalFav,
|
||||
text: 'Favorite'.tl,
|
||||
onPressed: openFavPanel,
|
||||
onLongPressed: quickFavorite,
|
||||
iconColor: context.useTextColor(Colors.purple),
|
||||
),
|
||||
if (comicSource.commentsLoader != null)
|
||||
@@ -278,7 +313,10 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: FilledButton(onPressed: read, child: Text("Read".tl)),
|
||||
child: hasHistory
|
||||
? FilledButton(
|
||||
onPressed: continueRead, child: Text("Continue".tl))
|
||||
: FilledButton(onPressed: read, child: Text("Read".tl)),
|
||||
)
|
||||
],
|
||||
).paddingHorizontal(16).paddingVertical(8),
|
||||
@@ -398,23 +436,23 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
||||
Text(comic.stars!.toStringAsFixed(2)),
|
||||
],
|
||||
).paddingLeft(16).paddingVertical(8),
|
||||
for (var e in comic.tags.entries)
|
||||
buildWrap(
|
||||
children: [
|
||||
if(e.value.isNotEmpty)
|
||||
for (var e in comic.tags.entries)
|
||||
buildWrap(
|
||||
children: [
|
||||
if (e.value.isNotEmpty)
|
||||
buildTag(text: e.key.ts(comicSource.key), isTitle: true),
|
||||
for (var tag in e.value)
|
||||
buildTag(
|
||||
text: enableTranslation
|
||||
? TagsTranslation.translationTagWithNamespace(
|
||||
tag,
|
||||
e.key.toLowerCase(),
|
||||
)
|
||||
: tag,
|
||||
onTap: () => onTapTag(tag, e.key),
|
||||
),
|
||||
],
|
||||
),
|
||||
for (var tag in e.value)
|
||||
buildTag(
|
||||
text: enableTranslation
|
||||
? TagsTranslation.translationTagWithNamespace(
|
||||
tag,
|
||||
e.key.toLowerCase(),
|
||||
)
|
||||
: tag,
|
||||
onTap: () => onTapTag(tag, e.key),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (comic.uploader != null)
|
||||
buildWrap(
|
||||
children: [
|
||||
@@ -458,7 +496,7 @@ class _ComicPageState extends LoadingState<ComicPage, ComicDetails>
|
||||
}
|
||||
|
||||
Widget buildRecommend() {
|
||||
if (comic.recommend == null) {
|
||||
if (comic.recommend == null || comic.recommend!.isEmpty) {
|
||||
return const SliverPadding(padding: EdgeInsets.zero);
|
||||
}
|
||||
return SliverMainAxisGroup(slivers: [
|
||||
@@ -503,12 +541,22 @@ abstract mixin class _ComicPageActions {
|
||||
|
||||
bool isFavorite = false;
|
||||
|
||||
void openFavPanel() {
|
||||
FavoriteItem _toFavoriteItem() {
|
||||
var tags = <String>[];
|
||||
for (var e in comic.tags.entries) {
|
||||
tags.addAll(e.value.map((tag) => '${e.key}:$tag'));
|
||||
}
|
||||
return FavoriteItem(
|
||||
id: comic.id,
|
||||
name: comic.title,
|
||||
coverPath: comic.cover,
|
||||
author: comic.subTitle ?? comic.uploader ?? '',
|
||||
type: comic.comicType,
|
||||
tags: tags,
|
||||
);
|
||||
}
|
||||
|
||||
void openFavPanel() {
|
||||
showSideBar(
|
||||
App.rootContext,
|
||||
_FavoritePanel(
|
||||
@@ -520,18 +568,25 @@ abstract mixin class _ComicPageActions {
|
||||
isAddToLocalFav = local ?? isAddToLocalFav;
|
||||
update();
|
||||
},
|
||||
favoriteItem: FavoriteItem(
|
||||
id: comic.id,
|
||||
name: comic.title,
|
||||
coverPath: comic.cover,
|
||||
author: comic.subTitle ?? comic.uploader ?? '',
|
||||
type: comic.comicType,
|
||||
tags: tags,
|
||||
),
|
||||
favoriteItem: _toFavoriteItem(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void quickFavorite() {
|
||||
var folder = appdata.settings['quickFavorite'];
|
||||
if(folder is! String) {
|
||||
return;
|
||||
}
|
||||
LocalFavoritesManager().addComic(
|
||||
folder,
|
||||
_toFavoriteItem(),
|
||||
);
|
||||
isAddToLocalFav = true;
|
||||
update();
|
||||
App.rootContext.showMessage(message: "Added".tl);
|
||||
}
|
||||
|
||||
void share() {
|
||||
var text = comic.title;
|
||||
if (comic.url != null) {
|
||||
@@ -765,11 +820,13 @@ class _ActionButton extends StatelessWidget {
|
||||
required this.icon,
|
||||
required this.text,
|
||||
required this.onPressed,
|
||||
this.onLongPressed,
|
||||
this.activeIcon,
|
||||
this.isActive,
|
||||
this.isLoading,
|
||||
this.iconColor,
|
||||
});
|
||||
|
||||
final Widget icon;
|
||||
|
||||
final Widget? activeIcon;
|
||||
@@ -783,6 +840,9 @@ class _ActionButton extends StatelessWidget {
|
||||
final bool? isLoading;
|
||||
|
||||
final Color? iconColor;
|
||||
|
||||
final void Function()? onLongPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
@@ -800,6 +860,7 @@ class _ActionButton extends StatelessWidget {
|
||||
onPressed();
|
||||
}
|
||||
},
|
||||
onLongPress: onLongPressed,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
child: IconTheme.merge(
|
||||
data: IconThemeData(size: 20, color: iconColor),
|
||||
@@ -961,6 +1022,8 @@ class _ComicThumbnailsState extends State<_ComicThumbnails> {
|
||||
|
||||
String? error;
|
||||
|
||||
bool isLoading = false;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
state = context.findAncestorStateOfType<_ComicPageState>()!;
|
||||
@@ -974,6 +1037,11 @@ class _ComicThumbnailsState extends State<_ComicThumbnails> {
|
||||
if (!isInitialLoading && next == null) {
|
||||
return;
|
||||
}
|
||||
Future.microtask(() {
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
});
|
||||
});
|
||||
var res = await state.comicSource.loadComicThumbnail!(state.comic.id, next);
|
||||
if (res.success) {
|
||||
thumbnails.addAll(res.data);
|
||||
@@ -982,13 +1050,15 @@ class _ComicThumbnailsState extends State<_ComicThumbnails> {
|
||||
} else {
|
||||
error = res.errorMessage;
|
||||
}
|
||||
setState(() {});
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SliverMainAxisGroup(
|
||||
slivers: [
|
||||
return MultiSliver(
|
||||
children: [
|
||||
SliverToBoxAdapter(
|
||||
child: ListTile(
|
||||
title: Text("Preview".tl),
|
||||
@@ -1088,7 +1158,7 @@ class _ComicThumbnailsState extends State<_ComicThumbnails> {
|
||||
],
|
||||
),
|
||||
)
|
||||
else if (next != null || isInitialLoading)
|
||||
else if (isLoading)
|
||||
const SliverToBoxAdapter(
|
||||
child: ListLoadingIndicator(),
|
||||
),
|
||||
@@ -1539,7 +1609,7 @@ class _SelectDownloadChapterState extends State<_SelectDownloadChapter> {
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: FilledButton(
|
||||
onPressed: () {
|
||||
onPressed: selected.isEmpty ? null : () {
|
||||
widget.finishSelect(selected);
|
||||
context.pop();
|
||||
},
|
||||
@@ -1550,7 +1620,7 @@ class _SelectDownloadChapterState extends State<_SelectDownloadChapter> {
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: MediaQuery.of(context).padding.bottom + 4),
|
||||
SizedBox(height: MediaQuery.of(context).padding.bottom),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
@@ -14,11 +14,11 @@ import 'package:venera/utils/translations.dart';
|
||||
class ComicSourcePage extends StatefulWidget {
|
||||
const ComicSourcePage({super.key});
|
||||
|
||||
static void checkComicSourceUpdate([bool showLoading = false]) async {
|
||||
static Future<void> checkComicSourceUpdate([bool implicit = false]) async {
|
||||
if (ComicSource.all().isEmpty) {
|
||||
return;
|
||||
}
|
||||
var controller = showLoading ? showLoadingDialog(App.rootContext) : null;
|
||||
var controller = implicit ? null : showLoadingDialog(App.rootContext);
|
||||
var dio = AppDio();
|
||||
var res = await dio.get<String>(
|
||||
"https://raw.githubusercontent.com/venera-app/venera-configs/master/index.json");
|
||||
@@ -40,6 +40,9 @@ class ComicSourcePage extends StatefulWidget {
|
||||
}
|
||||
controller?.close();
|
||||
if (shouldUpdate.isEmpty) {
|
||||
if(!implicit) {
|
||||
App.rootContext.showMessage(message: "No Update Available".tl);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var msg = "";
|
||||
@@ -47,10 +50,11 @@ class ComicSourcePage extends StatefulWidget {
|
||||
msg += "${ComicSource.find(key)?.name}: v${versions[key]}\n";
|
||||
}
|
||||
msg = msg.trim();
|
||||
showConfirmDialog(
|
||||
await showConfirmDialog(
|
||||
context: App.rootContext,
|
||||
title: "Updates Available".tl,
|
||||
content: msg,
|
||||
confirmText: "Update",
|
||||
onConfirm: () {
|
||||
for (var key in shouldUpdate) {
|
||||
var source = ComicSource.find(key);
|
||||
@@ -103,7 +107,7 @@ class _BodyState extends State<_Body> {
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.update_outlined),
|
||||
title: Text("Check updates".tl),
|
||||
onTap: () => ComicSourcePage.checkComicSourceUpdate(true),
|
||||
onTap: () => ComicSourcePage.checkComicSourceUpdate(false),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
),
|
||||
);
|
||||
@@ -160,71 +164,76 @@ class _BodyState extends State<_Body> {
|
||||
for (var item in source.settings!.entries) {
|
||||
var key = item.key;
|
||||
String type = item.value['type'];
|
||||
if (type == "select") {
|
||||
var current = source.data['settings'][key];
|
||||
if (current == null) {
|
||||
var d = item.value['default'];
|
||||
for (var option in item.value['options']) {
|
||||
if (option['value'] == d) {
|
||||
current = option['text'] ?? option['value'];
|
||||
break;
|
||||
try {
|
||||
if (type == "select") {
|
||||
var current = source.data['settings'][key];
|
||||
if (current == null) {
|
||||
var d = item.value['default'];
|
||||
for (var option in item.value['options']) {
|
||||
if (option['value'] == d) {
|
||||
current = option['text'] ?? option['value'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
yield ListTile(
|
||||
title: Text((item.value['title'] as String).ts(source.key)),
|
||||
trailing: Select(
|
||||
current: (current as String).ts(source.key),
|
||||
values: (item.value['options'] as List)
|
||||
.map<String>(
|
||||
(e) => ((e['text'] ?? e['value']) as String).ts(source.key))
|
||||
.toList(),
|
||||
onTap: (i) {
|
||||
source.data['settings'][key] = item.value['options'][i]['value'];
|
||||
source.saveData();
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
);
|
||||
} else if (type == "switch") {
|
||||
var current = source.data['settings'][key] ?? item.value['default'];
|
||||
yield ListTile(
|
||||
title: Text((item.value['title'] as String).ts(source.key)),
|
||||
trailing: Switch(
|
||||
value: current,
|
||||
onChanged: (v) {
|
||||
source.data['settings'][key] = v;
|
||||
source.saveData();
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
);
|
||||
} else if (type == "input") {
|
||||
var current =
|
||||
source.data['settings'][key] ?? item.value['default'] ?? '';
|
||||
yield ListTile(
|
||||
title: Text((item.value['title'] as String).ts(source.key)),
|
||||
subtitle: Text(current, maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.edit),
|
||||
onPressed: () {
|
||||
showInputDialog(
|
||||
context: context,
|
||||
title: (item.value['title'] as String).ts(source.key),
|
||||
initialValue: current,
|
||||
inputValidator: item.value['validator'] == null
|
||||
? null
|
||||
: RegExp(item.value['validator']),
|
||||
onConfirm: (value) {
|
||||
source.data['settings'][key] = value;
|
||||
source.saveData();
|
||||
setState(() {});
|
||||
return null;
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
yield ListTile(
|
||||
title: Text((item.value['title'] as String).ts(source.key)),
|
||||
trailing: Select(
|
||||
current: (current as String).ts(source.key),
|
||||
values: (item.value['options'] as List)
|
||||
.map<String>(
|
||||
(e) => ((e['text'] ?? e['value']) as String).ts(source.key))
|
||||
.toList(),
|
||||
onTap: (i) {
|
||||
source.data['settings'][key] = item.value['options'][i]['value'];
|
||||
source.saveData();
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
);
|
||||
} else if (type == "switch") {
|
||||
var current = source.data['settings'][key] ?? item.value['default'];
|
||||
yield ListTile(
|
||||
title: Text((item.value['title'] as String).ts(source.key)),
|
||||
trailing: Switch(
|
||||
value: current,
|
||||
onChanged: (v) {
|
||||
source.data['settings'][key] = v;
|
||||
source.saveData();
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
);
|
||||
} else if (type == "input") {
|
||||
var current =
|
||||
source.data['settings'][key] ?? item.value['default'] ?? '';
|
||||
yield ListTile(
|
||||
title: Text((item.value['title'] as String).ts(source.key)),
|
||||
subtitle: Text(current, maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.edit),
|
||||
onPressed: () {
|
||||
showInputDialog(
|
||||
context: context,
|
||||
title: (item.value['title'] as String).ts(source.key),
|
||||
initialValue: current,
|
||||
inputValidator: item.value['validator'] == null
|
||||
? null
|
||||
: RegExp(item.value['validator']),
|
||||
onConfirm: (value) {
|
||||
source.data['settings'][key] = value;
|
||||
source.saveData();
|
||||
setState(() {});
|
||||
return null;
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
catch(e, s) {
|
||||
Log.error("ComicSourcePage", "Failed to build a setting\n$e\n$s");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -445,10 +454,11 @@ class _ComicSourceListState extends State<_ComicSourceList> {
|
||||
itemBuilder: (context, index) {
|
||||
var key = json![index]["key"];
|
||||
var action = currentKey.contains(key)
|
||||
? const Icon(Icons.check)
|
||||
? const Icon(Icons.check, size: 20).paddingRight(8)
|
||||
: Tooltip(
|
||||
message: "Add",
|
||||
child: IconButton(
|
||||
child: Button.icon(
|
||||
color: context.colorScheme.primary,
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: () async {
|
||||
await widget.onAdd(
|
||||
|
@@ -27,7 +27,9 @@ class _DownloadingPageState extends State<DownloadingPage> {
|
||||
}
|
||||
|
||||
void update() {
|
||||
setState(() {});
|
||||
if(mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
@@ -5,8 +5,12 @@ import 'package:venera/foundation/appdata.dart';
|
||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||
import 'package:venera/foundation/res.dart';
|
||||
import 'package:venera/foundation/state_controller.dart';
|
||||
import 'package:venera/pages/search_result_page.dart';
|
||||
import 'package:venera/utils/ext.dart';
|
||||
import 'package:venera/utils/translations.dart';
|
||||
|
||||
import 'category_comics_page.dart';
|
||||
|
||||
class ExplorePage extends StatefulWidget {
|
||||
const ExplorePage({super.key});
|
||||
|
||||
@@ -15,7 +19,7 @@ class ExplorePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ExplorePageState extends State<ExplorePage>
|
||||
with TickerProviderStateMixin {
|
||||
with TickerProviderStateMixin, AutomaticKeepAliveClientMixin<ExplorePage> {
|
||||
late TabController controller;
|
||||
|
||||
bool showFB = true;
|
||||
@@ -24,6 +28,24 @@ class _ExplorePageState extends State<ExplorePage>
|
||||
|
||||
late List<String> pages;
|
||||
|
||||
void onSettingsChanged() {
|
||||
var explorePages = List<String>.from(appdata.settings["explore_pages"]);
|
||||
var all = ComicSource.all()
|
||||
.map((e) => e.explorePages)
|
||||
.expand((e) => e.map((e) => e.title))
|
||||
.toList();
|
||||
explorePages = explorePages.where((e) => all.contains(e)).toList();
|
||||
if (!pages.isEqualsTo(explorePages)) {
|
||||
setState(() {
|
||||
pages = explorePages;
|
||||
controller = TabController(
|
||||
length: pages.length,
|
||||
vsync: this,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
pages = List<String>.from(appdata.settings["explore_pages"]);
|
||||
@@ -36,9 +58,17 @@ class _ExplorePageState extends State<ExplorePage>
|
||||
length: pages.length,
|
||||
vsync: this,
|
||||
);
|
||||
appdata.settings.addListener(onSettingsChanged);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
controller.dispose();
|
||||
appdata.settings.removeListener(onSettingsChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
int page = controller.index;
|
||||
String currentPageId = pages[page];
|
||||
@@ -83,12 +113,14 @@ class _ExplorePageState extends State<ExplorePage>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
if (pages.isEmpty) {
|
||||
return buildEmpty();
|
||||
}
|
||||
|
||||
Widget tabBar = Material(
|
||||
child: FilledTabBar(
|
||||
key: Key(pages.toString()),
|
||||
tabs: pages.map((e) => buildTab(e)).toList(),
|
||||
controller: controller,
|
||||
),
|
||||
@@ -97,48 +129,52 @@ class _ExplorePageState extends State<ExplorePage>
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: Column(
|
||||
children: [
|
||||
tabBar,
|
||||
Expanded(
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: (notifications) {
|
||||
if (notifications.metrics.axis == Axis.horizontal) {
|
||||
if (!showFB) {
|
||||
child: Column(
|
||||
children: [
|
||||
tabBar,
|
||||
Expanded(
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: (notifications) {
|
||||
if (notifications.metrics.axis == Axis.horizontal) {
|
||||
if (!showFB) {
|
||||
setState(() {
|
||||
showFB = true;
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
var current = notifications.metrics.pixels;
|
||||
var overflow = notifications.metrics.outOfRange;
|
||||
if (current > location && current != 0 && showFB) {
|
||||
setState(() {
|
||||
showFB = false;
|
||||
});
|
||||
} else if ((current < location - 50 || current == 0) &&
|
||||
!showFB) {
|
||||
setState(() {
|
||||
showFB = true;
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
var current = notifications.metrics.pixels;
|
||||
|
||||
if ((current > location && current != 0) && showFB) {
|
||||
setState(() {
|
||||
showFB = false;
|
||||
});
|
||||
} else if ((current < location || current == 0) && !showFB) {
|
||||
setState(() {
|
||||
showFB = true;
|
||||
});
|
||||
}
|
||||
|
||||
location = current;
|
||||
return false;
|
||||
},
|
||||
child: MediaQuery.removePadding(
|
||||
context: context,
|
||||
removeTop: true,
|
||||
child: TabBarView(
|
||||
controller: controller,
|
||||
children: pages.map((e) => buildBody(e)).toList(),
|
||||
if ((current > location || current < location - 50) &&
|
||||
!overflow) {
|
||||
location = current;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
child: MediaQuery.removePadding(
|
||||
context: context,
|
||||
removeTop: true,
|
||||
child: TabBarView(
|
||||
controller: controller,
|
||||
children: pages.map((e) => buildBody(e)).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
)),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
right: 16,
|
||||
bottom: 16,
|
||||
@@ -159,6 +195,9 @@ class _ExplorePageState extends State<ExplorePage>
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
|
||||
class _SingleExplorePage extends StatefulWidget {
|
||||
@@ -170,7 +209,8 @@ class _SingleExplorePage extends StatefulWidget {
|
||||
State<_SingleExplorePage> createState() => _SingleExplorePageState();
|
||||
}
|
||||
|
||||
class _SingleExplorePageState extends StateWithController<_SingleExplorePage> {
|
||||
class _SingleExplorePageState extends StateWithController<_SingleExplorePage>
|
||||
with AutomaticKeepAliveClientMixin<_SingleExplorePage> {
|
||||
late final ExplorePageData data;
|
||||
|
||||
bool loading = true;
|
||||
@@ -183,6 +223,16 @@ class _SingleExplorePageState extends StateWithController<_SingleExplorePage> {
|
||||
|
||||
int key = 0;
|
||||
|
||||
bool _wantKeepAlive = true;
|
||||
|
||||
void onSettingsChanged() {
|
||||
var explorePages = appdata.settings["explore_pages"];
|
||||
if (!explorePages.contains(widget.title)) {
|
||||
_wantKeepAlive = false;
|
||||
updateKeepAlive();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -195,11 +245,19 @@ class _SingleExplorePageState extends StateWithController<_SingleExplorePage> {
|
||||
}
|
||||
}
|
||||
}
|
||||
appdata.settings.addListener(onSettingsChanged);
|
||||
throw "Explore Page ${widget.title} Not Found!";
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
appdata.settings.removeListener(onSettingsChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
if (data.loadMultiPart != null) {
|
||||
return buildMultiPart();
|
||||
} else if (data.loadPage != null || data.loadNext != null) {
|
||||
@@ -284,6 +342,9 @@ class _SingleExplorePageState extends StateWithController<_SingleExplorePage> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => _wantKeepAlive;
|
||||
}
|
||||
|
||||
class _MixedExplorePage extends StatefulWidget {
|
||||
@@ -367,13 +428,12 @@ Iterable<Widget> _buildExplorePagePart(
|
||||
if (part.viewMore != null)
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
// TODO: view more
|
||||
/*
|
||||
var context = App.mainNavigatorKey!.currentContext!;
|
||||
if (part.viewMore!.startsWith("search:")) {
|
||||
context.to(
|
||||
() => SearchResultPage(
|
||||
keyword: part.viewMore!.replaceFirst("search:", ""),
|
||||
() => SearchResultPage(
|
||||
text: part.viewMore!.replaceFirst("search:", ""),
|
||||
options: const [],
|
||||
sourceKey: sourceKey,
|
||||
),
|
||||
);
|
||||
@@ -385,16 +445,16 @@ Iterable<Widget> _buildExplorePagePart(
|
||||
p = null;
|
||||
}
|
||||
context.to(
|
||||
() => CategoryComicsPage(
|
||||
() => CategoryComicsPage(
|
||||
category: c,
|
||||
categoryKey:
|
||||
ComicSource.find(sourceKey)!.categoryData!.key,
|
||||
ComicSource.find(sourceKey)!.categoryData!.key,
|
||||
param: p,
|
||||
),
|
||||
);
|
||||
}*/
|
||||
}
|
||||
},
|
||||
child: Text("查看更多".tl),
|
||||
child: Text("View more".tl),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
@@ -6,7 +6,6 @@ Future<void> newFolder() async {
|
||||
context: App.rootContext,
|
||||
builder: (context) {
|
||||
var controller = TextEditingController();
|
||||
var folders = LocalFavoritesManager().folderNames;
|
||||
String? error;
|
||||
|
||||
return StatefulBuilder(builder: (context, setState) {
|
||||
@@ -35,12 +34,11 @@ Future<void> newFolder() async {
|
||||
child: Text("Import from file".tl),
|
||||
onPressed: () async {
|
||||
var file = await selectFile(ext: ['json']);
|
||||
if(file == null) return;
|
||||
if (file == null) return;
|
||||
var data = await file.readAsBytes();
|
||||
try {
|
||||
LocalFavoritesManager().fromJson(utf8.decode(data));
|
||||
}
|
||||
catch(e) {
|
||||
} catch (e) {
|
||||
context.showMessage(message: "Failed to import".tl);
|
||||
return;
|
||||
}
|
||||
@@ -114,7 +112,9 @@ void addFavorite(Comic comic) {
|
||||
name: comic.title,
|
||||
coverPath: comic.cover,
|
||||
author: comic.subtitle ?? '',
|
||||
type: ComicType((comic.sourceKey == 'local' ? 0 : comic.sourceKey.hashCode)),
|
||||
type: ComicType((comic.sourceKey == 'local'
|
||||
? 0
|
||||
: comic.sourceKey.hashCode)),
|
||||
tags: comic.tags ?? [],
|
||||
),
|
||||
);
|
||||
@@ -129,3 +129,162 @@ void addFavorite(Comic comic) {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<FavoriteItem>> updateComicsInfo(String folder) async {
|
||||
var comics = LocalFavoritesManager().getAllComics(folder);
|
||||
|
||||
Future<void> updateSingleComic(int index) async {
|
||||
int retry = 3;
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
var c = comics[index];
|
||||
var comicSource = c.type.comicSource;
|
||||
if (comicSource == null) return;
|
||||
|
||||
var newInfo = (await comicSource.loadComicInfo!(c.id)).data;
|
||||
|
||||
comics[index] = FavoriteItem(
|
||||
id: c.id,
|
||||
name: newInfo.title,
|
||||
coverPath: newInfo.cover,
|
||||
author: newInfo.subTitle ??
|
||||
newInfo.tags['author']?.firstOrNull ??
|
||||
c.author,
|
||||
type: c.type,
|
||||
tags: c.tags,
|
||||
);
|
||||
|
||||
LocalFavoritesManager().updateInfo(folder, comics[index]);
|
||||
return;
|
||||
} catch (e) {
|
||||
retry--;
|
||||
if (retry == 0) {
|
||||
rethrow;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var finished = ValueNotifier(0);
|
||||
|
||||
var errors = 0;
|
||||
|
||||
var index = 0;
|
||||
|
||||
bool isCanceled = false;
|
||||
|
||||
showDialog(
|
||||
context: App.rootContext,
|
||||
builder: (context) {
|
||||
return ValueListenableBuilder(
|
||||
valueListenable: finished,
|
||||
builder: (context, value, child) {
|
||||
var isFinished = value == comics.length;
|
||||
return ContentDialog(
|
||||
title: isFinished ? "Finished".tl : "Updating".tl,
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 4),
|
||||
LinearProgressIndicator(
|
||||
value: value / comics.length,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text("$value/${comics.length}"),
|
||||
const SizedBox(height: 4),
|
||||
if (errors > 0) Text("Errors: $errors"),
|
||||
],
|
||||
).paddingHorizontal(16),
|
||||
actions: [
|
||||
Button.filled(
|
||||
color: isFinished ? null : context.colorScheme.error,
|
||||
onPressed: () {
|
||||
isCanceled = true;
|
||||
context.pop();
|
||||
},
|
||||
child: isFinished ? Text("OK".tl) : Text("Cancel".tl),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
).then((_) {
|
||||
isCanceled = true;
|
||||
});
|
||||
|
||||
while (index < comics.length) {
|
||||
var futures = <Future>[];
|
||||
const maxConcurrency = 4;
|
||||
|
||||
if (isCanceled) {
|
||||
return comics;
|
||||
}
|
||||
|
||||
for (var i = 0; i < maxConcurrency; i++) {
|
||||
if (index + i >= comics.length) break;
|
||||
futures.add(updateSingleComic(index + i).then((v) {
|
||||
finished.value++;
|
||||
}, onError: (_) {
|
||||
errors++;
|
||||
finished.value++;
|
||||
}));
|
||||
}
|
||||
|
||||
await Future.wait(futures);
|
||||
index += maxConcurrency;
|
||||
}
|
||||
|
||||
return comics;
|
||||
}
|
||||
|
||||
Future<void> sortFolders() async {
|
||||
var folders = LocalFavoritesManager().folderNames;
|
||||
|
||||
await showPopUpWidget(
|
||||
App.rootContext,
|
||||
StatefulBuilder(builder: (context, setState) {
|
||||
return PopUpWidgetScaffold(
|
||||
title: "Sort".tl,
|
||||
tailing: [
|
||||
Tooltip(
|
||||
message: "Help".tl,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.help_outline),
|
||||
onPressed: () {
|
||||
showInfoDialog(
|
||||
context: context,
|
||||
title: "Reorder".tl,
|
||||
content: "Long press and drag to reorder.".tl,
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
body: ReorderableListView.builder(
|
||||
onReorder: (oldIndex, newIndex) {
|
||||
if (oldIndex < newIndex) {
|
||||
newIndex--;
|
||||
}
|
||||
setState(() {
|
||||
var item = folders.removeAt(oldIndex);
|
||||
folders.insert(newIndex, item);
|
||||
});
|
||||
},
|
||||
itemCount: folders.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
key: ValueKey(folders[index]),
|
||||
title: Text(folders[index]),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
LocalFavoritesManager().updateOrder(folders);
|
||||
}
|
||||
|
@@ -9,7 +9,9 @@ import 'package:venera/foundation/appdata.dart';
|
||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||
import 'package:venera/foundation/comic_type.dart';
|
||||
import 'package:venera/foundation/favorites.dart';
|
||||
import 'package:venera/foundation/local.dart';
|
||||
import 'package:venera/foundation/res.dart';
|
||||
import 'package:venera/network/download.dart';
|
||||
import 'package:venera/utils/io.dart';
|
||||
import 'package:venera/utils/translations.dart';
|
||||
|
||||
@@ -17,6 +19,7 @@ part 'favorite_actions.dart';
|
||||
part 'side_bar.dart';
|
||||
part 'local_favorites_page.dart';
|
||||
part 'network_favorites_page.dart';
|
||||
part 'local_search_page.dart';
|
||||
|
||||
const _kLeftBarWidth = 256.0;
|
||||
|
||||
@@ -151,7 +154,8 @@ class _FavoritesPageState extends State<FavoritesPage> {
|
||||
} else {
|
||||
var favoriteData = getFavoriteDataOrNull(folder!);
|
||||
if (favoriteData == null) {
|
||||
return const Center(child: Text("Unknown source"));
|
||||
folder = null;
|
||||
return buildBody();
|
||||
} else {
|
||||
return NetworkFavoritePage(favoriteData, key: Key(folder!));
|
||||
}
|
||||
|
@@ -15,10 +15,8 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
||||
late List<FavoriteItem> comics;
|
||||
|
||||
void updateComics() {
|
||||
print(comics.length);
|
||||
setState(() {
|
||||
comics = LocalFavoritesManager().getAllComics(widget.folder);
|
||||
print(comics.length);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -107,7 +105,9 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
||||
},
|
||||
).then(
|
||||
(value) {
|
||||
setState(() {});
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
);
|
||||
}),
|
||||
@@ -123,6 +123,45 @@ class _LocalFavoritesPageState extends State<_LocalFavoritesPage> {
|
||||
filename: "${widget.folder}.json",
|
||||
);
|
||||
}),
|
||||
MenuEntry(
|
||||
icon: Icons.update,
|
||||
text: "Update Comics Info".tl,
|
||||
onClick: () {
|
||||
updateComicsInfo(widget.folder).then((newComics) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
comics = newComics;
|
||||
});
|
||||
}
|
||||
});
|
||||
}),
|
||||
MenuEntry(
|
||||
icon: Icons.update,
|
||||
text: "Download All".tl,
|
||||
onClick: () async {
|
||||
int count = 0;
|
||||
for (var c in comics) {
|
||||
if (await LocalManager().isDownloaded(c.id, c.type)) {
|
||||
continue;
|
||||
}
|
||||
var comicSource = c.type.comicSource;
|
||||
if (comicSource == null) {
|
||||
continue;
|
||||
}
|
||||
LocalManager().addTask(ImagesDownloadTask(
|
||||
source: comicSource,
|
||||
comicId: c.id,
|
||||
comic: null,
|
||||
comicTitle: c.name,
|
||||
));
|
||||
count++;
|
||||
}
|
||||
context.showMessage(
|
||||
message: "Added @count comics to download queue."
|
||||
.tlParams({
|
||||
"count": count.toString(),
|
||||
}));
|
||||
}),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -199,6 +238,7 @@ class _ReorderComicsPageState extends State<_ReorderComicsPage> {
|
||||
var comicSource = e.type.comicSource;
|
||||
return ComicTile(
|
||||
key: Key(e.hashCode.toString()),
|
||||
enableLongPressed: false,
|
||||
comic: Comic(
|
||||
e.name,
|
||||
e.coverPath,
|
||||
@@ -206,7 +246,8 @@ class _ReorderComicsPageState extends State<_ReorderComicsPage> {
|
||||
e.author,
|
||||
e.tags,
|
||||
"${e.time} | ${comicSource?.name ?? "Unknown"}",
|
||||
comicSource?.key ?? "Unknown",
|
||||
comicSource?.key ??
|
||||
(e.type == ComicType.local ? "local" : "Unknown"),
|
||||
null,
|
||||
null,
|
||||
),
|
||||
|
41
lib/pages/favorites/local_search_page.dart
Normal file
41
lib/pages/favorites/local_search_page.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
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;
|
||||
},
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
@@ -80,7 +80,6 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 16),
|
||||
Icon(
|
||||
Icons.local_activity,
|
||||
color: context.colorScheme.secondary,
|
||||
@@ -88,20 +87,41 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
|
||||
const SizedBox(width: 12),
|
||||
Text("Local".tl),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
color: context.colorScheme.primary,
|
||||
onPressed: () {
|
||||
newFolder().then((value) {
|
||||
setState(() {
|
||||
folders = LocalFavoritesManager().folderNames;
|
||||
});
|
||||
});
|
||||
},
|
||||
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;
|
||||
});
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
],
|
||||
),
|
||||
).paddingHorizontal(16),
|
||||
);
|
||||
}
|
||||
index--;
|
||||
@@ -112,6 +132,7 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
|
||||
if (index == 0) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
margin: const EdgeInsets.only(top: 8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(
|
||||
@@ -211,13 +232,13 @@ class _LeftBarState extends State<_LeftBar> implements FolderList {
|
||||
|
||||
@override
|
||||
void update() {
|
||||
if(!mounted) return;
|
||||
if (!mounted) return;
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void updateFolders() {
|
||||
if(!mounted) return;
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
folders = LocalFavoritesManager().folderNames;
|
||||
networkFolders = ComicSource.all()
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sliver_tools/sliver_tools.dart';
|
||||
import 'package:venera/components/components.dart';
|
||||
import 'package:venera/foundation/app.dart';
|
||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||
@@ -17,9 +18,12 @@ import 'package:venera/pages/downloading_page.dart';
|
||||
import 'package:venera/pages/history_page.dart';
|
||||
import 'package:venera/pages/search_page.dart';
|
||||
import 'package:venera/utils/cbz.dart';
|
||||
import 'package:venera/utils/data_sync.dart';
|
||||
import 'package:venera/utils/ext.dart';
|
||||
import 'package:venera/utils/io.dart';
|
||||
import 'package:venera/utils/translations.dart';
|
||||
import 'package:sqlite3/sqlite3.dart' as sql;
|
||||
import 'dart:math';
|
||||
|
||||
import 'local_comics_page.dart';
|
||||
|
||||
@@ -32,6 +36,7 @@ class HomePage extends StatelessWidget {
|
||||
slivers: [
|
||||
SliverPadding(padding: EdgeInsets.only(top: context.padding.top)),
|
||||
const _SearchBar(),
|
||||
const _SyncDataWidget(),
|
||||
const _History(),
|
||||
const _Local(),
|
||||
const _ComicSourceWidget(),
|
||||
@@ -77,6 +82,97 @@ class _SearchBar extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _SyncDataWidget extends StatefulWidget {
|
||||
const _SyncDataWidget();
|
||||
|
||||
@override
|
||||
State<_SyncDataWidget> createState() => _SyncDataWidgetState();
|
||||
}
|
||||
|
||||
class _SyncDataWidgetState extends State<_SyncDataWidget> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
DataSync().addListener(update);
|
||||
}
|
||||
|
||||
void update() {
|
||||
if(mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
DataSync().removeListener(update);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget child;
|
||||
if(!DataSync().isEnabled) {
|
||||
child = const SliverPadding(padding: EdgeInsets.zero);
|
||||
} else if (DataSync().isUploading || DataSync().isDownloading) {
|
||||
child = SliverToBoxAdapter(
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.sync),
|
||||
title: Text('Syncing Data'.tl),
|
||||
trailing: const CircularProgressIndicator(strokeWidth: 2)
|
||||
.fixWidth(18)
|
||||
.fixHeight(18),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
child = SliverToBoxAdapter(
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: Theme.of(context).colorScheme.outlineVariant,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.sync),
|
||||
title: Text('Sync Data'.tl),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.cloud_upload_outlined),
|
||||
onPressed: () async {
|
||||
DataSync().uploadData();
|
||||
}
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.cloud_download_outlined),
|
||||
onPressed: () async {
|
||||
DataSync().downloadData();
|
||||
}
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return SliverAnimatedPaintExtent(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _History extends StatefulWidget {
|
||||
const _History();
|
||||
|
||||
@@ -162,6 +258,7 @@ class _HistoryState extends State<_History> {
|
||||
ImageProvider imageProvider = CachedImageProvider(
|
||||
cover,
|
||||
sourceKey: history[index].type.comicSource?.key,
|
||||
cid: history[index].id,
|
||||
);
|
||||
if (!cover.isURL) {
|
||||
var localComic = LocalManager().find(
|
||||
@@ -401,7 +498,14 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
|
||||
"Select a directory which contains the comic files.".tl,
|
||||
"Select a directory which contains the comic directories.".tl,
|
||||
"Select a cbz file.".tl,
|
||||
"Select an EhViewer database and a download folder.".tl
|
||||
][type];
|
||||
List<String> importMethods = [
|
||||
"Single Comic".tl,
|
||||
"Multiple Comics".tl,
|
||||
"A cbz file".tl,
|
||||
"EhViewer downloads".tl
|
||||
];
|
||||
|
||||
return ContentDialog(
|
||||
dismissible: !loading,
|
||||
@@ -419,36 +523,18 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(width: 600),
|
||||
RadioListTile(
|
||||
title: Text("Single Comic".tl),
|
||||
value: 0,
|
||||
groupValue: type,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
type = value as int;
|
||||
});
|
||||
},
|
||||
),
|
||||
RadioListTile(
|
||||
title: Text("Multiple Comics".tl),
|
||||
value: 1,
|
||||
groupValue: type,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
type = value as int;
|
||||
});
|
||||
},
|
||||
),
|
||||
RadioListTile(
|
||||
title: Text("A cbz file".tl),
|
||||
value: 2,
|
||||
groupValue: type,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
type = value as int;
|
||||
});
|
||||
},
|
||||
),
|
||||
...List.generate(importMethods.length, (index) {
|
||||
return RadioListTile(
|
||||
title: Text(importMethods[index]),
|
||||
value: index,
|
||||
groupValue: type,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
type = value as int;
|
||||
});
|
||||
},
|
||||
);
|
||||
}),
|
||||
ListTile(
|
||||
title: Text("Add to favorites".tl),
|
||||
trailing: Select(
|
||||
@@ -482,7 +568,7 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierColor: Colors.transparent,
|
||||
barrierColor: Colors.black.withOpacity(0.2),
|
||||
builder: (context) {
|
||||
var help = '';
|
||||
help +=
|
||||
@@ -493,8 +579,9 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
|
||||
help +=
|
||||
'${"If the directory contains a file named 'cover.*', it will be used as the cover image. Otherwise the first image will be used.".tl}\n\n';
|
||||
help +=
|
||||
"The directory name will be used as the comic title. And the name of chapter directories will be used as the chapter titles."
|
||||
"The directory name will be used as the comic title. And the name of chapter directories will be used as the chapter titles.\n"
|
||||
.tl;
|
||||
help +="If you import an EhViewer's database, program will automatically create folders according to the download label in that database.".tl;
|
||||
return ContentDialog(
|
||||
title: "Help".tl,
|
||||
content: Text(help).paddingHorizontal(16),
|
||||
@@ -529,14 +616,16 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
|
||||
await xFile!.saveTo(cache);
|
||||
var comic = await CBZ.import(File(cache));
|
||||
if (selectedFolder != null) {
|
||||
LocalFavoritesManager().addComic(selectedFolder!, FavoriteItem(
|
||||
id: comic.id,
|
||||
name: comic.title,
|
||||
coverPath: comic.cover,
|
||||
author: comic.subtitle,
|
||||
type: comic.comicType,
|
||||
tags: comic.tags,
|
||||
));
|
||||
LocalFavoritesManager().addComic(
|
||||
selectedFolder!,
|
||||
FavoriteItem(
|
||||
id: comic.id,
|
||||
name: comic.title,
|
||||
coverPath: comic.cover,
|
||||
author: comic.subtitle,
|
||||
type: comic.comicType,
|
||||
tags: comic.tags,
|
||||
));
|
||||
}
|
||||
await File(cache).deleteIgnoreError();
|
||||
} catch (e, s) {
|
||||
@@ -545,6 +634,135 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
|
||||
}
|
||||
controller.close();
|
||||
return;
|
||||
} else if (type == 3) {
|
||||
var dbFile = await selectFile(ext: ['db']);
|
||||
final picker = DirectoryPicker();
|
||||
final comicSrc = await picker.pickDirectory();
|
||||
if (dbFile == null || comicSrc == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool cancelled = false;
|
||||
var controller = showLoadingDialog(context, onCancel: () { cancelled = true; });
|
||||
|
||||
try {
|
||||
var cache = FilePath.join(App.cachePath, dbFile.name);
|
||||
await dbFile.saveTo(cache);
|
||||
var db = sql.sqlite3.open(cache);
|
||||
|
||||
Future<void> addTagComics(String destFolder, List<sql.Row> comics) async {
|
||||
for(var comic in comics) {
|
||||
if(cancelled) {
|
||||
return;
|
||||
}
|
||||
var comicDir = Directory(FilePath.join(comicSrc.path, comic['DIRNAME'] as String));
|
||||
if(!(await comicDir.exists())) {
|
||||
continue;
|
||||
}
|
||||
String titleJP = comic['TITLE_JPN'] == null ? "" : comic['TITLE_JPN'] as String;
|
||||
String title = titleJP == "" ? comic['TITLE'] as String : titleJP;
|
||||
if (LocalManager().findByName(title) != null) {
|
||||
Log.info("Import Comic", "Comic already exists: $title");
|
||||
continue;
|
||||
}
|
||||
|
||||
String coverURL = await comicDir.joinFile(".thumb").exists() ?
|
||||
comicDir.joinFile(".thumb").path :
|
||||
(comic['THUMB'] as String).replaceAll('s.exhentai.org', 'ehgt.org');
|
||||
int downloadedTimeStamp = comic['TIME'] as int;
|
||||
DateTime downloadedTime =
|
||||
downloadedTimeStamp != 0 ?
|
||||
DateTime.fromMillisecondsSinceEpoch(downloadedTimeStamp) : DateTime.now();
|
||||
var comicObj = LocalComic(
|
||||
id: LocalManager().findValidId(ComicType.local),
|
||||
title: title,
|
||||
subtitle: '',
|
||||
tags: [
|
||||
//1 >> x
|
||||
[
|
||||
"MISC",
|
||||
"DOUJINSHI",
|
||||
"MANGA",
|
||||
"ARTISTCG",
|
||||
"GAMECG",
|
||||
"IMAGE SET",
|
||||
"COSPLAY",
|
||||
"ASIAN PORN",
|
||||
"NON-H",
|
||||
"WESTERN",
|
||||
][(log(comic['CATEGORY'] as int) / ln2).floor()]
|
||||
],
|
||||
directory: comicDir.path,
|
||||
chapters: null,
|
||||
cover: coverURL,
|
||||
comicType: ComicType.local,
|
||||
downloadedChapters: [],
|
||||
createdAt: downloadedTime,
|
||||
);
|
||||
LocalManager().add(comicObj, comicObj.id);
|
||||
LocalFavoritesManager().addComic(
|
||||
destFolder,
|
||||
FavoriteItem(
|
||||
id: comicObj.id,
|
||||
name: comicObj.title,
|
||||
coverPath: comicObj.cover,
|
||||
author: comicObj.subtitle,
|
||||
type: comicObj.comicType,
|
||||
tags: comicObj.tags,
|
||||
favoriteTime: downloadedTime
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//default folder
|
||||
{
|
||||
var defaultFolderName = '(EhViewer)Default'.tl;
|
||||
if(!LocalFavoritesManager().existsFolder(defaultFolderName)) {
|
||||
LocalFavoritesManager().createFolder(defaultFolderName);
|
||||
}
|
||||
var comicList = db.select("""
|
||||
SELECT *
|
||||
FROM DOWNLOAD_DIRNAME DN
|
||||
LEFT JOIN DOWNLOADS DL
|
||||
ON DL.GID = DN.GID
|
||||
WHERE DL.LABEL IS NULL AND DL.STATE = 3
|
||||
ORDER BY DL.TIME DESC
|
||||
""").toList();
|
||||
await addTagComics(defaultFolderName, comicList);
|
||||
}
|
||||
|
||||
var folders = db.select("""
|
||||
SELECT * FROM DOWNLOAD_LABELS;
|
||||
""");
|
||||
|
||||
for (var folder in folders) {
|
||||
if(cancelled) {
|
||||
break;
|
||||
}
|
||||
var label = folder["LABEL"] as String;
|
||||
var folderName = '(EhViewer)$label';
|
||||
if(!LocalFavoritesManager().existsFolder(folderName)) {
|
||||
LocalFavoritesManager().createFolder(folderName);
|
||||
}
|
||||
var comicList = db.select("""
|
||||
SELECT *
|
||||
FROM DOWNLOAD_DIRNAME DN
|
||||
LEFT JOIN DOWNLOADS DL
|
||||
ON DL.GID = DN.GID
|
||||
WHERE DL.LABEL = ? AND DL.STATE = 3
|
||||
ORDER BY DL.TIME DESC
|
||||
""", [label]).toList();
|
||||
await addTagComics(folderName, comicList);
|
||||
}
|
||||
db.dispose();
|
||||
await File(cache).deleteIgnoreError();
|
||||
} catch (e, s) {
|
||||
Log.error("Import Comic", e.toString(), s);
|
||||
context.showMessage(message: e.toString());
|
||||
}
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
height = key.currentContext!.size!.height;
|
||||
setState(() {
|
||||
@@ -610,14 +828,16 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
|
||||
for (var comic in comics.values) {
|
||||
LocalManager().add(comic, LocalManager().findValidId(ComicType.local));
|
||||
if (selectedFolder != null) {
|
||||
LocalFavoritesManager().addComic(selectedFolder!, FavoriteItem(
|
||||
id: comic.id,
|
||||
name: comic.title,
|
||||
coverPath: comic.cover,
|
||||
author: comic.subtitle,
|
||||
type: comic.comicType,
|
||||
tags: comic.tags,
|
||||
));
|
||||
LocalFavoritesManager().addComic(
|
||||
selectedFolder!,
|
||||
FavoriteItem(
|
||||
id: comic.id,
|
||||
name: comic.title,
|
||||
coverPath: comic.cover,
|
||||
author: comic.subtitle,
|
||||
type: comic.comicType,
|
||||
tags: comic.tags,
|
||||
));
|
||||
}
|
||||
}
|
||||
context.pop();
|
||||
@@ -699,7 +919,7 @@ class _ImportComicsWidgetState extends State<_ImportComicsWidget> {
|
||||
subtitle: '',
|
||||
tags: [],
|
||||
directory: directory.name,
|
||||
chapters: Map.fromIterables(chapters, chapters),
|
||||
chapters: hasChapters ? Map.fromIterables(chapters, chapters) : null,
|
||||
cover: coverPath,
|
||||
comicType: ComicType.local,
|
||||
downloadedChapters: chapters,
|
||||
@@ -820,6 +1040,7 @@ class _AccountsWidgetState extends State<_AccountsWidget> {
|
||||
|
||||
void onComicSourceChange() {
|
||||
setState(() {
|
||||
accounts.clear();
|
||||
for (var c in ComicSource.all()) {
|
||||
if (c.isLogged) {
|
||||
accounts.add(c.name);
|
||||
|
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:venera/components/components.dart';
|
||||
import 'package:venera/foundation/app.dart';
|
||||
import 'package:venera/foundation/appdata.dart';
|
||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||
import 'package:venera/foundation/local.dart';
|
||||
import 'package:venera/pages/downloading_page.dart';
|
||||
import 'package:venera/utils/cbz.dart';
|
||||
@@ -17,15 +19,33 @@ class LocalComicsPage extends StatefulWidget {
|
||||
class _LocalComicsPageState extends State<LocalComicsPage> {
|
||||
late List<LocalComic> comics;
|
||||
|
||||
late LocalSortType sortType;
|
||||
|
||||
String keyword = "";
|
||||
|
||||
bool searchMode = false;
|
||||
|
||||
bool multiSelectMode = false;
|
||||
|
||||
Map<Comic, bool> selectedComics = {};
|
||||
|
||||
void update() {
|
||||
setState(() {
|
||||
comics = LocalManager().getComics();
|
||||
});
|
||||
if (keyword.isEmpty) {
|
||||
setState(() {
|
||||
comics = LocalManager().getComics(sortType);
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
comics = LocalManager().search(keyword);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
comics = LocalManager().getComics();
|
||||
var sort = appdata.implicitData["local_sort"] ?? "name";
|
||||
sortType = LocalSortType.fromString(sort);
|
||||
comics = LocalManager().getComics(sortType);
|
||||
LocalManager().addListener(update);
|
||||
super.initState();
|
||||
}
|
||||
@@ -36,37 +56,290 @@ class _LocalComicsPageState extends State<LocalComicsPage> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SmoothCustomScrollView(
|
||||
slivers: [
|
||||
SliverAppbar(
|
||||
title: Text("Local".tl),
|
||||
actions: [
|
||||
Tooltip(
|
||||
message: "Downloading".tl,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.download),
|
||||
onPressed: () {
|
||||
showPopUpWidget(context, const DownloadingPage());
|
||||
void sort() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return StatefulBuilder(builder: (context, setState) {
|
||||
return ContentDialog(
|
||||
title: "Sort".tl,
|
||||
content: Column(
|
||||
children: [
|
||||
RadioListTile<LocalSortType>(
|
||||
title: Text("Name".tl),
|
||||
value: LocalSortType.name,
|
||||
groupValue: sortType,
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
sortType = v!;
|
||||
});
|
||||
},
|
||||
),
|
||||
)
|
||||
RadioListTile<LocalSortType>(
|
||||
title: Text("Date".tl),
|
||||
value: LocalSortType.timeAsc,
|
||||
groupValue: sortType,
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
sortType = v!;
|
||||
});
|
||||
},
|
||||
),
|
||||
RadioListTile<LocalSortType>(
|
||||
title: Text("Date Desc".tl),
|
||||
value: LocalSortType.timeDesc,
|
||||
groupValue: sortType,
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
sortType = v!;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
appdata.implicitData["local_sort"] = sortType.value;
|
||||
appdata.writeImplicitData();
|
||||
Navigator.pop(context);
|
||||
update();
|
||||
},
|
||||
child: Text("Confirm".tl),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
void selectAll() {
|
||||
setState(() {
|
||||
selectedComics = comics.asMap().map((k, v) => MapEntry(v, true));
|
||||
});
|
||||
}
|
||||
|
||||
void deSelect() {
|
||||
setState(() {
|
||||
selectedComics.clear();
|
||||
});
|
||||
}
|
||||
|
||||
void invertSelection() {
|
||||
setState(() {
|
||||
comics.asMap().forEach((k, v) {
|
||||
selectedComics[v] = !selectedComics.putIfAbsent(v, () => false);
|
||||
});
|
||||
selectedComics.removeWhere((k, v) => !v);
|
||||
});
|
||||
}
|
||||
|
||||
void selectRange() {
|
||||
setState(() {
|
||||
List<int> l = [];
|
||||
selectedComics.forEach((k, v) {
|
||||
l.add(comics.indexOf(k as LocalComic));
|
||||
});
|
||||
if (l.isEmpty) {
|
||||
return;
|
||||
}
|
||||
l.sort();
|
||||
int start = l.first;
|
||||
int end = l.last;
|
||||
selectedComics.clear();
|
||||
selectedComics.addEntries(List.generate(end - start + 1, (i) {
|
||||
return MapEntry(comics[start + i], true);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
List<Widget> selectActions = [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.select_all),
|
||||
tooltip: "Select All".tl,
|
||||
onPressed: selectAll),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.deselect),
|
||||
tooltip: "Deselect".tl,
|
||||
onPressed: deSelect),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.flip),
|
||||
tooltip: "Invert Selection".tl,
|
||||
onPressed: invertSelection),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.border_horizontal_outlined),
|
||||
tooltip: "Select in range".tl,
|
||||
onPressed: selectRange),
|
||||
];
|
||||
|
||||
var body = Scaffold(
|
||||
body: SmoothCustomScrollView(
|
||||
slivers: [
|
||||
if (!searchMode && !multiSelectMode)
|
||||
SliverAppbar(
|
||||
title: Text("Local".tl),
|
||||
actions: [
|
||||
Tooltip(
|
||||
message: "Search".tl,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.search),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
searchMode = true;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
Tooltip(
|
||||
message: "Sort".tl,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.sort),
|
||||
onPressed: sort,
|
||||
),
|
||||
),
|
||||
Tooltip(
|
||||
message: "Downloading".tl,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.download),
|
||||
onPressed: () {
|
||||
showPopUpWidget(context, const DownloadingPage());
|
||||
},
|
||||
),
|
||||
),
|
||||
Tooltip(
|
||||
message: multiSelectMode
|
||||
? "Exit Multi-Select".tl
|
||||
: "Multi-Select".tl,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.checklist),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
multiSelectMode = !multiSelectMode;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
else if (multiSelectMode)
|
||||
SliverAppbar(
|
||||
leading: Tooltip(
|
||||
message: "Cancel".tl,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
multiSelectMode = false;
|
||||
selectedComics.clear();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
"Selected @c comics".tlParams({"c": selectedComics.length})),
|
||||
actions: selectActions,
|
||||
)
|
||||
else if (searchMode)
|
||||
SliverAppbar(
|
||||
leading: Tooltip(
|
||||
message: "Cancel".tl,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
searchMode = false;
|
||||
keyword = "";
|
||||
update();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
title: TextField(
|
||||
autofocus: true,
|
||||
decoration: InputDecoration(
|
||||
hintText: "Search".tl,
|
||||
border: InputBorder.none,
|
||||
),
|
||||
onChanged: (v) {
|
||||
keyword = v;
|
||||
update();
|
||||
},
|
||||
),
|
||||
),
|
||||
SliverGridComics(
|
||||
comics: comics,
|
||||
onTap: (c) {
|
||||
(c as LocalComic).read();
|
||||
},
|
||||
selections: selectedComics,
|
||||
onTap: multiSelectMode
|
||||
? (c) {
|
||||
setState(() {
|
||||
if (selectedComics.containsKey(c as LocalComic)) {
|
||||
selectedComics.remove(c);
|
||||
} else {
|
||||
selectedComics[c] = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
: (c) {
|
||||
(c as LocalComic).read();
|
||||
},
|
||||
menuBuilder: (c) {
|
||||
return [
|
||||
MenuEntry(
|
||||
icon: Icons.delete,
|
||||
text: "Delete".tl,
|
||||
onClick: () {
|
||||
LocalManager().deleteComic(c as LocalComic);
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
bool removeComicFile = true;
|
||||
return StatefulBuilder(builder: (context, state) {
|
||||
return ContentDialog(
|
||||
title: "Delete".tl,
|
||||
content: Column(
|
||||
children: [
|
||||
Text("Delete selected comics?".tl)
|
||||
.paddingVertical(8),
|
||||
Transform.scale(
|
||||
scale: 0.9,
|
||||
child: CheckboxListTile(
|
||||
title: Text(
|
||||
"Also remove files on disk".tl),
|
||||
value: removeComicFile,
|
||||
onChanged: (v) {
|
||||
state(() {
|
||||
removeComicFile =
|
||||
!removeComicFile;
|
||||
});
|
||||
})),
|
||||
],
|
||||
).paddingHorizontal(16).paddingVertical(8),
|
||||
actions: [
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
if (multiSelectMode) {
|
||||
for (var comic in selectedComics.keys) {
|
||||
LocalManager().deleteComic(
|
||||
comic as LocalComic,
|
||||
removeComicFile);
|
||||
}
|
||||
setState(() {
|
||||
selectedComics.clear();
|
||||
});
|
||||
} else {
|
||||
LocalManager().deleteComic(
|
||||
c as LocalComic, removeComicFile);
|
||||
}
|
||||
},
|
||||
child: Text("Confirm".tl),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
});
|
||||
}),
|
||||
MenuEntry(
|
||||
icon: Icons.outbox_outlined,
|
||||
@@ -77,11 +350,21 @@ class _LocalComicsPageState extends State<LocalComicsPage> {
|
||||
allowCancel: false,
|
||||
);
|
||||
try {
|
||||
var file = await CBZ.export(c as LocalComic);
|
||||
await saveFile(filename: file.name, file: file);
|
||||
await file.delete();
|
||||
}
|
||||
catch (e) {
|
||||
if (multiSelectMode) {
|
||||
for (var comic in selectedComics.keys) {
|
||||
var file = await CBZ.export(comic as LocalComic);
|
||||
await saveFile(filename: file.name, file: file);
|
||||
await file.delete();
|
||||
}
|
||||
setState(() {
|
||||
selectedComics.clear();
|
||||
});
|
||||
} else {
|
||||
var file = await CBZ.export(c as LocalComic);
|
||||
await saveFile(filename: file.name, file: file);
|
||||
await file.delete();
|
||||
}
|
||||
} catch (e) {
|
||||
context.showMessage(message: e.toString());
|
||||
}
|
||||
controller.close();
|
||||
@@ -92,5 +375,24 @@ class _LocalComicsPageState extends State<LocalComicsPage> {
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
return PopScope(
|
||||
canPop: !multiSelectMode && !searchMode,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if(multiSelectMode) {
|
||||
setState(() {
|
||||
multiSelectMode = false;
|
||||
selectedComics.clear();
|
||||
});
|
||||
} else if(searchMode) {
|
||||
setState(() {
|
||||
searchMode = false;
|
||||
keyword = "";
|
||||
update();
|
||||
});
|
||||
}
|
||||
},
|
||||
child: body,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -78,20 +78,25 @@ class _MainPageState extends State<MainPage> {
|
||||
activeIcon: Icons.category,
|
||||
),
|
||||
],
|
||||
onPageChanged: (i) {
|
||||
setState(() {
|
||||
index = i;
|
||||
});
|
||||
},
|
||||
paneActions: [
|
||||
if(index != 0)
|
||||
PaneActionEntry(
|
||||
icon: Icons.search,
|
||||
label: "Search".tl,
|
||||
onTap: () {
|
||||
to(() => const SearchPage());
|
||||
to(() => const SearchPage(), preventDuplicate: true);
|
||||
},
|
||||
),
|
||||
PaneActionEntry(
|
||||
icon: Icons.settings,
|
||||
label: "Settings".tl,
|
||||
onTap: () {
|
||||
to(() => const SettingsPage());
|
||||
to(() => const SettingsPage(), preventDuplicate: true);
|
||||
},
|
||||
)
|
||||
],
|
||||
|
@@ -12,14 +12,18 @@ class _ReaderGestureDetector extends StatefulWidget {
|
||||
class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
late TapGestureRecognizer _tapGestureRecognizer;
|
||||
|
||||
static const _kDoubleTapMinTime = Duration(milliseconds: 200);
|
||||
static const _kDoubleTapMaxTime = Duration(milliseconds: 200);
|
||||
|
||||
static const _kLongPressMinTime = Duration(milliseconds: 200);
|
||||
static const _kLongPressMinTime = Duration(milliseconds: 250);
|
||||
|
||||
static const _kDoubleTapMaxDistanceSquared = 20.0 * 20.0;
|
||||
|
||||
static const _kTapToTurnPagePercent = 0.3;
|
||||
|
||||
_DragListener? dragListener;
|
||||
|
||||
int fingers = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_tapGestureRecognizer = TapGestureRecognizer()
|
||||
@@ -28,6 +32,7 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
onSecondaryTapUp(details.globalPosition);
|
||||
};
|
||||
super.initState();
|
||||
context.readerScaffold._gestureDetectorState = this;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -35,14 +40,24 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
return Listener(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onPointerDown: (event) {
|
||||
fingers++;
|
||||
_lastTapPointer = event.pointer;
|
||||
_lastTapMoveDistance = Offset.zero;
|
||||
_tapGestureRecognizer.addPointer(event);
|
||||
if(_dragInProgress) {
|
||||
dragListener?.onEnd?.call();
|
||||
_dragInProgress = false;
|
||||
}
|
||||
Future.delayed(_kLongPressMinTime, () {
|
||||
if (_lastTapPointer == event.pointer &&
|
||||
_lastTapMoveDistance!.distanceSquared < 20.0 * 20.0) {
|
||||
onLongPressedDown(event.position);
|
||||
_longPressInProgress = true;
|
||||
if (_lastTapPointer == event.pointer && fingers == 1) {
|
||||
if(_lastTapMoveDistance!.distanceSquared < 20.0 * 20.0) {
|
||||
onLongPressedDown(event.position);
|
||||
_longPressInProgress = true;
|
||||
} else {
|
||||
_dragInProgress = true;
|
||||
dragListener?.onStart?.call(event.position);
|
||||
dragListener?.onMove?.call(_lastTapMoveDistance!);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -50,11 +65,31 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
if (event.pointer == _lastTapPointer) {
|
||||
_lastTapMoveDistance = event.delta + _lastTapMoveDistance!;
|
||||
}
|
||||
if(_dragInProgress) {
|
||||
dragListener?.onMove?.call(event.delta);
|
||||
}
|
||||
},
|
||||
onPointerUp: (event) {
|
||||
fingers--;
|
||||
if (_longPressInProgress) {
|
||||
onLongPressedUp(event.position);
|
||||
}
|
||||
if(_dragInProgress) {
|
||||
dragListener?.onEnd?.call();
|
||||
_dragInProgress = false;
|
||||
}
|
||||
_lastTapPointer = null;
|
||||
_lastTapMoveDistance = null;
|
||||
},
|
||||
onPointerCancel: (event) {
|
||||
fingers--;
|
||||
if (_longPressInProgress) {
|
||||
onLongPressedUp(event.position);
|
||||
}
|
||||
if(_dragInProgress) {
|
||||
dragListener?.onEnd?.call();
|
||||
_dragInProgress = false;
|
||||
}
|
||||
_lastTapPointer = null;
|
||||
_lastTapMoveDistance = null;
|
||||
},
|
||||
@@ -89,6 +124,8 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
|
||||
bool _longPressInProgress = false;
|
||||
|
||||
bool _dragInProgress = false;
|
||||
|
||||
void onTapUp(TapUpDetails event) {
|
||||
if (_longPressInProgress) {
|
||||
_longPressInProgress = false;
|
||||
@@ -107,7 +144,7 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
}
|
||||
}
|
||||
_previousEvent = event;
|
||||
Future.delayed(_kDoubleTapMinTime, () {
|
||||
Future.delayed(_kDoubleTapMaxTime, () {
|
||||
if (_previousEvent == event) {
|
||||
onTap(location);
|
||||
_previousEvent = null;
|
||||
@@ -183,25 +220,33 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
location,
|
||||
[
|
||||
MenuEntry(
|
||||
text: "Settings".tl,
|
||||
onClick: () {
|
||||
context.readerScaffold.openSetting();
|
||||
}),
|
||||
icon: Icons.settings,
|
||||
text: "Settings".tl,
|
||||
onClick: () {
|
||||
context.readerScaffold.openSetting();
|
||||
},
|
||||
),
|
||||
MenuEntry(
|
||||
text: "Chapters".tl,
|
||||
onClick: () {
|
||||
context.readerScaffold.openChapterDrawer();
|
||||
}),
|
||||
icon: Icons.menu,
|
||||
text: "Chapters".tl,
|
||||
onClick: () {
|
||||
context.readerScaffold.openChapterDrawer();
|
||||
},
|
||||
),
|
||||
MenuEntry(
|
||||
text: "Fullscreen".tl,
|
||||
onClick: () {
|
||||
context.reader.fullscreen();
|
||||
}),
|
||||
icon: Icons.fullscreen,
|
||||
text: "Fullscreen".tl,
|
||||
onClick: () {
|
||||
context.reader.fullscreen();
|
||||
},
|
||||
),
|
||||
MenuEntry(
|
||||
text: "Exit".tl,
|
||||
onClick: () {
|
||||
context.pop();
|
||||
}),
|
||||
icon: Icons.exit_to_app,
|
||||
text: "Exit".tl,
|
||||
onClick: () {
|
||||
context.pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -214,3 +259,11 @@ class _ReaderGestureDetectorState extends State<_ReaderGestureDetector> {
|
||||
context.reader._imageViewController?.handleLongPressDown(location);
|
||||
}
|
||||
}
|
||||
|
||||
class _DragListener {
|
||||
void Function(Offset point)? onStart;
|
||||
void Function(Offset offset)? onMove;
|
||||
void Function()? onEnd;
|
||||
|
||||
_DragListener({this.onStart, this.onMove, this.onEnd});
|
||||
}
|
@@ -116,6 +116,9 @@ class _GalleryModeState extends State<_GalleryMode>
|
||||
controller = PageController(initialPage: reader.page);
|
||||
reader._imageViewController = this;
|
||||
cached = List.filled(reader.maxPage + 2, false);
|
||||
Future.microtask(() {
|
||||
context.readerScaffold.setFloatingButton(0);
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@@ -180,11 +183,11 @@ class _GalleryModeState extends State<_GalleryMode>
|
||||
),
|
||||
onPageChanged: (i) {
|
||||
if (i == 0) {
|
||||
if (!reader.toNextChapter()) {
|
||||
if (!reader.toPrevChapter()) {
|
||||
reader.toPage(1);
|
||||
}
|
||||
} else if (i == reader.maxPage + 1) {
|
||||
if (!reader.toPrevChapter()) {
|
||||
if (!reader.toNextChapter()) {
|
||||
reader.toPage(reader.maxPage);
|
||||
}
|
||||
} else {
|
||||
@@ -220,6 +223,9 @@ class _GalleryModeState extends State<_GalleryMode>
|
||||
|
||||
@override
|
||||
void handleLongPressDown(Offset location) {
|
||||
if(!appdata.settings['enableLongPressToZoom']) {
|
||||
return;
|
||||
}
|
||||
var photoViewController = photoViewControllers[reader.page]!;
|
||||
double target = photoViewController.getInitialScale!.call()! * 1.75;
|
||||
var size = MediaQuery.of(context).size;
|
||||
@@ -231,6 +237,9 @@ class _GalleryModeState extends State<_GalleryMode>
|
||||
|
||||
@override
|
||||
void handleLongPressUp(Offset location) {
|
||||
if(!appdata.settings['enableLongPressToZoom']) {
|
||||
return;
|
||||
}
|
||||
var photoViewController = photoViewControllers[reader.page]!;
|
||||
double target = photoViewController.getInitialScale!.call()!;
|
||||
photoViewController.animateScale?.call(target);
|
||||
@@ -462,18 +471,24 @@ class _ContinuousModeState extends State<_ContinuousMode>
|
||||
},
|
||||
child: widget,
|
||||
);
|
||||
var width = MediaQuery.of(context).size.width;
|
||||
var height = MediaQuery.of(context).size.height;
|
||||
if(appdata.settings['limitImageWidth'] && width / height > 0.7) {
|
||||
width = height * 0.7;
|
||||
}
|
||||
|
||||
return PhotoView.customChild(
|
||||
backgroundDecoration: BoxDecoration(
|
||||
color: context.colorScheme.surface,
|
||||
),
|
||||
childSize: Size(width, height),
|
||||
minScale: 1.0,
|
||||
maxScale: 2.5,
|
||||
strictScale: true,
|
||||
controller: photoViewController,
|
||||
child: SizedBox(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
height: MediaQuery.of(context).size.height,
|
||||
width: width,
|
||||
height: height,
|
||||
child: widget,
|
||||
),
|
||||
);
|
||||
@@ -506,6 +521,9 @@ class _ContinuousModeState extends State<_ContinuousMode>
|
||||
|
||||
@override
|
||||
void handleLongPressDown(Offset location) {
|
||||
if(!appdata.settings['enableLongPressToZoom']) {
|
||||
return;
|
||||
}
|
||||
double target = photoViewController.getInitialScale!.call()! * 1.75;
|
||||
var size = MediaQuery.of(context).size;
|
||||
photoViewController.animateScale?.call(
|
||||
@@ -516,6 +534,9 @@ class _ContinuousModeState extends State<_ContinuousMode>
|
||||
|
||||
@override
|
||||
void handleLongPressUp(Offset location) {
|
||||
if(!appdata.settings['enableLongPressToZoom']) {
|
||||
return;
|
||||
}
|
||||
double target = photoViewController.getInitialScale!.call()!;
|
||||
photoViewController.animateScale?.call(target);
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ library venera_reader;
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
@@ -19,10 +20,13 @@ import 'package:venera/foundation/history.dart';
|
||||
import 'package:venera/foundation/image_provider/reader_image.dart';
|
||||
import 'package:venera/foundation/local.dart';
|
||||
import 'package:venera/pages/settings/settings_page.dart';
|
||||
import 'package:venera/utils/data_sync.dart';
|
||||
import 'package:venera/utils/file_type.dart';
|
||||
import 'package:venera/utils/io.dart';
|
||||
import 'package:venera/utils/translations.dart';
|
||||
import 'package:venera/utils/volume.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
import 'package:battery_plus/battery_plus.dart';
|
||||
|
||||
part 'scaffold.dart';
|
||||
part 'images.dart';
|
||||
@@ -96,6 +100,8 @@ class _ReaderState extends State<Reader> with _ReaderLocation, _ReaderWindow {
|
||||
|
||||
var focusNode = FocusNode();
|
||||
|
||||
VolumeListener? volumeListener;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
page = widget.initialPage ?? 1;
|
||||
@@ -105,6 +111,10 @@ class _ReaderState extends State<Reader> with _ReaderLocation, _ReaderWindow {
|
||||
Future.microtask(() {
|
||||
updateHistory();
|
||||
});
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
|
||||
if(appdata.settings['enableTurnPageByVolumeKey']) {
|
||||
handleVolumeEvent();
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@@ -112,6 +122,11 @@ class _ReaderState extends State<Reader> with _ReaderLocation, _ReaderWindow {
|
||||
void dispose() {
|
||||
autoPageTurningTimer?.cancel();
|
||||
focusNode.dispose();
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
stopVolumeEvent();
|
||||
Future.microtask(() {
|
||||
DataSync().onDataChanged();
|
||||
});
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -149,6 +164,31 @@ class _ReaderState extends State<Reader> with _ReaderLocation, _ReaderWindow {
|
||||
HistoryManager().addHistory(history!);
|
||||
}
|
||||
}
|
||||
|
||||
void handleVolumeEvent() {
|
||||
if(!App.isAndroid) {
|
||||
// Currently only support Android
|
||||
return;
|
||||
}
|
||||
if(volumeListener != null) {
|
||||
volumeListener?.cancel();
|
||||
}
|
||||
volumeListener = VolumeListener(
|
||||
onDown: () {
|
||||
toNextPage();
|
||||
},
|
||||
onUp: () {
|
||||
toPrevPage();
|
||||
},
|
||||
)..listen();
|
||||
}
|
||||
|
||||
void stopVolumeEvent() {
|
||||
if(volumeListener != null) {
|
||||
volumeListener?.cancel();
|
||||
volumeListener = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract mixin class _ReaderLocation {
|
||||
@@ -284,6 +324,8 @@ enum ReaderMode {
|
||||
|
||||
bool get isGallery => key.startsWith('gallery');
|
||||
|
||||
bool get isContinuous => key.startsWith('continuous');
|
||||
|
||||
const ReaderMode(this.key);
|
||||
|
||||
static ReaderMode fromKey(String key) {
|
||||
|
@@ -20,21 +20,68 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
|
||||
int showFloatingButtonValue = 0;
|
||||
|
||||
double fABValue = 0;
|
||||
var lastValue = 0;
|
||||
|
||||
var fABValue = ValueNotifier<double>(0);
|
||||
|
||||
_ReaderGestureDetectorState? _gestureDetectorState;
|
||||
|
||||
void setFloatingButton(int value) {
|
||||
lastValue = showFloatingButtonValue;
|
||||
if (value == 0) {
|
||||
if (showFloatingButtonValue != 0) {
|
||||
showFloatingButtonValue = 0;
|
||||
fABValue = 0;
|
||||
fABValue.value = 0;
|
||||
update();
|
||||
}
|
||||
_gestureDetectorState!.dragListener = null;
|
||||
}
|
||||
var readerMode = context.reader.mode;
|
||||
if (value == 1 && showFloatingButtonValue == 0) {
|
||||
showFloatingButtonValue = 1;
|
||||
_gestureDetectorState!.dragListener = _DragListener(
|
||||
onMove: (offset) {
|
||||
if (readerMode == ReaderMode.continuousTopToBottom) {
|
||||
fABValue.value -= offset.dy;
|
||||
} else if (readerMode == ReaderMode.continuousLeftToRight) {
|
||||
fABValue.value -= offset.dx;
|
||||
} else if (readerMode == ReaderMode.continuousRightToLeft) {
|
||||
fABValue.value += offset.dx;
|
||||
}
|
||||
},
|
||||
onEnd: () {
|
||||
if (fABValue.value.abs() > 58 * 3) {
|
||||
setState(() {
|
||||
showFloatingButtonValue = 0;
|
||||
});
|
||||
context.reader.toNextChapter();
|
||||
}
|
||||
fABValue.value = 0;
|
||||
},
|
||||
);
|
||||
update();
|
||||
} else if (value == -1 && showFloatingButtonValue == 0) {
|
||||
showFloatingButtonValue = -1;
|
||||
_gestureDetectorState!.dragListener = _DragListener(
|
||||
onMove: (offset) {
|
||||
if (readerMode == ReaderMode.continuousTopToBottom) {
|
||||
fABValue.value += offset.dy;
|
||||
} else if (readerMode == ReaderMode.continuousLeftToRight) {
|
||||
fABValue.value += offset.dx;
|
||||
} else if (readerMode == ReaderMode.continuousRightToLeft) {
|
||||
fABValue.value -= offset.dx;
|
||||
}
|
||||
},
|
||||
onEnd: () {
|
||||
if (fABValue.value.abs() > 58 * 3) {
|
||||
setState(() {
|
||||
showFloatingButtonValue = 0;
|
||||
});
|
||||
context.reader.toPrevChapter();
|
||||
}
|
||||
fABValue.value = 0;
|
||||
},
|
||||
);
|
||||
update();
|
||||
}
|
||||
}
|
||||
@@ -47,6 +94,9 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
sliderFocus.nextFocus();
|
||||
}
|
||||
});
|
||||
if (rotation != null) {
|
||||
SystemChrome.setPreferredOrientations(DeviceOrientation.values);
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@@ -57,6 +107,11 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
}
|
||||
|
||||
void openOrClose() {
|
||||
if (!_isOpen) {
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
} else {
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
|
||||
}
|
||||
setState(() {
|
||||
_isOpen = !_isOpen;
|
||||
});
|
||||
@@ -76,6 +131,13 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
child: widget.child,
|
||||
),
|
||||
buildPageInfoText(),
|
||||
buildStatusInfo(),
|
||||
AnimatedPositioned(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
right: 16,
|
||||
bottom: showFloatingButtonValue == 0 ? -58 : 36,
|
||||
child: buildEpChangeButton(),
|
||||
),
|
||||
AnimatedPositioned(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
top: _isOpen ? 0 : -(kTopBarHeight + context.padding.top),
|
||||
@@ -86,18 +148,13 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
),
|
||||
AnimatedPositioned(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
bottom: _isOpen ? 0 : -(kBottomBarHeight + context.padding.bottom),
|
||||
bottom: _isOpen
|
||||
? 0
|
||||
: -(kBottomBarHeight + MediaQuery.of(context).padding.bottom),
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: kBottomBarHeight + context.padding.bottom,
|
||||
child: buildBottom(),
|
||||
),
|
||||
AnimatedPositioned(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
right: 16,
|
||||
bottom: showFloatingButtonValue == 0 ? -58 : 16,
|
||||
child: buildEpChangeButton(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -150,7 +207,7 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
}
|
||||
|
||||
Widget child = SizedBox(
|
||||
height: kBottomBarHeight + MediaQuery.of(context).padding.bottom,
|
||||
height: kBottomBarHeight,
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(
|
||||
@@ -160,14 +217,34 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
children: [
|
||||
const SizedBox(width: 8),
|
||||
IconButton.filledTonal(
|
||||
onPressed: context.reader.toPrevChapter,
|
||||
onPressed: () {
|
||||
if (!context.reader.toPrevChapter()) {
|
||||
context.reader.toPage(1);
|
||||
} else {
|
||||
if (showFloatingButtonValue != 0) {
|
||||
setState(() {
|
||||
showFloatingButtonValue = 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.first_page),
|
||||
),
|
||||
Expanded(
|
||||
child: buildSlider(),
|
||||
),
|
||||
IconButton.filledTonal(
|
||||
onPressed: context.reader.toNextChapter,
|
||||
onPressed: () {
|
||||
if (!context.reader.toNextChapter()) {
|
||||
context.reader.toPage(context.reader.maxPage);
|
||||
} else {
|
||||
if (showFloatingButtonValue != 0) {
|
||||
setState(() {
|
||||
showFloatingButtonValue = 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.last_page)),
|
||||
const SizedBox(
|
||||
width: 8,
|
||||
@@ -186,7 +263,9 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
color: Theme.of(context).colorScheme.tertiaryContainer,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(text),
|
||||
child: Center(
|
||||
child: Text(text),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (App.isWindows)
|
||||
@@ -315,7 +394,7 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
|
||||
Widget buildPageInfoText() {
|
||||
var epName = context.reader.widget.chapters?.values
|
||||
.elementAt(context.reader.chapter - 1) ??
|
||||
.elementAtOrNull(context.reader.chapter - 1) ??
|
||||
"E${context.reader.chapter}";
|
||||
if (epName.length > 8) {
|
||||
epName = "${epName.substring(0, 8)}...";
|
||||
@@ -346,6 +425,24 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildStatusInfo() {
|
||||
if (appdata.settings['enableClockAndBatteryInfoInReader']) {
|
||||
return Positioned(
|
||||
bottom: 13,
|
||||
right: 25,
|
||||
child: Row(
|
||||
children: [
|
||||
_ClockWidget(),
|
||||
const SizedBox(width: 10),
|
||||
_BatteryWidget(),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
}
|
||||
|
||||
void openChapterDrawer() {
|
||||
showSideBar(
|
||||
context,
|
||||
@@ -354,19 +451,87 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<Uint8List> _getCurrentImageData() async {
|
||||
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![e.index - 1])
|
||||
.toList();
|
||||
String? selected;
|
||||
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,
|
||||
);
|
||||
}
|
||||
return InkWell(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(16)),
|
||||
onTap: () {
|
||||
selected = images[index];
|
||||
App.rootContext.pop();
|
||||
},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(16)),
|
||||
border: Border.all(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
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}"))!
|
||||
return (await CacheManager().findCache(
|
||||
"$imageKey@${context.reader.type.sourceKey}@${context.reader.cid}@${context.reader.eid}"))!
|
||||
.readAsBytes();
|
||||
}
|
||||
}
|
||||
|
||||
void saveCurrentImage() async {
|
||||
var data = await _getCurrentImageData();
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
var fileType = detectFileType(data);
|
||||
var filename = "${context.reader.page}${fileType.ext}";
|
||||
saveFile(data: data, filename: filename);
|
||||
@@ -374,6 +539,9 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
|
||||
void share() async {
|
||||
var data = await _getCurrentImageData();
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
var fileType = detectFileType(data);
|
||||
var filename = "${context.reader.page}${fileType.ext}";
|
||||
Share.shareFile(
|
||||
@@ -392,6 +560,13 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
context.reader.mode = ReaderMode.fromKey(appdata.settings[key]);
|
||||
App.rootContext.pop();
|
||||
}
|
||||
if (key == "enableTurnPageByVolumeKey") {
|
||||
if (appdata.settings[key]) {
|
||||
context.reader.handleVolumeEvent();
|
||||
} else {
|
||||
context.reader.stopVolumeEvent();
|
||||
}
|
||||
}
|
||||
context.reader.update();
|
||||
},
|
||||
),
|
||||
@@ -402,11 +577,6 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
Widget buildEpChangeButton() {
|
||||
if (context.reader.widget.chapters == null) return const SizedBox();
|
||||
switch (showFloatingButtonValue) {
|
||||
case -1:
|
||||
return FloatingActionButton(
|
||||
onPressed: () => context.reader.toPrevChapter(),
|
||||
child: const Icon(Icons.arrow_back_ios_outlined),
|
||||
);
|
||||
case 0:
|
||||
return Container(
|
||||
width: 58,
|
||||
@@ -417,11 +587,14 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
lastValue == 1
|
||||
? Icons.arrow_forward_ios
|
||||
: Icons.arrow_back_ios_outlined,
|
||||
size: 24,
|
||||
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||
),
|
||||
);
|
||||
case -1:
|
||||
case 1:
|
||||
return Container(
|
||||
width: 58,
|
||||
@@ -431,37 +604,54 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () => context.reader.toNextChapter(),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Center(
|
||||
child: Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
size: 24,
|
||||
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||
)),
|
||||
child: ValueListenableBuilder(
|
||||
valueListenable: fABValue,
|
||||
builder: (context, value, child) {
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
if (showFloatingButtonValue == 1) {
|
||||
context.reader.toNextChapter();
|
||||
} else if (showFloatingButtonValue == -1) {
|
||||
context.reader.toPrevChapter();
|
||||
}
|
||||
setFloatingButton(0);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Center(
|
||||
child: Icon(
|
||||
showFloatingButtonValue == 1
|
||||
? Icons.arrow_forward_ios
|
||||
: Icons.arrow_back_ios_outlined,
|
||||
size: 24,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: fABValue,
|
||||
child: ColoredBox(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.surfaceTint
|
||||
.withOpacity(0.2),
|
||||
child: const SizedBox.expand(),
|
||||
),
|
||||
)
|
||||
],
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: value.clamp(0, 58 * 3) / 3,
|
||||
child: ColoredBox(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.surfaceTint
|
||||
.withOpacity(0.2),
|
||||
child: const SizedBox.expand(),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -469,6 +659,188 @@ class _ReaderScaffoldState extends State<_ReaderScaffold> {
|
||||
}
|
||||
}
|
||||
|
||||
class _BatteryWidget extends StatefulWidget {
|
||||
@override
|
||||
_BatteryWidgetState createState() => _BatteryWidgetState();
|
||||
}
|
||||
|
||||
class _BatteryWidgetState extends State<_BatteryWidget> {
|
||||
late Battery _battery;
|
||||
late int _batteryLevel = 100;
|
||||
Timer? _timer;
|
||||
bool _hasBattery = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_battery = Battery();
|
||||
_checkBatteryAvailability();
|
||||
}
|
||||
|
||||
void _checkBatteryAvailability() async {
|
||||
try {
|
||||
_batteryLevel = await _battery.batteryLevel;
|
||||
if (_batteryLevel != -1) {
|
||||
setState(() {
|
||||
_hasBattery = true;
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
_battery.batteryLevel.then((level) => {
|
||||
if (_batteryLevel != level)
|
||||
{
|
||||
setState(() {
|
||||
_batteryLevel = level;
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
_hasBattery = false;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_hasBattery = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!_hasBattery) {
|
||||
return const SizedBox.shrink(); //Empty Widget
|
||||
}
|
||||
return _batteryInfo(_batteryLevel);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget _batteryInfo(int batteryLevel) {
|
||||
IconData batteryIcon;
|
||||
Color batteryColor = context.colorScheme.onSurface;
|
||||
|
||||
if (batteryLevel >= 96) {
|
||||
batteryIcon = Icons.battery_full_sharp;
|
||||
} else if (batteryLevel >= 84) {
|
||||
batteryIcon = Icons.battery_6_bar_sharp;
|
||||
} else if (batteryLevel >= 72) {
|
||||
batteryIcon = Icons.battery_5_bar_sharp;
|
||||
} else if (batteryLevel >= 60) {
|
||||
batteryIcon = Icons.battery_4_bar_sharp;
|
||||
} else if (batteryLevel >= 48) {
|
||||
batteryIcon = Icons.battery_3_bar_sharp;
|
||||
} else if (batteryLevel >= 36) {
|
||||
batteryIcon = Icons.battery_2_bar_sharp;
|
||||
} else if (batteryLevel >= 24) {
|
||||
batteryIcon = Icons.battery_1_bar_sharp;
|
||||
} else if (batteryLevel >= 12) {
|
||||
batteryIcon = Icons.battery_0_bar_sharp;
|
||||
} else {
|
||||
batteryIcon = Icons.battery_alert_sharp;
|
||||
batteryColor = Colors.red;
|
||||
}
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
Icon(
|
||||
batteryIcon,
|
||||
size: 16,
|
||||
color: batteryColor,
|
||||
// Stroke
|
||||
shadows: List.generate(
|
||||
9,
|
||||
(index) {
|
||||
if (index == 4) {
|
||||
return null;
|
||||
}
|
||||
double offsetX = (index % 3 - 1) * 0.8;
|
||||
double offsetY = ((index / 3).floor() - 1) * 0.8;
|
||||
return Shadow(
|
||||
color: context.colorScheme.onInverseSurface,
|
||||
offset: Offset(offsetX, offsetY),
|
||||
);
|
||||
},
|
||||
).whereType<Shadow>().toList(),
|
||||
),
|
||||
Stack(
|
||||
children: [
|
||||
Text(
|
||||
'$batteryLevel%',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
foreground: Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1.4
|
||||
..color = context.colorScheme.onInverseSurface,
|
||||
),
|
||||
),
|
||||
Text('$batteryLevel%'),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ClockWidget extends StatefulWidget {
|
||||
@override
|
||||
_ClockWidgetState createState() => _ClockWidgetState();
|
||||
}
|
||||
|
||||
class _ClockWidgetState extends State<_ClockWidget> {
|
||||
late String _currentTime;
|
||||
late Timer _timer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_currentTime = _getCurrentTime();
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
final time = _getCurrentTime();
|
||||
if (_currentTime != time) {
|
||||
setState(() {
|
||||
_currentTime = time;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
String _getCurrentTime() {
|
||||
final now = DateTime.now();
|
||||
return "${now.hour.toString().padLeft(2, '0')}:${now.minute.toString().padLeft(2, '0')}";
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
children: [
|
||||
Text(
|
||||
_currentTime,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
foreground: Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1.4
|
||||
..color = context.colorScheme.onInverseSurface,
|
||||
),
|
||||
),
|
||||
Text(_currentTime),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ChaptersView extends StatefulWidget {
|
||||
const _ChaptersView(this.reader);
|
||||
|
||||
|
@@ -369,6 +369,9 @@ class _SearchPageState extends State<SearchPage> {
|
||||
),
|
||||
trailing: const Icon(Icons.arrow_right),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
suggestions.clear();
|
||||
});
|
||||
handleAppLink(Uri.parse(controller.text));
|
||||
},
|
||||
);
|
||||
|
@@ -42,7 +42,7 @@ class _SearchResultPageState extends State<SearchResultPage> {
|
||||
|
||||
void search([String? text]) {
|
||||
if (text != null) {
|
||||
if(suggestionsController.entry != null) {
|
||||
if (suggestionsController.entry != null) {
|
||||
suggestionsController.remove();
|
||||
}
|
||||
setState(() {
|
||||
@@ -135,20 +135,24 @@ class _SearchResultPageState extends State<SearchResultPage> {
|
||||
onChanged: onChanged,
|
||||
action: buildAction(),
|
||||
),
|
||||
loadPage: source!.searchPageData!.loadPage == null ? null : (i) {
|
||||
return source.searchPageData!.loadPage!(
|
||||
text,
|
||||
i,
|
||||
options,
|
||||
);
|
||||
},
|
||||
loadNext: source.searchPageData!.loadNext == null ? null : (i) {
|
||||
return source.searchPageData!.loadNext!(
|
||||
text,
|
||||
i,
|
||||
options,
|
||||
);
|
||||
},
|
||||
loadPage: source!.searchPageData!.loadPage == null
|
||||
? null
|
||||
: (i) {
|
||||
return source.searchPageData!.loadPage!(
|
||||
text,
|
||||
i,
|
||||
options,
|
||||
);
|
||||
},
|
||||
loadNext: source.searchPageData!.loadNext == null
|
||||
? null
|
||||
: (i) {
|
||||
return source.searchPageData!.loadNext!(
|
||||
text,
|
||||
i,
|
||||
options,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -424,6 +428,11 @@ class _SearchSettingsDialogState extends State<_SearchSettingsDialog> {
|
||||
setState(() {
|
||||
searchTarget = e.key;
|
||||
options.clear();
|
||||
final searchOptions = ComicSource.find(searchTarget)!
|
||||
.searchPageData!
|
||||
.searchOptions ??
|
||||
<SearchOptions>[];
|
||||
options = searchOptions.map((e) => e.defaultValue).toList();
|
||||
onChanged();
|
||||
});
|
||||
},
|
||||
|
@@ -16,12 +16,12 @@ class _AboutSettingsState extends State<AboutSettings> {
|
||||
slivers: [
|
||||
SliverAppbar(title: Text("About".tl)),
|
||||
SizedBox(
|
||||
height: 136,
|
||||
height: 112,
|
||||
width: double.infinity,
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 136,
|
||||
height: 136,
|
||||
width: 112,
|
||||
height: 112,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(136),
|
||||
),
|
||||
@@ -53,30 +53,7 @@ class _AboutSettingsState extends State<AboutSettings> {
|
||||
setState(() {
|
||||
isCheckingUpdate = true;
|
||||
});
|
||||
checkUpdate().then((value) {
|
||||
if (value) {
|
||||
showDialog(
|
||||
context: App.rootContext,
|
||||
builder: (context) {
|
||||
return ContentDialog(
|
||||
title: "New version available".tl,
|
||||
content: Text(
|
||||
"A new version is available. Do you want to update now?"
|
||||
.tl),
|
||||
actions: [
|
||||
Button.text(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
launchUrlString(
|
||||
"https://github.com/venera-app/venera/releases");
|
||||
},
|
||||
child: Text("Update".tl),
|
||||
),
|
||||
]);
|
||||
});
|
||||
} else {
|
||||
context.showMessage(message: "No new version available".tl);
|
||||
}
|
||||
checkUpdateUi().then((value) {
|
||||
setState(() {
|
||||
isCheckingUpdate = false;
|
||||
});
|
||||
@@ -108,6 +85,33 @@ Future<bool> checkUpdate() async {
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> checkUpdateUi([bool showMessageIfNoUpdate = true]) async {
|
||||
var value = await checkUpdate();
|
||||
if (value) {
|
||||
showDialog(
|
||||
context: App.rootContext,
|
||||
builder: (context) {
|
||||
return ContentDialog(
|
||||
title: "New version available".tl,
|
||||
content: Text(
|
||||
"A new version is available. Do you want to update now?".tl),
|
||||
actions: [
|
||||
Button.text(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
launchUrlString(
|
||||
"https://github.com/venera-app/venera/releases");
|
||||
},
|
||||
child: Text("Update".tl),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
} else if (showMessageIfNoUpdate) {
|
||||
App.rootContext.showMessage(message: "No new version available".tl);
|
||||
}
|
||||
}
|
||||
|
||||
/// return true if version1 > version2
|
||||
bool _compareVersion(String version1, String version2) {
|
||||
var v1 = version1.split(".");
|
||||
|
@@ -20,16 +20,44 @@ class _AppSettingsState extends State<AppSettings> {
|
||||
ListTile(
|
||||
title: Text("Storage Path for local comics".tl),
|
||||
subtitle: Text(LocalManager().path, softWrap: false),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.copy),
|
||||
onPressed: () {
|
||||
Clipboard.setData(ClipboardData(text: LocalManager().path));
|
||||
context.showMessage(message: "Path copied to clipboard".tl);
|
||||
},
|
||||
),
|
||||
).toSliver(),
|
||||
_CallbackSetting(
|
||||
title: "Set New Storage Path".tl,
|
||||
actionTitle: "Set".tl,
|
||||
callback: () async {
|
||||
if (App.isMobile) {
|
||||
context.showMessage(message: "Not supported".tl);
|
||||
return;
|
||||
String? result;
|
||||
if (App.isAndroid) {
|
||||
var channel = const MethodChannel("venera/storage");
|
||||
var permission = await channel.invokeMethod('');
|
||||
if(permission != true) {
|
||||
context.showMessage(message: "Permission denied".tl);
|
||||
return;
|
||||
}
|
||||
var path = await selectDirectory();
|
||||
if(path != null) {
|
||||
// check if the path is writable
|
||||
var testFile = File(FilePath.join(path, "test"));
|
||||
try {
|
||||
await testFile.writeAsBytes([1]);
|
||||
await testFile.delete();
|
||||
} catch (e) {
|
||||
context.showMessage(message: "Permission denied".tl);
|
||||
return;
|
||||
}
|
||||
result = path;
|
||||
}
|
||||
} else if (App.isIOS) {
|
||||
result = await selectDirectoryIOS();
|
||||
} else {
|
||||
result = await selectDirectory();
|
||||
}
|
||||
var result = await selectDirectory();
|
||||
if (result == null) return;
|
||||
var loadingDialog = showLoadingDialog(
|
||||
App.rootContext,
|
||||
@@ -78,14 +106,49 @@ class _AppSettingsState extends State<AppSettings> {
|
||||
appdata.settings['cacheSize'] = int.parse(value);
|
||||
appdata.saveData();
|
||||
setState(() {});
|
||||
CacheManager()
|
||||
.setLimitSize(appdata.settings['cacheSize']);
|
||||
CacheManager().setLimitSize(appdata.settings['cacheSize']);
|
||||
return null;
|
||||
},
|
||||
);
|
||||
},
|
||||
actionTitle: 'Set'.tl,
|
||||
).toSliver(),
|
||||
_CallbackSetting(
|
||||
title: "Export App Data".tl,
|
||||
callback: () async {
|
||||
var controller = showLoadingDialog(context);
|
||||
var file = await exportAppData();
|
||||
await saveFile(filename: "data.venera", file: file);
|
||||
controller.close();
|
||||
},
|
||||
actionTitle: 'Export'.tl,
|
||||
).toSliver(),
|
||||
_CallbackSetting(
|
||||
title: "Import App Data".tl,
|
||||
callback: () async {
|
||||
var controller = showLoadingDialog(context);
|
||||
var file = await selectFile(ext: ['venera']);
|
||||
if (file != null) {
|
||||
var cacheFile = File(FilePath.join(App.cachePath, "temp.venera"));
|
||||
await file.saveTo(cacheFile.path);
|
||||
try {
|
||||
await importAppData(cacheFile);
|
||||
} catch (e, s) {
|
||||
Log.error("Import data", e.toString(), s);
|
||||
context.showMessage(message: "Failed to import data".tl);
|
||||
}
|
||||
}
|
||||
controller.close();
|
||||
},
|
||||
actionTitle: 'Import'.tl,
|
||||
).toSliver(),
|
||||
_CallbackSetting(
|
||||
title: "Data Sync".tl,
|
||||
callback: () async {
|
||||
showPopUpWidget(context, const _WebdavSetting());
|
||||
},
|
||||
actionTitle: 'Set'.tl,
|
||||
).toSliver(),
|
||||
_SettingPartTitle(
|
||||
title: "Log".tl,
|
||||
icon: Icons.error_outline,
|
||||
@@ -241,3 +304,129 @@ class _LogsPageState extends State<LogsPage> {
|
||||
saveFile(data: utf8.encode(log), filename: 'log.txt');
|
||||
}
|
||||
}
|
||||
|
||||
class _WebdavSetting extends StatefulWidget {
|
||||
const _WebdavSetting();
|
||||
|
||||
@override
|
||||
State<_WebdavSetting> createState() => _WebdavSettingState();
|
||||
}
|
||||
|
||||
class _WebdavSettingState extends State<_WebdavSetting> {
|
||||
String url = "";
|
||||
String user = "";
|
||||
String pass = "";
|
||||
|
||||
bool isTesting = false;
|
||||
|
||||
bool upload = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (appdata.settings['webdav'] is! List) {
|
||||
appdata.settings['webdav'] = [];
|
||||
}
|
||||
var configs = appdata.settings['webdav'] as List;
|
||||
if (configs.whereType<String>().length != 3) {
|
||||
return;
|
||||
}
|
||||
url = configs[0];
|
||||
user = configs[1];
|
||||
pass = configs[2];
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopUpWidgetScaffold(
|
||||
title: "Webdav",
|
||||
body: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: "URL",
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
controller: TextEditingController(text: url),
|
||||
onChanged: (value) => url = value,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Username".tl,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
controller: TextEditingController(text: user),
|
||||
onChanged: (value) => user = value,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Password".tl,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
controller: TextEditingController(text: pass),
|
||||
onChanged: (value) => pass = value,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Text("Operation".tl),
|
||||
Radio<bool>(
|
||||
groupValue: upload,
|
||||
value: true,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
upload = value!;
|
||||
});
|
||||
},
|
||||
),
|
||||
Text("Upload".tl),
|
||||
Radio<bool>(
|
||||
groupValue: upload,
|
||||
value: false,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
upload = value!;
|
||||
});
|
||||
},
|
||||
),
|
||||
Text("Download".tl),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Center(
|
||||
child: Button.filled(
|
||||
isLoading: isTesting,
|
||||
onPressed: () async {
|
||||
var oldConfig = appdata.settings['webdav'];
|
||||
appdata.settings['webdav'] = [url, user, pass];
|
||||
setState(() {
|
||||
isTesting = true;
|
||||
});
|
||||
var testResult = upload
|
||||
? await DataSync().uploadData()
|
||||
: await DataSync().downloadData();
|
||||
if (testResult.error) {
|
||||
setState(() {
|
||||
isTesting = false;
|
||||
});
|
||||
appdata.settings['webdav'] = oldConfig;
|
||||
context.showMessage(message: testResult.errorMessage!);
|
||||
return;
|
||||
}
|
||||
appdata.saveData();
|
||||
context.showMessage(message: "Saved".tl);
|
||||
App.rootPop();
|
||||
},
|
||||
child: Text("Continue".tl),
|
||||
),
|
||||
)
|
||||
],
|
||||
).paddingHorizontal(16),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,9 @@ class _AppearanceSettingsState extends State<AppearanceSettings> {
|
||||
"light": "Light".tl,
|
||||
"dark": "Dark".tl,
|
||||
},
|
||||
onChanged: () async {
|
||||
App.forceRebuild();
|
||||
},
|
||||
).toSliver(),
|
||||
SelectSetting(
|
||||
title: "Theme Color".tl,
|
||||
|
@@ -24,12 +24,20 @@ class _LocalFavoritesSettingsState extends State<LocalFavoritesSettings> {
|
||||
SelectSetting(
|
||||
title: "Move favorite after reading".tl,
|
||||
settingKey: "moveFavoriteAfterRead",
|
||||
optionTranslation: {
|
||||
optionTranslation: const {
|
||||
"none": "None",
|
||||
"end": "End",
|
||||
"start": "Start",
|
||||
},
|
||||
).toSliver(),
|
||||
SelectSetting(
|
||||
title: "Quick Favorite".tl,
|
||||
settingKey: "quickFavorite",
|
||||
help: "Long press on the favorite button to quickly add to this folder".tl,
|
||||
optionTranslation: {
|
||||
for (var e in LocalFavoritesManager().folderNames) e: e
|
||||
},
|
||||
).toSliver(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@@ -17,6 +17,13 @@ class _NetworkSettingsState extends State<NetworkSettings> {
|
||||
title: "Proxy".tl,
|
||||
builder: () => const _ProxySettingView(),
|
||||
).toSliver(),
|
||||
_SliderSetting(
|
||||
title: "Download Threads".tl,
|
||||
settingsIndex: 'downloadThreads',
|
||||
interval: 1,
|
||||
min: 1,
|
||||
max: 16,
|
||||
).toSliver(),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -42,50 +49,50 @@ class _ProxySettingViewState extends State<_ProxySettingView> {
|
||||
|
||||
// USERNAME:PASSWORD@HOST:PORT
|
||||
String toProxyStr() {
|
||||
if(type == 'direct') {
|
||||
if (type == 'direct') {
|
||||
return 'direct';
|
||||
} else if(type == 'system') {
|
||||
} else if (type == 'system') {
|
||||
return 'system';
|
||||
}
|
||||
var res = '';
|
||||
if(username.isNotEmpty) {
|
||||
if (username.isNotEmpty) {
|
||||
res += username;
|
||||
if(password.isNotEmpty) {
|
||||
if (password.isNotEmpty) {
|
||||
res += ':$password';
|
||||
}
|
||||
res += '@';
|
||||
}
|
||||
res += host;
|
||||
if(port.isNotEmpty) {
|
||||
if (port.isNotEmpty) {
|
||||
res += ':$port';
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void parseProxyString(String proxy) {
|
||||
if(proxy == 'direct') {
|
||||
if (proxy == 'direct') {
|
||||
type = 'direct';
|
||||
return;
|
||||
} else if(proxy == 'system') {
|
||||
} else if (proxy == 'system') {
|
||||
type = 'system';
|
||||
return;
|
||||
}
|
||||
type = 'manual';
|
||||
var parts = proxy.split('@');
|
||||
if(parts.length == 2) {
|
||||
if (parts.length == 2) {
|
||||
var auth = parts[0].split(':');
|
||||
if(auth.length == 2) {
|
||||
if (auth.length == 2) {
|
||||
username = auth[0];
|
||||
password = auth[1];
|
||||
}
|
||||
parts = parts[1].split(':');
|
||||
if(parts.length == 2) {
|
||||
if (parts.length == 2) {
|
||||
host = parts[0];
|
||||
port = parts[1];
|
||||
}
|
||||
} else {
|
||||
parts = proxy.split(':');
|
||||
if(parts.length == 2) {
|
||||
if (parts.length == 2) {
|
||||
host = parts[0];
|
||||
port = parts[1];
|
||||
}
|
||||
@@ -140,7 +147,7 @@ class _ProxySettingViewState extends State<_ProxySettingView> {
|
||||
});
|
||||
},
|
||||
),
|
||||
if(type == 'manual') buildManualProxy(),
|
||||
if (type == 'manual') buildManualProxy(),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -164,7 +171,7 @@ class _ProxySettingViewState extends State<_ProxySettingView> {
|
||||
host = v;
|
||||
},
|
||||
validator: (v) {
|
||||
if(v?.isEmpty ?? false) {
|
||||
if (v?.isEmpty ?? false) {
|
||||
return "Host cannot be empty".tl;
|
||||
}
|
||||
return null;
|
||||
@@ -181,10 +188,10 @@ class _ProxySettingViewState extends State<_ProxySettingView> {
|
||||
port = v;
|
||||
},
|
||||
validator: (v) {
|
||||
if(v?.isEmpty ?? true) {
|
||||
if (v?.isEmpty ?? true) {
|
||||
return null;
|
||||
}
|
||||
if(int.tryParse(v!) == null) {
|
||||
if (int.tryParse(v!) == null) {
|
||||
return "Port must be a number".tl;
|
||||
}
|
||||
return null;
|
||||
@@ -201,7 +208,7 @@ class _ProxySettingViewState extends State<_ProxySettingView> {
|
||||
username = v;
|
||||
},
|
||||
validator: (v) {
|
||||
if((v?.isEmpty ?? false) && password.isNotEmpty) {
|
||||
if ((v?.isEmpty ?? false) && password.isNotEmpty) {
|
||||
return "Username cannot be empty".tl;
|
||||
}
|
||||
return null;
|
||||
@@ -221,7 +228,7 @@ class _ProxySettingViewState extends State<_ProxySettingView> {
|
||||
const SizedBox(height: 16),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
if(formKey.currentState?.validate() ?? false) {
|
||||
if (formKey.currentState?.validate() ?? false) {
|
||||
appdata.settings['proxy'] = toProxyStr();
|
||||
appdata.saveData();
|
||||
App.rootContext.pop();
|
||||
|
@@ -54,6 +54,36 @@ class _ReaderSettingsState extends State<ReaderSettings> {
|
||||
widget.onChanged?.call("autoPageTurningInterval");
|
||||
},
|
||||
).toSliver(),
|
||||
_SwitchSetting(
|
||||
title: 'Long press to zoom'.tl,
|
||||
settingKey: 'enableLongPressToZoom',
|
||||
onChanged: () {
|
||||
widget.onChanged?.call('enableLongPressToZoom');
|
||||
},
|
||||
).toSliver(),
|
||||
_SwitchSetting(
|
||||
title: 'Limit image width'.tl,
|
||||
subtitle: 'When using Continuous(Top to Bottom) mode'.tl,
|
||||
settingKey: 'limitImageWidth',
|
||||
onChanged: () {
|
||||
widget.onChanged?.call('limitImageWidth');
|
||||
},
|
||||
).toSliver(),
|
||||
if(App.isAndroid)
|
||||
_SwitchSetting(
|
||||
title: 'Turn page by volume keys'.tl,
|
||||
settingKey: 'enableTurnPageByVolumeKey',
|
||||
onChanged: () {
|
||||
widget.onChanged?.call('enableTurnPageByVolumeKey');
|
||||
},
|
||||
).toSliver(),
|
||||
_SwitchSetting(
|
||||
title: "Display time & battery info in reader".tl,
|
||||
settingKey: "enableClockAndBatteryInfoInReader",
|
||||
onChanged: () {
|
||||
widget.onChanged?.call("enableClockAndBatteryInfoInReader");
|
||||
},
|
||||
).toSliver(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@@ -5,6 +5,7 @@ class _SwitchSetting extends StatefulWidget {
|
||||
required this.title,
|
||||
required this.settingKey,
|
||||
this.onChanged,
|
||||
this.subtitle,
|
||||
});
|
||||
|
||||
final String title;
|
||||
@@ -13,6 +14,8 @@ class _SwitchSetting extends StatefulWidget {
|
||||
|
||||
final VoidCallback? onChanged;
|
||||
|
||||
final String? subtitle;
|
||||
|
||||
@override
|
||||
State<_SwitchSetting> createState() => _SwitchSettingState();
|
||||
}
|
||||
@@ -24,6 +27,7 @@ class _SwitchSettingState extends State<_SwitchSetting> {
|
||||
|
||||
return ListTile(
|
||||
title: Text(widget.title),
|
||||
subtitle: widget.subtitle == null ? null : Text(widget.subtitle!),
|
||||
trailing: Switch(
|
||||
value: appdata.settings[widget.settingKey],
|
||||
onChanged: (value) {
|
||||
@@ -45,6 +49,7 @@ class SelectSetting extends StatelessWidget {
|
||||
required this.settingKey,
|
||||
required this.optionTranslation,
|
||||
this.onChanged,
|
||||
this.help,
|
||||
});
|
||||
|
||||
final String title;
|
||||
@@ -55,6 +60,8 @@ class SelectSetting extends StatelessWidget {
|
||||
|
||||
final VoidCallback? onChanged;
|
||||
|
||||
final String? help;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
@@ -67,6 +74,7 @@ class SelectSetting extends StatelessWidget {
|
||||
settingKey: settingKey,
|
||||
optionTranslation: optionTranslation,
|
||||
onChanged: onChanged,
|
||||
help: help,
|
||||
);
|
||||
} else {
|
||||
return _EndSelectorSelectSetting(
|
||||
@@ -74,6 +82,7 @@ class SelectSetting extends StatelessWidget {
|
||||
settingKey: settingKey,
|
||||
optionTranslation: optionTranslation,
|
||||
onChanged: onChanged,
|
||||
help: help,
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -88,6 +97,7 @@ class _DoubleLineSelectSettings extends StatefulWidget {
|
||||
required this.settingKey,
|
||||
required this.optionTranslation,
|
||||
this.onChanged,
|
||||
this.help,
|
||||
});
|
||||
|
||||
final String title;
|
||||
@@ -98,6 +108,8 @@ class _DoubleLineSelectSettings extends StatefulWidget {
|
||||
|
||||
final VoidCallback? onChanged;
|
||||
|
||||
final String? help;
|
||||
|
||||
@override
|
||||
State<_DoubleLineSelectSettings> createState() =>
|
||||
_DoubleLineSelectSettingsState();
|
||||
@@ -107,9 +119,37 @@ class _DoubleLineSelectSettingsState extends State<_DoubleLineSelectSettings> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
title: Text(widget.title),
|
||||
subtitle:
|
||||
Text(widget.optionTranslation[appdata.settings[widget.settingKey]]!),
|
||||
title: Row(
|
||||
children: [
|
||||
Text(widget.title),
|
||||
const SizedBox(width: 4),
|
||||
if (widget.help != null)
|
||||
Button.icon(
|
||||
size: 18,
|
||||
icon: const Icon(Icons.help_outline),
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return ContentDialog(
|
||||
title: "Help".tl,
|
||||
content: Text(widget.help!).paddingHorizontal(16).fixWidth(double.infinity),
|
||||
actions: [
|
||||
Button.filled(
|
||||
onPressed: context.pop,
|
||||
child: Text("OK".tl),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
subtitle: Text(
|
||||
widget.optionTranslation[appdata.settings[widget.settingKey]] ??
|
||||
"None"),
|
||||
trailing: const Icon(Icons.arrow_drop_down),
|
||||
onTap: () {
|
||||
var renderBox = context.findRenderObject() as RenderBox;
|
||||
@@ -152,6 +192,7 @@ class _EndSelectorSelectSetting extends StatefulWidget {
|
||||
required this.settingKey,
|
||||
required this.optionTranslation,
|
||||
this.onChanged,
|
||||
this.help,
|
||||
});
|
||||
|
||||
final String title;
|
||||
@@ -162,6 +203,8 @@ class _EndSelectorSelectSetting extends StatefulWidget {
|
||||
|
||||
final VoidCallback? onChanged;
|
||||
|
||||
final String? help;
|
||||
|
||||
@override
|
||||
State<_EndSelectorSelectSetting> createState() =>
|
||||
_EndSelectorSelectSettingState();
|
||||
@@ -172,10 +215,38 @@ class _EndSelectorSelectSettingState extends State<_EndSelectorSelectSetting> {
|
||||
Widget build(BuildContext context) {
|
||||
var options = widget.optionTranslation;
|
||||
return ListTile(
|
||||
title: Text(widget.title),
|
||||
title: Row(
|
||||
children: [
|
||||
Text(widget.title),
|
||||
const SizedBox(width: 4),
|
||||
if (widget.help != null)
|
||||
Button.icon(
|
||||
size: 18,
|
||||
icon: const Icon(Icons.help_outline),
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return ContentDialog(
|
||||
title: "Help".tl,
|
||||
content: Text(widget.help!).paddingHorizontal(16).fixWidth(double.infinity),
|
||||
actions: [
|
||||
Button.filled(
|
||||
onPressed: context.pop,
|
||||
child: Text("OK".tl),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
trailing: Select(
|
||||
current: options[appdata.settings[widget.settingKey]]!,
|
||||
current: options[appdata.settings[widget.settingKey]],
|
||||
values: options.values.toList(),
|
||||
minWidth: 64,
|
||||
onTap: (index) {
|
||||
setState(() {
|
||||
appdata.settings[widget.settingKey] = options.keys.elementAt(index);
|
||||
@@ -434,7 +505,7 @@ class _CallbackSetting extends StatelessWidget {
|
||||
return ListTile(
|
||||
title: Text(title),
|
||||
subtitle: subtitle == null ? null : Text(subtitle!),
|
||||
trailing: FilledButton(
|
||||
trailing: Button.normal(
|
||||
onPressed: callback,
|
||||
child: Text(actionTitle),
|
||||
).fixHeight(28),
|
||||
|
@@ -10,10 +10,12 @@ import 'package:venera/foundation/app.dart';
|
||||
import 'package:venera/foundation/appdata.dart';
|
||||
import 'package:venera/foundation/cache_manager.dart';
|
||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||
import 'package:venera/foundation/consts.dart';
|
||||
import 'package:venera/foundation/favorites.dart';
|
||||
import 'package:venera/foundation/local.dart';
|
||||
import 'package:venera/foundation/log.dart';
|
||||
import 'package:venera/network/app_dio.dart';
|
||||
import 'package:venera/utils/data.dart';
|
||||
import 'package:venera/utils/data_sync.dart';
|
||||
import 'package:venera/utils/io.dart';
|
||||
import 'package:venera/utils/translations.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
@@ -41,7 +43,7 @@ class _SettingsPageState extends State<SettingsPage> implements PopEntry {
|
||||
|
||||
ColorScheme get colors => Theme.of(context).colorScheme;
|
||||
|
||||
bool get enableTwoViews => context.width > changePoint;
|
||||
bool get enableTwoViews => context.width > 720;
|
||||
|
||||
final categories = <String>[
|
||||
"Explore",
|
||||
|
@@ -18,11 +18,11 @@ export 'package:flutter_inappwebview/flutter_inappwebview.dart'
|
||||
|
||||
extension WebviewExtension on InAppWebViewController {
|
||||
Future<List<io.Cookie>?> getCookies(String url) async {
|
||||
if(url.contains("https://")){
|
||||
if (url.contains("https://")) {
|
||||
url.replaceAll("https://", "");
|
||||
}
|
||||
if(url[url.length-1] == '/'){
|
||||
url = url.substring(0, url.length-1);
|
||||
if (url[url.length - 1] == '/') {
|
||||
url = url.substring(0, url.length - 1);
|
||||
}
|
||||
CookieManager cookieManager = CookieManager.instance();
|
||||
final cookies = await cookieManager.getCookies(url: WebUri(url));
|
||||
@@ -89,29 +89,29 @@ class _AppWebviewState extends State<AppWebview> {
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.more_horiz),
|
||||
onPressed: () {
|
||||
showMenu(
|
||||
context: context,
|
||||
position: RelativeRect.fromLTRB(
|
||||
MediaQuery.of(context).size.width,
|
||||
0,
|
||||
MediaQuery.of(context).size.width,
|
||||
0),
|
||||
items: [
|
||||
PopupMenuItem(
|
||||
child: Text("Open in browser".tl),
|
||||
onTap: () async =>
|
||||
launchUrlString((await controller?.getUrl())!.path),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Text("Copy link".tl),
|
||||
onTap: () async => Clipboard.setData(ClipboardData(
|
||||
text: (await controller?.getUrl())!.path)),
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Text("Reload".tl),
|
||||
onTap: () => controller?.reload(),
|
||||
),
|
||||
]);
|
||||
showMenuX(
|
||||
context,
|
||||
Offset(context.width, context.padding.top),
|
||||
[
|
||||
MenuEntry(
|
||||
icon: Icons.open_in_browser,
|
||||
text: "Open in browser".tl,
|
||||
onClick: () async =>
|
||||
launchUrlString((await controller?.getUrl())!.toString()),
|
||||
),
|
||||
MenuEntry(
|
||||
icon: Icons.copy,
|
||||
text: "Copy link".tl,
|
||||
onClick: () async => Clipboard.setData(ClipboardData(
|
||||
text: (await controller?.getUrl())!.toString())),
|
||||
),
|
||||
MenuEntry(
|
||||
icon: Icons.refresh,
|
||||
text: "Reload".tl,
|
||||
onClick: () => controller?.reload(),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
|
101
lib/utils/data.dart
Normal file
101
lib/utils/data.dart
Normal file
@@ -0,0 +1,101 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:isolate';
|
||||
|
||||
import 'package:venera/foundation/app.dart';
|
||||
import 'package:venera/foundation/appdata.dart';
|
||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||
import 'package:venera/foundation/favorites.dart';
|
||||
import 'package:venera/foundation/history.dart';
|
||||
import 'package:venera/network/cookie_jar.dart';
|
||||
import 'package:zip_flutter/zip_flutter.dart';
|
||||
|
||||
import 'io.dart';
|
||||
|
||||
Future<File> exportAppData() async {
|
||||
var time = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
var cacheFilePath = FilePath.join(App.cachePath, '$time.venera');
|
||||
var cacheFile = File(cacheFilePath);
|
||||
var dataPath = App.dataPath;
|
||||
if (await cacheFile.exists()) {
|
||||
await cacheFile.delete();
|
||||
}
|
||||
await Isolate.run(() {
|
||||
var zipFile = ZipFile.open(cacheFilePath);
|
||||
var historyFile = FilePath.join(dataPath, "history.db");
|
||||
var localFavoriteFile = FilePath.join(dataPath, "local_favorite.db");
|
||||
var appdata = FilePath.join(dataPath, "appdata.json");
|
||||
var cookies = FilePath.join(dataPath, "cookie.db");
|
||||
zipFile.addFile("history.db", historyFile);
|
||||
zipFile.addFile("local_favorite.db", localFavoriteFile);
|
||||
zipFile.addFile("appdata.json", appdata);
|
||||
zipFile.addFile("cookie.db", cookies);
|
||||
for (var file
|
||||
in Directory(FilePath.join(dataPath, "comic_source")).listSync()) {
|
||||
if (file is File) {
|
||||
zipFile.addFile("comic_source/${file.name}", file.path);
|
||||
}
|
||||
}
|
||||
zipFile.close();
|
||||
});
|
||||
return cacheFile;
|
||||
}
|
||||
|
||||
Future<void> importAppData(File file, [bool checkVersion = false]) async {
|
||||
var cacheDirPath = FilePath.join(App.cachePath, 'temp_data');
|
||||
var cacheDir = Directory(cacheDirPath);
|
||||
await Isolate.run(() {
|
||||
ZipFile.openAndExtract(file.path, cacheDirPath);
|
||||
});
|
||||
var historyFile = cacheDir.joinFile("history.db");
|
||||
var localFavoriteFile = cacheDir.joinFile("local_favorite.db");
|
||||
var appdataFile = cacheDir.joinFile("appdata.json");
|
||||
var cookieFile = cacheDir.joinFile("cookie.db");
|
||||
if (checkVersion && appdataFile.existsSync()) {
|
||||
var data = jsonDecode(await appdataFile.readAsString());
|
||||
var version = data["settings"]["dataVersion"];
|
||||
if (version is int && version <= appdata.settings["dataVersion"]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (await historyFile.exists()) {
|
||||
HistoryManager().close();
|
||||
File(FilePath.join(App.dataPath, "history.db")).deleteIfExistsSync();
|
||||
historyFile.renameSync(FilePath.join(App.dataPath, "history.db"));
|
||||
HistoryManager().init();
|
||||
}
|
||||
if (await localFavoriteFile.exists()) {
|
||||
LocalFavoritesManager().close();
|
||||
File(FilePath.join(App.dataPath, "local_favorite.db")).deleteIfExistsSync();
|
||||
localFavoriteFile
|
||||
.renameSync(FilePath.join(App.dataPath, "local_favorite.db"));
|
||||
LocalFavoritesManager().init();
|
||||
}
|
||||
if (await appdataFile.exists()) {
|
||||
// proxy settings should be kept
|
||||
var proxySettings = appdata.settings["proxy"];
|
||||
File(FilePath.join(App.dataPath, "appdata.json")).deleteIfExistsSync();
|
||||
appdataFile.renameSync(FilePath.join(App.dataPath, "appdata.json"));
|
||||
await appdata.init();
|
||||
appdata.settings["proxy"] = proxySettings;
|
||||
appdata.saveData();
|
||||
}
|
||||
if (await cookieFile.exists()) {
|
||||
SingleInstanceCookieJar.instance?.dispose();
|
||||
File(FilePath.join(App.dataPath, "cookie.db")).deleteIfExistsSync();
|
||||
cookieFile.renameSync(FilePath.join(App.dataPath, "cookie.db"));
|
||||
SingleInstanceCookieJar.instance =
|
||||
SingleInstanceCookieJar(FilePath.join(App.dataPath, "cookie.db"))
|
||||
..init();
|
||||
}
|
||||
var comicSourceDir = FilePath.join(cacheDirPath, "comic_source");
|
||||
if (Directory(comicSourceDir).existsSync()) {
|
||||
for (var file in Directory(comicSourceDir).listSync()) {
|
||||
if (file is File) {
|
||||
var targetFile = FilePath.join(App.dataPath, "comic_source", file.name);
|
||||
File(targetFile).deleteIfExistsSync();
|
||||
await file.copy(targetFile);
|
||||
}
|
||||
}
|
||||
await ComicSource.reload();
|
||||
}
|
||||
}
|
204
lib/utils/data_sync.dart
Normal file
204
lib/utils/data_sync.dart
Normal file
@@ -0,0 +1,204 @@
|
||||
import 'package:dio/io.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:venera/foundation/app.dart';
|
||||
import 'package:venera/foundation/appdata.dart';
|
||||
import 'package:venera/foundation/comic_source/comic_source.dart';
|
||||
import 'package:venera/foundation/favorites.dart';
|
||||
import 'package:venera/foundation/log.dart';
|
||||
import 'package:venera/foundation/res.dart';
|
||||
import 'package:venera/network/app_dio.dart';
|
||||
import 'package:venera/utils/data.dart';
|
||||
import 'package:venera/utils/ext.dart';
|
||||
import 'package:webdav_client/webdav_client.dart' hide File;
|
||||
|
||||
import 'io.dart';
|
||||
|
||||
class DataSync with ChangeNotifier {
|
||||
DataSync._() {
|
||||
if (isEnabled) {
|
||||
downloadData();
|
||||
}
|
||||
LocalFavoritesManager().addListener(onDataChanged);
|
||||
ComicSource.addListener(onDataChanged);
|
||||
}
|
||||
|
||||
void onDataChanged() {
|
||||
if (isEnabled) {
|
||||
uploadData();
|
||||
}
|
||||
}
|
||||
|
||||
static DataSync? instance;
|
||||
|
||||
factory DataSync() => instance ?? (instance = DataSync._());
|
||||
|
||||
bool isDownloading = false;
|
||||
|
||||
bool isUploading = false;
|
||||
|
||||
bool haveWaitingTask = false;
|
||||
|
||||
bool get isEnabled {
|
||||
var config = appdata.settings['webdav'];
|
||||
return config is List && config.isNotEmpty;
|
||||
}
|
||||
|
||||
List<String>? _validateConfig() {
|
||||
var config = appdata.settings['webdav'];
|
||||
if (config is! List || (config.isNotEmpty && config.length != 3)) {
|
||||
return null;
|
||||
}
|
||||
if (config.whereType<String>().length != 3) {
|
||||
return null;
|
||||
}
|
||||
return List.from(config);
|
||||
}
|
||||
|
||||
Future<Res<bool>> uploadData() async {
|
||||
if(isDownloading) return const Res(true);
|
||||
if (haveWaitingTask) return const Res(true);
|
||||
while (isUploading) {
|
||||
haveWaitingTask = true;
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
haveWaitingTask = false;
|
||||
isUploading = true;
|
||||
notifyListeners();
|
||||
try {
|
||||
var config = _validateConfig();
|
||||
if (config == null) {
|
||||
return const Res.error('Invalid WebDAV configuration');
|
||||
}
|
||||
if (config.isEmpty) {
|
||||
return const Res(true);
|
||||
}
|
||||
String url = config[0];
|
||||
String user = config[1];
|
||||
String pass = config[2];
|
||||
|
||||
var proxy = await AppDio.getProxy();
|
||||
|
||||
var client = newClient(
|
||||
url,
|
||||
user: user,
|
||||
password: pass,
|
||||
adapter: IOHttpClientAdapter(
|
||||
createHttpClient: () {
|
||||
return HttpClient()
|
||||
..findProxy = (uri) => proxy == null ? "DIRECT" : "PROXY $proxy";
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
await client.ping();
|
||||
} catch (e) {
|
||||
Log.error("Upload Data", 'Failed to connect to WebDAV server');
|
||||
return const Res.error('Failed to connect to WebDAV server');
|
||||
}
|
||||
|
||||
try {
|
||||
appdata.settings['dataVersion']++;
|
||||
await appdata.saveData();
|
||||
var data = await exportAppData();
|
||||
var time =
|
||||
(DateTime.now().millisecondsSinceEpoch ~/ 86400000).toString();
|
||||
var filename = time;
|
||||
filename += '-';
|
||||
filename += appdata.settings['dataVersion'].toString();
|
||||
filename += '.venera';
|
||||
var files = await client.readDir('/');
|
||||
files = files.where((e) => e.name!.endsWith('.venera')).toList();
|
||||
var old = files.firstWhereOrNull( (e) => e.name!.startsWith("$time-"));
|
||||
if (old != null) {
|
||||
await client.remove(old.name!);
|
||||
}
|
||||
if (files.length >= 10) {
|
||||
files.sort((a, b) => a.name!.compareTo(b.name!));
|
||||
await client.remove(files.first.name!);
|
||||
}
|
||||
await client.write(filename, await data.readAsBytes());
|
||||
Log.info("Upload Data", "Data uploaded successfully");
|
||||
return const Res(true);
|
||||
} catch (e, s) {
|
||||
Log.error("Upload Data", e, s);
|
||||
return Res.error(e.toString());
|
||||
}
|
||||
} finally {
|
||||
isUploading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<Res<bool>> downloadData() async {
|
||||
if (haveWaitingTask) return const Res(true);
|
||||
while (isDownloading || isUploading) {
|
||||
haveWaitingTask = true;
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
haveWaitingTask = false;
|
||||
isDownloading = true;
|
||||
notifyListeners();
|
||||
try {
|
||||
var config = _validateConfig();
|
||||
if (config == null) {
|
||||
return const Res.error('Invalid WebDAV configuration');
|
||||
}
|
||||
if (config.isEmpty) {
|
||||
return const Res(true);
|
||||
}
|
||||
String url = config[0];
|
||||
String user = config[1];
|
||||
String pass = config[2];
|
||||
|
||||
var proxy = await AppDio.getProxy();
|
||||
|
||||
var client = newClient(
|
||||
url,
|
||||
user: user,
|
||||
password: pass,
|
||||
adapter: IOHttpClientAdapter(
|
||||
createHttpClient: () {
|
||||
return HttpClient()
|
||||
..findProxy = (uri) => proxy == null ? "DIRECT" : "PROXY $proxy";
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
await client.ping();
|
||||
} catch (e) {
|
||||
Log.error("Data Sync", 'Failed to connect to WebDAV server');
|
||||
return const Res.error('Failed to connect to WebDAV server');
|
||||
}
|
||||
|
||||
try {
|
||||
var files = await client.readDir('/');
|
||||
files.sort((a, b) => b.name!.compareTo(a.name!));
|
||||
var file = files.firstWhereOrNull((e) => e.name!.endsWith('.venera'));
|
||||
var version =
|
||||
file!.name!.split('-').elementAtOrNull(1)?.split('.').first;
|
||||
if (version != null && int.tryParse(version) != null) {
|
||||
var currentVersion = appdata.settings['dataVersion'];
|
||||
if (currentVersion != null && int.parse(version) <= currentVersion) {
|
||||
Log.info("Data Sync", 'No new data to download');
|
||||
return const Res(true);
|
||||
}
|
||||
}
|
||||
Log.info("Data Sync", "Downloading data from WebDAV server");
|
||||
var localFile = File(FilePath.join(App.cachePath, file.name!));
|
||||
await client.read2File(file.name!, localFile.path);
|
||||
await importAppData(localFile, true);
|
||||
await localFile.delete();
|
||||
Log.info("Data Sync", "Data downloaded successfully");
|
||||
return const Res(true);
|
||||
} catch (e, s) {
|
||||
Log.error("Data Sync", e, s);
|
||||
return Res.error(e.toString());
|
||||
}
|
||||
} finally {
|
||||
isDownloading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
@@ -24,6 +24,18 @@ extension ListExt<T> on List<T>{
|
||||
add(value);
|
||||
}
|
||||
}
|
||||
|
||||
bool isEqualsTo(List<T> list){
|
||||
if(length != list.length){
|
||||
return false;
|
||||
}
|
||||
for(int i=0; i<length; i++){
|
||||
if(this[i] != list[i]){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
extension StringExt on String{
|
||||
|
@@ -1,5 +1,3 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:mime/mime.dart';
|
||||
|
||||
class FileType {
|
||||
@@ -7,6 +5,14 @@ class FileType {
|
||||
final String mime;
|
||||
|
||||
const FileType(this.ext, this.mime);
|
||||
|
||||
static FileType fromExtension(String ext) {
|
||||
if(ext.startsWith('.')) {
|
||||
ext = ext.substring(1);
|
||||
}
|
||||
var mime = lookupMimeType('no-file.$ext');
|
||||
return FileType(".$ext", mime ?? 'application/octet-stream');
|
||||
}
|
||||
}
|
||||
|
||||
FileType detectFileType(List<int> data) {
|
||||
|
316
lib/utils/image.dart
Normal file
316
lib/utils/image.dart
Normal file
@@ -0,0 +1,316 @@
|
||||
import 'dart:ffi';
|
||||
import 'dart:isolate';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui' as ui;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_qjs/flutter_qjs.dart';
|
||||
import 'package:lodepng_flutter/lodepng_flutter.dart' as lodepng;
|
||||
|
||||
class Image {
|
||||
final Uint32List _data;
|
||||
|
||||
final int width;
|
||||
|
||||
final int height;
|
||||
|
||||
Image(this._data, this.width, this.height) {
|
||||
if (_data.length != width * height) {
|
||||
throw ArgumentError(
|
||||
'Invalid argument: data length must be equal to width * height.');
|
||||
}
|
||||
}
|
||||
|
||||
Image.empty(this.width, this.height) : _data = Uint32List(width * height);
|
||||
|
||||
static Future<Image> decodeImage(Uint8List data) async {
|
||||
var codec = await ui.instantiateImageCodec(data);
|
||||
var frame = await codec.getNextFrame();
|
||||
codec.dispose();
|
||||
var info = await frame.image.toByteData();
|
||||
if (info == null) {
|
||||
throw Exception('Failed to decode image');
|
||||
}
|
||||
var image = Image(
|
||||
info.buffer.asUint32List(),
|
||||
frame.image.width,
|
||||
frame.image.height,
|
||||
);
|
||||
frame.image.dispose();
|
||||
return image;
|
||||
}
|
||||
|
||||
Image copyRange(int x, int y, int width, int height) {
|
||||
if (width + x > this.width) {
|
||||
throw ArgumentError('''
|
||||
Invalid argument: x + width must be less than or equal to the image width.
|
||||
x: $x, width: $width, image width: ${this.width}
|
||||
'''
|
||||
.trim());
|
||||
}
|
||||
if (height + y > this.height) {
|
||||
throw ArgumentError('''
|
||||
Invalid argument: y + height must be less than or equal to the image height.
|
||||
y: $y, height: $height, image height: ${this.height}
|
||||
'''
|
||||
.trim());
|
||||
}
|
||||
var data = Uint32List(width * height);
|
||||
for (var j = 0; j < height; j++) {
|
||||
for (var i = 0; i < width; i++) {
|
||||
data[j * width + i] = _data[(j + y) * this.width + i + x];
|
||||
}
|
||||
}
|
||||
return Image(data, width, height);
|
||||
}
|
||||
|
||||
void fillImageAt(int x, int y, Image image) {
|
||||
if (x + image.width > width) {
|
||||
throw ArgumentError('''
|
||||
Invalid argument: x + image width must be less than or equal to the image width.
|
||||
x: $x, image width: ${image.width}, image width: $width
|
||||
'''
|
||||
.trim());
|
||||
}
|
||||
if (y + image.height > height) {
|
||||
throw ArgumentError('''
|
||||
Invalid argument: y + image height must be less than or equal to the image height.
|
||||
y: $y, image height: ${image.height}, image height: $height
|
||||
'''
|
||||
.trim());
|
||||
}
|
||||
for (var j = 0; j < image.height && (j + y) < height; j++) {
|
||||
for (var i = 0; i < image.width && (i + x) < width; i++) {
|
||||
_data[(j + y) * width + i + x] = image._data[j * image.width + i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void fillImageRangeAt(
|
||||
int x, int y, Image image, int srcX, int srcY, int width, int height) {
|
||||
if (x + width > this.width) {
|
||||
throw ArgumentError('''
|
||||
Invalid argument: x + width must be less than or equal to the image width.
|
||||
x: $x, width: $width, image width: ${this.width}
|
||||
'''
|
||||
.trim());
|
||||
}
|
||||
if (y + height > this.height) {
|
||||
throw ArgumentError('''
|
||||
Invalid argument: y + height must be less than or equal to the image height.
|
||||
y: $y, height: $height, image height: ${this.height}
|
||||
'''
|
||||
.trim());
|
||||
}
|
||||
if (srcX + width > image.width) {
|
||||
throw ArgumentError('''
|
||||
Invalid argument: srcX + width must be less than or equal to the image width.
|
||||
srcX: $srcX, width: $width, image width: ${image.width}
|
||||
'''
|
||||
.trim());
|
||||
}
|
||||
if (srcY + height > image.height) {
|
||||
throw ArgumentError('''
|
||||
Invalid argument: srcY + height must be less than or equal to the image height.
|
||||
srcY: $srcY, height: $height, image height: ${image.height}
|
||||
'''
|
||||
.trim());
|
||||
}
|
||||
for (var j = 0; j < height; j++) {
|
||||
for (var i = 0; i < width; i++) {
|
||||
_data[(j + y) * this.width + i + x] =
|
||||
image._data[(j + srcY) * image.width + i + srcX];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Image copyAndRotate90() {
|
||||
var data = Uint32List(width * height);
|
||||
for (var j = 0; j < height; j++) {
|
||||
for (var i = 0; i < width; i++) {
|
||||
data[i * height + height - j - 1] = _data[j * width + i];
|
||||
}
|
||||
}
|
||||
return Image(data, height, width);
|
||||
}
|
||||
|
||||
Color getPixel(int x, int y) {
|
||||
if (x < 0 || x >= width) {
|
||||
throw ArgumentError(
|
||||
'Invalid argument: x must be in the range of [0, $width).');
|
||||
}
|
||||
if (y < 0 || y >= height) {
|
||||
throw ArgumentError(
|
||||
'Invalid argument: y must be in the range of [0, $height).');
|
||||
}
|
||||
return Color.fromValue(_data[y * width + x]);
|
||||
}
|
||||
|
||||
void setPixel(int x, int y, Color color) {
|
||||
if (x < 0 || x >= width) {
|
||||
throw ArgumentError(
|
||||
'Invalid argument: x must be in the range of [0, $width).');
|
||||
}
|
||||
if (y < 0 || y >= height) {
|
||||
throw ArgumentError(
|
||||
'Invalid argument: y must be in the range of [0, $height).');
|
||||
}
|
||||
_data[y * width + x] = color.value;
|
||||
}
|
||||
|
||||
Uint8List encodePng() {
|
||||
var data = lodepng.encodePngToPointer(lodepng.Image(
|
||||
_data.buffer.asUint8List(),
|
||||
width,
|
||||
height,
|
||||
));
|
||||
return Pointer<Uint8>.fromAddress(data.address).asTypedList(data.length,
|
||||
finalizer: lodepng.ByteBuffer.finalizer);
|
||||
}
|
||||
}
|
||||
|
||||
class Color {
|
||||
final int value;
|
||||
|
||||
Color(int r, int g, int b, [int a = 255])
|
||||
: value = (a << 24) | (r << 16) | (g << 8) | b;
|
||||
|
||||
Color.fromValue(this.value);
|
||||
|
||||
int get r => (value >> 16) & 0xFF;
|
||||
|
||||
int get g => (value >> 8) & 0xFF;
|
||||
|
||||
int get b => value & 0xFF;
|
||||
|
||||
int get a => (value >> 24) & 0xFF;
|
||||
}
|
||||
|
||||
class JsEngine {
|
||||
static final JsEngine _instance = JsEngine._();
|
||||
|
||||
factory JsEngine() => _instance;
|
||||
|
||||
JsEngine._() {
|
||||
_engine = FlutterQjs();
|
||||
_engine!.dispatch();
|
||||
var setGlobalFunc =
|
||||
_engine!.evaluate("(key, value) => { this[key] = value; }");
|
||||
(setGlobalFunc as JSInvokable)(["sendMessage", _messageReceiver]);
|
||||
setGlobalFunc.free();
|
||||
}
|
||||
|
||||
FlutterQjs? _engine;
|
||||
|
||||
dynamic runCode(String js, [String? name]) {
|
||||
return _engine!.evaluate(js, name: name);
|
||||
}
|
||||
|
||||
var images = <int, Image>{};
|
||||
|
||||
int _key = 0;
|
||||
|
||||
int setImage(Image image) {
|
||||
var key = _key++;
|
||||
images[key] = image;
|
||||
return key;
|
||||
}
|
||||
|
||||
Object? _messageReceiver(dynamic message) {
|
||||
if (message is! Map) return null;
|
||||
var method = message['method'];
|
||||
if (method == 'image') {
|
||||
switch (message['function']) {
|
||||
case 'copyRange':
|
||||
var key = message['key'];
|
||||
var image = images[key];
|
||||
if (image == null) return null;
|
||||
var x = message['x'];
|
||||
var y = message['y'];
|
||||
var width = message['width'];
|
||||
var height = message['height'];
|
||||
var newImage = image.copyRange(x, y, width, height);
|
||||
return setImage(newImage);
|
||||
case 'copyAndRotate90':
|
||||
var key = message['key'];
|
||||
var image = images[key];
|
||||
if (image == null) return null;
|
||||
var newImage = image.copyAndRotate90();
|
||||
return setImage(newImage);
|
||||
case 'fillImageAt':
|
||||
var key = message['key'];
|
||||
var image = images[key];
|
||||
if (image == null) return null;
|
||||
var x = message['x'];
|
||||
var y = message['y'];
|
||||
var key2 = message['image'];
|
||||
var image2 = images[key2];
|
||||
if (image2 == null) return null;
|
||||
image.fillImageAt(x, y, image2);
|
||||
return null;
|
||||
case 'fillImageRangeAt':
|
||||
var key = message['key'];
|
||||
var image = images[key];
|
||||
if (image == null) return null;
|
||||
var x = message['x'];
|
||||
var y = message['y'];
|
||||
var key2 = message['image'];
|
||||
var image2 = images[key2];
|
||||
if (image2 == null) return null;
|
||||
var srcX = message['srcX'];
|
||||
var srcY = message['srcY'];
|
||||
var width = message['width'];
|
||||
var height = message['height'];
|
||||
image.fillImageRangeAt(x, y, image2, srcX, srcY, width, height);
|
||||
return null;
|
||||
case 'getWidth':
|
||||
var key = message['key'];
|
||||
var image = images[key];
|
||||
if (image == null) return null;
|
||||
return image.width;
|
||||
case 'getHeight':
|
||||
var key = message['key'];
|
||||
var image = images[key];
|
||||
if (image == null) return null;
|
||||
return image.height;
|
||||
case 'emptyImage':
|
||||
var width = message['width'];
|
||||
var height = message['height'];
|
||||
var newImage = Image.empty(width, height);
|
||||
return setImage(newImage);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
var _tasksCount = 0;
|
||||
|
||||
Future<Uint8List> modifyImageWithScript(Uint8List data, String script) async {
|
||||
while (_tasksCount > 3) {
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
}
|
||||
_tasksCount++;
|
||||
try {
|
||||
var image = await Image.decodeImage(data);
|
||||
var initJs = await rootBundle.loadString('assets/init.js');
|
||||
return await Isolate.run(() {
|
||||
var jsEngine = JsEngine();
|
||||
jsEngine.runCode(initJs, '<init>');
|
||||
jsEngine.runCode(script);
|
||||
var key = jsEngine.setImage(image);
|
||||
var res = jsEngine.runCode('''
|
||||
let func = () => {
|
||||
let image = new Image($key);
|
||||
let result = modifyImage(image);
|
||||
return result.key;
|
||||
}
|
||||
func();
|
||||
''');
|
||||
var newImage = jsEngine.images[res];
|
||||
var data = newImage!.encodePng();
|
||||
return Uint8List.fromList(data);
|
||||
});
|
||||
} finally {
|
||||
_tasksCount--;
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_file_dialog/flutter_file_dialog.dart';
|
||||
@@ -8,6 +9,7 @@ import 'package:venera/utils/ext.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:share_plus/share_plus.dart' as s;
|
||||
import 'package:file_selector/file_selector.dart' as file_selector;
|
||||
import 'package:venera/utils/file_type.dart';
|
||||
|
||||
export 'dart:io';
|
||||
export 'dart:typed_data';
|
||||
@@ -44,6 +46,18 @@ extension FileSystemEntityExt on FileSystemEntity {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteIfExists({bool recursive = false}) async {
|
||||
if (existsSync()) {
|
||||
await delete(recursive: recursive);
|
||||
}
|
||||
}
|
||||
|
||||
void deleteIfExistsSync({bool recursive = false}) {
|
||||
if (existsSync()) {
|
||||
deleteSync(recursive: recursive);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension FileExtension on File {
|
||||
@@ -73,7 +87,7 @@ extension DirectoryExtension on Directory {
|
||||
}
|
||||
|
||||
String sanitizeFileName(String fileName) {
|
||||
if(fileName.endsWith('.')) {
|
||||
if (fileName.endsWith('.')) {
|
||||
fileName = fileName.substring(0, fileName.length - 1);
|
||||
}
|
||||
const maxLength = 255;
|
||||
@@ -113,6 +127,13 @@ Future<void> copyDirectory(Directory source, Directory destination) async {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> copyDirectoryIsolate(
|
||||
Directory source, Directory destination) async {
|
||||
await Isolate.run(() {
|
||||
copyDirectory(source, destination);
|
||||
});
|
||||
}
|
||||
|
||||
String findValidDirectoryName(String path, String directory) {
|
||||
var name = sanitizeFileName(directory);
|
||||
var dir = Directory("$path/$name");
|
||||
@@ -160,16 +181,51 @@ class DirectoryPicker {
|
||||
}
|
||||
}
|
||||
|
||||
class IOSDirectoryPicker {
|
||||
static const MethodChannel _channel = MethodChannel("venera/method_channel");
|
||||
|
||||
// 调用 iOS 目录选择方法
|
||||
static Future<String?> selectDirectory() async {
|
||||
try {
|
||||
final String? path = await _channel.invokeMethod('selectDirectory');
|
||||
return path;
|
||||
} catch (e) {
|
||||
print("Error selecting directory: $e");
|
||||
// 返回报错信息
|
||||
return e.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<file_selector.XFile?> selectFile({required List<String> ext}) async {
|
||||
var extensions = App.isMacOS || App.isIOS ? null : ext;
|
||||
if (App.isAndroid) {
|
||||
for (var e in ext) {
|
||||
var fileType = FileType.fromExtension(e);
|
||||
if (fileType.mime == "application/octet-stream") {
|
||||
extensions = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
file_selector.XTypeGroup typeGroup = file_selector.XTypeGroup(
|
||||
label: 'files',
|
||||
extensions: App.isMacOS || App.isIOS ? null : ext,
|
||||
extensions: extensions,
|
||||
);
|
||||
final file_selector.XFile? file = await file_selector.openFile(
|
||||
acceptedTypeGroups: <file_selector.XTypeGroup>[typeGroup],
|
||||
);
|
||||
if (file == null) return null;
|
||||
if (!ext.contains(file?.path.split(".").last)) {
|
||||
file_selector.XFile? file;
|
||||
if (extensions == null && App.isAndroid) {
|
||||
const selectFileChannel = MethodChannel("venera/select_file");
|
||||
var filePath = await selectFileChannel.invokeMethod("selectFile");
|
||||
if (filePath == null) return null;
|
||||
file = file_selector.XFile(filePath);
|
||||
} else {
|
||||
file = await file_selector.openFile(
|
||||
acceptedTypeGroups: <file_selector.XTypeGroup>[typeGroup],
|
||||
);
|
||||
if (file == null) return null;
|
||||
}
|
||||
if (!ext.contains(file.path.split(".").last)) {
|
||||
App.rootContext.showMessage(message: "Invalid file type");
|
||||
return null;
|
||||
}
|
||||
return file;
|
||||
@@ -180,6 +236,11 @@ Future<String?> selectDirectory() async {
|
||||
return path;
|
||||
}
|
||||
|
||||
// selectDirectoryIOS
|
||||
Future<String?> selectDirectoryIOS() async {
|
||||
return IOSDirectoryPicker.selectDirectory();
|
||||
}
|
||||
|
||||
Future<void> saveFile(
|
||||
{Uint8List? data, required String filename, File? file}) async {
|
||||
if (data == null && file == null) {
|
||||
|
31
lib/utils/volume.dart
Normal file
31
lib/utils/volume.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class VolumeListener {
|
||||
static const channel = EventChannel('venera/volume');
|
||||
|
||||
void Function()? onUp;
|
||||
|
||||
void Function()? onDown;
|
||||
|
||||
VolumeListener({this.onUp, this.onDown});
|
||||
|
||||
StreamSubscription? stream;
|
||||
|
||||
void listen() {
|
||||
stream = channel.receiveBroadcastStream().listen(onEvent);
|
||||
}
|
||||
|
||||
void onEvent(event) {
|
||||
if (event == 1) {
|
||||
onUp!();
|
||||
} else if (event == 2) {
|
||||
onDown!();
|
||||
}
|
||||
}
|
||||
|
||||
void cancel() {
|
||||
stream?.cancel();
|
||||
}
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
//
|
||||
// Generated file. Do not edit.
|
||||
//
|
||||
|
||||
// clang-format off
|
||||
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <desktop_webview_window/desktop_webview_window_plugin.h>
|
||||
#include <file_selector_linux/file_selector_plugin.h>
|
||||
#include <flutter_qjs/flutter_qjs_plugin.h>
|
||||
#include <gtk/gtk_plugin.h>
|
||||
#include <screen_retriever/screen_retriever_plugin.h>
|
||||
#include <sqlite3_flutter_libs/sqlite3_flutter_libs_plugin.h>
|
||||
#include <url_launcher_linux/url_launcher_plugin.h>
|
||||
#include <window_manager/window_manager_plugin.h>
|
||||
|
||||
void fl_register_plugins(FlPluginRegistry* registry) {
|
||||
g_autoptr(FlPluginRegistrar) desktop_webview_window_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "DesktopWebviewWindowPlugin");
|
||||
desktop_webview_window_plugin_register_with_registrar(desktop_webview_window_registrar);
|
||||
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
|
||||
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
|
||||
g_autoptr(FlPluginRegistrar) flutter_qjs_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterQjsPlugin");
|
||||
flutter_qjs_plugin_register_with_registrar(flutter_qjs_registrar);
|
||||
g_autoptr(FlPluginRegistrar) gtk_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "GtkPlugin");
|
||||
gtk_plugin_register_with_registrar(gtk_registrar);
|
||||
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
|
||||
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
|
||||
g_autoptr(FlPluginRegistrar) sqlite3_flutter_libs_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "Sqlite3FlutterLibsPlugin");
|
||||
sqlite3_flutter_libs_plugin_register_with_registrar(sqlite3_flutter_libs_registrar);
|
||||
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
|
||||
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
|
||||
g_autoptr(FlPluginRegistrar) window_manager_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
|
||||
window_manager_plugin_register_with_registrar(window_manager_registrar);
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
//
|
||||
// Generated file. Do not edit.
|
||||
//
|
||||
|
||||
// clang-format off
|
||||
|
||||
#ifndef GENERATED_PLUGIN_REGISTRANT_
|
||||
#define GENERATED_PLUGIN_REGISTRANT_
|
||||
|
||||
#include <flutter_linux/flutter_linux.h>
|
||||
|
||||
// Registers Flutter plugins.
|
||||
void fl_register_plugins(FlPluginRegistry* registry);
|
||||
|
||||
#endif // GENERATED_PLUGIN_REGISTRANT_
|
@@ -1,32 +0,0 @@
|
||||
#
|
||||
# Generated file, do not edit.
|
||||
#
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
desktop_webview_window
|
||||
file_selector_linux
|
||||
flutter_qjs
|
||||
gtk
|
||||
screen_retriever
|
||||
sqlite3_flutter_libs
|
||||
url_launcher_linux
|
||||
window_manager
|
||||
)
|
||||
|
||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||
zip_flutter
|
||||
)
|
||||
|
||||
set(PLUGIN_BUNDLED_LIBRARIES)
|
||||
|
||||
foreach(plugin ${FLUTTER_PLUGIN_LIST})
|
||||
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin})
|
||||
target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
|
||||
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
|
||||
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
|
||||
endforeach(plugin)
|
||||
|
||||
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
|
||||
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
|
||||
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
|
||||
endforeach(ffi_plugin)
|
@@ -1,30 +0,0 @@
|
||||
//
|
||||
// Generated file. Do not edit.
|
||||
//
|
||||
|
||||
import FlutterMacOS
|
||||
import Foundation
|
||||
|
||||
import app_links
|
||||
import desktop_webview_window
|
||||
import file_selector_macos
|
||||
import flutter_inappwebview_macos
|
||||
import path_provider_foundation
|
||||
import screen_retriever
|
||||
import share_plus
|
||||
import sqlite3_flutter_libs
|
||||
import url_launcher_macos
|
||||
import window_manager
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
AppLinksMacosPlugin.register(with: registry.registrar(forPlugin: "AppLinksMacosPlugin"))
|
||||
DesktopWebviewWindowPlugin.register(with: registry.registrar(forPlugin: "DesktopWebviewWindowPlugin"))
|
||||
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
|
||||
InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin"))
|
||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
|
||||
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
|
||||
Sqlite3FlutterLibsPlugin.register(with: registry.registrar(forPlugin: "Sqlite3FlutterLibsPlugin"))
|
||||
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
|
||||
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
|
||||
}
|
164
pubspec.lock
164
pubspec.lock
@@ -49,6 +49,22 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.11.0"
|
||||
battery_plus:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: battery_plus
|
||||
sha256: "220c8f1961efb01d6870493b5ac5a80afaeaffc8757f7a11ed3025a8570d29e7"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.2.0"
|
||||
battery_plus_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: battery_plus_platform_interface
|
||||
sha256: e8342c0f32de4b1dfd0223114b6785e48e579bfc398da9471c9179b907fa4910
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -57,6 +73,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
build_cli_annotations:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: build_cli_annotations
|
||||
sha256: b59d2769769efd6c9ff6d4c4cede0be115a566afc591705c2040b707534b1172
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
characters:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -101,10 +125,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: crypto
|
||||
sha256: ec30d999af904f33454ba22ed9a86162b35e52b44ac4807d1d93c288041d7d27
|
||||
sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.5"
|
||||
version: "3.0.6"
|
||||
csslib:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -113,6 +137,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
dbus:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: dbus
|
||||
sha256: "365c771ac3b0e58845f39ec6deebc76e3276aa9922b0cc60840712094d9047ac"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.10"
|
||||
desktop_webview_window:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -337,10 +369,18 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_reorderable_grid_view
|
||||
sha256: "40abcc5bff228ebff119326502e7357ee6399956b60b80b17385e9770b7458c0"
|
||||
sha256: "93a2b9e279bf40b9333428a67e70e520ca1528554984eb6f6304538400897e64"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.0.1"
|
||||
version: "5.3.2"
|
||||
flutter_rust_bridge:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_rust_bridge
|
||||
sha256: "5fe868d3cb8cbc4d83091748552e03f00ccfa41b8e44691bc382611f831d5f8b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.5.1"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
@@ -368,6 +408,14 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
freezed_annotation:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: freezed_annotation
|
||||
sha256: c2e2d632dd9b8a2b7751117abcfc2b4888ecfe181bd9fca7170d9ef02e595fe2
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.4"
|
||||
gtk:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -380,10 +428,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: html
|
||||
sha256: "3a7812d5bcd2894edf53dfaf8cd640876cf6cef50a8f238745c8b8120ea74d3a"
|
||||
sha256: "1fc58edeaec4307368c60d59b7e15b9d658b57d7f3125098b6294153c75337ec"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.15.4"
|
||||
version: "0.15.5"
|
||||
http:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -424,6 +472,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.1"
|
||||
json_annotation:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: json_annotation
|
||||
sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.9.0"
|
||||
leak_tracker:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -456,6 +512,15 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.0"
|
||||
lodepng_flutter:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: d1c96cd6503103b3270dfe2f320d4a1c93780f53
|
||||
resolved-ref: d1c96cd6503103b3270dfe2f320d4a1c93780f53
|
||||
url: "https://github.com/venera-app/lodepng_flutter"
|
||||
source: git
|
||||
version: "0.0.1"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -552,6 +617,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.0"
|
||||
petitparser:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: petitparser
|
||||
sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.0.2"
|
||||
photo_view:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -585,14 +658,54 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.9.1"
|
||||
rhttp:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: rhttp
|
||||
sha256: "92fb57dea6338370efe1e4e2101e8b521f91f15bc60ef6908469b4392dd9803a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.9.1"
|
||||
screen_retriever:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: screen_retriever
|
||||
sha256: "6ee02c8a1158e6dae7ca430da79436e3b1c9563c8cf02f524af997c201ac2b90"
|
||||
sha256: "570dbc8e4f70bac451e0efc9c9bb19fa2d6799a11e6ef04f946d7886d2e23d0c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.9"
|
||||
version: "0.2.0"
|
||||
screen_retriever_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: screen_retriever_linux
|
||||
sha256: f7f8120c92ef0784e58491ab664d01efda79a922b025ff286e29aa123ea3dd18
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.2.0"
|
||||
screen_retriever_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: screen_retriever_macos
|
||||
sha256: "71f956e65c97315dd661d71f828708bd97b6d358e776f1a30d5aa7d22d78a149"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.2.0"
|
||||
screen_retriever_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: screen_retriever_platform_interface
|
||||
sha256: ee197f4581ff0d5608587819af40490748e1e39e648d7680ecf95c05197240c0
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.2.0"
|
||||
screen_retriever_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: screen_retriever_windows
|
||||
sha256: "449ee257f03ca98a57288ee526a301a430a344a161f9202b4fcc38576716fe13"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.2.0"
|
||||
scrollable_positioned_list:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -651,10 +764,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: sqlite3
|
||||
sha256: "45f168ae2213201b54e09429ed0c593dc2c88c924a1488d6f9c523a255d567cb"
|
||||
sha256: bb174b3ec2527f9c5f680f73a89af8149dd99782fbb56ea88ad0807c5638f2ed
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.6"
|
||||
version: "2.4.7"
|
||||
sqlite3_flutter_libs:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -711,6 +824,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.2"
|
||||
upower:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: upower
|
||||
sha256: cf042403154751180affa1d15614db7fa50234bc2373cd21c3db666c38543ebf
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.0"
|
||||
url_launcher:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -807,6 +928,15 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
webdav_client:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: "285f87f15bccd2d5d5ff443761348c6ee47b98d1"
|
||||
resolved-ref: "285f87f15bccd2d5d5ff443761348c6ee47b98d1"
|
||||
url: "https://github.com/wgh136/webdav_client"
|
||||
source: git
|
||||
version: "1.2.2"
|
||||
win32:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -819,10 +949,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: window_manager
|
||||
sha256: ab8b2a7f97543d3db2b506c9d875e637149d48ee0c6a5cb5f5fd6e0dac463792
|
||||
sha256: "732896e1416297c63c9e3fb95aea72d0355f61390263982a47fd519169dc5059"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.4.2"
|
||||
version: "0.4.3"
|
||||
xdg_directories:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -831,6 +961,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.4"
|
||||
xml:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: xml
|
||||
sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.5.0"
|
||||
yaml:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -849,5 +987,5 @@ packages:
|
||||
source: git
|
||||
version: "0.0.1"
|
||||
sdks:
|
||||
dart: ">=3.5.0 <4.0.0"
|
||||
dart: ">=3.5.4 <4.0.0"
|
||||
flutter: ">=3.24.4"
|
||||
|
24
pubspec.yaml
24
pubspec.yaml
@@ -2,7 +2,7 @@ name: venera
|
||||
description: "A comic app."
|
||||
publish_to: 'none'
|
||||
|
||||
version: 1.0.0-beta+1
|
||||
version: 1.0.5+105
|
||||
|
||||
environment:
|
||||
sdk: '>=3.5.0 <4.0.0'
|
||||
@@ -15,16 +15,16 @@ dependencies:
|
||||
flutter_localizations:
|
||||
sdk: flutter
|
||||
intl: any
|
||||
window_manager: ^0.4.2
|
||||
sqlite3: any
|
||||
window_manager: ^0.4.3
|
||||
sqlite3: ^2.4.7
|
||||
sqlite3_flutter_libs: any
|
||||
flutter_qjs:
|
||||
git:
|
||||
url: https://github.com/wgh136/flutter_qjs
|
||||
ref: ade0b9d
|
||||
crypto: any
|
||||
dio: any
|
||||
html: any
|
||||
crypto: ^3.0.6
|
||||
dio: ^5.7.0
|
||||
html: ^0.15.5
|
||||
pointycastle: any
|
||||
url_launcher: ^6.3.0
|
||||
path: ^1.9.0
|
||||
@@ -39,7 +39,7 @@ dependencies:
|
||||
url: https://github.com/venera-app/flutter.widgets
|
||||
ref: 09e756b1f1b04e6298318d99ec20a787fb360f59
|
||||
path: packages/scrollable_positioned_list
|
||||
flutter_reorderable_grid_view: 5.0.1
|
||||
flutter_reorderable_grid_view: 5.3.2
|
||||
yaml: any
|
||||
uuid: ^4.5.1
|
||||
desktop_webview_window:
|
||||
@@ -54,6 +54,16 @@ dependencies:
|
||||
zip_flutter:
|
||||
git:
|
||||
url: https://github.com/wgh136/zip_flutter
|
||||
lodepng_flutter:
|
||||
git:
|
||||
url: https://github.com/venera-app/lodepng_flutter
|
||||
ref: d1c96cd6503103b3270dfe2f320d4a1c93780f53
|
||||
rhttp: 0.9.1
|
||||
webdav_client:
|
||||
git:
|
||||
url: https://github.com/wgh136/webdav_client
|
||||
ref: 285f87f15bccd2d5d5ff443761348c6ee47b98d1
|
||||
battery_plus: ^6.2.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
@@ -51,8 +51,12 @@ Source: "{#RootPath}\build\windows\x64\runner\Release\desktop_webview_window_plu
|
||||
Source: "{#RootPath}\build\windows\x64\runner\Release\WebView2Loader.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "{#RootPath}\build\windows\x64\runner\Release\share_plus_plugin.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "{#RootPath}\build\windows\x64\runner\Release\url_launcher_windows_plugin.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "{#RootPath}\build\windows\x64\runner\Release\screen_retriever_plugin.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "{#RootPath}\build\windows\x64\runner\Release\battery_plus_plugin.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "{#RootPath}\build\windows\x64\runner\Release\screen_retriever_windows_plugin.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "{#RootPath}\build\windows\x64\runner\Release\window_manager_plugin.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "{#RootPath}\build\windows\x64\runner\Release\zip_flutter.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "{#RootPath}\build\windows\x64\runner\Release\rhttp.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "{#RootPath}\build\windows\x64\runner\Release\lodepng_flutter.dll"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "{#RootPath}\build\windows\x64\runner\Release\data\*"; DestDir: "{app}\data"; Flags: ignoreversion recursesubdirs createallsubdirs
|
||||
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
|
||||
|
||||
|
@@ -1,41 +0,0 @@
|
||||
//
|
||||
// Generated file. Do not edit.
|
||||
//
|
||||
|
||||
// clang-format off
|
||||
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <app_links/app_links_plugin_c_api.h>
|
||||
#include <desktop_webview_window/desktop_webview_window_plugin.h>
|
||||
#include <file_selector_windows/file_selector_windows.h>
|
||||
#include <flutter_inappwebview_windows/flutter_inappwebview_windows_plugin_c_api.h>
|
||||
#include <flutter_qjs/flutter_qjs_plugin.h>
|
||||
#include <screen_retriever/screen_retriever_plugin.h>
|
||||
#include <share_plus/share_plus_windows_plugin_c_api.h>
|
||||
#include <sqlite3_flutter_libs/sqlite3_flutter_libs_plugin.h>
|
||||
#include <url_launcher_windows/url_launcher_windows.h>
|
||||
#include <window_manager/window_manager_plugin.h>
|
||||
|
||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||
AppLinksPluginCApiRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("AppLinksPluginCApi"));
|
||||
DesktopWebviewWindowPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("DesktopWebviewWindowPlugin"));
|
||||
FileSelectorWindowsRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("FileSelectorWindows"));
|
||||
FlutterInappwebviewWindowsPluginCApiRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("FlutterInappwebviewWindowsPluginCApi"));
|
||||
FlutterQjsPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("FlutterQjsPlugin"));
|
||||
ScreenRetrieverPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
|
||||
SharePlusWindowsPluginCApiRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi"));
|
||||
Sqlite3FlutterLibsPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("Sqlite3FlutterLibsPlugin"));
|
||||
UrlLauncherWindowsRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
|
||||
WindowManagerPluginRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
//
|
||||
// Generated file. Do not edit.
|
||||
//
|
||||
|
||||
// clang-format off
|
||||
|
||||
#ifndef GENERATED_PLUGIN_REGISTRANT_
|
||||
#define GENERATED_PLUGIN_REGISTRANT_
|
||||
|
||||
#include <flutter/plugin_registry.h>
|
||||
|
||||
// Registers Flutter plugins.
|
||||
void RegisterPlugins(flutter::PluginRegistry* registry);
|
||||
|
||||
#endif // GENERATED_PLUGIN_REGISTRANT_
|
@@ -1,34 +0,0 @@
|
||||
#
|
||||
# Generated file, do not edit.
|
||||
#
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
app_links
|
||||
desktop_webview_window
|
||||
file_selector_windows
|
||||
flutter_inappwebview_windows
|
||||
flutter_qjs
|
||||
screen_retriever
|
||||
share_plus
|
||||
sqlite3_flutter_libs
|
||||
url_launcher_windows
|
||||
window_manager
|
||||
)
|
||||
|
||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||
zip_flutter
|
||||
)
|
||||
|
||||
set(PLUGIN_BUNDLED_LIBRARIES)
|
||||
|
||||
foreach(plugin ${FLUTTER_PLUGIN_LIST})
|
||||
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin})
|
||||
target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
|
||||
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
|
||||
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
|
||||
endforeach(plugin)
|
||||
|
||||
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
|
||||
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
|
||||
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
|
||||
endforeach(ffi_plugin)
|
@@ -123,6 +123,26 @@ Win32Window::~Win32Window() {
|
||||
bool Win32Window::Create(const std::wstring& title,
|
||||
const Point& origin,
|
||||
const Size& size) {
|
||||
HWND hwnd = ::FindWindow(kWindowClassName, title.c_str());
|
||||
if (hwnd) {
|
||||
WINDOWPLACEMENT place = { sizeof(WINDOWPLACEMENT) };
|
||||
GetWindowPlacement(hwnd, &place);
|
||||
SetForegroundWindow(hwnd);
|
||||
switch (place.showCmd) {
|
||||
case SW_SHOWMAXIMIZED:
|
||||
ShowWindow(hwnd, SW_SHOWMAXIMIZED);
|
||||
break;
|
||||
case SW_SHOWMINIMIZED:
|
||||
ShowWindow(hwnd, SW_RESTORE);
|
||||
break;
|
||||
default:
|
||||
ShowWindow(hwnd, SW_NORMAL);
|
||||
break;
|
||||
}
|
||||
|
||||
SetWindowPos(0, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
|
||||
return false;
|
||||
}
|
||||
Destroy();
|
||||
|
||||
const wchar_t* window_class =
|
||||
|
Reference in New Issue
Block a user