move keyboard shortcuts into own file

This commit is contained in:
Christien Rioux 2025-03-23 10:41:19 -04:00
parent d6b1c20906
commit 6830b54ce8
4 changed files with 19 additions and 70 deletions

View file

@ -1,15 +1,12 @@
import 'package:animated_theme_switcher/animated_theme_switcher.dart';
import 'package:async_tools/async_tools.dart';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_translate/flutter_translate.dart';
import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:provider/provider.dart';
import 'package:veilid_support/veilid_support.dart';
import 'account_manager/account_manager.dart';
import 'init.dart';
@ -19,17 +16,8 @@ import 'router/router.dart';
import 'settings/settings.dart';
import 'theme/theme.dart';
import 'tick.dart';
import 'tools/loggy.dart';
import 'veilid_processor/veilid_processor.dart';
class ReloadThemeIntent extends Intent {
const ReloadThemeIntent();
}
class AttachDetachIntent extends Intent {
const AttachDetachIntent();
}
class ScrollBehaviorModified extends ScrollBehavior {
const ScrollBehaviorModified();
@override
@ -47,59 +35,6 @@ class VeilidChatApp extends StatelessWidget {
final ThemeData initialThemeData;
void reloadTheme(BuildContext context) {
singleFuture(this, () async {
log.info('Reloading theme');
await VeilidChatGlobalInit.loadAssetManifest();
final theme =
PreferencesRepository.instance.value.themePreference.themeData();
if (context.mounted) {
ThemeSwitcher.of(context).changeTheme(theme: theme);
// Hack to reload translations
final localizationDelegate = LocalizedApp.of(context).delegate;
await LocalizationDelegate.create(
fallbackLocale: localizationDelegate.fallbackLocale.toString(),
supportedLocales: localizationDelegate.supportedLocales
.map((x) => x.toString())
.toList());
}
});
}
void _attachDetach(BuildContext context) {
singleFuture(this, () async {
if (ProcessorRepository.instance.processorConnectionState.isAttached) {
log.info('Detaching');
await Veilid.instance.detach();
} else if (ProcessorRepository
.instance.processorConnectionState.isDetached) {
log.info('Attaching');
await Veilid.instance.attach();
}
});
}
Widget _buildShortcuts({required Widget Function(BuildContext) builder}) =>
ThemeSwitcher(
builder: (context) => Shortcuts(
shortcuts: <LogicalKeySet, Intent>{
LogicalKeySet(
LogicalKeyboardKey.alt, LogicalKeyboardKey.keyR):
const ReloadThemeIntent(),
LogicalKeySet(
LogicalKeyboardKey.alt, LogicalKeyboardKey.keyD):
const AttachDetachIntent(),
},
child: Actions(actions: <Type, Action<Intent>>{
ReloadThemeIntent: CallbackAction<ReloadThemeIntent>(
onInvoke: (intent) => reloadTheme(context)),
AttachDetachIntent: CallbackAction<AttachDetachIntent>(
onInvoke: (intent) => _attachDetach(context)),
}, child: Focus(autofocus: true, child: builder(context)))));
Widget appBuilder(
BuildContext context, LocalizationDelegate localizationDelegate) =>
ThemeProvider(
@ -138,8 +73,7 @@ class VeilidChatApp extends StatelessWidget {
accountRepository: AccountRepository.instance,
locator: context.read)),
],
child:
BackgroundTicker(child: _buildShortcuts(builder: (context) {
child: BackgroundTicker(child: Builder(builder: (context) {
final scale = theme.extension<ScaleScheme>()!;
final scaleConfig = theme.extension<ScaleConfig>()!;