Skip to content

Commit db4431d

Browse files
committed
Add AVNC screen scale feature
1 parent 0793f58 commit db4431d

File tree

6 files changed

+80
-31
lines changed

6 files changed

+80
-31
lines changed

l10n.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
synthetic-package: false
21
arb-dir: lib/l10n
32
template-arb-file: intl_en.arb

lib/l10n/intl_en.arb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"fixGetifaddrsPermission": "Fix getifaddrs permission on Android 13",
3434
"fakeUOSSystem": "Pretend System as UOS",
3535
"displaySettings": "Display Settings",
36-
"avncAdvantages": "AVNC provides better control experience than noVNC:\nTouchpad controls, two-finger tap for keyboard, auto clipboard, picture-in-picture mode, etc. This is an experimental feature.",
36+
"avncAdvantages": "AVNC provides better control experience than noVNC:\nTouchpad controls, two-finger tap for keyboard, auto clipboard, picture-in-picture mode, etc.",
3737
"avncSettings": "AVNC Settings",
3838
"aboutAVNC": "About AVNC",
3939
"avncResolution": "AVNC Startup Resolution",
@@ -44,11 +44,11 @@
4444
"save": "Save",
4545
"applyOnNextLaunch": "Apply on next launch",
4646
"useAVNCByDefault": "Use AVNC by default",
47-
"termuxX11Advantages": "Termux:X11 provides faster performance than VNC with better compatibility in some cases.\nSupports DRI3 (enable in Graphics Acceleration) for significant performance boost.\nNow supports features like bidirectional clipboard.\nExperimental feature! If black screen occurs, try fully closing and restarting the app.",
47+
"termuxX11Advantages": "Termux:X11 may provide faster speeds than VNC in certain scenarios.\n\nNote that Termux:X11 operates slightly differently from AVNC:\n- A two-finger tap acts as a right mouse click\n- Pressing the back button reveals the additional keyboard\n\nSupports DRI3 (requires enabling in graphics acceleration settings), which can significantly improve performance.\nIf you encounter a black screen, try completely closing and restarting the application.",
4848
"termuxX11Preferences": "Termux:X11 Preferences",
4949
"useTermuxX11ByDefault": "Use Termux:X11 by default",
5050
"disableVNC": "Disable VNC. Requires restart",
51-
"hidpiAdvantages": "HiDPI support provides sharper display for high-resolution screens!\n\nNote:\nDisplay may appear too large - set appropriate resolution.\nSome apps may have display issues or slower rendering.",
51+
"hidpiAdvantages": "One-click to enable HiDPI mode for clearer display... at the cost of reduced speed.",
5252
"hidpiEnvVar": "HiDPI Environment Variables",
5353
"hidpiSupport": "HiDPI Support",
5454
"fileAccess": "File Access",
@@ -107,5 +107,8 @@
107107
"solutionUrl": "Usage Guide",
108108
"discussionUrl": "Discussion",
109109
"firstLoadInstructions": "The first load may take about 5 to 10 minutes...\n\nNormally, the software will automatically redirect to the graphical interface after loading.\n\nIn the graphical interface:\n- Tap for left-click\n- Long press for right-click\n- Two-finger tap to open the keyboard\n- Two-finger swipe for mouse wheel\n\nPlease do not exit the software during installation.\n\nWhile waiting, you can click the button below to request permissions.\n\nMany folders in Tiny Computer (e.g., Downloads, Documents, Pictures) are bound to the corresponding device folders. Without these permissions, access to these folders will be denied.\n\nIf you don't need to access these folders, you can skip granting file permissions (but this may cause Firefox to fail when downloading files due to denied access to the Downloads folder).",
110-
"updateRequest": "Please try to use the latest version. Visit the project address to check for the latest version."
110+
"updateRequest": "Please try to use the latest version. Visit the project address to check for the latest version.",
111+
"avncScreenResize": "Adaptive Screen Size",
112+
"avncResizeFactor": "Screen Scaling Ratio",
113+
"avncResizeFactorValue": "Current scaling is"
111114
}

