Termux x11 port

This commit is contained in:
Caten
2024-09-20 21:39:48 +08:00
parent 958d7839ff
commit a117050fde
136 changed files with 19410 additions and 92 deletions

View File

@@ -149,7 +149,7 @@ class _SettingPageState extends State<SettingPage> {
});
}),
OutlinedButton(style: D.commandButtonStyle, child: const Text("Signal9错误页面"), onPressed: () async {
await D.avncChannel.invokeMethod("launchSignal9Page", {});
await D.androidChannel.invokeMethod("launchSignal9Page", {});
}),
]),
const SizedBox.square(dimension: 8),
@@ -276,15 +276,15 @@ class _SettingPageState extends State<SettingPage> {
return const ListTile(title: Text("显示设置"));
}), body: Padding(padding: const EdgeInsets.all(12), child: Column(children: [
const SizedBox.square(dimension: 16),
const Text("""AVNC可以带来获得更好的操控体验;
const Text("""AVNC可以带来相比noVNC更好的操控体验;
如触摸板触控,双指单击弹出键盘,自动剪切板,画中画模式等等。这是一个实验性功能。"""),
const SizedBox.square(dimension: 16),
Wrap(alignment: WrapAlignment.center, spacing: 4.0, runSpacing: 4.0, children: [
OutlinedButton(style: D.commandButtonStyle, child: const Text("AVNC设置"), onPressed: () async {
await D.avncChannel.invokeMethod("launchPrefsPage", {});
await D.androidChannel.invokeMethod("launchPrefsPage", {});
}),
OutlinedButton(style: D.commandButtonStyle, child: const Text("关于AVNC"), onPressed: () async {
await D.avncChannel.invokeMethod("launchAboutPage", {});
await D.androidChannel.invokeMethod("launchAboutPage", {});
}),
OutlinedButton(style: D.commandButtonStyle, child: const Text("AVNC启动时分辨率设置"), onPressed: () async {
final s = WidgetsBinding.instance.platformDispatcher.views.first.physicalSize;
@@ -337,6 +337,22 @@ sed -i -E "s@^(VNC_RESOLUTION)=.*@\\1=${w}x${h}@" \$(command -v startvnc)""");
const SizedBox.square(dimension: 16),
const Divider(height: 2, indent: 8, endIndent: 8),
const SizedBox.square(dimension: 16),
const Text("""Termux X11可以带来比VNC更快的速度某些情况下兼容性也会更好。这是一个实验性功能。
随着版本的迭代Termux X11如今也支持了双向剪切板等功能。"""),
const SizedBox.square(dimension: 16),
Wrap(alignment: WrapAlignment.center, spacing: 4.0, runSpacing: 4.0, children: [
OutlinedButton(style: D.commandButtonStyle, child: const Text("Termux X11设置"), onPressed: () async {
await D.androidChannel.invokeMethod("launchX11PrefsPage", {});
}),
]),
const SizedBox.square(dimension: 8),
SwitchListTile(title: const Text("默认使用Termux X11"), subtitle: const Text("不使用VNC。重启生效"), value: Util.getGlobal("useX11") as bool, onChanged:(value) {
G.prefs.setBool("useX11", value);
setState(() {});
},),
const SizedBox.square(dimension: 16),
const Divider(height: 2, indent: 8, endIndent: 8),
const SizedBox.square(dimension: 16),
const Text("""高分辨率支持可以为大屏幕设备带来更高清的体验!
注意:
@@ -1406,24 +1422,19 @@ class _MyHomePageState extends State<MyHomePage> {
),
floatingActionButton: ValueListenableBuilder(valueListenable: G.pageIndex, builder:(context, value, child) {
return Visibility(visible: isLoadingComplete && (value == 0),
child: SpeedDial(
children: [SpeedDialChild(
child: const Icon(Icons.laptop_outlined),
label: "使用noVNC",
onTap: () => Workflow.launchBrowser(),
),SpeedDialChild(
child: const Icon(Icons.screenshot_monitor_outlined),
label: "使用AVNC",
onTap: () => Workflow.launchAvnc(),
)],
activeChild: const Icon(Icons.close),
child: FloatingActionButton(
tooltip: "进入图形界面",
onPressed: () {
if (G.wasX11Enabled) {
Workflow.launchX11();
} else if (G.wasAvncEnabled) {
Workflow.launchAvnc();
} else {
Workflow.launchBrowser();
}
},
child: const Icon(Icons.play_arrow),
)
// FloatingActionButton(
// onPressed: () => Workflow.launchBrowser(),
// tooltip: "进入图形界面",
// child: const Icon(Icons.play_arrow),
// ),
);
}), // This trailing comma makes auto-formatting nicer for build methods.
);

View File

@@ -71,7 +71,7 @@ class Util {
//所有key
//int defaultContainer = 0: 默认启动第0个容器
//int defaultAudioPort = 4718: 默认pulseaudio端口(为了避免和其它软件冲突改成4718了原默认4713)
//bool autoLaunchVnc = true: 是否自动启动VNC并跳转
//bool autoLaunchVnc = true: 是否自动启动图形界面并跳转 以前只支持VNC就这么起名了
//String lastDate: 上次启动软件的日期yyyy-MM-dd
//bool isTerminalWriteEnabled = false
//bool isTerminalCommandsEnabled = false
@@ -118,6 +118,7 @@ class Util {
case "wakelock" : return b ? G.prefs.getBool(key)! : (value){G.prefs.setBool(key, value); return value;}(false);
case "isHidpiEnabled" : return b ? G.prefs.getBool(key)! : (value){G.prefs.setBool(key, value); return value;}(false);
case "useAvnc" : return b ? G.prefs.getBool(key)! : (value){G.prefs.setBool(key, value); return value;}(true);
case "useX11" : return b ? G.prefs.getBool(key)! : (value){G.prefs.setBool(key, value); return value;}(false);
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");
case "defaultVirglCommand" : return b ? G.prefs.getString(key)! : (value){G.prefs.setString(key, value); return value;}("--socket-path=\$CONTAINER_DIR/tmp/.virgl_test");
case "defaultVirglOpt" : return b ? G.prefs.getString(key)! : (value){G.prefs.setString(key, value); return value;}("GALLIUM_DRIVER=virpipe");
@@ -272,7 +273,7 @@ class TermPty {
}
//Signal 9 hint
if (code == -9) {
D.avncChannel.invokeMethod("launchSignal9Page", {});
D.androidChannel.invokeMethod("launchSignal9Page", {});
}
});
terminal.onOutput = (data) {
@@ -462,7 +463,7 @@ rm /tmp/wps.deb"""},
padding: const EdgeInsets.fromLTRB(8, 4, 8, 4)
);
static const MethodChannel avncChannel = MethodChannel("avnc");
static const MethodChannel androidChannel = MethodChannel("android");
}
@@ -541,6 +542,9 @@ class G {
static bool wasBoxEnabled = false; //本次启动时是否启用了box86/64
static bool wasWineEnabled = false; //本次启动时是否启用了wine
static bool wasAvncEnabled = false;
static bool wasX11Enabled = false;
static late SharedPreferences prefs;
@@ -689,6 +693,14 @@ sed -i -E "s@^(VNC_RESOLUTION)=.*@\\1=${w}x${h}@" \$(command -v startvnc)""";
G.prefs.setBool("reinstallBootstrap", false);
}
//开启了什么图形界面?
if (Util.getGlobal("useX11")) {
G.wasX11Enabled = true;
Workflow.launchXServer();
} else if (Util.getGlobal("useAvnc")) {
G.wasAvncEnabled = true;
}
G.termFontScale.value = Util.getGlobal("termFontScale") as double;
G.controller = WebViewController()..setJavaScriptMode(JavaScriptMode.unrestricted);
@@ -781,7 +793,7 @@ export PROOT_LOADER=\$DATA_DIR/libexec/proot/loader
export PROOT_LOADER_32=\$DATA_DIR/libexec/proot/loader32
${Util.getCurrentProp("boot")}
${G.postCommand}
${(Util.getGlobal("autoLaunchVnc") as bool)?Util.getCurrentProp("vnc"):""}
${(Util.getGlobal("autoLaunchVnc") as bool)?((Util.getGlobal("useX11") as bool)?"/etc/X11/xinit/Xsession &":Util.getCurrentProp("vnc")):""}
clear""");
}
@@ -823,7 +835,15 @@ clear""");
}
static Future<void> launchAvnc() async {
await D.avncChannel.invokeMethod("launchUsingUri", {"vncUri": Util.getCurrentProp("vncUri") as String});
await D.androidChannel.invokeMethod("launchUsingUri", {"vncUri": Util.getCurrentProp("vncUri") as String});
}
static Future<void> launchXServer() async {
await D.androidChannel.invokeMethod("launchXServer", {"tmpdir":"${G.dataPath}/containers/${G.currentContainer}/tmp", "xkb":"${G.dataPath}/containers/${G.currentContainer}/usr/share/X11/xkb"});
}
static Future<void> launchX11() async {
await D.androidChannel.invokeMethod("launchX11Page", {});
}
static Future<void> workflow() async {
@@ -833,7 +853,11 @@ clear""");
setupAudio();
launchCurrentContainer();
if (Util.getGlobal("autoLaunchVnc") as bool) {
waitForConnection().then((value) => (Util.getGlobal("useAvnc") as bool)?launchAvnc():launchBrowser());
if (G.wasX11Enabled) {
launchX11();
return;
}
waitForConnection().then((value) => G.wasAvncEnabled?launchAvnc():launchBrowser());
}
}
}