Skip to content

Commit

Permalink
Add one-click update all profiles
Browse files Browse the repository at this point in the history
Add expire show
  • Loading branch information
chen08209 committed Jun 8, 2024
1 parent d2d9bda commit c657467
Show file tree
Hide file tree
Showing 24 changed files with 449 additions and 273 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: build
on:
push:
tags:
- 'v*'
- '*'

jobs:
build:
Expand Down Expand Up @@ -82,6 +82,7 @@ jobs:


upload-release:
if: ${{ !endsWith(github.ref, '-debug') }}
permissions: write-all
needs: [ build ]
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion core/Clash.Meta
4 changes: 3 additions & 1 deletion lib/application.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ class ApplicationState extends State<Application> {
AppLocalizations.delegate.supportedLocales,
themeMode: state.themeMode,
theme: ThemeData(
pageTransitionsTheme: _pageTransitionsTheme,
useMaterial3: true,
fontFamily: '',
pageTransitionsTheme: _pageTransitionsTheme,
colorScheme: _getAppColorScheme(
brightness: Brightness.light,
systemColorSchemes: systemColorSchemes,
Expand All @@ -170,6 +171,7 @@ class ApplicationState extends State<Application> {
),
darkTheme: ThemeData(
useMaterial3: true,
fontFamily: '',
pageTransitionsTheme: _pageTransitionsTheme,
colorScheme: _getAppColorScheme(
brightness: Brightness.dark,
Expand Down
6 changes: 5 additions & 1 deletion lib/common/datetime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ extension DateTimeExtension on DateTime {
}
return appLocalizations.just;
}
}

String get show {
return toIso8601String().substring(0, 10);
}
}
11 changes: 11 additions & 0 deletions lib/common/measure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Measure {
double? _bodyMediumHeight;
double? _bodySmallHeight;
double? _labelSmallHeight;
double? _labelMediumHeight;
double? _titleLargeHeight;
double? _titleMediumHeight;

Expand Down Expand Up @@ -56,6 +57,16 @@ class Measure {
return _labelSmallHeight!;
}

double get labelMediumHeight {
_labelMediumHeight ??= computeTextSize(
Text(
"",
style: context.textTheme.labelMedium,
),
).height;
return _labelMediumHeight!;
}

double get titleLargeHeight {
_titleLargeHeight ??= computeTextSize(
Text(
Expand Down
19 changes: 9 additions & 10 deletions lib/common/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ class Request {
Request() {
_dio = Dio(
BaseOptions(
connectTimeout: httpTimeoutDuration,
sendTimeout: httpTimeoutDuration,
receiveTimeout: httpTimeoutDuration,
headers: {"User-Agent": coreName},
),
);
Expand All @@ -37,7 +34,7 @@ class Request {
_dio.httpClientAdapter = IOHttpClientAdapter(
createHttpClient: () {
final client = HttpClient();
if(!_isStart) return client;
if (!_isStart) return client;
client.findProxy = (url) {
return "PROXY localhost:$_port;DIRECT";
};
Expand All @@ -56,7 +53,7 @@ class Request {
),
)
.timeout(
httpTimeoutDuration,
httpTimeoutDuration * 2,
);
return response;
}
Expand Down Expand Up @@ -86,12 +83,14 @@ class Request {
"https://ipinfo.io/json/": IpInfo.fromIpInfoIoJson,
};

Future<IpInfo?> checkIp() async {
Future<IpInfo?> checkIp(CancelToken? cancelToken) async {
for (final source in _ipInfoSources.entries) {
try {
final response = await _dio.get<Map<String, dynamic>>(
source.key,
);
final response = await _dio
.get<Map<String, dynamic>>(source.key, cancelToken: cancelToken)
.timeout(
httpTimeoutDuration,
);
if (response.statusCode == 200 && response.data != null) {
return source.value(response.data!);
}
Expand All @@ -103,4 +102,4 @@ class Request {
}
}

final request = Request();
final request = Request();
5 changes: 5 additions & 0 deletions lib/common/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ extension TextStyleExtension on TextStyle {
return copyWith(color: color?.toLight());
}

toLighter() {
return copyWith(color: color?.toLighter());
}


toSoftBold() {
return copyWith(fontWeight: FontWeight.w500);
}
Expand Down
22 changes: 16 additions & 6 deletions lib/controller.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:fl_clash/enum/enum.dart';
import 'package:fl_clash/state.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -96,7 +97,7 @@ class AppController {
}
}

updateProfile(String id) async {
Future<void> updateProfile(String id) async {
final profile = config.getCurrentProfileForId(id);
if (profile != null) {
final tempProfile = profile.copyWith();
Expand Down Expand Up @@ -135,16 +136,25 @@ class AppController {

autoUpdateProfiles() async {
for (final profile in config.profiles) {
if (!profile.autoUpdate) return;
if (!profile.autoUpdate) continue;
final isNotNeedUpdate = profile.lastUpdateDate
?.add(
profile.autoUpdateDuration,
)
.isBeforeNow;
if (isNotNeedUpdate == false ||
profile.url == null ||
profile.url!.isEmpty) continue;
await profile.update();
if (isNotNeedUpdate == false || profile.type == ProfileType.file) {
continue;
}
await updateProfile(profile.id);
}
}

updateProfiles() async {
for (final profile in config.profiles) {
if (profile.type == ProfileType.file) {
continue;
}
await updateProfile(profile.id);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/enum/enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ enum MessageType { log, tun, delay, process, now }
enum RecoveryOption {
all,
onlyProfiles,
}
}
65 changes: 46 additions & 19 deletions lib/fragments/dashboard/network_detection.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:country_flags/country_flags.dart';
import 'package:dio/dio.dart';
import 'package:fl_clash/common/common.dart';
import 'package:fl_clash/models/models.dart';
import 'package:fl_clash/state.dart';
Expand All @@ -16,20 +17,29 @@ class NetworkDetection extends StatefulWidget {
class _NetworkDetectionState extends State<NetworkDetection> {
final ipInfoNotifier = ValueNotifier<IpInfo?>(null);
final timeoutNotifier = ValueNotifier<bool>(false);
bool? _preIsStart;
CancelToken? cancelToken;

_checkIp(
bool isInit,
bool isStart,
) async {
if (!isInit) return;
if (_preIsStart == false && _preIsStart == isStart) return;
if (cancelToken != null) {
cancelToken!.cancel();
cancelToken = null;
}
ipInfoNotifier.value = null;
final ipInfo = await request.checkIp();
final ipInfo = await request.checkIp(cancelToken);
if (ipInfo == null) {
timeoutNotifier.value = true;
return;
} else {
timeoutNotifier.value = false;
}
ipInfoNotifier.value = await request.checkIp();
_preIsStart = isStart;
ipInfoNotifier.value = ipInfo;
}

_checkIpContainer(Widget child) {
Expand All @@ -42,9 +52,7 @@ class _NetworkDetectionState extends State<NetworkDetection> {
);
},
builder: (_, state, __) {
_checkIp(
state.isInit,
);
_checkIp(state.isInit, state.isStart);
return child;
},
child: child,
Expand Down Expand Up @@ -82,15 +90,30 @@ class _NetworkDetectionState extends State<NetworkDetection> {
width: 24,
height: 24,
)
: TooltipText(
text: Text(
appLocalizations.checking,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
.titleMedium,
),
: ValueListenableBuilder(
valueListenable: timeoutNotifier,
builder: (_, timeout, __) {
if (timeout) {
return Text(
appLocalizations.checkError,
style: Theme.of(context)
.textTheme
.titleMedium,
maxLines: 1,
overflow: TextOverflow.ellipsis,
);
}
return TooltipText(
text: Text(
appLocalizations.checking,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
.textTheme
.titleMedium,
),
);
},
),
),
),
Expand Down Expand Up @@ -126,17 +149,21 @@ class _NetworkDetectionState extends State<NetworkDetection> {
: ValueListenableBuilder(
valueListenable: timeoutNotifier,
builder: (_, timeout, __) {
if(timeout){
if (timeout) {
return Text(
appLocalizations.ipCheckError,
style: context.textTheme.bodyMedium
appLocalizations.ipCheckTimeout,
style: context.textTheme.titleLarge
?.toSoftBold(),
maxLines: 1,
overflow: TextOverflow.ellipsis,
);
}
return const SizedBox(
child: CircularProgressIndicator(),
return Container(
padding: const EdgeInsets.all(2),
child: const AspectRatio(
aspectRatio: 1,
child: CircularProgressIndicator(),
),
);
},
),
Expand Down
6 changes: 6 additions & 0 deletions lib/fragments/logs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class _LogsFragmentState extends State<LogsFragment> {
);
},
icon: const Icon(Icons.search),
),
const SizedBox(
width: 8,
)
];
});
Expand Down Expand Up @@ -139,6 +142,9 @@ class LogsSearchDelegate extends SearchDelegate {
},
icon: const Icon(Icons.clear),
),
const SizedBox(
width: 8,
)
];
}

Expand Down
3 changes: 2 additions & 1 deletion lib/fragments/profiles/edit_profile.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:fl_clash/common/common.dart';
import 'package:fl_clash/enum/enum.dart';
import 'package:fl_clash/models/models.dart';
import 'package:fl_clash/state.dart';
import 'package:fl_clash/widgets/widgets.dart';
Expand Down Expand Up @@ -82,7 +83,7 @@ class _EditProfileState extends State<EditProfile> {
},
),
),
if (widget.profile.url != null && widget.profile.url!.isNotEmpty == true)...[
if (widget.profile.type == ProfileType.url)...[
ListItem(
title: TextFormField(
controller: urlController,
Expand Down
Loading

0 comments on commit c657467

Please sign in to comment.