lib/l10n/intl_zh.arb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"fixGetifaddrsPermission": "修复安卓13设备getifaddrs无权限",
3434
"fakeUOSSystem": "伪装系统为UOS",
3535
"displaySettings": "显示设置",
36-
"avncAdvantages": "AVNC可以带来相比noVNC更好的操控体验;\n如触摸板触控,双指单击弹出键盘,自动剪切板,画中画模式等等。这是一个实验性功能。",
36+
"avncAdvantages": "AVNC可以带来相比noVNC更好的操控体验;\n如触摸板触控,双指单击弹出键盘,自动剪切板,画中画模式等等。",
3737
"avncSettings": "AVNC设置",
3838
"aboutAVNC": "关于AVNC",
3939
"avncResolution": "AVNC启动时分辨率设置",
@@ -44,11 +44,11 @@
4444
"applyOnNextLaunch": "下次启动时生效",
4545
"save": "保存",
4646
"useAVNCByDefault": "默认使用AVNC",
47-
"termuxX11Advantages": "Termux:X11可以带来比VNC更快的速度,某些情况下兼容性也会更好。\n支持使用DRI3(需在图形加速中开启),可以带来相当大的性能提升。\n随着版本的迭代,Termux:X11如今也支持了双向剪切板等功能。\n这是一个实验性功能!如果黑屏,请尝试彻底关闭本应用再重新启动。",
47+
"termuxX11Advantages": "Termux:X11某些情况下可以带来比VNC更快的速度。\n\n注意Termux:X11的操作与AVNC略有不同。\n- 双指点击为鼠标右键\n- 返回弹出附加键盘\n\n支持使用DRI3(需在图形加速中开启),可以带来相当大的性能提升。\n如果黑屏,请尝试彻底关闭本应用再重新启动。",
4848
"termuxX11Preferences": "Termux:X11偏好设置",
4949
"useTermuxX11ByDefault": "默认使用Termux:X11",
5050
"disableVNC": "不使用VNC。重启生效",
51-
"hidpiAdvantages": "高分辨率支持可以为拥有高分辨率屏幕的设备带来更高清的体验!\n\n注意:\n选项开启后显示会变得很大,请设置一个合适的分辨率。\n\n一些软件可能会存在显示问题,或者显示速度变慢。",
51+
"hidpiAdvantages": "一键开启高清模式,显示更清晰的同时...速度会变慢。",
5252
"hidpiEnvVar": "HiDPI环境变量",
5353
"hidpiSupport": "高分辨率支持",
5454
"fileAccess": "文件访问",
@@ -107,5 +107,8 @@
107107
"solutionUrl": "典型场景使用指南",
108108
"discussionUrl": "论坛与讨论",
109109
"firstLoadInstructions": "第一次加载大概需要5到10分钟...\n\n正常情况下,加载完成后软件会自动跳转到图形界面。\n\n在图形界面时:\n- 点击为鼠标左键\n- 长按为鼠标右键\n- 双指点击可弹出键盘\n- 双指划动为鼠标滚轮\n\n请不要在安装时退出软件。\n\n在等待时,可以点击下面的按钮申请一下权限。\n\n小小电脑的许多文件夹,比如下载、文档、图片等等都和设备的对应文件夹绑定,如果不授予这些权限会导致这些文件夹无权访问。\n\n但如果你不需要访问这些文件夹,也可以不授予文件权限(可能导致火狐浏览器下载文件失败,因为无权访问下载文件夹)。",
110-
"updateRequest": "请尽量使用最新版本。前往项目地址可查看最新版本。"
110+
"updateRequest": "请尽量使用最新版本。前往项目地址可查看最新版本。",
111+
"avncScreenResize": "自适应屏幕尺寸",
112+
"avncResizeFactor": "屏幕缩放比",
113+
"avncResizeFactorValue": "当前缩放为"
111114
}

