feat: separate ssh term theme setting (#305)

This commit is contained in:
lollipopkit
2024-03-11 23:56:19 -06:00
parent f187bc6ccf
commit baffe6dbe0
4 changed files with 46 additions and 2 deletions

View File

@@ -63,7 +63,6 @@ extension DialogX on BuildContext {
Future<String?> showPwdDialog({
String? user,
required String hostId,
void Function()? onCorrectPwd,
}) async {
if (!mounted) return null;
return await showRoundDialog<String>(

View File

@@ -259,6 +259,10 @@ class SettingStore extends PersistentStore {
/// Used for [DialogX.showPwdDialog]
late final rememberPwdInMem = property('rememberPwdInMem', true);
/// SSH Term Theme
/// 0: follow app theme, 1: light, 2: dark
late final termTheme = property('termTheme', 0);
// Never show these settings for users
//
// ------BEGIN------

View File

@@ -170,6 +170,7 @@ class _SettingPageState extends State<SettingPage> {
Widget _buildSSH() {
return Column(
children: [
_buildTermTheme(),
_buildFont(),
_buildTermFontSize(),
_buildTermCursor(),
@@ -1090,4 +1091,40 @@ class _SettingPageState extends State<SettingPage> {
trailing: StoreSwitch(prop: _setting.rememberPwdInMem),
);
}
Widget _buildTermTheme() {
String index2Str(int index) {
switch (index) {
case 0:
return l10n.system;
case 1:
return l10n.light;
case 2:
return l10n.dark;
default:
return l10n.error;
}
}
return ListTile(
title: Text(l10n.theme),
trailing: ValueListenableBuilder(
valueListenable: _setting.termTheme.listenable(),
builder: (_, val, __) => Text(
index2Str(val),
style: UIs.text15,
),
),
onTap: () async {
final selected = await context.showPickSingleDialog(
items: List.generate(3, (index) => index),
name: (p0) => index2Str(p0),
initial: _setting.termTheme.fetch(),
);
if (selected != null) {
_setting.termTheme.put(selected);
}
},
);
}
}

View File

@@ -91,7 +91,11 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
super.didChangeDependencies();
_isDark = context.isDark;
_media = MediaQuery.of(context);
_terminalTheme = _isDark ? TerminalThemes.dark : TerminalThemes.light;
_terminalTheme = switch (Stores.setting.termTheme.fetch()) {
1 => TerminalThemes.light,
2 => TerminalThemes.dark,
_ => _isDark ? TerminalThemes.dark : TerminalThemes.light,
};
// Because the virtual keyboard only displayed on mobile devices
if (isMobile || isDebuggingMobileLayoutOnDesktop) {