app/lib/main.dart

123 lines
4.1 KiB
Dart
Raw Normal View History

2023-10-09 09:32:07 +08:00
import 'package:desktop_webview_window/desktop_webview_window.dart';
2024-03-07 23:01:32 +08:00
import 'package:fluent_ui/fluent_ui.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
2024-03-15 00:01:06 +08:00
import 'package:starcitizen_doctor/generated/l10n.dart';
2023-10-09 09:32:07 +08:00
import 'package:window_manager/window_manager.dart';
2024-03-15 00:01:06 +08:00
import 'package:flutter_localizations/flutter_localizations.dart';
2023-10-09 09:32:07 +08:00
2024-03-07 23:01:32 +08:00
import 'app.dart';
2023-10-09 09:32:07 +08:00
void main(List<String> args) async {
2024-03-07 23:01:32 +08:00
// webview window
2023-10-09 09:32:07 +08:00
if (runWebViewTitleBarWidget(args,
backgroundColor: const Color.fromRGBO(19, 36, 49, 1),
builder: _defaultWebviewTitleBar)) {
return;
}
2024-03-07 23:01:32 +08:00
WidgetsFlutterBinding.ensureInitialized();
await _initWindow();
// run app
runApp(const ProviderScope(child: App()));
2023-10-09 09:32:07 +08:00
}
2024-03-07 23:01:32 +08:00
_initWindow() async {
await windowManager.ensureInitialized();
await windowManager.setTitleBarStyle(
TitleBarStyle.hidden,
windowButtonVisibility: false,
);
await windowManager.center(animate: true);
}
class App extends HookConsumerWidget {
const App({super.key});
2023-10-09 09:32:07 +08:00
@override
2024-03-07 23:01:32 +08:00
Widget build(BuildContext context, WidgetRef ref) {
final router = ref.watch(routerProvider);
final appState = ref.watch(appGlobalModelProvider);
return FluentApp.router(
title: "StarCitizenToolBox",
restorationScopeId: "StarCitizenToolBox",
2023-10-09 09:32:07 +08:00
themeMode: ThemeMode.dark,
2024-03-15 00:01:06 +08:00
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
FluentLocalizations.delegate,
],
supportedLocales: S.delegate.supportedLocales,
2023-12-13 22:53:03 +08:00
builder: (context, child) {
return MediaQuery(
data:
2024-03-17 12:44:50 +08:00
MediaQuery.of(context).copyWith(textScaler: TextScaler.noScaling),
2023-12-13 22:53:03 +08:00
child: child ?? const SizedBox(),
);
},
2023-11-11 01:18:30 +08:00
theme: FluentThemeData(
brightness: Brightness.dark,
fontFamily: "SourceHanSansCN-Regular",
navigationPaneTheme: NavigationPaneThemeData(
2024-03-07 23:01:32 +08:00
backgroundColor: appState.themeConf.backgroundColor,
),
2024-03-07 23:01:32 +08:00
menuColor: appState.themeConf.menuColor,
micaBackgroundColor: appState.themeConf.micaColor,
buttonTheme: ButtonThemeData(
defaultButtonStyle: ButtonStyle(
2024-03-17 12:44:50 +08:00
shape: ButtonState.all(RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4),
side: BorderSide(color: Colors.white.withOpacity(.01)))),
))),
2024-03-17 16:54:09 +08:00
locale: appState.appLocale,
2023-10-09 09:32:07 +08:00
debugShowCheckedModeBanner: false,
2024-03-07 23:01:32 +08:00
routeInformationParser: router.routeInformationParser,
routerDelegate: router.routerDelegate,
routeInformationProvider: router.routeInformationProvider,
2023-10-09 09:32:07 +08:00
);
}
}
Widget _defaultWebviewTitleBar(BuildContext context) {
final state = TitleBarWebViewState.of(context);
final controller = TitleBarWebViewController.of(context);
return FluentTheme(
data: FluentThemeData.dark(),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
IconButton(
onPressed: !state.canGoBack ? null : controller.back,
icon: const Icon(FluentIcons.chevron_left),
),
const SizedBox(width: 12),
IconButton(
onPressed: !state.canGoForward ? null : controller.forward,
icon: const Icon(FluentIcons.chevron_right),
),
const SizedBox(width: 12),
if (state.isLoading)
IconButton(
onPressed: controller.stop,
icon: const Icon(FluentIcons.chrome_close),
)
else
IconButton(
onPressed: controller.reload,
icon: const Icon(FluentIcons.refresh),
),
const SizedBox(width: 12),
(state.isLoading)
? const SizedBox(
2024-03-17 12:44:50 +08:00
width: 24,
height: 24,
child: ProgressRing(),
)
2023-10-09 09:32:07 +08:00
: const SizedBox(width: 24),
const SizedBox(width: 12),
2023-10-29 11:04:22 +08:00
SelectableText(state.url ?? ""),
2023-10-09 09:32:07 +08:00
const Spacer()
],
));
}