mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-04-19 15:06:05 -04:00
Merge branch 'debugging' into 'main'
oops See merge request veilid/veilidchat!39
This commit is contained in:
commit
db8bfdf94b
98
lib/keyboard_shortcuts.dart
Normal file
98
lib/keyboard_shortcuts.dart
Normal file
@ -0,0 +1,98 @@
|
||||
import 'package:animated_theme_switcher/animated_theme_switcher.dart';
|
||||
import 'package:async_tools/async_tools.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_translate/flutter_translate.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import 'init.dart';
|
||||
import 'router/router.dart';
|
||||
import 'settings/settings.dart';
|
||||
import 'theme/theme.dart';
|
||||
import 'tools/tools.dart';
|
||||
import 'veilid_processor/veilid_processor.dart';
|
||||
|
||||
class ReloadThemeIntent extends Intent {
|
||||
const ReloadThemeIntent();
|
||||
}
|
||||
|
||||
class AttachDetachIntent extends Intent {
|
||||
const AttachDetachIntent();
|
||||
}
|
||||
|
||||
class DeveloperPageIntent extends Intent {
|
||||
const DeveloperPageIntent();
|
||||
}
|
||||
|
||||
class KeyboardShortcuts extends StatelessWidget {
|
||||
const KeyboardShortcuts({required this.child, super.key});
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _developerPage(BuildContext context) {
|
||||
singleFuture(this, () async {
|
||||
final path = GoRouter.of(context).location();
|
||||
if (path != '/developer') {
|
||||
await GoRouterHelper(context).push('/developer');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ThemeSwitcher(
|
||||
builder: (context) => Shortcuts(
|
||||
shortcuts: <LogicalKeySet, Intent>{
|
||||
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.keyR):
|
||||
const ReloadThemeIntent(),
|
||||
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.keyD):
|
||||
const AttachDetachIntent(),
|
||||
LogicalKeySet(
|
||||
LogicalKeyboardKey.alt, LogicalKeyboardKey.backquote):
|
||||
const DeveloperPageIntent(),
|
||||
},
|
||||
child: Actions(actions: <Type, Action<Intent>>{
|
||||
ReloadThemeIntent: CallbackAction<ReloadThemeIntent>(
|
||||
onInvoke: (intent) => reloadTheme(context)),
|
||||
AttachDetachIntent: CallbackAction<AttachDetachIntent>(
|
||||
onInvoke: (intent) => _attachDetach(context)),
|
||||
DeveloperPageIntent: CallbackAction<DeveloperPageIntent>(
|
||||
onInvoke: (intent) => _developerPage(context)),
|
||||
}, child: Focus(autofocus: true, child: child))));
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
final Widget child;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user