lib/l10n/intl_zh_Hant.arb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"fixGetifaddrsPermission": "修復 Android 13 裝置 getifaddrs 無權限",
3434
"fakeUOSSystem": "偽裝系統為 UOS",
3535
"displaySettings": "顯示設定",
36-
"avncAdvantages": "AVNC 可帶來比 noVNC 更好的操作體驗;如觸控板觸控、雙指單擊喚出鍵盤、自動剪貼簿、畫中畫模式等。這是一個實驗性功能。",
36+
"avncAdvantages": "AVNC 可帶來比 noVNC 更好的操作體驗;如觸控板觸控、雙指單擊喚出鍵盤、自動剪貼簿、畫中畫模式等。",
3737
"avncSettings": "AVNC 設定",
3838
"aboutAVNC": "關於 AVNC",
3939
"avncResolution": "AVNC 啟動時解析度設定",
@@ -44,11 +44,11 @@
4444
"applyOnNextLaunch": "下次啟動時生效",
4545
"save": "儲存",
4646
"useAVNCByDefault": "預設使用 AVNC",
47-
"termuxX11Advantages": "Termux:X11 可帶來比 VNC 更快的速度,有時兼容性也更好。\n支援使用 DRI3(需在圖形加速中開啟),可大幅提升效能。",
47+
"termuxX11Advantages": "Termux:X11 在某些情況下可能比 VNC 提供更快的速度。\n\n請注意 Termux:X11 的操作與 AVNC 略有不同:\n- 雙指點擊相當於滑鼠右鍵\n- 返回鍵可彈出附加鍵盤\n\n支援 DRI3(需在圖形加速設定中開啟),可帶來顯著的性能提升。\n若出現黑屏,請嘗試完全關閉本應用後重新啟動。",
4848
"termuxX11Preferences": "Termux:X11 偏好設定",
4949
"useTermuxX11ByDefault": "預設使用 Termux:X11",
5050
"disableVNC": "停用 VNC。重啟生效",
51-
"hidpiAdvantages": "高解析度支援可讓有高解析度螢幕的裝置獲得更清晰的體驗!\n\n注意:\n啟用後顯示會變很大,請設定合適的解析度。",
51+
"hidpiAdvantages": "一鍵開啟高清模式,顯示更清晰的同時...速度會變慢。",
5252
"hidpiEnvVar": "HiDPI 環境變數",
5353
"hidpiSupport": "高解析度支援",
5454
"fileAccess": "檔案存取",
@@ -107,5 +107,8 @@
107107
"solutionUrl": "操作指南",
108108
"discussionUrl": "討論",
109109
"firstLoadInstructions": "第一次載入大概需要5到10分鐘...\n\n正常情況下,載入完成後軟體會自動跳轉到圖形介面。\n\n在圖形介面時:\n- 點擊為滑鼠左鍵\n- 長按為滑鼠右鍵\n- 雙指點擊可彈出鍵盤\n- 雙指滑動為滑鼠滾輪\n\n請不要在安裝時退出軟體。\n\n在等待時,可以點擊下面的按鈕申請權限。\n\n小小電腦的許多資料夾,比如下載、文件、圖片等等都和裝置的這些資料夾綁定,如果不授予這些權限會導致這些資料夾無權存取。\n\n但如果你不需要存取這些資料夾,也可以不授予檔案權限(可能導致火狐瀏覽器下載檔案失敗,因為無權存取下載資料夾)。",
110-
"updateRequest": "請盡量使用最新版本。前往專案網址查看最新版本。"
110+
"updateRequest": "請盡量使用最新版本。前往專案網址查看最新版本。",
111+
"avncScreenResize": "自適應螢幕尺寸",
112+
"avncResizeFactor": "螢幕縮放比",
113+
"avncResizeFactorValue": "目前縮放為"
111114
}

