Skip to content

Commit

Permalink
feat(gebura): support scan local folder
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Oct 16, 2024
1 parent 779a811 commit 0e6b8ee
Show file tree
Hide file tree
Showing 13 changed files with 1,186 additions and 189 deletions.
51 changes: 51 additions & 0 deletions lib/bloc/gebura/gebura_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import 'package:tuihub_protos/librarian/v1/common.pb.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:uuid/uuid.dart';

import '../../common/app_scan/app_scan.dart';
import '../../common/app_scan/model.dart';
import '../../common/bloc_event_status_mixin.dart';
import '../../common/platform.dart';
import '../../common/steam/steam.dart';
Expand Down Expand Up @@ -44,10 +46,17 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
.loadTrackedAppInsts()
.asMap()
.map((_, value) => MapEntry(value.uuid, value));
final localCommonLibraryFolders = state.localCommonLibraryFolders ??
_repo
.loadTrackedCommonAppFolders()
.asMap()
.map((_, value) => MapEntry(value.basePath, value));

add(GeburaRefreshLibraryListEvent());
emit(state.copyWith(
localTrackedApps: localTrackedApps,
localTrackedAppInsts: localTrackedAppInsts,
localCommonLibraryFolders: localCommonLibraryFolders,
));
});

Expand Down Expand Up @@ -229,6 +238,18 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
));
});

on<GeburaSaveLocalCommonAppFolderSettingEvent>((event, emit) async {
final setting = event.setting;
await _repo.setTrackedCommonAppFolder(setting);
emit(state.copyWith(
localCommonLibraryFolders: {
...state.localCommonLibraryFolders ?? {},
setting.basePath: setting,
},
));
add(GeburaScanLocalLibraryEvent());
}, transformer: droppable());

on<GeburaSearchAppInfosEvent>((event, emit) async {
emit(GeburaSearchAppInfosState(state, EventStatus.processing));
final resp = await _api.doRequest(
Expand Down Expand Up @@ -504,6 +525,36 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
});

on<GeburaScanLocalLibraryEvent>((event, emit) async {
add(GeburaScanLocalCommonLibraryEvent());
add(GeburaScanLocalSteamLibraryEvent());
}, transformer: droppable());

on<GeburaScanLocalCommonLibraryEvent>((event, emit) async {
emit(state.copyWith(
localLibraryStateMessage: S.current.scanningLocalFiles));
final folders = state.localCommonLibraryFolders ?? {};
for (final folder in folders.values) {
final result = await scanCommonApps(folder);
final tracked = _repo.loadTrackedAppInsts();
final unTracked = result.installedApps.where(
(element) => !tracked.any(
(t) =>
t.type == LocalAppInstType.common &&
t.path == element.installPath,
),
);
emit(state.copyWith(
localLibraryStateMessage: unTracked.isNotEmpty
? S.current.newApplicationFound(unTracked.length)
: '',
localInstalledCommonAppInsts: result.installedApps
.asMap()
.map((_, value) => MapEntry(value.installPath, value)),
));
}
}, transformer: droppable());

on<GeburaScanLocalSteamLibraryEvent>((event, emit) async {
if (!PlatformHelper.isWindowsApp()) {
return;
}
Expand Down
10 changes: 10 additions & 0 deletions lib/bloc/gebura/gebura_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ final class GeburaApplyLibraryFilterEvent extends GeburaEvent {

final class GeburaScanLocalLibraryEvent extends GeburaEvent {}

final class GeburaScanLocalCommonLibraryEvent extends GeburaEvent {}

final class GeburaScanLocalSteamLibraryEvent extends GeburaEvent {}

final class GeburaClearLocalLibraryStateEvent extends GeburaEvent {}

final class GeburaTrackSteamAppsEvent extends GeburaEvent {
Expand Down Expand Up @@ -61,6 +65,12 @@ final class GeburaLaunchLocalCommonAppInstEvent extends GeburaEvent {
GeburaLaunchLocalCommonAppInstEvent(this.uuid);
}

final class GeburaSaveLocalCommonAppFolderSettingEvent extends GeburaEvent {
final CommonAppFolderScanSetting setting;

GeburaSaveLocalCommonAppFolderSettingEvent(this.setting);
}

// Events handle server data.

// TODO: review
Expand Down
12 changes: 12 additions & 0 deletions lib/bloc/gebura/gebura_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class GeburaState {
late LibrarySettings? librarySettings;
late Map<String, LocalTrackedApp>? localTrackedApps;
late Map<String, LocalTrackedAppInst>? localTrackedAppInsts;
late Map<String, InstalledCommonApps>? localInstalledCommonAppInsts;
late Map<String, InstalledSteamApps>? localInstalledSteamAppInsts;
late Map<String, CommonAppFolderScanSetting>? localCommonLibraryFolders;
late List<String>? localSteamLibraryFolders;

Map<App, List<AppInst>> getAppInsts(Int64 id) {
Expand Down Expand Up @@ -84,7 +86,9 @@ class GeburaState {
this.librarySettings,
this.localTrackedApps,
this.localTrackedAppInsts,
this.localInstalledCommonAppInsts,
this.localInstalledSteamAppInsts,
this.localCommonLibraryFolders,
this.localSteamLibraryFolders,
});

Expand All @@ -101,7 +105,9 @@ class GeburaState {
LibrarySettings? librarySettings,
Map<String, LocalTrackedApp>? localTrackedApps,
Map<String, LocalTrackedAppInst>? localTrackedAppInsts,
Map<String, InstalledCommonApps>? localInstalledCommonAppInsts,
Map<String, InstalledSteamApps>? localInstalledSteamAppInsts,
Map<String, CommonAppFolderScanSetting>? localCommonLibraryFolders,
List<String>? localSteamLibraryFolders,
}) {
return GeburaState(
Expand All @@ -118,8 +124,12 @@ class GeburaState {
librarySettings: librarySettings ?? this.librarySettings,
localTrackedApps: localTrackedApps ?? this.localTrackedApps,
localTrackedAppInsts: localTrackedAppInsts ?? this.localTrackedAppInsts,
localInstalledCommonAppInsts:
localInstalledCommonAppInsts ?? this.localInstalledCommonAppInsts,
localInstalledSteamAppInsts:
localInstalledSteamAppInsts ?? this.localInstalledSteamAppInsts,
localCommonLibraryFolders:
localCommonLibraryFolders ?? this.localCommonLibraryFolders,
localSteamLibraryFolders:
localSteamLibraryFolders ?? this.localSteamLibraryFolders,
);
Expand All @@ -140,7 +150,9 @@ class GeburaState {
librarySettings = other.librarySettings;
localTrackedApps = other.localTrackedApps;
localTrackedAppInsts = other.localTrackedAppInsts;
localInstalledCommonAppInsts = other.localInstalledCommonAppInsts;
localInstalledSteamAppInsts = other.localInstalledSteamAppInsts;
localCommonLibraryFolders = other.localCommonLibraryFolders;
localSteamLibraryFolders = other.localSteamLibraryFolders;
}
}
Expand Down
Loading

0 comments on commit 0e6b8ee

Please sign in to comment.