197 lines
5.9 KiB
Dart
Raw Normal View History

2023-10-24 13:39:05 +08:00
import 'package:appflowy/plugins/document/presentation/more/cubit/document_appearance_cubit.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/user_settings_service.dart';
import 'package:appflowy/workspace/application/notifications/notification_service.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy/workspace/application/settings/notifications/notification_settings_cubit.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
2023-10-24 13:39:05 +08:00
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
2023-10-24 13:39:05 +08:00
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
2021-06-19 23:41:19 +08:00
2023-10-24 13:39:05 +08:00
import 'prelude.dart';
feat: Customize the storage folder path (#1538) * feat: support customize folder path * feat: add l10n and optimize the logic * chore: code refactor * feat: add file read/write permission for macOS * fix: add toast for restoring path * feat: fetch apps and show them * feat: fetch apps and show them * feat: implement select document logic * feat: l10n and add select item callback * feat: add space between tile * chore: move file exporter to settings * chore: update UI * feat: support customizing folder when launching the app * feat: auto register after customizing folder * feat: l10n * feat: l10n * chore: reinitialize flowy sdk when calling init_sdk * chore: remove flowysdk const keyword to make sure it can be rebuild * chore: clear kv values when user logout * chore: replace current workspace id key in kv.db * feat: add config.name as a part of seesion_cache_key * feat: support open folder when launching * chore: fix some bugs * chore: dart fix & flutter analyze * chore: wrap 'sign up with ramdom user' as interface * feat: dismiss settings view after changing the folder * fix: read kv value after initializaing with new path * chore: remove user_id prefix from current workspace key * fix: move open latest view action to bloc * test: add test utils for integration tests * chore: move integration_test to its parent directory * test: add integration_test ci * test: switch to B from A, then switch to A again * chore: fix warings and format code and fix tests * chore: remove comment out codes * chore: rename some properties name and optimize the logic * chore: abstract logic of settings file exporter widget to cubit * chore: abstract location customizer view from file system view * chore: abstract settings page index to enum type * chore: remove the redundant underscore * test: fix integration test error * chore: enable integration test for windows and ubuntu * feat: abstract file picker as service and mock it under integration test * chore: fix bloc test Co-authored-by: nathan <nathan@appflowy.io>
2022-12-20 11:14:42 +08:00
2022-02-20 16:10:50 +08:00
class InitAppWidgetTask extends LaunchTask {
const InitAppWidgetTask();
2021-06-19 23:41:19 +08:00
@override
LaunchTaskType get type => LaunchTaskType.appLauncher;
@override
2022-01-28 18:34:21 +08:00
Future<void> initialize(LaunchContext context) async {
2023-10-02 09:12:24 +02:00
WidgetsFlutterBinding.ensureInitialized();
await NotificationService.initialize();
feat: Customize the storage folder path (#1538) * feat: support customize folder path * feat: add l10n and optimize the logic * chore: code refactor * feat: add file read/write permission for macOS * fix: add toast for restoring path * feat: fetch apps and show them * feat: fetch apps and show them * feat: implement select document logic * feat: l10n and add select item callback * feat: add space between tile * chore: move file exporter to settings * chore: update UI * feat: support customizing folder when launching the app * feat: auto register after customizing folder * feat: l10n * feat: l10n * chore: reinitialize flowy sdk when calling init_sdk * chore: remove flowysdk const keyword to make sure it can be rebuild * chore: clear kv values when user logout * chore: replace current workspace id key in kv.db * feat: add config.name as a part of seesion_cache_key * feat: support open folder when launching * chore: fix some bugs * chore: dart fix & flutter analyze * chore: wrap 'sign up with ramdom user' as interface * feat: dismiss settings view after changing the folder * fix: read kv value after initializaing with new path * chore: remove user_id prefix from current workspace key * fix: move open latest view action to bloc * test: add test utils for integration tests * chore: move integration_test to its parent directory * test: add integration_test ci * test: switch to B from A, then switch to A again * chore: fix warings and format code and fix tests * chore: remove comment out codes * chore: rename some properties name and optimize the logic * chore: abstract logic of settings file exporter widget to cubit * chore: abstract location customizer view from file system view * chore: abstract settings page index to enum type * chore: remove the redundant underscore * test: fix integration test error * chore: enable integration test for windows and ubuntu * feat: abstract file picker as service and mock it under integration test * chore: fix bloc test Co-authored-by: nathan <nathan@appflowy.io>
2022-12-20 11:14:42 +08:00
final widget = context.getIt<EntryPoint>().create(context.config);
final appearanceSetting =
await UserSettingsBackendService().getAppearanceSetting();
2023-10-02 09:12:24 +02:00
final dateTimeSettings =
await UserSettingsBackendService().getDateTimeSettings();
// If the passed-in context is not the same as the context of the
// application widget, the application widget will be rebuilt.
2022-01-28 18:34:21 +08:00
final app = ApplicationWidget(
key: ValueKey(context),
2022-10-25 17:30:57 +08:00
appearanceSetting: appearanceSetting,
2023-10-02 09:12:24 +02:00
dateTimeSettings: dateTimeSettings,
appTheme: await appTheme(appearanceSetting.theme),
2022-08-31 09:19:31 +08:00
child: widget,
2022-01-28 18:34:21 +08:00
);
Bloc.observer = ApplicationBlocObserver();
runApp(
EasyLocalization(
supportedLocales: const [
// In alphabetical order
2023-10-24 17:41:46 +08:00
Locale('am', 'ET'),
Locale('ar', 'SA'),
Locale('ca', 'ES'),
Locale('de', 'DE'),
Locale('en'),
Locale('es', 'VE'),
Locale('eu', 'ES'),
Locale('fr', 'FR'),
Locale('fr', 'CA'),
Locale('hu', 'HU'),
Locale('id', 'ID'),
Locale('it', 'IT'),
Locale('ja', 'JP'),
Locale('ko', 'KR'),
Locale('pl', 'PL'),
Locale('pt', 'BR'),
Locale('ru', 'RU'),
2023-11-28 11:46:11 +08:00
Locale('sv', 'SE'),
Locale('th', 'TH'),
Locale('tr', 'TR'),
Locale('uk', 'UA'),
Locale('ur'),
Locale('vi', 'VN'),
Locale('zh', 'CN'),
Locale('zh', 'TW'),
Locale('fa'),
2023-10-15 19:43:14 +05:30
Locale('hin'),
],
path: 'assets/translations',
fallbackLocale: const Locale('en'),
useFallbackTranslations: true,
saveLocale: false,
child: app,
),
2021-12-07 22:58:50 +05:30
);
2021-07-12 23:27:58 +08:00
2023-10-02 09:12:24 +02:00
return;
2021-06-19 23:41:19 +08:00
}
@override
Future<void> dispose() async {}
2021-06-19 23:41:19 +08:00
}
class ApplicationWidget extends StatefulWidget {
const ApplicationWidget({
2023-10-02 09:12:24 +02:00
super.key,
2021-06-19 23:41:19 +08:00
required this.child,
required this.appTheme,
2022-10-25 17:30:57 +08:00
required this.appearanceSetting,
2023-10-02 09:12:24 +02:00
required this.dateTimeSettings,
});
final Widget child;
final AppTheme appTheme;
final AppearanceSettingsPB appearanceSetting;
2023-10-02 09:12:24 +02:00
final DateTimeSettingsPB dateTimeSettings;
2021-06-19 23:41:19 +08:00
@override
State<ApplicationWidget> createState() => _ApplicationWidgetState();
}
class _ApplicationWidgetState extends State<ApplicationWidget> {
late final GoRouter routerConfig;
@override
void initState() {
super.initState();
// avoid rebuild routerConfig when the appTheme is changed.
routerConfig = generateRouter(widget.child);
}
@override
Widget build(BuildContext context) {
[feat] Allow user to select any Google Font (#2895) * chore: add label for font selection drop down * chore: add method to set font family * feat: add drop down to setting appearance view * feat: add fontFamily to document appearance cubit * feat: add bloc provider to root for document appearance style * feat: syncFont family from setting appearance dialog * feat: plumbing for font style in editor * fix: add blocprovider before pushing overlay * chore: add kv_keys * fix: use fontFamily in document appearance cubit * fix: remove bloc providers because bloc is supplied in ancestor * fix: remove unecessary bloc provider * chore: add constraints to popover * chore: add translation for search box * feat: add levenshtein for string sort * feat: add search bar view * refactor: levenshtein * chore: add tests for levenshtein algorithm * feat: add unit tests for appearance cubit * fix: analyzer warnings * feat: sort by ascending if query is empty * chore: add test for the font family setting widget * feat: make comparison case insensitive * feat: lazy load with listview.builder Co-authored-by: Yijing Huang <hyj891204@gmail.com> * fix: fonts loaded on open application * fix: checkmark doesn't show * fix: try catch before getFont * fix: clear text editing value on close * fix: remove autofocus for search text field * chore: add tests * feat: use sliver protocol Co-authored-by: Yijing Huang <hyj891204@gmail.com> * fix: avoid using intrinsic height Co-authored-by: Yijing Huang <hyj891204@gmail.com> * fix: extra paren caused build failure * feat: switch order of font family setting --------- Co-authored-by: Yijing Huang <hyj891204@gmail.com>
2023-07-04 14:30:38 -07:00
return MultiBlocProvider(
providers: [
BlocProvider<AppearanceSettingsCubit>(
create: (_) => AppearanceSettingsCubit(
widget.appearanceSetting,
2023-10-02 09:12:24 +02:00
widget.dateTimeSettings,
widget.appTheme,
)..readLocaleWhenAppLaunch(context),
),
BlocProvider<NotificationSettingsCubit>(
create: (_) => NotificationSettingsCubit(),
),
[feat] Allow user to select any Google Font (#2895) * chore: add label for font selection drop down * chore: add method to set font family * feat: add drop down to setting appearance view * feat: add fontFamily to document appearance cubit * feat: add bloc provider to root for document appearance style * feat: syncFont family from setting appearance dialog * feat: plumbing for font style in editor * fix: add blocprovider before pushing overlay * chore: add kv_keys * fix: use fontFamily in document appearance cubit * fix: remove bloc providers because bloc is supplied in ancestor * fix: remove unecessary bloc provider * chore: add constraints to popover * chore: add translation for search box * feat: add levenshtein for string sort * feat: add search bar view * refactor: levenshtein * chore: add tests for levenshtein algorithm * feat: add unit tests for appearance cubit * fix: analyzer warnings * feat: sort by ascending if query is empty * chore: add test for the font family setting widget * feat: make comparison case insensitive * feat: lazy load with listview.builder Co-authored-by: Yijing Huang <hyj891204@gmail.com> * fix: fonts loaded on open application * fix: checkmark doesn't show * fix: try catch before getFont * fix: clear text editing value on close * fix: remove autofocus for search text field * chore: add tests * feat: use sliver protocol Co-authored-by: Yijing Huang <hyj891204@gmail.com> * fix: avoid using intrinsic height Co-authored-by: Yijing Huang <hyj891204@gmail.com> * fix: extra paren caused build failure * feat: switch order of font family setting --------- Co-authored-by: Yijing Huang <hyj891204@gmail.com>
2023-07-04 14:30:38 -07:00
BlocProvider<DocumentAppearanceCubit>(
create: (_) => DocumentAppearanceCubit()..fetch(),
),
],
child: BlocBuilder<AppearanceSettingsCubit, AppearanceSettingsState>(
builder: (context, state) => MaterialApp.router(
builder: overlayManagerBuilder(),
debugShowCheckedModeBanner: false,
theme: state.lightTheme,
darkTheme: state.darkTheme,
themeMode: state.themeMode,
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: state.locale,
routerConfig: routerConfig,
),
),
2022-06-01 15:22:18 +08:00
);
}
2021-06-19 23:41:19 +08:00
}
class AppGlobals {
// static GlobalKey<ScaffoldMessengerState> scaffoldMessengerKey = GlobalKey();
2021-06-19 23:41:19 +08:00
static GlobalKey<NavigatorState> rootNavKey = GlobalKey();
static NavigatorState get nav => rootNavKey.currentState!;
}
class ApplicationBlocObserver extends BlocObserver {
@override
// ignore: unnecessary_overrides
void onTransition(Bloc bloc, Transition transition) {
// Log.debug("[current]: ${transition.currentState} \n\n[next]: ${transition.nextState}");
2022-04-14 21:16:29 +08:00
// Log.debug("${transition.nextState}");
super.onTransition(bloc, transition);
}
@override
void onError(BlocBase bloc, Object error, StackTrace stackTrace) {
Log.debug(error);
super.onError(bloc, error, stackTrace);
}
2021-11-04 13:22:35 +08:00
2022-04-14 21:16:29 +08:00
// @override
// void onEvent(Bloc bloc, Object? event) {
// Log.debug("$event");
// super.onEvent(bloc, event);
// }
}
Future<AppTheme> appTheme(String themeName) async {
if (themeName.isEmpty) {
return AppTheme.fallback;
} else {
try {
return await AppTheme.fromName(themeName);
} catch (e) {
return AppTheme.fallback;
}
}
}