-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.dart
138 lines (130 loc) · 4.36 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import 'dart:ui';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'constant/shortcuts.dart';
import 'gen/assets.gen.dart';
import 'i18n/strings.g.dart';
import 'provider/general_settings_notifier_provider.dart';
import 'provider/shared_preferences_provider.dart';
import 'provider/theme_data_provider.dart';
import 'router/router.dart';
import 'rust/frb_generated.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
LicenseRegistry.addLicense(() async* {
yield LicenseEntryWithLineBreaks(
['BIZ UDGothic'],
await rootBundle.loadString(Assets.fonts.bIZUDGothic.ofl),
);
yield LicenseEntryWithLineBreaks(
['BIZ UDMincho'],
await rootBundle.loadString(Assets.fonts.bIZUDMincho.ofl),
);
yield LicenseEntryWithLineBreaks(
['M PLUS 1'],
await rootBundle.loadString(Assets.fonts.mplus1.ofl),
);
yield LicenseEntryWithLineBreaks(
['M PLUS 2'],
await rootBundle.loadString(Assets.fonts.mplus2.ofl),
);
yield LicenseEntryWithLineBreaks(
['Noto Sans JP'],
await rootBundle.loadString(Assets.fonts.notoSansJP.ofl),
);
yield LicenseEntryWithLineBreaks(
['Noto Sans KR'],
await rootBundle.loadString(Assets.fonts.notoSansKR.ofl),
);
yield LicenseEntryWithLineBreaks(
['Noto Sans SC'],
await rootBundle.loadString(Assets.fonts.notoSansSC.ofl),
);
yield LicenseEntryWithLineBreaks(
['Noto Sans TC'],
await rootBundle.loadString(Assets.fonts.notoSansTC.ofl),
);
yield LicenseEntryWithLineBreaks(
['Noto Serif JP'],
await rootBundle.loadString(Assets.fonts.notoSerifJP.ofl),
);
yield LicenseEntryWithLineBreaks(
['Pretendard'],
await rootBundle.loadString(Assets.fonts.pretendard.license),
);
yield LicenseEntryWithLineBreaks(
['misskey'],
await rootBundle.loadString(Assets.misskey.copying),
);
yield LicenseEntryWithLineBreaks(
['misskey'],
await rootBundle.loadString(Assets.misskey.license),
);
});
final prefs = await SharedPreferences.getInstance();
await RustLib.init();
runApp(
ProviderScope(
overrides: [sharedPreferencesProvider.overrideWithValue(prefs)],
child: TranslationProvider(child: const Aria()),
),
);
}
class Aria extends ConsumerWidget {
const Aria({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final router = ref.watch(routerProvider);
final lightTheme = ref.watch(themeDataProvider(Brightness.light));
final darkTheme = ref.watch(themeDataProvider(Brightness.dark));
final themeMode = ref.watch(
generalSettingsNotifierProvider.select((settings) => settings.themeMode),
);
return MaterialApp.router(
routerConfig: router,
title: 'Aria',
theme: lightTheme,
darkTheme: darkTheme,
themeMode: themeMode,
locale: TranslationProvider.of(context).flutterLocale,
supportedLocales: AppLocaleUtils.supportedLocales,
localizationsDelegates: GlobalMaterialLocalizations.delegates,
scrollBehavior: AppScrollBehavior(),
shortcuts: {
...WidgetsApp.defaultShortcuts,
darkModeActivator: VoidCallbackIntent(() {
final themeMode = ref.read(
generalSettingsNotifierProvider
.select((settings) => settings.themeMode),
);
ref.read(generalSettingsNotifierProvider.notifier).setThemeMode(
switch (themeMode) {
ThemeMode.system || ThemeMode.light => ThemeMode.dark,
ThemeMode.dark => ThemeMode.light,
},
);
}),
focusUpActivator: const DirectionalFocusIntent(TraversalDirection.up),
focusDownActivator:
const DirectionalFocusIntent(TraversalDirection.down),
},
debugShowCheckedModeBanner: false,
);
}
}
class AppScrollBehavior extends MaterialScrollBehavior {
@override
Widget buildScrollbar(
BuildContext context,
Widget child,
ScrollableDetails details,
) {
return child;
}
@override
Set<PointerDeviceKind> get dragDevices => PointerDeviceKind.values.toSet();
}