mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-04-11 18:39:24 -04:00
move keyboard shortcuts into own file
This commit is contained in:
parent
d6b1c20906
commit
6830b54ce8
68
lib/app.dart
68
lib/app.dart
@ -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>()!;
|
||||
|
||||
|
@ -9,7 +9,7 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../../../account_manager/account_manager.dart';
|
||||
import '../../../app.dart';
|
||||
import '../../../keyboard_shortcuts.dart';
|
||||
import '../../../theme/theme.dart';
|
||||
import '../../../tools/tools.dart';
|
||||
import '../../../veilid_processor/veilid_processor.dart';
|
||||
@ -366,7 +366,7 @@ class _DrawerMenuState extends State<DrawerMenu> {
|
||||
GestureDetector(
|
||||
onLongPress: () async {
|
||||
context
|
||||
.findAncestorWidgetOfExactType<VeilidChatApp>()!
|
||||
.findAncestorWidgetOfExactType<KeyboardShortcuts>()!
|
||||
.reloadTheme(context);
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
|
@ -16,6 +16,8 @@ import '../../tools/tools.dart';
|
||||
import '../../veilid_processor/views/developer.dart';
|
||||
import '../views/router_shell.dart';
|
||||
|
||||
export 'package:go_router/go_router.dart';
|
||||
|
||||
part 'router_cubit.freezed.dart';
|
||||
part 'router_cubit.g.dart';
|
||||
|
||||
@ -164,3 +166,14 @@ class RouterCubit extends Cubit<RouterState> {
|
||||
_accountRepositorySubscription;
|
||||
GoRouter? _router;
|
||||
}
|
||||
|
||||
extension GoRouterExtension on GoRouter {
|
||||
String location() {
|
||||
final lastMatch = routerDelegate.currentConfiguration.last;
|
||||
final matchList = lastMatch is ImperativeRouteMatch
|
||||
? lastMatch.matches
|
||||
: routerDelegate.currentConfiguration;
|
||||
final location = matchList.uri.toString();
|
||||
return location;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../keyboard_shortcuts.dart';
|
||||
import '../../notifications/notifications.dart';
|
||||
|
||||
class RouterShell extends StatelessWidget {
|
||||
const RouterShell({required Widget child, super.key}) : _child = child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => NotificationsWidget(child: _child);
|
||||
Widget build(BuildContext context) =>
|
||||
NotificationsWidget(child: KeyboardShortcuts(child: _child));
|
||||
|
||||
final Widget _child;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user