Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
GooRingX committed Nov 25, 2024
1 parent 83f0628 commit 01a7718
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ app.*.map.json
/dist/*.apk
/dist/*.exe
/dist/*.zip
/dist/*.xcarchive
/bind/apple/Libbox.xcframework
/bind/android
/bind/windows
Expand Down
24 changes: 14 additions & 10 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,28 @@ Future<void> run(List<String> 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;
Expand All @@ -109,11 +118,6 @@ Future<void> run(List<String> args) async {
break;
}
}
String version = await AppUtils.getPackgetVersion();
if (AppUtils.getBuildinVersion() != version) {
startFailedReason = StartFailedReason.invalidVersion;
break;
}
} while (false);
} catch (err, stacktrace) {
startFailedReason = StartFailedReason.exception;
Expand Down
26 changes: 16 additions & 10 deletions lib/screens/diversion_group_custom_edit_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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");
Expand All @@ -266,6 +267,7 @@ class _DiversionGroupCustomEditScreenState
_textControllerLinkProcessName.text += "\n";
}
}

if (widget.options.processPath != null) {
if (group.processPath.isNotEmpty) {
_textControllerLinkProcessPath.text = group.processPath.join("\n");
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ class _HomeScreenState extends LasyRenderingState<HomeScreen>
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,
Expand Down
4 changes: 3 additions & 1 deletion lib/screens/launch_failed_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ class _LaunchFailedScreenState extends LasyRenderingState<LaunchFailedScreen> {
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;
Expand Down
41 changes: 32 additions & 9 deletions lib/screens/net_connections_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -220,6 +221,19 @@ class NetConnectionState {

return process;
}

String getMacosAppName() {
if (!Platform.isMacOS) {
return "";
}
List<String> parts = process.split("/");
for (var part in parts) {
if (part.endsWith(".app")) {
return part.replaceAll(".app", "");
}
}
return "";
}
}

class NetConnectionsScreen extends LasyRenderingStatefulWidget {
Expand Down Expand Up @@ -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) {
Expand All @@ -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(
Expand Down Expand Up @@ -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,
),
Expand All @@ -753,6 +774,7 @@ class _NetConnectionsScreenState
? Row(children: [
Text(
current.package,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 12,
),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 01a7718

Please sign in to comment.