Skip to content

Commit

Permalink
手机端请求收藏&请求编辑发送直接查看响应体
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghongenpin committed Aug 26, 2023
1 parent cfd23cd commit 4154bda
Show file tree
Hide file tree
Showing 12 changed files with 437 additions and 135 deletions.
12 changes: 3 additions & 9 deletions lib/network/bin/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ class Configuration {
//是否设置系统代理
bool enableSystemProxy = true;

//是否引导
bool guide = false;

//是否显示更新内容公告
bool upgradeNotice = true;
bool upgradeNoticeV2 = true;

//请求重写
RequestRewrites requestRewrites = RequestRewrites.instance;
Expand Down Expand Up @@ -112,7 +109,6 @@ class Configuration {
var file = await configFile();
var exits = await file.exists();
if (!exits) {
guide = true;
return;
}

Expand All @@ -121,8 +117,7 @@ class Configuration {
port = config['port'] ?? port;
enableSsl = config['enableSsl'] == true;
enableSystemProxy = config['enableSystemProxy'] ?? (config['enableDesktop'] ?? true);
guide = config['guide'] ?? false;
upgradeNotice = config['upgradeNotice'] ?? true;
upgradeNoticeV2 = config['upgradeNoticeV2'] ?? true;
if (config['externalProxy'] != null) {
externalProxy = ProxyInfo.fromJson(config['externalProxy']);
}
Expand Down Expand Up @@ -163,8 +158,7 @@ class Configuration {

Map<String, dynamic> toJson() {
return {
'guide': guide,
'upgradeNotice': upgradeNotice,
'upgradeNoticeV2': upgradeNoticeV2,
'port': port,
'enableSsl': enableSsl,
'enableSystemProxy': enableSystemProxy,
Expand Down
1 change: 0 additions & 1 deletion lib/network/http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class HttpClients {
var proxyTypes = request.uri.startsWith("https://") ? ProxyTypes.https : ProxyTypes.http;
proxyInfo = await SystemProxy.getSystemProxy(proxyTypes);
}
print(proxyInfo);
var httpResponseHandler = HttpResponseHandler();

HostAndPort hostPort = HostAndPort.of(request.uri);
Expand Down
23 changes: 13 additions & 10 deletions lib/ui/desktop/desktop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class _DesktopHomePagePageState extends State<DesktopHomePage> implements EventL
proxyServer = ProxyServer(widget.configuration, listener: this);
panel = NetworkTabController(tabStyle: const TextStyle(fontSize: 18), proxyServer: proxyServer);

if (widget.configuration.guide) {
if (widget.configuration.upgradeNoticeV2) {
WidgetsBinding.instance.addPostFrameCallback((_) {
guideDialog();
showUpgradeNotice();
});
}
}
Expand Down Expand Up @@ -112,30 +112,33 @@ class _DesktopHomePagePageState extends State<DesktopHomePage> implements EventL
});
}

//首次引导
guideDialog() {
//更新引导
showUpgradeNotice() {
showDialog(
context: context,
barrierDismissible: false,
builder: (_) {
return AlertDialog(
scrollable: true,
actions: [
TextButton(
onPressed: () {
widget.configuration.guide = false;
widget.configuration.upgradeNoticeV2 = false;
widget.configuration.flushConfig();
Navigator.pop(context);
},
child: const Text('关闭'))
],
title: const Text('提示', style: TextStyle(fontSize: 18)),
title: const Text('更新内容V1.0.2', style: TextStyle(fontSize: 18)),
content: const Text(
'默认不会开启HTTPS抓包,请安装证书后再开启HTTPS抓包。\n'
'提示:默认不会开启HTTPS抓包,请安装证书后再开启HTTPS抓包。\n'
'点击的HTTPS抓包(加锁图标),选择安装根证书,按照提示操作即可。\n\n'
'新增更新:\n'
'1. 增加高级搜索,点击搜索Icon触发。\n'
'2. 显示SSL握手异常、建立连接异常、未知异常等请求。\n'
'3.响应体大时异步加载json,请求重写增加域名,修复手机扫码连接未开启代理时不转发问题',
'1.请求编辑发送可直接查看响应体,发送请求无需开启代理;\n'
'2. 详情增加快速请求重写, 复制cURL格式可直接导入Postman;\n'
'3. 增加请求收藏功能;\n'
'4. 主题增加Material3切换;\n'
'5. 请求删除&大响应体直接转发;',
style: TextStyle(fontSize: 14)));
});
}
Expand Down
4 changes: 4 additions & 0 deletions lib/ui/desktop/left/favorite.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class _FavoritesState extends State<Favorites> {
builder: (BuildContext context, AsyncSnapshot<Queue<HttpRequest>> snapshot) {
if (snapshot.hasData) {
var favorites = snapshot.data ?? Queue();
if (favorites.isEmpty) {
return const Center(child: Text("暂无收藏"));
}

return ListView.separated(
itemCount: favorites.length,
itemBuilder: (_, index) {
Expand Down
9 changes: 4 additions & 5 deletions lib/ui/desktop/left/request_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class RequestEditorState extends State<RequestEditor> {
@override
void dispose() {
RawKeyboard.instance.removeListener(onKeyEvent);
responseChange.dispose();
super.dispose();
}

Expand Down Expand Up @@ -123,11 +124,6 @@ class _HttpState extends State<_HttpWidget> {
final headerKey = GlobalKey<HeadersState>();
String? body;

@override
void initState() {
super.initState();
}

String? getBody() {
return body;
}
Expand Down Expand Up @@ -175,6 +171,9 @@ class _HttpState extends State<_HttpWidget> {
body = const JsonEncoder.withIndent(' ').convert(const JsonDecoder().convert(body!));
} catch (_) {}
}
if (widget.readOnly) {
return SelectableText(body ?? '');
}

return TextField(
autofocus: true,
Expand Down
43 changes: 23 additions & 20 deletions lib/ui/desktop/toolbar/setting/external_proxy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,29 @@ class _ExternalProxyDialogState extends State<ExternalProxyDialog> {
socket.destroy();
} on SocketException catch (_) {
setting = false;

await showDialog(
context: context,
builder: (_) => AlertDialog(
title: const Text("外部代理连接失败"),
content: const Text('网络不通所有接口将会访问失败,是否继续设置外部代理。', style: TextStyle(fontSize: 12)),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text("取消")),
TextButton(
onPressed: () {
setting = true;
Navigator.of(context).pop();
},
child: const Text("确定"))
],
));
if (context.mounted) {
await showDialog(
context: context,
builder: (_) =>
AlertDialog(
title: const Text("外部代理连接失败"),
content: const Text(
'网络不通所有接口将会访问失败,是否继续设置外部代理。', style: TextStyle(fontSize: 12)),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text("取消")),
TextButton(
onPressed: () {
setting = true;
Navigator.of(context).pop();
},
child: const Text("确定"))
],
));
}
}
}

Expand Down
20 changes: 14 additions & 6 deletions lib/ui/mobile/menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:network_proxy/network/util/host_filter.dart';
import 'package:network_proxy/ui/desktop/toolbar/setting/setting.dart';
import 'package:network_proxy/ui/desktop/toolbar/setting/theme.dart';
import 'package:network_proxy/ui/mobile/connect_remote.dart';
import 'package:network_proxy/ui/mobile/request/favorite.dart';
import 'package:network_proxy/ui/mobile/setting/app_whitelist.dart';
import 'package:network_proxy/ui/mobile/setting/filter.dart';
import 'package:network_proxy/ui/mobile/setting/request_rewrite.dart';
Expand All @@ -33,19 +34,26 @@ class DrawerWidget extends StatelessWidget {
children: [
DrawerHeader(
decoration: BoxDecoration(color: Theme.of(context).colorScheme.primaryContainer),
child: const Text('设置'),
child: const Text(''),
),
ListTile(
leading: const Icon(Icons.favorite),
title: const Text("收藏"),
trailing: const Icon(Icons.arrow_right),
onTap: () => navigator(context, MobileFavorites(proxyServer: proxyServer))),
const Divider(thickness: 0.3),
PortWidget(proxyServer: proxyServer),
ListTile(
title: const Text("HTTPS抓包"),
trailing: const Icon(Icons.arrow_right),
onTap: () => navigator(context, MobileSslWidget(proxyServer: proxyServer))),
const ThemeSetting(),
Platform.isIOS ? const SizedBox() :
ListTile(
title: const Text("应用白名单"),
trailing: const Icon(Icons.arrow_right),
onTap: () => navigator(context, AppWhitelist(proxyServer: proxyServer))),
Platform.isIOS
? const SizedBox()
: ListTile(
title: const Text("应用白名单"),
trailing: const Icon(Icons.arrow_right),
onTap: () => navigator(context, AppWhitelist(proxyServer: proxyServer))),
ListTile(
title: const Text("域名白名单"),
trailing: const Icon(Icons.arrow_right),
Expand Down
44 changes: 26 additions & 18 deletions lib/ui/mobile/mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ class MobileHomeState extends State<MobileHomePage> implements EventListener {
});

super.initState();

WidgetsBinding.instance.addPostFrameCallback((_) {
if (widget.configuration.upgradeNotice) {
if (widget.configuration.upgradeNoticeV2) {
WidgetsBinding.instance.addPostFrameCallback((_) {
showUpgradeNotice();
}
});
});
}
}

@override
Expand Down Expand Up @@ -106,11 +105,16 @@ class MobileHomeState extends State<MobileHomePage> implements EventListener {
}

showUpgradeNotice() {
String content = '1. 增加高级搜索,点击搜索icon触发。\n'
'2. 显示SSL握手异常、建立连接异常、未知异常等请求。\n'
'3.响应体大时异步加载json,请求重写增加域名,修复手机扫码连接未开启代理时不转发问题';
showAlertDialog('更新内容', content, () {
widget.configuration.upgradeNotice = false;
String content = '提示:默认不会开启HTTPS抓包,请安装证书后再开启HTTPS抓包。\n\n'
'新增更新:\n'
'1.请求编辑发送可直接查看响应体,发送请求无需开启代理;\n'
'2. 详情增加快速请求重写, 复制cURL格式可直接导入Postman;\n'
'3. 增加请求收藏功能;\n'
'4. 主题增加Material3切换;\n'
'5. 请求删除&大响应体直接转发;\n'
'6. 安卓应用白名单,调整请求展示列表;';
showAlertDialog('更新内容V1.0.2', content, () {
widget.configuration.upgradeNoticeV2 = false;
widget.configuration.flushConfig();
});
}
Expand All @@ -134,14 +138,18 @@ class MobileHomeState extends State<MobileHomePage> implements EventListener {
context: context,
barrierDismissible: false,
builder: (_) {
return AlertDialog(actions: [
TextButton(
onPressed: () {
onClose.call();
Navigator.pop(context);
},
child: const Text('关闭'))
], title: Text(title, style: const TextStyle(fontSize: 18)), content: Text(content));
return AlertDialog(
scrollable: true,
actions: [
TextButton(
onPressed: () {
onClose.call();
Navigator.pop(context);
},
child: const Text('关闭'))
],
title: Text(title, style: const TextStyle(fontSize: 18)),
content: Text(content));
});
}

Expand Down
Loading

0 comments on commit 4154bda

Please sign in to comment.