From 01a7718e543cdd0757315919a1162573c82e2ba8 Mon Sep 17 00:00:00 2001 From: GooRingX Date: Mon, 25 Nov 2024 12:01:25 +0800 Subject: [PATCH] update --- .gitignore | 1 + lib/main.dart | 24 ++++++----- .../diversion_group_custom_edit_screen.dart | 26 +++++++----- lib/screens/home_screen.dart | 1 - lib/screens/launch_failed_screen.dart | 4 +- lib/screens/net_connections_screen.dart | 41 +++++++++++++++---- pubspec.yaml | 5 ++- 7 files changed, 70 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index fa27a40..2b4f10b 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,7 @@ app.*.map.json /dist/*.apk /dist/*.exe /dist/*.zip +/dist/*.xcarchive /bind/apple/Libbox.xcframework /bind/android /bind/windows diff --git a/lib/main.dart b/lib/main.dart index a6d9f6d..ca3b3dd 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -81,19 +81,28 @@ Future run(List args) async { startFailedReason = StartFailedReason.invalidProfile; break; } + String version = await AppUtils.getPackgetVersion(); + if (AppUtils.getBuildinVersion() != version) { + startFailedReason = StartFailedReason.invalidVersion; + break; + } + String exePath = Platform.resolvedExecutable.toUpperCase(); + if (PlatformUtils.isPC()) { + if (path.basename(exePath).toLowerCase() != + AppUtils.getKaringExe().toLowerCase()) { + startFailedReason = StartFailedReason.invalidProcess; + break; + } + } if (Platform.isWindows) { var tmp = await getTemporaryDirectory(); - String exePath = Platform.resolvedExecutable.toUpperCase(); if (exePath.contains("UNC/") || exePath.contains("UNC\\") || exePath.startsWith(tmp.absolute.path.toUpperCase())) { startFailedReason = StartFailedReason.invalidInstallPath; break; } - if (path.basename(exePath).toLowerCase() != AppUtils.getKaringExe()) { - startFailedReason = StartFailedReason.invalidProcess; - break; - } + if (VersionHelper.instance.majorVersion != 0 && VersionHelper.instance.majorVersion < 10) { startFailedReason = StartFailedReason.systemVersionLow; @@ -109,11 +118,6 @@ Future run(List args) async { break; } } - String version = await AppUtils.getPackgetVersion(); - if (AppUtils.getBuildinVersion() != version) { - startFailedReason = StartFailedReason.invalidVersion; - break; - } } while (false); } catch (err, stacktrace) { startFailedReason = StartFailedReason.exception; diff --git a/lib/screens/diversion_group_custom_edit_screen.dart b/lib/screens/diversion_group_custom_edit_screen.dart index c61467f..fa7897a 100644 --- a/lib/screens/diversion_group_custom_edit_screen.dart +++ b/lib/screens/diversion_group_custom_edit_screen.dart @@ -4,6 +4,7 @@ import 'package:android_package_manager/android_package_manager.dart'; import 'package:flutter/material.dart'; import 'package:karing/app/modules/server_manager.dart'; import 'package:karing/app/utils/network_utils.dart'; +import 'package:karing/app/utils/platform_utils.dart'; import 'package:karing/app/utils/proxy_conf_utils.dart'; import 'package:karing/app/utils/ruleset_codes_utils.dart'; import 'package:karing/i18n/strings.g.dart'; @@ -253,7 +254,7 @@ class _DiversionGroupCustomEditScreenState } } } - if (Platform.isWindows) { + if (PlatformUtils.isPC()) { if (widget.options.processName != null) { if (group.processName.isNotEmpty) { _textControllerLinkProcessName.text = group.processName.join("\n"); @@ -266,6 +267,7 @@ class _DiversionGroupCustomEditScreenState _textControllerLinkProcessName.text += "\n"; } } + if (widget.options.processPath != null) { if (group.processPath.isNotEmpty) { _textControllerLinkProcessPath.text = group.processPath.join("\n"); @@ -443,26 +445,29 @@ class _DiversionGroupCustomEditScreenState _listViewParts.add(item); } } - if (Platform.isWindows) { + if (PlatformUtils.isPC()) { if (widget.options.processName != null) { ListViewMultiPartsItem item = ListViewMultiPartsItem(); item.creator = (data, index, bindNO) { final tcontext = Translations.of(context); - + String processName = Platform.isWindows + ? "Telegram.exe\nchrome.com" + : "Google Chrome Helper\nCode Helper"; return createTextField(_textControllerLinkProcessName, - tcontext.processName, "Telegram.exe\nchrome.com"); + tcontext.processName, processName); }; _listViewParts.add(item); } + if (widget.options.processPath != null) { ListViewMultiPartsItem item = ListViewMultiPartsItem(); item.creator = (data, index, bindNO) { final tcontext = Translations.of(context); - - return createTextField( - _textControllerLinkProcessPath, - tcontext.processPath, - "C:\\Program Files (x86)\\Telegram Desktop\\Telegram.exe\nC:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"); + String processPath = Platform.isWindows + ? "C:\\Program Files (x86)\\Telegram Desktop\\Telegram.exe\nC:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" + : "/Applications/Google Chrome.app/Contents/Frameworks/Google Chrome Framework.framework/Versions/130.0.6723.92/Helpers/Google Chrome Helper.app/Contents/MacOS/Google Chrome Helper\n/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper"; + return createTextField(_textControllerLinkProcessPath, + tcontext.processPath, processPath); }; _listViewParts.add(item); } @@ -848,11 +853,12 @@ class _DiversionGroupCustomEditScreenState newGroup.package = convertToList(_textControllerLinkPackage.text); } } - if (Platform.isWindows) { + if (PlatformUtils.isPC()) { if (widget.options.processName != null) { newGroup.processName = convertToList(_textControllerLinkProcessName.text); } + if (widget.options.processPath != null) { newGroup.processPath = convertToList(_textControllerLinkProcessPath.text); diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart index a4bd26e..07b9a1d 100644 --- a/lib/screens/home_screen.dart +++ b/lib/screens/home_screen.dart @@ -292,7 +292,6 @@ class _HomeScreenState extends LasyRenderingState String errorPath = await PathUtils.serviceStdErrorFilePath(); String? content = await FileUtils.readAndDelete(errorPath); if (content != null && content.isNotEmpty) { - content = content.replaceAll("sing-box", ""); if (!content.contains("Config expired, Please start from app")) { AnalyticsUtils.logEvent( analyticsEventType: analyticsEventTypeApp, diff --git a/lib/screens/launch_failed_screen.dart b/lib/screens/launch_failed_screen.dart index be326bf..fda956d 100644 --- a/lib/screens/launch_failed_screen.dart +++ b/lib/screens/launch_failed_screen.dart @@ -87,7 +87,9 @@ class _LaunchFailedScreenState extends LasyRenderingState { final tcontext = Translations.of(context); String host = RemoteConfigManager.getConfig().host; String error = ""; - if (widget.startFailedReason == StartFailedReason.invalidProfile) { + if (widget.startFailedReason == StartFailedReason.invalidProcess) { + error = tcontext.LaunchFailedScreen.invalidProcess; + } else if (widget.startFailedReason == StartFailedReason.invalidProfile) { error = tcontext.LaunchFailedScreen.invalidProfile; } else if (widget.startFailedReason == StartFailedReason.invalidVersion) { error = tcontext.LaunchFailedScreen.invalidVersion; diff --git a/lib/screens/net_connections_screen.dart b/lib/screens/net_connections_screen.dart index a6ee1ac..98192c6 100644 --- a/lib/screens/net_connections_screen.dart +++ b/lib/screens/net_connections_screen.dart @@ -9,6 +9,7 @@ import 'package:flutter/services.dart'; import 'package:karing/app/modules/remote_config_manager.dart'; import 'package:karing/app/modules/server_manager.dart'; import 'package:karing/app/utils/app_utils.dart'; +import 'package:karing/app/utils/platform_utils.dart'; import 'package:karing/app/utils/proxy_conf_utils.dart'; import 'package:karing/app/utils/singbox_config_builder.dart'; import 'package:karing/i18n/strings.g.dart'; @@ -220,6 +221,19 @@ class NetConnectionState { return process; } + + String getMacosAppName() { + if (!Platform.isMacOS) { + return ""; + } + List parts = process.split("/"); + for (var part in parts) { + if (part.endsWith(".app")) { + return part.replaceAll(".app", ""); + } + } + return ""; + } } class NetConnectionsScreen extends LasyRenderingStatefulWidget { @@ -646,7 +660,12 @@ class _NetConnectionsScreenState padding * 2 * 2 - arrow_forward_ios_rounded; double height = 90; - if (current.showProcess.isNotEmpty) { + String processName = current.showProcess; + if (processName.isNotEmpty) { + String appName = current.getMacosAppName(); + if (appName.isNotEmpty) { + processName = "$appName[$processName]"; + } height += 18; } if (current.package.isNotEmpty) { @@ -656,6 +675,7 @@ class _NetConnectionsScreenState current.getUpload() - current.getLastUpload()); String lastDownload = ProxyConfUtils.convertTrafficToStringDouble( current.getDownload() - current.getLastDownload()); + return Container( margin: const EdgeInsets.only(bottom: 1), child: Material( @@ -739,10 +759,11 @@ class _NetConnectionsScreenState ), ), ]), - current.showProcess.isNotEmpty + processName.isNotEmpty ? Row(children: [ Text( - current.showProcess, + processName, + overflow: TextOverflow.ellipsis, style: const TextStyle( fontSize: 12, ), @@ -753,6 +774,7 @@ class _NetConnectionsScreenState ? Row(children: [ Text( current.package, + overflow: TextOverflow.ellipsis, style: const TextStyle( fontSize: 12, ), @@ -1109,8 +1131,9 @@ class _NetConnectionsScreenState DiversionGroupCustomScreen(options: options))); }))); } - if (Platform.isWindows && current.process.isNotEmpty) { + if (PlatformUtils.isPC() && current.process.isNotEmpty) { String processName = current.getProcessName(); + options.add(GroupItemOptions( pushOptions: GroupItemPushOptions( name: tcontext.processName, @@ -1172,11 +1195,13 @@ class _NetConnectionsScreenState return true; } } - if (Platform.isWindows) { - if (current.getProcessName() == AppUtils.getKaringExe()) { + if (PlatformUtils.isPC()) { + if (current.process.toLowerCase() == + Platform.resolvedExecutable.toLowerCase()) { return true; } } + if (Platform.isAndroid) { if (current.package == AppUtils.getId()) { return true; @@ -1198,9 +1223,7 @@ class _NetConnectionsScreenState break; } } - var sortMethod = Platform.isIOS || Platform.isMacOS - ? sortCompareHost - : sortCompareProcess; + var sortMethod = Platform.isIOS ? sortCompareHost : sortCompareProcess; if (index != -1) { var nlc = list.take(index + 1).toList(); var nlnc = list.skip(index + 1).toList(); diff --git a/pubspec.yaml b/pubspec.yaml index aabb3fd..44ba4ff 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,7 +17,7 @@ publish_to: none # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.35+461 +version: 1.0.35+467 environment: sdk: ">=3.2.3 <4.0.0" @@ -53,6 +53,9 @@ dependencies: class_to_string: ^1.0.0 ffi: ^2.1.3 url_launcher: ^6.3.1 + #webview_flutter: ^4.10.0 + #webview_win_floating: ^2.2.9 + #flutter_inappwebview: ^6.1.5 web_socket_channel: ^2.4.0 #flutter_test #sqlite3_flutter_libs: ^0.5.17 #sqlite_async: ^0.5.2