Update popup menu

Add file editor

Fix android service issues

Optimize desktop background performance

Optimize android main process performance

Optimize delay test

Optimize vpn protect
This commit is contained in:
chen08209
2025-01-13 19:08:17 +08:00
parent 6a39b7ef5a
commit b340feeb49
92 changed files with 4000 additions and 3081 deletions

View File

@@ -7,18 +7,11 @@ import 'package:fl_clash/models/models.dart';
import 'package:fl_clash/state.dart';
import 'package:fl_clash/widgets/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'add_profile.dart';
enum PopupMenuItemEnum { delete, edit }
enum ProfileActions {
edit,
update,
delete,
}
class ProfilesFragment extends StatefulWidget {
const ProfilesFragment({super.key});
@@ -185,18 +178,16 @@ class ProfileItem extends StatelessWidget {
});
_handleDeleteProfile(BuildContext context) async {
globalState.showMessage(
final res = await globalState.showMessage(
title: appLocalizations.tip,
message: TextSpan(
text: appLocalizations.deleteProfileTip,
),
onTab: () async {
await globalState.appController.deleteProfile(profile.id);
if (context.mounted) {
Navigator.of(context).pop();
}
},
);
if (res != true) {
return;
}
await globalState.appController.deleteProfile(profile.id);
}
_handleUpdateProfile() async {
@@ -266,6 +257,36 @@ class ProfileItem extends StatelessWidget {
];
}
_handleCopyLink(BuildContext context) async {
await Clipboard.setData(
ClipboardData(
text: profile.url,
),
);
if (context.mounted) {
context.showNotifier(appLocalizations.copySuccess);
}
}
_handleExportFile(BuildContext context) async {
final commonScaffoldState = context.commonScaffoldState;
final res = await commonScaffoldState?.loadingRun<bool>(
() async {
final file = await profile.getFile();
final value = await picker.saveFile(
profile.label ?? profile.id,
file.readAsBytesSync(),
);
if (value == null) return false;
return true;
},
title: appLocalizations.tip,
);
if (res == true && context.mounted) {
context.showNotifier(appLocalizations.exportSuccess);
}
}
@override
Widget build(BuildContext context) {
return CommonCard(
@@ -286,46 +307,59 @@ class ProfileItem extends StatelessWidget {
padding: EdgeInsets.all(8),
child: CircularProgressIndicator(),
)
: CommonPopupMenu<ProfileActions>(
icon: Icon(Icons.more_vert),
items: [
CommonPopupMenuItem(
action: ProfileActions.edit,
label: appLocalizations.edit,
iconData: Icons.edit,
),
if (profile.type == ProfileType.url)
CommonPopupMenuItem(
action: ProfileActions.update,
label: appLocalizations.update,
iconData: Icons.sync,
: CommonPopupBox(
popup: CommonPopupMenu(
items: [
ActionItemData(
icon: Icons.edit_outlined,
label: appLocalizations.edit,
onPressed: () {
_handleShowEditExtendPage(context);
},
),
CommonPopupMenuItem(
action: ProfileActions.delete,
label: appLocalizations.delete,
iconData: Icons.delete,
),
],
onSelected: (ProfileActions? action) async {
switch (action) {
case ProfileActions.edit:
_handleShowEditExtendPage(context);
break;
case ProfileActions.delete:
_handleDeleteProfile(context);
break;
case ProfileActions.update:
_handleUpdateProfile();
break;
case null:
break;
}
},
if (profile.type == ProfileType.url) ...[
ActionItemData(
icon: Icons.sync_alt_sharp,
label: appLocalizations.sync,
onPressed: () {
_handleUpdateProfile();
},
),
ActionItemData(
icon: Icons.copy,
label: appLocalizations.copyLink,
onPressed: () {
_handleCopyLink(context);
},
),
],
ActionItemData(
icon: Icons.file_copy_outlined,
label: appLocalizations.exportFile,
onPressed: () {
_handleExportFile(context);
},
),
ActionItemData(
icon: Icons.delete_outlined,
iconSize: 20,
label: appLocalizations.delete,
onPressed: () {
_handleDeleteProfile(context);
},
type: ActionType.danger,
),
],
),
target: IconButton(
onPressed: () {},
icon: Icon(Icons.more_vert),
),
),
),
),
title: Container(
padding: const EdgeInsets.symmetric(vertical: 4),
padding: const EdgeInsets.symmetric(vertical: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,