mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-07-08 01:30:28 +08:00
Update
This commit is contained in:
@@ -2,6 +2,9 @@ import 'dart:io';
|
||||
import 'package:cookie_jar/cookie_jar.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'api/client.dart';
|
||||
@@ -39,6 +42,29 @@ void initApi(String baseUrl) {
|
||||
_api = EHApi(dio, baseUrl: baseUrl);
|
||||
}
|
||||
|
||||
bool tryInitApi(BuildContext context) {
|
||||
bool? skipBaseUrl = const bool.fromEnvironment("skipBaseUrl");
|
||||
if (skipBaseUrl == true) {
|
||||
if (_api != null) {
|
||||
return true;
|
||||
}
|
||||
initApi("/api");
|
||||
return true;
|
||||
}
|
||||
String? baseUrl = prefs.getString("baseUrl");
|
||||
if (baseUrl == null) {
|
||||
SchedulerBinding.instance.addPostFrameCallback((_) {
|
||||
context.go("/set_server");
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (_api != null && _api!.baseUrl == baseUrl) {
|
||||
return true;
|
||||
}
|
||||
initApi(baseUrl);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool get apiInited {
|
||||
return _api != null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user