Desktop: save the left and right panel ratio

This commit is contained in:
wanghongenpin
2024-08-21 16:56:41 +08:00
parent 3faf91062b
commit f559f246ca
4 changed files with 48 additions and 14 deletions

View File

@@ -6,9 +6,16 @@ class VerticalSplitView extends StatefulWidget {
final double ratio;
final double minRatio;
final double maxRatio;
final Function(double ratio)? onRatioChanged;
const VerticalSplitView(
{super.key, required this.left, required this.right, this.ratio = 0.5, this.minRatio = 0, this.maxRatio = 1})
{super.key,
required this.left,
required this.right,
this.ratio = 0.5,
this.minRatio = 0,
this.maxRatio = 1,
this.onRatioChanged})
: assert(ratio >= 0 && ratio <= 1);
@override
@@ -59,6 +66,9 @@ class _VerticalSplitViewState extends State<VerticalSplitView> {
? const Icon(Icons.drag_handle, size: 16)
: const VerticalDivider(thickness: 1),
)),
onPanEnd: (DragEndDetails details) {
widget.onRatioChanged?.call(_ratio);
},
onPanUpdate: (DragUpdateDetails details) {
setState(() {
_ratio += details.delta.dx / _maxWidth;

View File

@@ -43,6 +43,9 @@ class AppConfiguration {
//桌面window位置
Offset? windowPosition;
//左侧面板占比
double panelRatio = 0.3;
AppConfiguration._();
/// 单例
@@ -132,13 +135,22 @@ class AppConfiguration {
windowPosition = config['windowPosition'] == null
? null
: Offset(config['windowPosition']['dx'], config['windowPosition']['dy']);
if (config['panelRatio'] != null) {
panelRatio = config['panelRatio'];
}
} catch (e) {
print(e);
}
}
/// 是否正在写入
bool _isWriting = false;
/// 刷新配置文件
flushConfig() async {
if (_isWriting) return;
_isWriting = true;
var file = await _path;
var exists = await file.exists();
if (!exists) {
@@ -146,7 +158,8 @@ class AppConfiguration {
}
var json = jsonEncode(toJson());
file.writeAsString(json);
await file.writeAsString(json);
_isWriting = false;
}
Map<String, dynamic> toJson() {
@@ -155,11 +168,16 @@ class AppConfiguration {
'useMaterial3': _theme.useMaterial3,
'upgradeNoticeV12': upgradeNoticeV12,
"language": _language?.languageCode,
'pipEnabled': pipEnabled.value,
'pipIcon': pipIcon.value ? true : null,
"headerExpanded": headerExpanded,
"windowSize": windowSize == null ? null : {"width": windowSize?.width, "height": windowSize?.height},
"windowPosition": windowPosition == null ? null : {"dx": windowPosition?.dx, "dy": windowPosition?.dy},
if (Platforms.isMobile()) 'pipEnabled': pipEnabled.value,
if (Platforms.isMobile()) 'pipIcon': pipIcon.value ? true : null,
if (Platforms.isDesktop())
"windowSize": windowSize == null ? null : {"width": windowSize?.width, "height": windowSize?.height},
if (Platforms.isDesktop())
"windowPosition": windowPosition == null ? null : {"dx": windowPosition?.dx, "dy": windowPosition?.dy},
if (Platforms.isDesktop()) 'panelRatio': panelRatio,
};
}
}

View File

@@ -82,9 +82,13 @@ class _DesktopHomePagePageState extends State<DesktopHomePage> implements EventL
selectIndex: _selectIndex, appConfiguration: widget.appConfiguration, proxyServer: proxyServer),
Expanded(
child: VerticalSplitView(
ratio: 0.3,
ratio: widget.appConfiguration.panelRatio,
minRatio: 0.15,
maxRatio: 0.9,
onRatioChanged: (ratio) {
widget.appConfiguration.panelRatio = double.parse(ratio.toStringAsFixed(2));
widget.appConfiguration.flushConfig();
},
left: ValueListenableBuilder(
valueListenable: _selectIndex,
builder: (_, index, __) => IndexedStack(index: index, children: [
@@ -120,21 +124,23 @@ class _DesktopHomePagePageState extends State<DesktopHomePage> implements EventL
child: Text(localizations.cancel))
],
title: Text(isCN ? '更新内容V1.1.2' : "Update content V1.1.2", style: const TextStyle(fontSize: 18)),
content: Text(
content: SelectableText(
isCN
? '提示默认不会开启HTTPS抓包请安装证书后再开启HTTPS抓包。\n'
'点击HTTPS抓包(加锁图标),选择安装根证书,按照提示操作即可。\n\n'
'1. iOS 通知栏显示VPN状态\n'
'2. iOS修复停止长时间切换后台再开启抓包无网络问题\n'
'3. 修复请求重发和脚本导致URL错误\n'
'4. 修复脚本二进制body转换问题\n'
'5. 修复请求编辑中文路径编码问题;\n'
'3. 桌面端保存调整左右面板比例\n'
'4. 修复请求重发和脚本导致URL错误\n'
'5. 修复脚本二进制body转换问题;\n'
'6. 修复请求编辑中文路径编码问题;\n'
: 'TipsBy default, HTTPS packet capture will not be enabled. Please install the certificate before enabling HTTPS packet capture。\n'
'Click HTTPS Capture packets(Lock icon)Choose to install the root certificate and follow the prompts to proceed。\n\n'
'1. iOS notification bar displays VPN status\n'
'2. iOS fix: Stop switching to the background for a long time and then start packet capture without network problem\n'
'3. fix request repeat & script change url wrong\n'
'4. fix script binary body convert\n'
'3. Desktop: save the left and right panel ratio\n'
'4. fix request repeat & script change url wrong\n'
'5. fix script binary body convert\n'
'',
style: const TextStyle(fontSize: 14)));
});

View File

@@ -273,7 +273,7 @@ class MobileHomeState extends State<MobileHomePage> implements EventListener, Li
child: Text(localizations.cancel))
],
title: Text(title, style: const TextStyle(fontSize: 18)),
content: Text(content));
content: SelectableText(content));
});
}