From 23c86c520cca82b24f08966d3ed33b110d6b4c7f Mon Sep 17 00:00:00 2001 From: Philipp Mengs Date: Sat, 23 Nov 2024 21:29:13 +0100 Subject: [PATCH 1/3] Added Function keys (F1-F12) to SSH virtual keyboard options Signed-off-by: Philipp Mengs --- lib/data/model/ssh/virtual_key.dart | 37 ++++++++++++++++- lib/data/model/ssh/virtual_key.g.dart | 60 +++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/lib/data/model/ssh/virtual_key.dart b/lib/data/model/ssh/virtual_key.dart index 1c70d6cec..25c1ad2e3 100644 --- a/lib/data/model/ssh/virtual_key.dart +++ b/lib/data/model/ssh/virtual_key.dart @@ -75,7 +75,30 @@ enum VirtKey { colon, @HiveField(31) semicolon, - ; + @HiveField(32) + f1, + @HiveField(33) + f2, + @HiveField(34) + f3, + @HiveField(35) + f4, + @HiveField(36) + f5, + @HiveField(37) + f6, + @HiveField(38) + f7, + @HiveField(39) + f8, + @HiveField(40) + f9, + @HiveField(41) + f10, + @HiveField(42) + f11, + @HiveField(43) + f12; } extension VirtKeyX on VirtKey { @@ -146,6 +169,18 @@ extension VirtKeyX on VirtKey { VirtKey.right => TerminalKey.arrowRight, VirtKey.pgup => TerminalKey.pageUp, VirtKey.pgdn => TerminalKey.pageDown, + VirtKey.f1 => TerminalKey.f1, + VirtKey.f2 => TerminalKey.f2, + VirtKey.f3 => TerminalKey.f3, + VirtKey.f4 => TerminalKey.f4, + VirtKey.f5 => TerminalKey.f5, + VirtKey.f6 => TerminalKey.f6, + VirtKey.f7 => TerminalKey.f7, + VirtKey.f8 => TerminalKey.f8, + VirtKey.f9 => TerminalKey.f9, + VirtKey.f10 => TerminalKey.f10, + VirtKey.f11 => TerminalKey.f11, + VirtKey.f12 => TerminalKey.f12, _ => null, }; diff --git a/lib/data/model/ssh/virtual_key.g.dart b/lib/data/model/ssh/virtual_key.g.dart index a4af59011..bc7b614f1 100644 --- a/lib/data/model/ssh/virtual_key.g.dart +++ b/lib/data/model/ssh/virtual_key.g.dart @@ -77,6 +77,30 @@ class VirtKeyAdapter extends TypeAdapter { return VirtKey.colon; case 31: return VirtKey.semicolon; + case 32: + return VirtKey.f1; + case 33: + return VirtKey.f2; + case 34: + return VirtKey.f3; + case 35: + return VirtKey.f4; + case 36: + return VirtKey.f5; + case 37: + return VirtKey.f6; + case 38: + return VirtKey.f7; + case 39: + return VirtKey.f8; + case 40: + return VirtKey.f9; + case 41: + return VirtKey.f10; + case 42: + return VirtKey.f11; + case 43: + return VirtKey.f12; default: return VirtKey.esc; } @@ -181,6 +205,42 @@ class VirtKeyAdapter extends TypeAdapter { case VirtKey.semicolon: writer.writeByte(31); break; + case VirtKey.f1: + writer.writeByte(32); + break; + case VirtKey.f2: + writer.writeByte(33); + break; + case VirtKey.f3: + writer.writeByte(34); + break; + case VirtKey.f4: + writer.writeByte(35); + break; + case VirtKey.f5: + writer.writeByte(36); + break; + case VirtKey.f6: + writer.writeByte(37); + break; + case VirtKey.f7: + writer.writeByte(38); + break; + case VirtKey.f8: + writer.writeByte(39); + break; + case VirtKey.f9: + writer.writeByte(40); + break; + case VirtKey.f10: + writer.writeByte(41); + break; + case VirtKey.f11: + writer.writeByte(42); + break; + case VirtKey.f12: + writer.writeByte(43); + break; } } From 592fcc9b3be1f45072bf83dae36a6f2e5068e603 Mon Sep 17 00:00:00 2001 From: Philipp Mengs Date: Sat, 23 Nov 2024 23:09:55 +0100 Subject: [PATCH 2/3] Added a simple delay that waits 10 seconds before requesting biometric authentication Added a settings entry (under App/Android, App/iOS) to enable this. --- lib/data/store/setting.dart | 3 ++ lib/view/page/home/home.dart | 18 ++++++++++- lib/view/page/setting/platform/android.dart | 2 ++ lib/view/page/setting/platform/ios.dart | 2 ++ .../page/setting/platform/platform_pub.dart | 30 +++++++++++++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) diff --git a/lib/data/store/setting.dart b/lib/data/store/setting.dart index f7b85d27b..d55f1b526 100644 --- a/lib/data/store/setting.dart +++ b/lib/data/store/setting.dart @@ -130,6 +130,9 @@ class SettingStore extends PersistentStore { /// Only valid on iOS / Android / Windows late final useBioAuth = property('useBioAuth', false); + /// Delay to lock the App with BioAuth + late final delayBioAuthLock = property('delayBioAuthLock', false); + /// The performance of highlight is bad late final editorHighlight = property('editorHighlight', true); diff --git a/lib/view/page/home/home.dart b/lib/view/page/home/home.dart index e74b2ccd7..8e9bd3b08 100644 --- a/lib/view/page/home/home.dart +++ b/lib/view/page/home/home.dart @@ -30,6 +30,7 @@ class _HomePageState extends State bool _switchingPage = false; bool _shouldAuth = false; + DateTime? _pausedTime; @override void dispose() { @@ -72,13 +73,28 @@ class _HomePageState extends State switch (state) { case AppLifecycleState.resumed: - if (_shouldAuth) _goAuth(); + if (_shouldAuth) { + if (Stores.setting.delayBioAuthLock.fetch() && _pausedTime != null) { + if (DateTime.now() + .difference(_pausedTime ?? DateTime.now()) + .inSeconds > + 10) { + _goAuth(); + } else { + _shouldAuth = false; + } + _pausedTime = null; + } else { + _goAuth(); + } + } if (!ServerProvider.isAutoRefreshOn) { ServerProvider.startAutoRefresh(); } HomeWidgetMC.update(); break; case AppLifecycleState.paused: + _pausedTime = DateTime.now(); _shouldAuth = true; // Keep running in background on Android device if (isAndroid && Stores.setting.bgRun.fetch()) { diff --git a/lib/view/page/setting/platform/android.dart b/lib/view/page/setting/platform/android.dart index 6151fe04a..86944a5b6 100644 --- a/lib/view/page/setting/platform/android.dart +++ b/lib/view/page/setting/platform/android.dart @@ -25,6 +25,8 @@ class _AndroidSettingsPageState extends State { _buildAndroidWidgetSharedPreference(), if (BioAuth.isPlatformSupported) PlatformPublicSettings.buildBioAuth(), + if (BioAuth.isPlatformSupported) + PlatformPublicSettings.buildBioAuthDelay(), ].map((e) => CardX(child: e)).toList(), ), ); diff --git a/lib/view/page/setting/platform/ios.dart b/lib/view/page/setting/platform/ios.dart index 5063aec25..4ae785464 100644 --- a/lib/view/page/setting/platform/ios.dart +++ b/lib/view/page/setting/platform/ios.dart @@ -36,6 +36,8 @@ class _IOSSettingsPageState extends State { _buildWatchApp(), if (BioAuth.isPlatformSupported) PlatformPublicSettings.buildBioAuth(), + if (BioAuth.isPlatformSupported) + PlatformPublicSettings.buildBioAuthDelay(), ].map((e) => CardX(child: e)).toList(), ), ); diff --git a/lib/view/page/setting/platform/platform_pub.dart b/lib/view/page/setting/platform/platform_pub.dart index b45757c05..f79a10ebf 100644 --- a/lib/view/page/setting/platform/platform_pub.dart +++ b/lib/view/page/setting/platform/platform_pub.dart @@ -3,6 +3,36 @@ import 'package:flutter/material.dart'; import 'package:server_box/data/res/store.dart'; abstract final class PlatformPublicSettings { + static Widget buildBioAuthDelay() { + return FutureWidget( + future: BioAuth.isAvail, + loading: ListTile( + title: Text(libL10n.bioAuth), + subtitle: const Text('...', style: UIs.textGrey), + ), + error: (e, __) => ListTile( + title: Text(libL10n.bioAuth), + subtitle: Text('${libL10n.fail}: $e', style: UIs.textGrey), + ), + success: (can) { + return ListTile( + title: Text("Delay before locking the app"), + subtitle: can == true + ? Text("Wait for 10 seconds before locking the app") + : const Text( + 'Not available', + style: UIs.textGrey, + ), + trailing: can == true + ? StoreSwitch( + prop: Stores.setting.delayBioAuthLock, + callback: (val) async => + Stores.setting.delayBioAuthLock.put(val)) + : null); + }, + ); + } + static Widget buildBioAuth() { return FutureWidget( future: BioAuth.isAvail, From 08288901b17838963b08ff430ac3646c97e87511 Mon Sep 17 00:00:00 2001 From: Philipp Mengs Date: Sat, 23 Nov 2024 23:32:11 +0100 Subject: [PATCH 3/3] removed the two changed files from the previous commit --- lib/data/model/ssh/virtual_key.dart | 37 +---------------- lib/data/model/ssh/virtual_key.g.dart | 60 --------------------------- 2 files changed, 1 insertion(+), 96 deletions(-) diff --git a/lib/data/model/ssh/virtual_key.dart b/lib/data/model/ssh/virtual_key.dart index 25c1ad2e3..1c70d6cec 100644 --- a/lib/data/model/ssh/virtual_key.dart +++ b/lib/data/model/ssh/virtual_key.dart @@ -75,30 +75,7 @@ enum VirtKey { colon, @HiveField(31) semicolon, - @HiveField(32) - f1, - @HiveField(33) - f2, - @HiveField(34) - f3, - @HiveField(35) - f4, - @HiveField(36) - f5, - @HiveField(37) - f6, - @HiveField(38) - f7, - @HiveField(39) - f8, - @HiveField(40) - f9, - @HiveField(41) - f10, - @HiveField(42) - f11, - @HiveField(43) - f12; + ; } extension VirtKeyX on VirtKey { @@ -169,18 +146,6 @@ extension VirtKeyX on VirtKey { VirtKey.right => TerminalKey.arrowRight, VirtKey.pgup => TerminalKey.pageUp, VirtKey.pgdn => TerminalKey.pageDown, - VirtKey.f1 => TerminalKey.f1, - VirtKey.f2 => TerminalKey.f2, - VirtKey.f3 => TerminalKey.f3, - VirtKey.f4 => TerminalKey.f4, - VirtKey.f5 => TerminalKey.f5, - VirtKey.f6 => TerminalKey.f6, - VirtKey.f7 => TerminalKey.f7, - VirtKey.f8 => TerminalKey.f8, - VirtKey.f9 => TerminalKey.f9, - VirtKey.f10 => TerminalKey.f10, - VirtKey.f11 => TerminalKey.f11, - VirtKey.f12 => TerminalKey.f12, _ => null, }; diff --git a/lib/data/model/ssh/virtual_key.g.dart b/lib/data/model/ssh/virtual_key.g.dart index bc7b614f1..a4af59011 100644 --- a/lib/data/model/ssh/virtual_key.g.dart +++ b/lib/data/model/ssh/virtual_key.g.dart @@ -77,30 +77,6 @@ class VirtKeyAdapter extends TypeAdapter { return VirtKey.colon; case 31: return VirtKey.semicolon; - case 32: - return VirtKey.f1; - case 33: - return VirtKey.f2; - case 34: - return VirtKey.f3; - case 35: - return VirtKey.f4; - case 36: - return VirtKey.f5; - case 37: - return VirtKey.f6; - case 38: - return VirtKey.f7; - case 39: - return VirtKey.f8; - case 40: - return VirtKey.f9; - case 41: - return VirtKey.f10; - case 42: - return VirtKey.f11; - case 43: - return VirtKey.f12; default: return VirtKey.esc; } @@ -205,42 +181,6 @@ class VirtKeyAdapter extends TypeAdapter { case VirtKey.semicolon: writer.writeByte(31); break; - case VirtKey.f1: - writer.writeByte(32); - break; - case VirtKey.f2: - writer.writeByte(33); - break; - case VirtKey.f3: - writer.writeByte(34); - break; - case VirtKey.f4: - writer.writeByte(35); - break; - case VirtKey.f5: - writer.writeByte(36); - break; - case VirtKey.f6: - writer.writeByte(37); - break; - case VirtKey.f7: - writer.writeByte(38); - break; - case VirtKey.f8: - writer.writeByte(39); - break; - case VirtKey.f9: - writer.writeByte(40); - break; - case VirtKey.f10: - writer.writeByte(41); - break; - case VirtKey.f11: - writer.writeByte(42); - break; - case VirtKey.f12: - writer.writeByte(43); - break; } }