Skip to content

Commit aada65d

Browse files
committed
fix: SFX played while scanning the library
1 parent 6bf62e5 commit aada65d

File tree

8 files changed

+124
-149
lines changed

8 files changed

+124
-149
lines changed

lib/config/routes.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import '../messages/collection.pb.dart';
1919

2020
final Map<String, WidgetBuilder> routes = {
2121
'/': (context) => const home.HomePage(),
22-
'/welcome/scanning': (context) => const welcome.ScanningPage(),
22+
'/scanning': (context) => const welcome.ScanningPage(),
2323
'/library': (context) => const library_home.LibraryHomePage(),
2424
'/artists': (context) => const collections.CollectionPage(
2525
key: ValueKey("Artists"),

lib/main.dart

+7-3
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,16 @@ class Rune extends StatelessWidget {
179179
final routeName = settings.name!;
180180

181181
if (routeName == '/') {
182-
final builder = routes["/"]!;
183-
final page = builder(context);
182+
return NoEffectPageRoute<dynamic>(
183+
settings: settings,
184+
builder: (context) => routes["/"]!(context),
185+
);
186+
}
184187

188+
if (routeName == '/scanning') {
185189
return NoEffectPageRoute<dynamic>(
186190
settings: settings,
187-
builder: (context) => page,
191+
builder: (context) => routes["/scanning"]!(context),
188192
);
189193
}
190194

lib/providers/library_manager.dart

+30-27
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:async';
33
import 'package:fluent_ui/fluent_ui.dart';
44

55
import '../utils/settings_manager.dart';
6+
import '../utils/router/navigation.dart';
67
import '../screens/collection/utils/collection_data_provider.dart';
78
import '../screens/settings_analysis/settings_analysis.dart';
89
import '../messages/library_manage.pb.dart';
@@ -96,34 +97,8 @@ class LibraryManagerProvider with ChangeNotifier {
9697
initialize,
9798
);
9899

99-
_cancelTaskSubscription =
100-
CancelTaskResponse.rustSignalStream.listen((event) {
101-
final cancelResponse = event.message;
102-
if (cancelResponse.success) {
103-
if (cancelResponse.type == CancelTaskType.ScanAudioLibrary) {
104-
_updateScanProgress(
105-
cancelResponse.path,
106-
ScanTaskType.IndexFiles,
107-
0,
108-
0,
109-
TaskStatus.cancelled,
110-
false,
111-
);
112-
} else if (cancelResponse.type ==
113-
CancelTaskType.AnalyseAudioLibrary) {
114-
_updateAnalyseProgress(
115-
cancelResponse.path,
116-
0,
117-
0,
118-
TaskStatus.cancelled,
119-
false,
120-
);
121-
}
122-
}
123-
});
124-
125100
if (initialize) {
126-
analyseLibrary(scanResult.path);
101+
$$replace("/library");
127102
}
128103

129104
// Complete the scan task
@@ -159,6 +134,31 @@ class LibraryManagerProvider with ChangeNotifier {
159134
_analyseCompleters[analyseResult.path]?.complete();
160135
_analyseCompleters.remove(analyseResult.path);
161136
});
137+
138+
_cancelTaskSubscription =
139+
CancelTaskResponse.rustSignalStream.listen((event) {
140+
final cancelResponse = event.message;
141+
if (cancelResponse.success) {
142+
if (cancelResponse.type == CancelTaskType.ScanAudioLibrary) {
143+
_updateScanProgress(
144+
cancelResponse.path,
145+
ScanTaskType.IndexFiles,
146+
0,
147+
0,
148+
TaskStatus.cancelled,
149+
false,
150+
);
151+
} else if (cancelResponse.type == CancelTaskType.AnalyseAudioLibrary) {
152+
_updateAnalyseProgress(
153+
cancelResponse.path,
154+
0,
155+
0,
156+
TaskStatus.cancelled,
157+
false,
158+
);
159+
}
160+
}
161+
});
162162
}
163163

164164
void _updateScanProgress(
@@ -210,6 +210,9 @@ class LibraryManagerProvider with ChangeNotifier {
210210
}
211211

212212
Future<void> scanLibrary(String path, [bool isInitializeTask = false]) async {
213+
if (isInitializeTask) {
214+
$$replace('/scanning');
215+
}
213216
_updateScanProgress(
214217
path,
215218
ScanTaskType.IndexFiles,

lib/screens/home/widgets/select_library.dart

+7-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'package:provider/provider.dart';
55
import 'package:fluent_ui/fluent_ui.dart';
66
import 'package:material_symbols_icons/symbols.dart';
77

8-
import '../../../utils/router/navigation.dart';
98
import '../../../utils/dialogs/failed_to_initialize_library.dart';
109
import '../../../providers/library_path.dart';
1110
import '../../../providers/responsive_providers.dart';
@@ -99,7 +98,6 @@ class _SelectLibraryPageState extends State<SelectLibraryPage> {
9998
return const AddLibrarySettingButton(
10099
tryClose: false,
101100
navigateIfFailed: false,
102-
useRootNavigate: true,
103101
);
104102
}
105103

@@ -117,15 +115,13 @@ class _SelectLibraryPageState extends State<SelectLibraryPage> {
117115
final (switched, error) =
118116
await libraryPath.setLibraryPath(path);
119117

120-
if (switched) {
121-
$$replace('/library');
122-
} else {
123-
if (!context.mounted) return;
124-
await showFailedToInitializeLibrary(
125-
context,
126-
error,
127-
);
128-
}
118+
if (!context.mounted) return;
119+
if (switched) return;
120+
121+
await showFailedToInitializeLibrary(
122+
context,
123+
error,
124+
);
129125
},
130126
);
131127
},

lib/screens/home/widgets/welcome.dart

-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'package:permission_handler/permission_handler.dart';
88

99
import '../../../providers/library_manager.dart';
1010
import '../../../utils/ax_shadow.dart';
11-
import '../../../utils/router/navigation.dart';
1211
import '../../../utils/dialogs/failed_to_initialize_library.dart';
1312
import '../../../providers/library_path.dart';
1413
import '../../../providers/responsive_providers.dart';
@@ -88,7 +87,6 @@ class WelcomePage extends StatelessWidget {
8887

8988
if (success) {
9089
libraryManager.scanLibrary(path, true);
91-
$$replace("/library");
9290
} else {
9391
if (!context.mounted) return;
9492
await showFailedToInitializeLibrary(

lib/screens/settings_library/settings_library.dart

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class _SettingsLibraryPageState extends State<SettingsLibraryPage> {
6666
const AddLibrarySettingButton(
6767
tryClose: true,
6868
navigateIfFailed: true,
69-
useRootNavigate: false,
7069
),
7170
SettingsButton(
7271
icon: Symbols.refresh,

lib/screens/settings_library/widgets/add_library_setting_button.dart

-7
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ class AddLibrarySettingButton extends StatelessWidget {
1616
super.key,
1717
required this.tryClose,
1818
required this.navigateIfFailed,
19-
required this.useRootNavigate,
2019
});
2120

2221
final bool tryClose;
2322
final bool navigateIfFailed;
24-
final bool useRootNavigate;
2523

2624
@override
2725
Widget build(BuildContext context) {
@@ -48,11 +46,6 @@ class AddLibrarySettingButton extends StatelessWidget {
4846

4947
if (switched) {
5048
libraryManager.scanLibrary(path, true);
51-
if (useRootNavigate) {
52-
$$replace('/library');
53-
} else {
54-
$push('/library');
55-
}
5649
} else {
5750
if (!context.mounted) return;
5851
await showFailedToInitializeLibrary(context, error);

lib/widgets/router/rune_router_frame_implementation.dart

+79-97
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import 'package:fluent_ui/fluent_ui.dart';
33

44
import '../../main.dart';
55

6-
import '../../routes/welcome.dart' as welcome;
7-
import '../../providers/library_manager.dart';
8-
96
import '../../screens/bsod/bsod.dart';
107

118
import '../../widgets/navigation_bar/flip_animation.dart';
@@ -48,103 +45,88 @@ class _RuneRouterFrameImplementationState
4845
final r = Provider.of<ResponsiveProvider>(context);
4946
final crash = Provider.of<CrashProvider>(context);
5047

51-
return Selector<LibraryManagerProvider, bool>(
52-
selector: (_, libraryManager) {
53-
final scanProgress =
54-
libraryManager.getScanTaskProgress(library.currentPath);
55-
final scanning = scanProgress?.status == TaskStatus.working;
56-
57-
return scanning && (scanProgress?.initialize ?? false);
58-
},
59-
builder: (context, scanning, child) {
60-
final isCar = r.smallerOrEqualTo(DeviceType.car, false);
61-
final isZune = r.smallerOrEqualTo(DeviceType.zune, false);
62-
final diskOnRight = r.smallerOrEqualTo(DeviceType.car, false);
63-
64-
final showDisk = isZune || isCar;
65-
66-
if (crash.report != null) {
67-
return Bsod(report: crash.report!);
68-
}
69-
70-
if (scanning) {
71-
return const welcome.ScanningPage();
72-
}
73-
74-
if (library.currentPath == null) {
75-
return Container();
76-
}
77-
78-
final mainContent = FocusTraversalOrder(
79-
order: const NumericFocusOrder(2),
80-
child: widget.child,
81-
);
82-
83-
final path = Provider.of<RouterPathProvider>(context).path;
84-
85-
return Stack(
86-
children: [
87-
if (!disableBrandingAnimation) const BrandingAnimation(),
88-
ScaleFadeContainer(
89-
delay: disableBrandingAnimation
90-
? const Duration(milliseconds: 0)
91-
: const Duration(milliseconds: 4350),
92-
duration: disableBrandingAnimation
93-
? const Duration(milliseconds: 200)
94-
: const Duration(milliseconds: 500),
95-
child: FlipAnimationContext(
96-
child: FocusTraversalGroup(
97-
policy: OrderedTraversalPolicy(),
98-
child: RuneStack(
99-
alignment: diskOnRight
100-
? Alignment.centerRight
101-
: Alignment.bottomCenter,
102-
children: [
103-
if (path == '/cover_wall' && !showDisk) mainContent,
104-
if (!showDisk)
105-
const FocusTraversalOrder(
106-
order: NumericFocusOrder(3),
107-
child: PlaybackController(),
108-
),
109-
FocusTraversalOrder(
110-
order: const NumericFocusOrder(1),
111-
child: DeviceTypeBuilder(
112-
deviceType: const [
113-
DeviceType.band,
114-
DeviceType.dock,
115-
DeviceType.tv
116-
],
117-
builder: (context, activeBreakpoint) {
118-
final isSmallView =
119-
activeBreakpoint == DeviceType.band ||
120-
activeBreakpoint == DeviceType.dock;
121-
122-
if (!isSmallView) {
123-
return NavigationBar(path: path);
124-
}
125-
126-
return const Positioned(
127-
top: -12,
128-
left: -12,
129-
child: NavigationBackButton(),
130-
);
131-
},
132-
),
133-
),
134-
if (!(path == '/cover_wall' && !showDisk)) mainContent,
135-
if (showDisk)
136-
const FocusTraversalOrder(
137-
order: NumericFocusOrder(4),
138-
child: CoverArtDisk(),
139-
),
140-
],
48+
final isCar = r.smallerOrEqualTo(DeviceType.car, false);
49+
final isZune = r.smallerOrEqualTo(DeviceType.zune, false);
50+
final diskOnRight = r.smallerOrEqualTo(DeviceType.car, false);
51+
52+
final showDisk = isZune || isCar;
53+
54+
if (crash.report != null) {
55+
return Bsod(report: crash.report!);
56+
}
57+
58+
if (library.currentPath == null) {
59+
return Container();
60+
}
61+
62+
final mainContent = FocusTraversalOrder(
63+
order: const NumericFocusOrder(2),
64+
child: widget.child,
65+
);
66+
67+
final path = Provider.of<RouterPathProvider>(context).path;
68+
69+
return Stack(
70+
children: [
71+
if (!disableBrandingAnimation) const BrandingAnimation(),
72+
ScaleFadeContainer(
73+
delay: disableBrandingAnimation
74+
? const Duration(milliseconds: 0)
75+
: const Duration(milliseconds: 4350),
76+
duration: disableBrandingAnimation
77+
? const Duration(milliseconds: 200)
78+
: const Duration(milliseconds: 500),
79+
child: FlipAnimationContext(
80+
child: FocusTraversalGroup(
81+
policy: OrderedTraversalPolicy(),
82+
child: RuneStack(
83+
alignment: diskOnRight
84+
? Alignment.centerRight
85+
: Alignment.bottomCenter,
86+
children: [
87+
if (path == '/cover_wall' && !showDisk) mainContent,
88+
if (!showDisk)
89+
const FocusTraversalOrder(
90+
order: NumericFocusOrder(3),
91+
child: PlaybackController(),
92+
),
93+
FocusTraversalOrder(
94+
order: const NumericFocusOrder(1),
95+
child: DeviceTypeBuilder(
96+
deviceType: const [
97+
DeviceType.band,
98+
DeviceType.dock,
99+
DeviceType.tv
100+
],
101+
builder: (context, activeBreakpoint) {
102+
final isSmallView =
103+
activeBreakpoint == DeviceType.band ||
104+
activeBreakpoint == DeviceType.dock;
105+
106+
if (!isSmallView) {
107+
return NavigationBar(path: path);
108+
}
109+
110+
return const Positioned(
111+
top: -12,
112+
left: -12,
113+
child: NavigationBackButton(),
114+
);
115+
},
116+
),
141117
),
142-
),
118+
if (!(path == '/cover_wall' && !showDisk)) mainContent,
119+
if (showDisk)
120+
const FocusTraversalOrder(
121+
order: NumericFocusOrder(4),
122+
child: CoverArtDisk(),
123+
),
124+
],
143125
),
144126
),
145-
],
146-
);
147-
},
127+
),
128+
),
129+
],
148130
);
149131
}
150132
}

0 commit comments

Comments
 (0)