alroyso 1 yıl önce
ebeveyn
işleme
8649058673

+ 23 - 0
Makefile

@@ -0,0 +1,23 @@
+BUILD_DMG=flutter_distributor package --platform macos --targets dmg
+BUILD_EXE=flutter_distributor package --platform windows --targets exe
+
+init-arm64:
+	flutter pub get
+	dart run --define=OS_ARCH=arm64 ./scripts/init.dart
+
+init-amd64:
+	flutter pub get
+	dart run --define=OS_ARCH=amd64 ./scripts/init.dart
+
+
+build-darwin-arm64:
+	${BUILD_DMG} --build-dart-define=OS_ARCH=arm64
+
+build-darwin-amd64:
+	${BUILD_DMG} --build-dart-define=OS_ARCH=amd64
+
+build-windows-arm64:
+	${BUILD_EXE} --build-dart-define=OS_ARCH=arm64
+
+build-windows-amd64:
+	${BUILD_EXE} --build-dart-define=OS_ARCH=amd64

+ 3 - 3
lib/app/const/const.dart

@@ -11,7 +11,7 @@ class ClashName {
   }
 
   static String get arch {
-    return const String.fromEnvironment('OS_ARCH', defaultValue: 'amd64');
+    return const String.fromEnvironment('OS_ARCH', defaultValue: 'arm64'); //amd64
   }
 
   static String get ext {
@@ -41,7 +41,7 @@ class Paths {
   }
 
   static Directory get config {
-    return Directory(path.join(userHomePath, '.config', 'naiyou'));
+    return Directory(path.join(userHomePath, '.config', 'ccore'));
   }
 }
 
@@ -51,7 +51,7 @@ class Files {
   }
 
   static File get assetsClashService {
-    return File(path.join(Paths.assetsBin.path, 'naiyou-service-${ClashName.platform}-${ClashName.arch}${ClashName.ext}'));
+    return File(path.join(Paths.assetsBin.path, 'ccore-service-${ClashName.platform}-${ClashName.arch}${ClashName.ext}'));
   }
 
   static File get assetsCountryMmdb {

+ 1 - 0
lib/app/controller/config.dart

@@ -53,6 +53,7 @@ class ConfigController extends GetxController {
       config.value.subs.add(ConfigSub(name: 'example.yaml', url: '', updateTime: 0));
       config.value.selected = 'example.yaml';
     }
+    await save();
     await readClashCoreApi();
   }
 

+ 4 - 3
lib/app/controller/service.dart

@@ -21,7 +21,7 @@ import 'package:web_socket_channel/io.dart';
 
 
 
