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;
|
||||
String? customDns;
|
||||
void main(List<String> args) async {
|
||||
cfResolutionWebviewServer();
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
if (Platform.isLinux && runWebViewTitleBarWidget(args)) return;
|
||||
MediaKit.ensureInitialized();
|
||||
|
|
@ -93,6 +92,7 @@ Future<void> _postLaunchInit(StorageProvider storage) async {
|
|||
await discordRpc?.initialize();
|
||||
}
|
||||
await storage.deleteBtDirectory();
|
||||
await cfResolutionWebviewServer();
|
||||
}
|
||||
|
||||
class MyApp extends ConsumerStatefulWidget {
|
||||
|
|
@ -119,6 +119,8 @@ class _MyAppState extends ConsumerState<MyApp> {
|
|||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (ref.read(clearChapterCacheOnAppLaunchStateProvider)) {
|
||||
// Watch before calling clearcache to keep it alive, so that _getTotalDiskSpace completes safely
|
||||
ref.watch(totalChapterCacheSizeStateProvider);
|
||||
ref
|
||||
.read(totalChapterCacheSizeStateProvider.notifier)
|
||||
.clearCache(showToast: false);
|
||||
|
|
@ -157,6 +159,7 @@ class _MyAppState extends ConsumerState<MyApp> {
|
|||
void dispose() {
|
||||
_linkSubscription?.cancel();
|
||||
discordRpc?.destroy();
|
||||
stopCfResolutionWebviewServer();
|
||||
AppLogger.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -964,30 +964,31 @@ mp.register_script_message('call_button_${button.id}_long', button${button.id}lo
|
|||
@override
|
||||
void dispose() {
|
||||
_currentPosition.removeListener(_updateRpcTimestamp);
|
||||
_subDelayController.removeListener(_onSubDelayChanged);
|
||||
_subSpeedController.removeListener(_onSubSpeedChanged);
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_setCurrentPosition(true);
|
||||
_player.dispose();
|
||||
_player.stop();
|
||||
_completed.cancel();
|
||||
_currentPositionSub.cancel();
|
||||
_currentTotalDurationSub.cancel();
|
||||
_completed.cancel();
|
||||
_currentPosition.dispose();
|
||||
_currentTotalDuration.dispose();
|
||||
_video.dispose();
|
||||
_playbackSpeed.dispose();
|
||||
_isDoubleSpeed.dispose();
|
||||
_currentTotalDuration.dispose();
|
||||
_showFitLabel.dispose();
|
||||
_isCompleted.dispose();
|
||||
_tempPosition.dispose();
|
||||
_fit.dispose();
|
||||
if (!_isDesktop) {
|
||||
_setLandscapeMode(false);
|
||||
}
|
||||
_skipPhase.dispose();
|
||||
discordRpc?.showIdleText();
|
||||
discordRpc?.showOriginalTimestamp();
|
||||
_currentPosition.dispose();
|
||||
_subDelayController.dispose();
|
||||
_subSpeedController.dispose();
|
||||
if (!_isDesktop) _setLandscapeMode(false);
|
||||
discordRpc?.showIdleText();
|
||||
discordRpc?.showOriginalTimestamp();
|
||||
_streamController.keepAliveLink?.close();
|
||||
_player.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ Future<dynamic> updateMangaDetail(
|
|||
|
||||
final genre =
|
||||
getManga.genre
|
||||
?.map((e) => e.toString().trim().trimLeft().trimRight())
|
||||
?.map((e) => e.toString().trim())
|
||||
.toList()
|
||||
.toSet()
|
||||
.toList() ??
|
||||
|
|
@ -80,7 +80,7 @@ Future<dynamic> updateMangaDetail(
|
|||
for (var i = 0; i < newChapsIndex; i++) {
|
||||
final chapter = Chapter(
|
||||
name: chaps[i].name!,
|
||||
url: chaps[i].url!.trim().trimLeft().trimRight(),
|
||||
url: chaps[i].url!.trim(),
|
||||
dateUpload: chaps[i].dateUpload == null
|
||||
? DateTime.now().millisecondsSinceEpoch.toString()
|
||||
: chaps[i].dateUpload.toString(),
|
||||
|
|
@ -171,8 +171,8 @@ Future<dynamic> updateMangaDetail(
|
|||
|
||||
extension DefaultValueExtension on String? {
|
||||
String? trimmedOrDefault(String? defaultValue) {
|
||||
if (this?.trim().trimLeft().trimRight().isNotEmpty ?? false) {
|
||||
return this!.trim().trimLeft().trimRight();
|
||||
if (this?.trim().isNotEmpty ?? false) {
|
||||
return this!.trim();
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,10 @@ part 'storage_usage.g.dart';
|
|||
class TotalChapterCacheSizeState extends _$TotalChapterCacheSizeState {
|
||||
@override
|
||||
String build() {
|
||||
_getTotalDiskSpace().then((value) => state = _formatBytes(value));
|
||||
_getTotalDiskSpace().then((value) {
|
||||
if (!ref.mounted) return;
|
||||
state = _formatBytes(value);
|
||||
});
|
||||
return "0.00 B";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -292,11 +292,15 @@ class ResolveCloudFlareChallenge extends RetryPolicy {
|
|||
}
|
||||
|
||||
int cfPort = 0;
|
||||
void cfResolutionWebviewServer() async {
|
||||
final server = await HttpServer.bind(InternetAddress.loopbackIPv4, cfPort);
|
||||
cfPort = server.port;
|
||||
HttpServer? _cfServer;
|
||||
|
||||
server.listen((HttpRequest request) {
|
||||
/// Cloudflare Resolution Webview Server
|
||||
Future<void> cfResolutionWebviewServer() async {
|
||||
try {
|
||||
_cfServer = await HttpServer.bind(InternetAddress.loopbackIPv4, cfPort);
|
||||
cfPort = _cfServer!.port;
|
||||
_cfServer!.listen(
|
||||
(HttpRequest request) {
|
||||
if (request.method == 'POST' && request.uri.path == '/resolve_cf') {
|
||||
_handleResolveCf(request);
|
||||
} else {
|
||||
|
|
@ -305,7 +309,27 @@ void cfResolutionWebviewServer() async {
|
|||
..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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue