mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
Compare commits
7 Commits
v1.4.2-dev
...
v1.4.3
Author | SHA1 | Date | |
---|---|---|---|
![]() |
9f048685e4 | ||
![]() |
bc1f5e11b5 | ||
1f2147ef72 | |||
fba365fd93 | |||
a5e3fbaee5 | |||
190e645a12 | |||
![]() |
8a83ff5367 |
@@ -39,6 +39,32 @@ let Convert = {
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @param str {string}
|
||||
* @returns {ArrayBuffer}
|
||||
*/
|
||||
encodeGbk: (str) => {
|
||||
return sendMessage({
|
||||
method: "convert",
|
||||
type: "gbk",
|
||||
value: str,
|
||||
isEncode: true
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @param value {ArrayBuffer}
|
||||
* @returns {string}
|
||||
*/
|
||||
decodeGbk: (value) => {
|
||||
return sendMessage({
|
||||
method: "convert",
|
||||
type: "gbk",
|
||||
value: value,
|
||||
isEncode: false
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {ArrayBuffer} value
|
||||
* @returns {string}
|
||||
@@ -176,7 +202,7 @@ let Convert = {
|
||||
decryptAesCbc: (value, key, iv) => {
|
||||
return sendMessage({
|
||||
method: "convert",
|
||||
type: "aes-ecb",
|
||||
type: "aes-cbc",
|
||||
value: value,
|
||||
key: key,
|
||||
iv: iv,
|
||||
|
@@ -390,7 +390,8 @@
|
||||
"Show single image on first page": "在首页显示单张图片",
|
||||
"Click to select an image": "点击选择一张图片",
|
||||
"Source URL": "源地址",
|
||||
"The URL should point to a 'index.json' file": "该URL应指向一个'index.json'文件"
|
||||
"The URL should point to a 'index.json' file": "该URL应指向一个'index.json'文件",
|
||||
"Double tap to zoom": "双击缩放"
|
||||
},
|
||||
"zh_TW": {
|
||||
"Home": "首頁",
|
||||
@@ -783,6 +784,7 @@
|
||||
"Show single image on first page": "在首頁顯示單張圖片",
|
||||
"Click to select an image": "點擊選擇一張圖片",
|
||||
"Source URL": "源地址",
|
||||
"The URL should point to a 'index.json' file": "該URL應指向一個'index.json'文件"
|
||||
"The URL should point to a 'index.json' file": "該URL應指向一個'index.json'文件",
|
||||
"Double tap to zoom": "雙擊縮放"
|
||||
}
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ export "widget_utils.dart";
|
||||
export "context.dart";
|
||||
|
||||
class _App {
|
||||
final version = "1.4.2";
|
||||
final version = "1.4.3";
|
||||
|
||||
bool get isAndroid => Platform.isAndroid;
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
import 'dart:ffi';
|
||||
import 'dart:isolate';
|
||||
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:sqlite3/sqlite3.dart';
|
||||
import 'package:venera/utils/io.dart';
|
||||
|
||||
@@ -21,6 +23,51 @@ class CacheManager {
|
||||
|
||||
int _limitSize = 2 * 1024 * 1024 * 1024;
|
||||
|
||||
static Future<int> _scanDir(Pointer<void> dbP, String dir) async {
|
||||
var res = await Isolate.run(() async {
|
||||
int totalSize = 0;
|
||||
List<String> unmanagedFiles = [];
|
||||
var db = sqlite3.fromPointer(dbP);
|
||||
await for (var file in Directory(dir).list(recursive: true)) {
|
||||
if (file is File) {
|
||||
var size = await file.length();
|
||||
var segments = file.uri.pathSegments;
|
||||
var name = segments.last;
|
||||
var dir = segments.elementAtOrNull(segments.length - 2) ?? "*";
|
||||
var res = db.select('''
|
||||
SELECT * FROM cache
|
||||
WHERE dir = ? AND name = ?
|
||||
''', [dir, name]);
|
||||
if (res.isEmpty) {
|
||||
unmanagedFiles.add(file.path);
|
||||
} else {
|
||||
totalSize += size;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
'totalSize': totalSize,
|
||||
'unmanagedFiles': unmanagedFiles,
|
||||
};
|
||||
});
|
||||
// delete unmanaged files
|
||||
// Only modify the database in the main isolate to avoid deadlock
|
||||
for (var filePath in res['unmanagedFiles'] as List<String>) {
|
||||
var file = File(filePath);
|
||||
if (await file.exists()) {
|
||||
await file.delete();
|
||||
}
|
||||
var segments = file.uri.pathSegments;
|
||||
var name = segments.last;
|
||||
var dir = segments.elementAtOrNull(segments.length - 2) ?? "*";
|
||||
CacheManager()._db.execute('''
|
||||
DELETE FROM cache
|
||||
WHERE dir = ? AND name = ?
|
||||
''', [dir, name]);
|
||||
}
|
||||
return res['totalSize'] as int;
|
||||
}
|
||||
|
||||
CacheManager._create() {
|
||||
Directory(cachePath).createSync(recursive: true);
|
||||
_db = sqlite3.open('${App.dataPath}/cache.db');
|
||||
@@ -33,7 +80,7 @@ class CacheManager {
|
||||
type TEXT
|
||||
)
|
||||
''');
|
||||
compute((path) => Directory(path).size, cachePath).then((value) {
|
||||
_scanDir(_db.handle, cachePath).then((value) {
|
||||
_currentSize = value;
|
||||
checkCache();
|
||||
});
|
||||
@@ -50,6 +97,7 @@ class CacheManager {
|
||||
/// Write cache to disk.
|
||||
Future<void> writeCache(String key, List<int> data,
|
||||
[int duration = 7 * 24 * 60 * 60 * 1000]) async {
|
||||
await delete(key);
|
||||
this.dir++;
|
||||
this.dir %= 100;
|
||||
var dir = this.dir;
|
||||
@@ -146,10 +194,12 @@ class CacheManager {
|
||||
await file.delete();
|
||||
}
|
||||
}
|
||||
if (res.isNotEmpty) {
|
||||
_db.execute('''
|
||||
DELETE FROM cache
|
||||
WHERE expires < ?
|
||||
''', [DateTime.now().millisecondsSinceEpoch]);
|
||||
}
|
||||
|
||||
while (_currentSize != null && _currentSize! > _limitSize) {
|
||||
var res = _db.select('''
|
||||
@@ -157,6 +207,13 @@ class CacheManager {
|
||||
ORDER BY expires ASC
|
||||
limit 10
|
||||
''');
|
||||
if (res.isEmpty) {
|
||||
// There are many files unmanaged by the cache manager.
|
||||
// Clear all cache.
|
||||
await Directory(cachePath).delete(recursive: true);
|
||||
Directory(cachePath).createSync(recursive: true);
|
||||
break;
|
||||
}
|
||||
for (var row in res) {
|
||||
var key = row[0] as String;
|
||||
var dir = row[1] as String;
|
||||
|
@@ -3,6 +3,7 @@ import 'dart:io';
|
||||
import 'dart:math' as math;
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:dio/io.dart';
|
||||
import 'package:enough_convert/enough_convert.dart';
|
||||
import 'package:flutter/foundation.dart' show protected;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:html/parser.dart' as html;
|
||||
@@ -372,6 +373,11 @@ mixin class _JSEngineApi {
|
||||
switch (type) {
|
||||
case "utf8":
|
||||
return isEncode ? utf8.encode(value) : utf8.decode(value);
|
||||
case "gbk":
|
||||
final codec = const GbkCodec();
|
||||
return isEncode
|
||||
? Uint8List.fromList(codec.encode(value))
|
||||
: codec.decode(value);
|
||||
case "base64":
|
||||
return isEncode ? base64Encode(value) : base64Decode(value);
|
||||
case "md5":
|
||||
|
@@ -234,6 +234,7 @@ class _StreamWrapper<T> {
|
||||
}
|
||||
|
||||
void _listen() async {
|
||||
try {
|
||||
await for (var data in _stream) {
|
||||
if (isClosed) {
|
||||
break;
|
||||
@@ -244,11 +245,21 @@ class _StreamWrapper<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
for (var controller in controllers) {
|
||||
if (!controller.isClosed) {
|
||||
controller.addError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
for (var controller in controllers) {
|
||||
if (!controller.isClosed) {
|
||||
controller.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
controllers.clear();
|
||||
isClosed = true;
|
||||
onClosed(this);
|
||||
|
@@ -178,6 +178,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.7.0"
|
||||
enough_convert:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: enough_convert
|
||||
sha256: c67d85ca21aaa0648f155907362430701db41f7ec8e6501a58ad9cd9d8569d01
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.6.0"
|
||||
fake_async:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@@ -2,7 +2,7 @@ name: venera
|
||||
description: "A comic app."
|
||||
publish_to: 'none'
|
||||
|
||||
version: 1.4.2+142
|
||||
version: 1.4.3+143
|
||||
|
||||
environment:
|
||||
sdk: '>=3.6.0 <4.0.0'
|
||||
@@ -85,6 +85,7 @@ dependencies:
|
||||
flutter_localizations:
|
||||
sdk: flutter
|
||||
yaml: ^3.1.3
|
||||
enough_convert: ^1.6.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
Reference in New Issue
Block a user