-final headers = {"User-Agent": "naiyou-for-flutter/0.0.1"};
+final headers = {"User-Agent": "ccore-for-flutter/0.0.1"};
 
 class ServiceController extends GetxController {
   late final dio ;
@@ -43,7 +43,8 @@ class ServiceController extends GetxController {
   ServiceController();
 
   Future<void> startService() async {
-    servicePort.value = await getFreePort();
+    servicePort.value = controllers.config.config.value.port;
+    print('http://127.0.0.1:${servicePort.value}');
     dio = Dio(BaseOptions(baseUrl: 'http://127.0.0.1:${servicePort.value}', headers: headers));
 
 
@@ -143,7 +144,7 @@ class ServiceController extends GetxController {
     }
 
     IOWebSocketChannel fetchLogWs() {
-      return IOWebSocketChannel.connect(Uri.parse('ws://127.0.0.1:9089/logs'), headers: headers);
+      return IOWebSocketChannel.connect(Uri.parse('ws://127.0.0.1:${servicePort.value}/logs'), headers: headers);
     }
 
     Future<void> fetchStart(String name) async {

+ 7 - 1
lib/main.dart

@@ -7,6 +7,7 @@ import 'package:bot_toast/bot_toast.dart';
 import 'package:dart_json_mapper/dart_json_mapper.dart';
 import 'package:flutter/foundation.dart';
 import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
 
 import 'package:get/get.dart';
 import 'package:kommon/tool/sp_util.dart';
@@ -101,7 +102,12 @@ Future<void> initWindow() async {
 
 Future<void> initAppService() async {
   await SpUtil.getInstance();
-
+  // var ach = await MethodChannel('app.channel.shared.data');
+  // if (ach == "arm64"){
+  //
+  // } else {
+  //
+  // }
 }
 
 Future<void> initAppTray(

+ 1 - 1
macos/Podfile.lock

@@ -94,4 +94,4 @@ SPEC CHECKSUMS:
 
 PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367
 
-COCOAPODS: 1.13.0
+COCOAPODS: 1.12.1

+ 0 - 1
macos/Runner/AppDelegate.swift

@@ -21,5 +21,4 @@ class AppDelegate: FlutterAppDelegate {
 //       }
 //       return true
 //     }
-
 }

+ 77 - 27
scripts/init.dart

@@ -17,21 +17,22 @@ Future downloadLatestClashCore() async {
   final version = "v1.16.0";
   final String clashCoreName = 'clash.meta-${ClashName.platform}-${ClashName.arch}-cgo-$version';
   print(clashCoreName);
-  final info = await dio.get('https://api.github.com/repos/MetaCubeX/Clash.Meta/releases');
-  final Map<String, dynamic> latest = (info.data['assets'] as List<dynamic>).firstWhere((it) => (it['name'] as String).contains(clashCoreName));
-
-  final String name = latest['name'];
+  // final info = await dio.get('https://api.github.com/repos/MetaCubeX/Clash.Meta/releases');
+  // final Map<String, dynamic> latest = (info.data['assets'] as List<dynamic>).firstWhere((it) => (it['name'] as String).contains(clashCoreName));
+  //
+  final String newName = 'clash-${ClashName.platform}-${ClashName.arch}';
+  final String name = "$clashCoreName.gz";
   final tempFile = File(path.join(binDir.path, '$name.temp'));
-
+//https://github.com/MetaCubeX/Clash.Meta/releases/download/v1.16.0/clash.meta-linux-amd64-cgo-v1.16.0.gz
   print('Downloading $name');
-  await dio.download(latest['browser_download_url'], tempFile.path);
+  await dio.download("https://github.com/MetaCubeX/Clash.Meta/releases/download/v1.16.0/$name", tempFile.path);
   print('Download Success');
 
   print('Unarchiving $name');
   final tempBetys = await tempFile.readAsBytes();
   if (name.contains('.gz')) {
     final bytes = GZipDecoder().decodeBytes(tempBetys);
-    final String filePath = path.join(binDir.path, clashCoreName);
+    final String filePath = path.join(binDir.path, newName);
     await File(filePath).writeAsBytes(bytes);
     await Process.run('chmod', ['+x', filePath]);
   } else {
@@ -41,31 +42,80 @@ Future downloadLatestClashCore() async {
   await tempFile.delete();
   print('Unarchiv Success');
 }
-
-Future downloadLatestClashService() async {
-  final String serviceName = 'clash-for-flutter-service-${ClashName.platform}-${ClashName.arch}';
-  final info = await dio.get('https://api.github.com/repos/csj8520/clash-for-flutter-service/releases/latest');
-  final Map<String, dynamic> latest = (info.data['assets'] as List<dynamic>).firstWhere((it) => (it['name'] as String).contains(serviceName));
-
-  final String name = latest['name'];
-  final tempFile = File(path.join(binDir.path, '$name.temp'));
-
-  print('Downloading $name');
-  await dio.download(latest['browser_download_url'], tempFile.path);
+Future<void> downloadAndUnarchiveService() async {
+ // const String token = "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"; // 请确保不在公共代码中硬编码这个token
+
+  final serviceName = 'ccore-service-${ClashName.platform}-${ClashName.arch}';
+  // "name" -> "ccore-service-darwin-amd64-v1.0.0.gz"
+  //final newSericeName = "$serviceName-v1.0.0.gz";
+  // 获取GitHub release信息
+ // dio.options.headers["Authorization"] = "token $token";
+  final response = await dio.get('https://api.github.com/repos/alroyso/core-service/releases/latest');
+  final Map<String, dynamic> latest = (response.data['assets'] as List<dynamic>)
+      .firstWhere((it) => (it['name'] as String).contains(serviceName));
+
+  final downloadUrl = latest['browser_download_url'];
+
+  print('Downloading $downloadUrl');
+
+  final tempFile = File(path.join(binDir.path, '${latest['name']}.temp'));
+  try
+  {
+    print(dio.options.headers);
+    await dio.download(downloadUrl, tempFile.path);
+  } catch (e){
+    print(e);
+    return;
+  }
   print('Download Success');
+  print('Unarchiving ${latest['name']}');
 
-  print('Unarchiving $name');
-  final tempBetys = await tempFile.readAsBytes();
-  if (name.contains('.gz')) {
-    final bytes = GZipDecoder().decodeBytes(tempBetys);
-    final String filePath = path.join(binDir.path, serviceName);
-    await File(filePath).writeAsBytes(bytes);
-    await Process.run('chmod', ['+x', filePath]);
+  final tempBytes = await tempFile.readAsBytes();
+
+  if (latest['name'].contains('.gz')) {
+    final bytes = GZipDecoder().decodeBytes(tempBytes);
+    await File(path.join(binDir.path, serviceName)).writeAsBytes(bytes);
   } else {
-    final file = ZipDecoder().decodeBytes(tempBetys).first;
+    final file = ZipDecoder().decodeBytes(tempBytes).first;
     await File(path.join(binDir.path, file.name)).writeAsBytes(file.content);
   }
+
+  final filePath = path.join(binDir.path, serviceName);
+  await Process.run('chmod', ['+x', filePath]);
+
   await tempFile.delete();
+
+  print('Unarchive Success');
+}
+
+Future downloadLatestClashService() async {
+    final String serviceName = 'ccore-service-${ClashName.platform}-${ClashName.arch}';
+  // // final info = await dio.get('https://api.github.com/repos/alroyso/clash-for-flutter-service/releases/latest');
+  // // final Map<String, dynamic> latest = (info.data['assets'] as List<dynamic>).firstWhere((it) => (it['name'] as String).contains(serviceName));
+  // //https://github.com/alroyso/clash-for-flutter-service/releases/download/untagged-8273cca760b55d0725ab/naiyou-service-darwin-arm64-v1.0.1.gz
+  // var verion = 'v1.0.1';
+  // final String name = 'naiyou-service-${ClashName.platform}-${ClashName.arch}-$verion.gz';
+  // final tempFile = File(path.join(binDir.path, '$name.temp'));
+  // var url = "https://github.com/alroyso/clash-for-flutter-service/releases/tag/untagged-8273cca760b55d0725ab";
+  // print('Downloading $url/$name');
+  // dio.options.headers["Authorization"] = "token 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";
+  // await dio.download('$url/$name', tempFile.path);
+  // print('Download Success');
+  //
+  // print('Unarchiving $name');
+  // final tempBetys = await tempFile.readAsBytes();
+  // if (name.contains('.gz')) {
+  //   final bytes = GZipDecoder().decodeBytes(tempBetys);
+  //   final String filePath = path.join(binDir.path, serviceName);
+  //   await File(filePath).writeAsBytes(bytes);
+  //   await Process.run('chmod', ['+x', filePath]);
+  // } else {
+  //   final file = ZipDecoder().decodeBytes(tempBetys).first;
+  //   await File(path.join(binDir.path, file.name)).writeAsBytes(file.content);
+  // }
+  final String filePath = path.join(binDir.path, serviceName);
+  await Process.run('chmod', ['+x', filePath]);
+  //await tempFile.delete();
   print('Unarchiv Success');
 }
 
@@ -94,7 +144,7 @@ void main() async {
   if (!(await depDir.exists())) await depDir.create();
 
   await downloadLatestClashCore();
-  // await downloadLatestClashService();
+  await downloadAndUnarchiveService();
 
   await downloadCountryMmdb();
   if (Platform.isWindows) await downloadWintun();