lib/main.dart

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ class _SettingPageState extends State<SettingPage> {
172172

173173
final List<bool> _expandState = [false, false, false, false, false, false];
174174

175+
double _avncScaleFactor = Util.getGlobal("avncScaleFactor") as double;
176+
175177
@override
176178
Widget build(BuildContext context) {
177179
return ExpansionPanelList(
@@ -337,6 +339,25 @@ class _SettingPageState extends State<SettingPage> {
337339
headerBuilder: ((context, isExpanded) {
338340
return ListTile(title: Text(AppLocalizations.of(context)!.displaySettings));
339341
}), body: Padding(padding: const EdgeInsets.all(12), child: Column(children: [
342+
const SizedBox.square(dimension: 16),
343+
Text(AppLocalizations.of(context)!.hidpiAdvantages),
344+
const SizedBox.square(dimension: 16),
345+
TextFormField(maxLines: null, initialValue: Util.getGlobal("defaultHidpiOpt") as String, decoration: InputDecoration(border: OutlineInputBorder(), labelText: AppLocalizations.of(context)!.hidpiEnvVar),
346+
onChanged: (value) async {
347+
await G.prefs.setString("defaultHidpiOpt", value);
348+
},
349+
),
350+
const SizedBox.square(dimension: 8),
351+
SwitchListTile(title: Text(AppLocalizations.of(context)!.hidpiSupport), subtitle: Text(AppLocalizations.of(context)!.applyOnNextLaunch), value: Util.getGlobal("isHidpiEnabled") as bool, onChanged:(value) {
352+
G.prefs.setBool("isHidpiEnabled", value);
353+
// 开启高分辨率后把缩放比调为原来的两倍 +log4(2) = 0.5
354+
_avncScaleFactor += value ? 0.5 : -0.5;
355+
_avncScaleFactor = _avncScaleFactor.clamp(-1, 1);
356+
G.prefs.setDouble("avncScaleFactor", _avncScaleFactor);
357+
setState(() {});
358+
},),
359+
const SizedBox.square(dimension: 16),
360+
const Divider(height: 2, indent: 8, endIndent: 8),
340361
const SizedBox.square(dimension: 16),
341362
Text(AppLocalizations.of(context)!.avncAdvantages),
342363
const SizedBox.square(dimension: 16),
@@ -347,7 +368,7 @@ class _SettingPageState extends State<SettingPage> {
347368
OutlinedButton(style: D.commandButtonStyle, child: Text(AppLocalizations.of(context)!.aboutAVNC), onPressed: () async {
348369
await AvncFlutter.launchAboutPage();
349370
}),
350-
OutlinedButton(style: D.commandButtonStyle, child: Text(AppLocalizations.of(context)!.avncResolution), onPressed: () async {
371+
OutlinedButton(style: D.commandButtonStyle, onPressed: Util.getGlobal("avncResizeDesktop") as bool ? null : () async {
351372
final s = WidgetsBinding.instance.platformDispatcher.views.first.physicalSize;
352373
final w0 = max(s.width, s.height);
353374
final h0 = min(s.width, s.height);
@@ -388,13 +409,44 @@ sed -i -E "s@^(VNC_RESOLUTION)=.*@\\1=${w}x${h}@" \$(command -v startvnc)""");
388409
}, child: Text(AppLocalizations.of(context)!.save)),
389410
]);
390411
});
391-
}),
412+
}, child: Text(AppLocalizations.of(context)!.avncResolution)),
392413
]),
393414
const SizedBox.square(dimension: 8),
394415
SwitchListTile(title: Text(AppLocalizations.of(context)!.useAVNCByDefault), subtitle: Text(AppLocalizations.of(context)!.applyOnNextLaunch), value: Util.getGlobal("useAvnc") as bool, onChanged:(value) {
395416
G.prefs.setBool("useAvnc", value);
396417
setState(() {});
397418
},),
419+
const SizedBox.square(dimension: 8),
420+
SwitchListTile(title: Text(AppLocalizations.of(context)!.avncScreenResize), value: Util.getGlobal("avncResizeDesktop") as bool, onChanged:(value) {
421+
G.prefs.setBool("avncResizeDesktop", value);
422+
setState(() {});
423+
},),
424+
const SizedBox.square(dimension: 8),
425+
ListTile(
426+
title: Text(AppLocalizations.of(context)!.avncResizeFactor),
427+
onTap: () {},
428+
subtitle: Column(
429+
crossAxisAlignment: CrossAxisAlignment.start,
430+
children: [
431+
SizedBox(height: 8),
432+
Text('${AppLocalizations.of(context)!.avncResizeFactorValue} ${pow(4, _avncScaleFactor).toStringAsFixed(2)}x'),
433+
SizedBox(height: 12),
434+
Slider(
435+
value: _avncScaleFactor,
436+
min: -1,
437+
max: 1,
438+
divisions: 96,
439+
onChangeEnd: (double value) {
440+
G.prefs.setDouble("avncScaleFactor", value);
441+
},
442+
onChanged: Util.getGlobal("avncResizeDesktop") as bool ? (double value) {
443+
_avncScaleFactor = value;
444+
setState(() {});
445+
} : null,
446+
),
447+
],
448+
),
449+
),
398450
const SizedBox.square(dimension: 16),
399451
const Divider(height: 2, indent: 8, endIndent: 8),
400452
const SizedBox.square(dimension: 16),
@@ -414,21 +466,6 @@ sed -i -E "s@^(VNC_RESOLUTION)=.*@\\1=${w}x${h}@" \$(command -v startvnc)""");
414466
setState(() {});
415467
},),
416468
const SizedBox.square(dimension: 16),
417-
const Divider(height: 2, indent: 8, endIndent: 8),
418-
const SizedBox.square(dimension: 16),
419-
Text(AppLocalizations.of(context)!.hidpiAdvantages),
420-
const SizedBox.square(dimension: 16),
421-
TextFormField(maxLines: null, initialValue: Util.getGlobal("defaultHidpiOpt") as String, decoration: InputDecoration(border: OutlineInputBorder(), labelText: AppLocalizations.of(context)!.hidpiEnvVar),
422-
onChanged: (value) async {
423-
await G.prefs.setString("defaultHidpiOpt", value);
424-
},
425-
),
426-
const SizedBox.square(dimension: 8),
427-
SwitchListTile(title: Text(AppLocalizations.of(context)!.hidpiSupport), subtitle: Text(AppLocalizations.of(context)!.applyOnNextLaunch), value: Util.getGlobal("isHidpiEnabled") as bool, onChanged:(value) {
428-
G.prefs.setBool("isHidpiEnabled", value);
429-
setState(() {});
430-
},),
431-
const SizedBox.square(dimension: 16),
432469
],))),
433470
ExpansionPanel(
434471
isExpanded: _expandState[3],

lib/workflow.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class Util {
9292
//bool isHidpiEnabled = false 是否开启高分辨率
9393
//bool isJpEnabled = false 是否切换系统到日语
9494
//bool useAvnc = false 是否默认使用AVNC
95+
//bool avncResizeDesktop = true 是否默认AVNC按当前屏幕大小调整分辨率
96+
//double avncScaleFactor = -0.5 AVNC:在当前屏幕大小的基础上调整缩放的比例。范围-1~1,对应比例4^-1~4^1
9597
//String defaultHidpiOpt 默认HiDPI环境变量
9698
//? int bootstrapVersion: 启动包版本
9799
//String[] containersInfo: 所有容器信息(json)
@@ -120,6 +122,8 @@ class Util {
120122
case "isHidpiEnabled" : return b ? G.prefs.getBool(key)! : (value){G.prefs.setBool(key, value); return value;}(false);
121123
case "isJpEnabled" : return b ? G.prefs.getBool(key)! : (value){G.prefs.setBool(key, value); return value;}(false);
122124
case "useAvnc" : return b ? G.prefs.getBool(key)! : (value){G.prefs.setBool(key, value); return value;}(true);
125+
case "avncResizeDesktop" : return b ? G.prefs.getBool(key)! : (value){G.prefs.setBool(key, value); return value;}(true);
126+
case "avncScaleFactor" : return b ? G.prefs.getDouble(key)!.clamp(-1.0, 1.0) : (value){G.prefs.setDouble(key, value); return value;}(-0.5);
123127
case "useX11" : return b ? G.prefs.getBool(key)! : (value){G.prefs.setBool(key, value); return value;}(false);
124128
case "defaultFFmpegCommand" : return b ? G.prefs.getString(key)! : (value){G.prefs.setString(key, value); return value;}("-hide_banner -an -max_delay 1000000 -r 30 -f android_camera -camera_index 0 -i 0:0 -vf scale=iw/2:-1 -rtsp_transport udp -f rtsp rtsp://127.0.0.1:8554/stream");
125129
case "defaultVirglCommand" : return b ? G.prefs.getString(key)! : (value){G.prefs.setString(key, value); return value;}("--use-egl-surfaceless --use-gles --socket-path=\$CONTAINER_DIR/tmp/.virgl_test");
@@ -771,7 +775,7 @@ clear""");
771775
}
772776

773777
static Future<void> launchAvnc() async {
774-
await AvncFlutter.launchUsingUri(Util.getCurrentProp("vncUri") as String);
778+
await AvncFlutter.launchUsingUri(Util.getCurrentProp("vncUri") as String, resizeRemoteDesktop: Util.getGlobal("avncResizeDesktop") as bool, resizeRemoteDesktopScaleFactor: pow(4, Util.getGlobal("avncScaleFactor") as double).toDouble());
775779
}
776780

777781
static Future<void> launchXServer() async {

0 commit comments

Comments
 (0)