Skip to content

Commit

Permalink
[+]proxies list
Browse files Browse the repository at this point in the history
  • Loading branch information
Muska-Ami committed Dec 19, 2023
1 parent c287ba7 commit 9590f90
Show file tree
Hide file tree
Showing 14 changed files with 230 additions and 48 deletions.
4 changes: 2 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ linter:
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
# avoid_print: false # Uncomment to disable the `avoid_print` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
7 changes: 4 additions & 3 deletions lib/controller/dsetting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ class DSettingController extends GetxController {
}

//Future<FrpcList> _getList() async {
//final ct = CancelToken();
//await FrpcDownloadDio()(arch: 'amd64', platform: 'windows', progressCallback: () {}, cancelToken: ct);
//final ct = CancelToken();
//await FrpcDownloadDio()(arch: 'amd64', platform: 'windows', progressCallback: () {}, cancelToken: ct);
//}

DropdownMenuItem _buildDMIWidget({required String version, required int value}) {
DropdownMenuItem _buildDMIWidget(
{required String version, required int value}) {
return DropdownMenuItem(
child: Text(version),
value: value,
Expand Down
3 changes: 1 addition & 2 deletions lib/controller/frpc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class FrpcController extends GetxController {

load() async {
exist.value = await file().exists();

}

/// 获取Frpc文件对象
Expand All @@ -27,4 +26,4 @@ class FrpcController extends GetxController {
String path = await _support_path + "/frpc/frpc_info.json";
return await File(path).readAsString();
}
}
}
76 changes: 72 additions & 4 deletions lib/controller/proxies.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,83 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:nyalcf/dio/proxies/get.dart';
import 'package:nyalcf/model/ProxyInfo.dart';

import 'frpc.dart';

class ProxiesController extends GetxController {
final FrpcController f_c = Get.find();
var proxiesListWidgets = <DataRow>[
DataRow(cells: <DataCell>[
DataCell(Text("加载中喵喵喵?")),
DataCell(Text("加载中喵喵喵?")),
DataCell(Text("加载中喵喵喵?")),
DataCell(Text("加载中喵喵喵?"))
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text("-")),
])
].obs;

load() {}
load(username, token) async {
var proxies = await ProxiesGetDio().get(username, token);
if (proxies is List<ProxyInfo>) {
List<DataRow> widgets = <DataRow>[];
proxies.forEach((element) => widgets.add(DataRow(cells: <DataCell>[
DataCell(
Container(
width: 150.0,
height: 30.0,
child: SelectableText(element.proxy_name),
),
),
DataCell(SelectableText(element.id.toString())),
DataCell(SelectableText(element.node.toString())),
DataCell(SelectableText(element.proxy_type)),
DataCell(SelectableText(element.local_ip)),
DataCell(
SelectableText("${element.local_port} -> ${element.remote_port}"),
),
DataCell(
Row(
children: [
IconButton(
icon: Icon(Icons.play_circle),
onPressed: () {
Process.run("cmd.exe", ["start", "cmd.exe"]);
},
),
IconButton(
icon: Icon(Icons.edit),
onPressed: () {
Get.snackbar("谁让你点了?", "还没写,爬去面板编辑喵喵喵!");
},
),
],
),
),
])));
proxiesListWidgets.value = widgets;
} else {
proxiesListWidgets.value = <DataRow>[
DataRow(cells: <DataCell>[
DataCell(Text("获取失败,请尝试刷新一下~")),
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text("-")),
DataCell(Text("-")),
])
];
Get.snackbar(
"发生错误",
"无法获取隧道列表信息: ${proxies}",
snackPosition: SnackPosition.BOTTOM,
animationDuration: Duration(milliseconds: 300),
);
}
}
}
12 changes: 6 additions & 6 deletions lib/controller/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import 'package:nyalcf/model/User.dart';
class UserController extends GetxController {
var user = "".obs;
var email = "".obs;
var token = "".obs;
var avatar = "https://cravatar.cn/avatar/".obs;
var token = ''.obs;
var avatar = 'https://cravatar.cn/avatar/'.obs;
var inbound = 0.obs;
var outbound = 0.obs;
var frp_token = "".obs;
var frp_token = ''.obs;

var welcomeText = "好".obs;
var welcomeText = '好'.obs;

load() async {
User userinfo = await InfoCache.getInfo();
Expand All @@ -26,9 +26,9 @@ class UserController extends GetxController {
int hour = DateTime.now().hour;

if (hour <= 12) {
welcomeText.value = "上午好";
welcomeText.value = '上午好';
} else {
welcomeText.value = "下午好";
welcomeText.value = '下午好';
}
}
}
49 changes: 48 additions & 1 deletion lib/dio/proxies/get.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,54 @@
import 'package:dio/dio.dart';
import 'package:nyalcf/dio/basicConfig.dart';
import 'package:nyalcf/model/ProxyInfo.dart';

class ProxiesGetDio {
final dio = Dio();

Future<dynamic> get() async {}
Future<dynamic> get(username, token) async {
try {
Map<String, dynamic> params_map = Map();
params_map['username'] = username;

Options options = Options();
Map<String, dynamic> options_map = Map();
options_map['Content-Type'] =
'application/x-www-form-urlencoded;charset=UTF-8';
options_map['Authorization'] = 'Bearer $token';
options = options.copyWith(headers: options_map);

//print(options.headers?.keys);

var response = await dio.get(
"${basicConfig.api_v2_url}/proxies/getlist",
queryParameters: params_map,
options: options,
);
Map<String, dynamic> resJson = response.data;
Map<String, dynamic> resData = resJson['data'];
print(resData['proxies']);
List<Map<String, dynamic>> proxies = List.from(resData['proxies']);
List<ProxyInfo> list = <ProxyInfo>[];
proxies.forEach((element) {
list.add(ProxyInfo(
proxy_name: element['proxy_name'],
use_compression: bool.parse(element['use_compression']),
local_ip: element['local_ip'],
node: element['node'],
local_port: element['local_port'],
remote_port: int.parse(element['remote_port']),
domain: element['domain'],
icp: element['icp'],
sk: element['sk'],
id: element['id'],
proxy_type: element['proxy_type'],
use_encryption: bool.parse(element['use_encryption']),
status: element['status']));
});
return list;
} catch (e) {
print(e);
return e;
}
}
}
8 changes: 4 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class App extends StatelessWidget {
theme: ThemeData(
useMaterial3: true,
fontFamily: 'HarmonyOS Sans',
colorScheme: ColorScheme.fromSeed(seedColor: Colors.pink.shade300).copyWith(
primary: Colors.pink.shade500,
secondary: Colors.pink.shade400
)));
colorScheme: ColorScheme.fromSeed(seedColor: Colors.pink.shade300)
.copyWith(
primary: Colors.pink.shade500,
secondary: Colors.pink.shade400)));
}
}
30 changes: 30 additions & 0 deletions lib/model/ProxyInfo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class ProxyInfo {
ProxyInfo(
{required this.proxy_name,
required this.use_compression,
required this.local_ip,
required this.node,
required this.local_port,
required this.remote_port,
required this.domain,
required this.icp,
required this.sk,
required this.id,
required this.proxy_type,
required this.use_encryption,
required this.status});

final String proxy_name;
final bool use_compression;
final String local_ip;
final int node;
final int local_port;
final int remote_port;
final String domain;
final String? icp;
final String sk;
final int id;
final String proxy_type;
final bool use_encryption;
final status;
}
45 changes: 30 additions & 15 deletions lib/ui/auth/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,47 @@ class _LoginState extends State<Login> {

_login() async {
if (userController.text == "") {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('请输入用户名'),
));
Get.snackbar(
"无效数据",
'请输入用户名',
snackPosition: SnackPosition.BOTTOM,
animationDuration: Duration(milliseconds: 300),
);
} else if (passwordController.text == "") {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('请输入密码'),
));
Get.snackbar(
"无效数据",
'请输入密码',
snackPosition: SnackPosition.BOTTOM,
animationDuration: Duration(milliseconds: 300),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('正在登录...'),
));
Get.snackbar(
"登录中",
'正在请求...',
snackPosition: SnackPosition.BOTTOM,
animationDuration: Duration(milliseconds: 300),
);
final res = await LoginDio()
.requestLogin(userController.text, passwordController.text);
if (res is User) {
//UserInfoCache.info = res;
//print(UserInfoCache.info);
await InfoCache.setInfo(res);
InfoCache.saveToFile();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('登录成功,欢迎您 ${res.user}'),
));
Get.snackbar(
"登录成功",
"欢迎您,指挥官 ${res.user}",
snackPosition: SnackPosition.BOTTOM,
animationDuration: Duration(milliseconds: 300),
);
Get.toNamed("/panel/home");
} else {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('登陆失败:${res}'),
));
Get.snackbar(
'登陆失败',
res,
snackPosition: SnackPosition.BOTTOM,
animationDuration: Duration(milliseconds: 300),
);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/ui/home.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:nyalcf/controller/frpc.dart';
import 'package:nyalcf/ui/model/FloatingActionButton.dart';

import 'model/AppbarActions.dart';

class Home extends StatelessWidget {
const Home({super.key, required this.title});
Home({super.key, required this.title});

final String title;
final FrpcController f_c = Get.put(FrpcController());

@override
Widget build(BuildContext context) {
Expand All @@ -27,9 +29,7 @@ class Home extends StatelessWidget {
"欢迎使用Nya LoCyanFrp! Launcher",
style: TextStyle(fontSize: 30),
),
const Text(
"にゃ~にゃ~,请选择一项操作"
),
const Text("にゃ~にゃ~,请选择一项操作"),
Container(
margin: const EdgeInsets.all(20.0),
child: Row(
Expand Down
13 changes: 12 additions & 1 deletion lib/ui/panel/console.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:nyalcf/controller/user.dart';
import 'package:nyalcf/ui/model/AppbarActions.dart';
import 'package:nyalcf/ui/model/Drawer.dart';
import 'package:nyalcf/ui/model/FloatingActionButton.dart';
import 'package:url_launcher/url_launcher.dart';

class PanelConsole extends StatelessWidget {
PanelConsole({super.key, required this.title});
Expand All @@ -30,7 +31,17 @@ class PanelConsole extends StatelessWidget {
.actions(),
),
drawer: DrawerX(context: context).drawer(),
body: ListView(children: []),
body: Center(
child: ListView(children: [
Text("这里还什么都没有,不过你可以为这里贡献一下ww~"),
ElevatedButton(
onPressed: () {
launchUrl(Uri.parse("https://github.com/Muska-Ami/NyaLCF"));
},
child: SelectableText("https://github.com/Muska-Ami/NyaLCF"),
),
]),
),
floatingActionButton: FloatingActionButtonX().button());
}
}
Loading

0 comments on commit 9590f90

Please sign in to comment.