Skip to content

Commit

Permalink
pref: boot speed (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaoMint authored Oct 10, 2023
1 parent b89a200 commit db0e18d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
10 changes: 10 additions & 0 deletions lib/controllers/extension_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class ExtensionPageController extends GetxController {
RxMap<String, ExtensionService> runtimes = <String, ExtensionService>{}.obs;
RxMap<String, String> errors = <String, String>{}.obs;
RxBool isInstallloading = false.obs;
bool needRefresh = true;
bool isPageOpen = false;

@override
void onInit() {
Expand All @@ -19,4 +21,12 @@ class ExtensionPageController extends GetxController {
runtimes.addAll(ExtensionUtils.runtimes);
errors.addAll(ExtensionUtils.extensionErrorMap);
}

callRefresh() {
if (isPageOpen) {
onRefresh();
} else {
needRefresh = true;
}
}
}
10 changes: 10 additions & 0 deletions lib/controllers/search_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class SearchPageController extends GetxController {
int get finishCount =>
searchResultList.where((element) => element.completed).length;
bool needRefresh = true;
bool isPageOpen = false;
// 是否打开了这个页面

@override
void onInit() {
Expand Down Expand Up @@ -89,6 +91,14 @@ class SearchPageController extends GetxController {
getPackgeByIndex(int index) {
return searchResultList[index].runitme.extension.package;
}

callRefresh() {
if (isPageOpen) {
getRuntime();
} else {
needRefresh = true;
}
}
}

class SearchResult {
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ void main(List<String> args) async {

// 主窗口
await MiruStorage.ensureInitialized();
await ExtensionUtils.ensureInitialized();
await ApplicationUtils.ensureInitialized();
ExtensionUtils.ensureInitialized();
MediaKit.ensureInitialized();

if (!Platform.isAndroid) {
Expand Down
8 changes: 4 additions & 4 deletions lib/utils/extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import 'package:miru_app/views/widgets/messenger.dart';
import 'package:path/path.dart' as path;

class ExtensionUtils {
static late Map<String, ExtensionService> runtimes;
static late Map<String, String> extensionErrorMap;
static Map<String, ExtensionService> runtimes = {};
static Map<String, String> extensionErrorMap = {};
static Timer? _timer;

static Future<String> get getExtensionsDir async =>
Expand Down Expand Up @@ -69,11 +69,11 @@ class ExtensionUtils {
extensionErrorMap = extErrorMap;
// 重载扩展页面
if (Get.isRegistered<ExtensionPageController>()) {
Get.find<ExtensionPageController>().onRefresh();
Get.find<ExtensionPageController>().callRefresh();
}
// 重载搜索页面
if (Get.isRegistered<SearchPageController>()) {
Get.find<SearchPageController>().needRefresh = true;
Get.find<SearchPageController>().callRefresh();
}
}

Expand Down
10 changes: 10 additions & 0 deletions lib/views/pages/extension/extension_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,19 @@ class _ExtensionPageState extends State<ExtensionPage> {
@override
void initState() {
c = Get.put(ExtensionPageController());
c.isPageOpen = true;
if (c.needRefresh) {
c.onRefresh();
}
super.initState();
}

@override
void dispose() {
c.isPageOpen = false;
super.dispose();
}

// 导入扩展对话框
_importDialog() {
String url = '';
Expand Down
7 changes: 7 additions & 0 deletions lib/views/pages/search/search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,19 @@ class _SearchPageState extends State<SearchPage> {
@override
void initState() {
c = Get.put(SearchPageController());
c.isPageOpen = true;
if (c.needRefresh) {
c.getRuntime();
}
super.initState();
}

@override
void dispose() {
c.isPageOpen = false;
super.dispose();
}

Widget _buildAndroidSearch(BuildContext context) {
return DefaultTabController(
length: 4,
Expand Down

0 comments on commit db0e18d

Please sign in to comment.