mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
9f048685e4 | ||
![]() |
bc1f5e11b5 | ||
1f2147ef72 | |||
fba365fd93 | |||
a5e3fbaee5 |
@@ -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
|
* @param {ArrayBuffer} value
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
@@ -176,7 +202,7 @@ let Convert = {
|
|||||||
decryptAesCbc: (value, key, iv) => {
|
decryptAesCbc: (value, key, iv) => {
|
||||||
return sendMessage({
|
return sendMessage({
|
||||||
method: "convert",
|
method: "convert",
|
||||||
type: "aes-ecb",
|
type: "aes-cbc",
|
||||||
value: value,
|
value: value,
|
||||||
key: key,
|
key: key,
|
||||||
iv: iv,
|
iv: iv,
|
||||||
|
@@ -13,7 +13,7 @@ export "widget_utils.dart";
|
|||||||
export "context.dart";
|
export "context.dart";
|
||||||
|
|
||||||
class _App {
|
class _App {
|
||||||
final version = "1.4.2";
|
final version = "1.4.3";
|
||||||
|
|
||||||
bool get isAndroid => Platform.isAndroid;
|
bool get isAndroid => Platform.isAndroid;
|
||||||
|
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
|
import 'dart:ffi';
|
||||||
|
import 'dart:isolate';
|
||||||
|
|
||||||
import 'package:crypto/crypto.dart';
|
import 'package:crypto/crypto.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:sqlite3/sqlite3.dart';
|
import 'package:sqlite3/sqlite3.dart';
|
||||||
import 'package:venera/utils/io.dart';
|
import 'package:venera/utils/io.dart';
|
||||||
|
|
||||||
@@ -21,6 +23,51 @@ class CacheManager {
|
|||||||
|
|
||||||
int _limitSize = 2 * 1024 * 1024 * 1024;
|
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() {
|
CacheManager._create() {
|
||||||
Directory(cachePath).createSync(recursive: true);
|
Directory(cachePath).createSync(recursive: true);
|
||||||
_db = sqlite3.open('${App.dataPath}/cache.db');
|
_db = sqlite3.open('${App.dataPath}/cache.db');
|
||||||
@@ -33,7 +80,7 @@ class CacheManager {
|
|||||||
type TEXT
|
type TEXT
|
||||||
)
|
)
|
||||||
''');
|
''');
|
||||||
compute((path) => Directory(path).size, cachePath).then((value) {
|
_scanDir(_db.handle, cachePath).then((value) {
|
||||||
_currentSize = value;
|
_currentSize = value;
|
||||||
checkCache();
|
checkCache();
|
||||||
});
|
});
|
||||||
@@ -50,6 +97,7 @@ class CacheManager {
|
|||||||
/// Write cache to disk.
|
/// Write cache to disk.
|
||||||
Future<void> writeCache(String key, List<int> data,
|
Future<void> writeCache(String key, List<int> data,
|
||||||
[int duration = 7 * 24 * 60 * 60 * 1000]) async {
|
[int duration = 7 * 24 * 60 * 60 * 1000]) async {
|
||||||
|
await delete(key);
|
||||||
this.dir++;
|
this.dir++;
|
||||||
this.dir %= 100;
|
this.dir %= 100;
|
||||||
var dir = this.dir;
|
var dir = this.dir;
|
||||||
@@ -146,10 +194,12 @@ class CacheManager {
|
|||||||
await file.delete();
|
await file.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_db.execute('''
|
if (res.isNotEmpty) {
|
||||||
|
_db.execute('''
|
||||||
DELETE FROM cache
|
DELETE FROM cache
|
||||||
WHERE expires < ?
|
WHERE expires < ?
|
||||||
''', [DateTime.now().millisecondsSinceEpoch]);
|
''', [DateTime.now().millisecondsSinceEpoch]);
|
||||||
|
}
|
||||||
|
|
||||||
while (_currentSize != null && _currentSize! > _limitSize) {
|
while (_currentSize != null && _currentSize! > _limitSize) {
|
||||||
var res = _db.select('''
|
var res = _db.select('''
|
||||||
@@ -157,6 +207,13 @@ class CacheManager {
|
|||||||
ORDER BY expires ASC
|
ORDER BY expires ASC
|
||||||
limit 10
|
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) {
|
for (var row in res) {
|
||||||
var key = row[0] as String;
|
var key = row[0] as String;
|
||||||
var dir = row[1] as String;
|
var dir = row[1] as String;
|
||||||
|
@@ -3,6 +3,7 @@ import 'dart:io';
|
|||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
import 'package:crypto/crypto.dart';
|
import 'package:crypto/crypto.dart';
|
||||||
import 'package:dio/io.dart';
|
import 'package:dio/io.dart';
|
||||||
|
import 'package:enough_convert/enough_convert.dart';
|
||||||
import 'package:flutter/foundation.dart' show protected;
|
import 'package:flutter/foundation.dart' show protected;
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:html/parser.dart' as html;
|
import 'package:html/parser.dart' as html;
|
||||||
@@ -372,6 +373,11 @@ mixin class _JSEngineApi {
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case "utf8":
|
case "utf8":
|
||||||
return isEncode ? utf8.encode(value) : utf8.decode(value);
|
return isEncode ? utf8.encode(value) : utf8.decode(value);
|
||||||
|
case "gbk":
|
||||||
|
final codec = const GbkCodec();
|
||||||
|
return isEncode
|
||||||
|
? Uint8List.fromList(codec.encode(value))
|
||||||
|
: codec.decode(value);
|
||||||
case "base64":
|
case "base64":
|
||||||
return isEncode ? base64Encode(value) : base64Decode(value);
|
return isEncode ? base64Encode(value) : base64Decode(value);
|
||||||
case "md5":
|
case "md5":
|
||||||
|
@@ -234,19 +234,30 @@ class _StreamWrapper<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _listen() async {
|
void _listen() async {
|
||||||
await for (var data in _stream) {
|
try {
|
||||||
if (isClosed) {
|
await for (var data in _stream) {
|
||||||
break;
|
if (isClosed) {
|
||||||
}
|
break;
|
||||||
for (var controller in controllers) {
|
}
|
||||||
if (!controller.isClosed) {
|
for (var controller in controllers) {
|
||||||
controller.add(data);
|
if (!controller.isClosed) {
|
||||||
|
controller.add(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (var controller in controllers) {
|
catch (e) {
|
||||||
if (!controller.isClosed) {
|
for (var controller in controllers) {
|
||||||
controller.close();
|
if (!controller.isClosed) {
|
||||||
|
controller.addError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
for (var controller in controllers) {
|
||||||
|
if (!controller.isClosed) {
|
||||||
|
controller.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
controllers.clear();
|
controllers.clear();
|
||||||
|
@@ -178,6 +178,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.7.0"
|
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:
|
fake_async:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@@ -2,7 +2,7 @@ name: venera
|
|||||||
description: "A comic app."
|
description: "A comic app."
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
|
|
||||||
version: 1.4.2+142
|
version: 1.4.3+143
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.6.0 <4.0.0'
|
sdk: '>=3.6.0 <4.0.0'
|
||||||
@@ -85,6 +85,7 @@ dependencies:
|
|||||||
flutter_localizations:
|
flutter_localizations:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
yaml: ^3.1.3
|
yaml: ^3.1.3
|
||||||
|
enough_convert: ^1.6.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
Reference in New Issue
Block a user