mirror of
https://github.com/kodjodevf/mangayomi.git
synced 2026-03-11 17:25:32 +00:00
commit
958e91ac9a
5 changed files with 59 additions and 28 deletions
|
|
@ -50,7 +50,6 @@ DiscordRPC? discordRpc;
|
||||||
WebViewEnvironment? webViewEnvironment;
|
WebViewEnvironment? webViewEnvironment;
|
||||||
String? customDns;
|
String? customDns;
|
||||||
void main(List<String> args) async {
|
void main(List<String> args) async {
|
||||||
cfResolutionWebviewServer();
|
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
if (Platform.isLinux && runWebViewTitleBarWidget(args)) return;
|
if (Platform.isLinux && runWebViewTitleBarWidget(args)) return;
|
||||||
MediaKit.ensureInitialized();
|
MediaKit.ensureInitialized();
|
||||||
|
|
@ -93,6 +92,7 @@ Future<void> _postLaunchInit(StorageProvider storage) async {
|
||||||
await discordRpc?.initialize();
|
await discordRpc?.initialize();
|
||||||
}
|
}
|
||||||
await storage.deleteBtDirectory();
|
await storage.deleteBtDirectory();
|
||||||
|
await cfResolutionWebviewServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends ConsumerStatefulWidget {
|
class MyApp extends ConsumerStatefulWidget {
|
||||||
|
|
@ -119,6 +119,8 @@ class _MyAppState extends ConsumerState<MyApp> {
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
if (ref.read(clearChapterCacheOnAppLaunchStateProvider)) {
|
if (ref.read(clearChapterCacheOnAppLaunchStateProvider)) {
|
||||||
|
// Watch before calling clearcache to keep it alive, so that _getTotalDiskSpace completes safely
|
||||||
|
ref.watch(totalChapterCacheSizeStateProvider);
|
||||||
ref
|
ref
|
||||||
.read(totalChapterCacheSizeStateProvider.notifier)
|
.read(totalChapterCacheSizeStateProvider.notifier)
|
||||||
.clearCache(showToast: false);
|
.clearCache(showToast: false);
|
||||||
|
|
@ -157,6 +159,7 @@ class _MyAppState extends ConsumerState<MyApp> {
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_linkSubscription?.cancel();
|
_linkSubscription?.cancel();
|
||||||
discordRpc?.destroy();
|
discordRpc?.destroy();
|
||||||
|
stopCfResolutionWebviewServer();
|
||||||
AppLogger.dispose();
|
AppLogger.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -964,30 +964,31 @@ mp.register_script_message('call_button_${button.id}_long', button${button.id}lo
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_currentPosition.removeListener(_updateRpcTimestamp);
|
_currentPosition.removeListener(_updateRpcTimestamp);
|
||||||
|
_subDelayController.removeListener(_onSubDelayChanged);
|
||||||
|
_subSpeedController.removeListener(_onSubSpeedChanged);
|
||||||
WidgetsBinding.instance.removeObserver(this);
|
WidgetsBinding.instance.removeObserver(this);
|
||||||
_setCurrentPosition(true);
|
_setCurrentPosition(true);
|
||||||
_player.dispose();
|
_player.stop();
|
||||||
|
_completed.cancel();
|
||||||
_currentPositionSub.cancel();
|
_currentPositionSub.cancel();
|
||||||
_currentTotalDurationSub.cancel();
|
_currentTotalDurationSub.cancel();
|
||||||
_completed.cancel();
|
_currentPosition.dispose();
|
||||||
|
_currentTotalDuration.dispose();
|
||||||
_video.dispose();
|
_video.dispose();
|
||||||
_playbackSpeed.dispose();
|
_playbackSpeed.dispose();
|
||||||
_isDoubleSpeed.dispose();
|
_isDoubleSpeed.dispose();
|
||||||
_currentTotalDuration.dispose();
|
|
||||||
_showFitLabel.dispose();
|
_showFitLabel.dispose();
|
||||||
_isCompleted.dispose();
|
_isCompleted.dispose();
|
||||||
_tempPosition.dispose();
|
_tempPosition.dispose();
|
||||||
_fit.dispose();
|
_fit.dispose();
|
||||||
if (!_isDesktop) {
|
|
||||||
_setLandscapeMode(false);
|
|
||||||
}
|
|
||||||
_skipPhase.dispose();
|
_skipPhase.dispose();
|
||||||
discordRpc?.showIdleText();
|
|
||||||
discordRpc?.showOriginalTimestamp();
|
|
||||||
_currentPosition.dispose();
|
|
||||||
_subDelayController.dispose();
|
_subDelayController.dispose();
|
||||||
_subSpeedController.dispose();
|
_subSpeedController.dispose();
|
||||||
|
if (!_isDesktop) _setLandscapeMode(false);
|
||||||
|
discordRpc?.showIdleText();
|
||||||
|
discordRpc?.showOriginalTimestamp();
|
||||||
_streamController.keepAliveLink?.close();
|
_streamController.keepAliveLink?.close();
|
||||||
|
_player.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ Future<dynamic> updateMangaDetail(
|
||||||
|
|
||||||
final genre =
|
final genre =
|
||||||
getManga.genre
|
getManga.genre
|
||||||
?.map((e) => e.toString().trim().trimLeft().trimRight())
|
?.map((e) => e.toString().trim())
|
||||||
.toList()
|
.toList()
|
||||||
.toSet()
|
.toSet()
|
||||||
.toList() ??
|
.toList() ??
|
||||||
|
|
@ -80,7 +80,7 @@ Future<dynamic> updateMangaDetail(
|
||||||
for (var i = 0; i < newChapsIndex; i++) {
|
for (var i = 0; i < newChapsIndex; i++) {
|
||||||
final chapter = Chapter(
|
final chapter = Chapter(
|
||||||
name: chaps[i].name!,
|
name: chaps[i].name!,
|
||||||
url: chaps[i].url!.trim().trimLeft().trimRight(),
|
url: chaps[i].url!.trim(),
|
||||||
dateUpload: chaps[i].dateUpload == null
|
dateUpload: chaps[i].dateUpload == null
|
||||||
? DateTime.now().millisecondsSinceEpoch.toString()
|
? DateTime.now().millisecondsSinceEpoch.toString()
|
||||||
: chaps[i].dateUpload.toString(),
|
: chaps[i].dateUpload.toString(),
|
||||||
|
|
@ -171,8 +171,8 @@ Future<dynamic> updateMangaDetail(
|
||||||
|
|
||||||
extension DefaultValueExtension on String? {
|
extension DefaultValueExtension on String? {
|
||||||
String? trimmedOrDefault(String? defaultValue) {
|
String? trimmedOrDefault(String? defaultValue) {
|
||||||
if (this?.trim().trimLeft().trimRight().isNotEmpty ?? false) {
|
if (this?.trim().isNotEmpty ?? false) {
|
||||||
return this!.trim().trimLeft().trimRight();
|
return this!.trim();
|
||||||
}
|
}
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,10 @@ part 'storage_usage.g.dart';
|
||||||
class TotalChapterCacheSizeState extends _$TotalChapterCacheSizeState {
|
class TotalChapterCacheSizeState extends _$TotalChapterCacheSizeState {
|
||||||
@override
|
@override
|
||||||
String build() {
|
String build() {
|
||||||
_getTotalDiskSpace().then((value) => state = _formatBytes(value));
|
_getTotalDiskSpace().then((value) {
|
||||||
|
if (!ref.mounted) return;
|
||||||
|
state = _formatBytes(value);
|
||||||
|
});
|
||||||
return "0.00 B";
|
return "0.00 B";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -292,20 +292,44 @@ class ResolveCloudFlareChallenge extends RetryPolicy {
|
||||||
}
|
}
|
||||||
|
|
||||||
int cfPort = 0;
|
int cfPort = 0;
|
||||||
void cfResolutionWebviewServer() async {
|
HttpServer? _cfServer;
|
||||||
final server = await HttpServer.bind(InternetAddress.loopbackIPv4, cfPort);
|
|
||||||
cfPort = server.port;
|
|
||||||
|
|
||||||
server.listen((HttpRequest request) {
|
/// Cloudflare Resolution Webview Server
|
||||||
if (request.method == 'POST' && request.uri.path == '/resolve_cf') {
|
Future<void> cfResolutionWebviewServer() async {
|
||||||
_handleResolveCf(request);
|
try {
|
||||||
} else {
|
_cfServer = await HttpServer.bind(InternetAddress.loopbackIPv4, cfPort);
|
||||||
request.response
|
cfPort = _cfServer!.port;
|
||||||
..statusCode = HttpStatus.notFound
|
_cfServer!.listen(
|
||||||
..write('Not Found')
|
(HttpRequest request) {
|
||||||
..close();
|
if (request.method == 'POST' && request.uri.path == '/resolve_cf') {
|
||||||
}
|
_handleResolveCf(request);
|
||||||
});
|
} else {
|
||||||
|
request.response
|
||||||
|
..statusCode = HttpStatus.notFound
|
||||||
|
..write('Not Found')
|
||||||
|
..close();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onError: (e, st) {
|
||||||
|
debugPrint("CF server listener error: $e\n$st");
|
||||||
|
},
|
||||||
|
cancelOnError: false,
|
||||||
|
);
|
||||||
|
} catch (e, st) {
|
||||||
|
debugPrint("Couldn't start Cloudflare Resolution Webview Server: $e\n$st");
|
||||||
|
botToast("Couldn't start Cloudflare Resolution Webview Server.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> stopCfResolutionWebviewServer() async {
|
||||||
|
final server = _cfServer;
|
||||||
|
if (server == null) return;
|
||||||
|
try {
|
||||||
|
await server.close(force: true);
|
||||||
|
} finally {
|
||||||
|
_cfServer = null;
|
||||||
|
cfPort = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleResolveCf(HttpRequest request) async {
|
void _handleResolveCf(HttpRequest request) async {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue