Skip to content

Commit

Permalink
Fix url validate issues
Browse files Browse the repository at this point in the history
Fix check ip performance problem

Optimize resources page
  • Loading branch information
chen08209 committed Jul 7, 2024
1 parent 5c3a0c5 commit b20d9ed
Show file tree
Hide file tree
Showing 34 changed files with 1,052 additions and 974 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ class FlClashVpnService : VpnService() {
"192.168.*"
)

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
return START_STICKY
}

fun start(port: Int, props: Props?) {
fd = with(Builder()) {
addAddress("172.16.0.1", 30)
Expand Down
2 changes: 1 addition & 1 deletion core/Clash.Meta
5 changes: 5 additions & 0 deletions core/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"path/filepath"
"runtime"
"strings"
"sync"
"syscall"
"time"
)
Expand Down Expand Up @@ -420,7 +421,11 @@ func patchSelectGroup() {
}
}

var applyLock sync.Mutex

func applyConfig() {
applyLock.Lock()
defer applyLock.Unlock()
cfg, err := config.ParseRawConfig(currentConfig)
if err != nil {
cfg, _ = config.ParseRawConfig(config.DefaultRawConfig())
Expand Down
2 changes: 1 addition & 1 deletion core/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ func updateConfig(s *C.char, port C.longlong) {
go func() {
var params = &GenerateConfigParams{}
err := json.Unmarshal([]byte(paramsString), params)
configParams = params.Params
if err != nil {
bridge.SendToPort(i, err.Error())
return
}
configParams = params.Params
prof := decorationConfig(params.ProfilePath, params.Config)
currentConfig = prof
applyConfig()
Expand Down
1 change: 0 additions & 1 deletion lib/application.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ class ApplicationState extends State<Application> {
lightColorScheme: lightDynamic,
darkColorScheme: darkDynamic,
);

WidgetsBinding.instance.addPostFrameCallback((_) {
globalState.appController.updateSystemColorSchemes(systemColorSchemes);
});
Expand Down
3 changes: 2 additions & 1 deletion lib/common/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export 'app_localizations.dart';
export 'function.dart';
export 'package.dart';
export 'measure.dart';
export 'service.dart';
export 'service.dart';
export 'iterable.dart';
13 changes: 13 additions & 0 deletions lib/common/iterable.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extension IterableExt<T> on Iterable<T> {
Iterable<T> separated(T separator) sync* {
final iterator = this.iterator;
if (!iterator.moveNext()) return;

yield iterator.current;

while (iterator.moveNext()) {
yield separator;
yield iterator.current;
}
}
}
33 changes: 13 additions & 20 deletions lib/common/picker.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:fl_clash/common/common.dart';
import 'package:image_picker/image_picker.dart';

class Picker {
Future<PlatformFile?> pickerConfigFile() async {
FilePickerResult? filePickerResult;
if (Platform.isAndroid) {
filePickerResult = await FilePicker.platform.pickFiles(
withData: true,
allowMultiple: false,
);
} else {
filePickerResult = await FilePicker.platform.pickFiles(
withData: true,
type: FileType.custom,
allowedExtensions: ['yaml', 'txt', 'conf'],
);
}
final file = filePickerResult?.files.first;
if (file == null) {
return null;
}
return file;
final filePickerResult = await FilePicker.platform.pickFiles(
withData: true,
allowMultiple: false,
);
return filePickerResult?.files.first;
}

Future<PlatformFile?> pickerGeoDataFile() async {
final filePickerResult = await FilePicker.platform.pickFiles(
withData: true,
allowMultiple: false,
);
return filePickerResult?.files.first;
}

Future<String?> pickerConfigQRCode() async {
Expand Down
9 changes: 7 additions & 2 deletions lib/common/string.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
extension StringExtension on String {
bool get isUrl {
return RegExp(
r"^(http(s)?://)?(www\.)?[a-zA-Z0-9]+([\-.][a-zA-Z0-9]+)*\.[a-zA-Z]{2,5}(:[0-9]{1,5})?(/.*)?$",
r'^(https?:\/\/)?'
r'((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|'
r'((\d{1,3}\.){3}\d{1,3}))'
r'(:\d+)?'
r'(\/[-a-z\d%_.~+]*)*'
r'(\?[;&a-z\d%_.~+=-]*)?'
r'(\#[-a-z\d_]*)?$',
caseSensitive: false,
multiLine: false,
).hasMatch(this);
}
}
4 changes: 4 additions & 0 deletions lib/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AppController {
late ClashConfig clashConfig;
late Measure measure;
late Function updateClashConfigDebounce;
late Function addCheckIpNumDebounce;

AppController(this.context) {
appState = context.read<AppState>();
Expand All @@ -25,6 +26,9 @@ class AppController {
updateClashConfigDebounce = debounce<Function()>(() async {
await updateClashConfig();
});
addCheckIpNumDebounce = debounce((){
appState.checkIpNum++;
});
measure = Measure.of(context);
}

Expand Down
171 changes: 81 additions & 90 deletions lib/fragments/backup_and_recovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:fl_clash/models/dav.dart';
import 'package:fl_clash/state.dart';
import 'package:fl_clash/widgets/fade_box.dart';
import 'package:fl_clash/widgets/list.dart';
import 'package:fl_clash/widgets/section.dart';
import 'package:fl_clash/widgets/text.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -34,7 +33,7 @@ class _BackupAndRecoveryState extends State<BackupAndRecovery> {
final res = await commonScaffoldState?.loadingRun<bool>(() async {
return await _client?.backup();
});
if(res != true) return;
if (res != true) return;
globalState.showMessage(
title: appLocalizations.recovery,
message: TextSpan(text: appLocalizations.backupSuccess),
Expand All @@ -46,7 +45,7 @@ class _BackupAndRecoveryState extends State<BackupAndRecovery> {
final res = await commonScaffoldState?.loadingRun<bool>(() async {
return await _client?.recovery(recoveryOption: recoveryOption);
});
if(res != true) return;
if (res != true) return;
globalState.showMessage(
title: appLocalizations.recovery,
message: TextSpan(text: appLocalizations.recoverySuccess),
Expand All @@ -69,89 +68,83 @@ class _BackupAndRecoveryState extends State<BackupAndRecovery> {
if (dav == null) {
return ListView(
children: [
Section(
ListHeader(
title: appLocalizations.account,
child: Builder(
builder: (_) {
return ListItem(
leading: const Icon(Icons.account_box),
title: Text(appLocalizations.noInfo),
subtitle: Text(appLocalizations.pleaseBindWebDAV),
trailing: FilledButton.tonal(
onPressed: () {
_showAddWebDAV(dav);
},
child: Text(
appLocalizations.bind,
),
),
);
),
ListItem(
leading: const Icon(Icons.account_box),
title: Text(appLocalizations.noInfo),
subtitle: Text(appLocalizations.pleaseBindWebDAV),
trailing: FilledButton.tonal(
onPressed: () {
_showAddWebDAV(dav);
},
child: Text(
appLocalizations.bind,
),
),
)
),
],
);
}
_client = DAVClient(dav);
final pingFuture = _client!.pingCompleter.future;
return ListView(
children: [
Section(
title: appLocalizations.account,
child: ListItem(
leading: const Icon(Icons.account_box),
title: TooltipText(
text: Text(
dav.user,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
ListHeader(title: appLocalizations.account),
ListItem(
leading: const Icon(Icons.account_box),
title: TooltipText(
text: Text(
dav.user,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
subtitle: Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(appLocalizations.connectivity),
FutureBuilder<bool>(
future: pingFuture,
builder: (_, snapshot) {
return Center(
child: FadeBox(
key: const Key("fade_box_1"),
child: snapshot.connectionState ==
ConnectionState.waiting
? const SizedBox(
width: 12,
height: 12,
child: CircularProgressIndicator(
strokeWidth: 1,
),
)
: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: snapshot.data == true
? Colors.green
: Colors.red,
),
width: 12,
height: 12,
),
subtitle: Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(appLocalizations.connectivity),
FutureBuilder<bool>(
future: pingFuture,
builder: (_, snapshot) {
return Center(
child: FadeBox(
key: const Key("fade_box_1"),
child: snapshot.connectionState ==
ConnectionState.waiting
? const SizedBox(
width: 12,
height: 12,
child: CircularProgressIndicator(
strokeWidth: 1,
),
),
);
},
),
],
),
)
: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: snapshot.data == true
? Colors.green
: Colors.red,
),
width: 12,
height: 12,
),
),
);
},
),
],
),
trailing: FilledButton.tonal(
onPressed: () {
_showAddWebDAV(dav);
},
child: Text(
appLocalizations.edit,
),
),
trailing: FilledButton.tonal(
onPressed: () {
_showAddWebDAV(dav);
},
child: Text(
appLocalizations.edit,
),
),
),
Expand All @@ -161,22 +154,21 @@ class _BackupAndRecoveryState extends State<BackupAndRecovery> {
return FadeBox(
key: const Key("fade_box_2"),
child: snapshot.data == true
? Section(
title: appLocalizations.backupAndRecovery,
child: Column(
children: [
ListItem(
onTab: _backup,
title: Text(appLocalizations.backup),
subtitle: Text(appLocalizations.backupDesc),
),
ListItem(
onTab: _handleRecovery,
title: Text(appLocalizations.recovery),
subtitle: Text(appLocalizations.recoveryDesc),
),
],
),
? Column(
children: [
ListHeader(
title: appLocalizations.backupAndRecovery),
ListItem(
onTab: _backup,
title: Text(appLocalizations.backup),
subtitle: Text(appLocalizations.backupDesc),
),
ListItem(
onTab: _handleRecovery,
title: Text(appLocalizations.recovery),
subtitle: Text(appLocalizations.recoveryDesc),
),
],
)
: Container(),
);
Expand Down Expand Up @@ -228,7 +220,6 @@ class _WebDAVFormDialogState extends State<WebDAVFormDialog> {
Navigator.pop(context);
}


@override
void dispose() {
super.dispose();
Expand Down
Loading

0 comments on commit b20d9ed

Please sign in to comment.