-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
app.dart
84 lines (74 loc) · 2.06 KB
/
app.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
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:tray_manager/tray_manager.dart';
import 'package:window_manager/window_manager.dart';
import '../apps_list/apps_list.dart';
import '../logs/log_page.dart';
import '../theme/theme.dart';
import 'loading/loading_page.dart';
import 'settings/settings.dart';
import 'window/nyrna_window.dart';
class App extends StatefulWidget {
const App({Key? key}) : super(key: key);
@override
State<App> createState() => _AppState();
}
class _AppState extends State<App> with TrayListener, WindowListener {
@override
void initState() {
trayManager.addListener(this);
windowManager.addListener(this);
super.initState();
}
@override
void dispose() {
trayManager.removeListener(this);
windowManager.removeListener(this);
super.dispose();
}
@override
void onWindowClose() {
/// Only working on Windows for some reason.
/// Linux will use `flutter_window_close` instead.
if (settingsCubit.state.closeToTray) {
NyrnaWindow.instance.hide();
return;
} else {
super.onWindowClose();
}
}
@override
void onWindowRestore() {
appsListCubit.manualRefresh();
super.onWindowRestore();
}
@override
void onTrayIconMouseDown() {
trayManager.popUpContextMenu();
super.onTrayIconMouseDown();
}
@override
void onTrayIconRightMouseDown() {
trayManager.popUpContextMenu();
super.onTrayIconRightMouseDown();
}
@override
Widget build(BuildContext context) {
return BlocBuilder<ThemeCubit, ThemeState>(
builder: (context, state) {
return MaterialApp(
title: 'Nyrna',
debugShowCheckedModeBanner: false,
theme: state.themeData,
routes: {
LoadingPage.id: (context) => const LoadingPage(),
LogPage.id: (context) => LogPage(),
AppsListPage.id: (context) => const AppsListPage(),
SettingsPage.id: (conext) => SettingsPage(),
},
home: const LoadingPage(),
);
},
);
}
}