Skip to content

Commit

Permalink
feat(gebura): rebuild local app scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Oct 15, 2024
1 parent 1034b28 commit 779a811
Show file tree
Hide file tree
Showing 34 changed files with 1,996 additions and 1,168 deletions.
7 changes: 7 additions & 0 deletions l10n_arb/intl_zh_CN.arb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"gebura": "Gebura",
"store": "商店",
"library": "库",
"localLibraryManage": "本地库管理",
"unknownApp": "未知应用",
"pleaseSetupApplicationPath": "请设置应用程序路径",
"pleaseDontReRunApplication": "请不要重复运行应用程序",
Expand All @@ -79,6 +80,12 @@
"importSteamApplicationFinished": "导入Steam应用程序完成,成功 {success} 个,失败 {failed} 个。",
"noAppInLibrary": "库中没有应用",
"addApplication": "添加应用",
"steamScanResultPlatformUnsupported": "不支持当前平台",
"steamScanResultSteamNotFound": "未发现Steam客户端",
"steamScanResultLibraryNotFound": "未发现Steam游戏库",
"steamScanResultLibraryEmpty": "Steam游戏库为空",
"steamScanResultUnknownError": "扫描时出现未知错误",
"steamScanResultFinished": "扫描完成",

"yesod": "Yesod",
"feedConfigManage": "订阅管理",
Expand Down
167 changes: 1 addition & 166 deletions lib/bloc/gebura/gebura_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:uuid/uuid.dart';

import '../../common/bloc_event_status_mixin.dart';
import '../../common/platform.dart';
import '../../common/steam/local_library.dart';
import '../../common/steam/steam.dart';
import '../../ffi/ffi.dart';
import '../../ffi/ffi_model.dart';
import '../../l10n/l10n.dart';
Expand Down Expand Up @@ -587,171 +587,6 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
));
}, transformer: droppable());

on<GeburaImportNewAppInstEvent>((event, emit) async {
emit(GeburaImportNewAppInstState(state, EventStatus.processing));
var id = event.appID;
if (id == null || event.newAppWithInfoID != null) {
final appResp = await _api.doRequest(
(client) => client.createApp,
CreateAppRequest(
app: App(
name: event.name,
),
),
);
if (appResp.status != ApiStatus.success) {
emit(GeburaImportNewAppInstState(state, EventStatus.failed,
msg: appResp.error));
return;
}
id = appResp.getData().id;
if (event.newAppWithInfoID != null) {
final assignResp = await _api.doRequest(
(client) => client.assignApp,
AssignAppRequest(
appInfoId: event.newAppWithInfoID,
appId: id,
),
);
if (assignResp.status != ApiStatus.success) {
emit(GeburaImportNewAppInstState(state, EventStatus.failed,
msg: appResp.error));
return;
}
}
}
final instResp = await _api.doRequest(
(client) => client.createAppInst,
CreateAppInstRequest(
appInst: AppInst(
appId: id,
deviceId: _deviceID,
),
),
);
if (instResp.status != ApiStatus.success) {
emit(GeburaImportNewAppInstState(state, EventStatus.failed,
msg: instResp.error));
return;
}
await _repo.setLocalAppInstIndependent(LocalAppInstIndependent(
appInstID: instResp.getData().id.id.toInt(),
path: event.path,
));
// TODO
// await _repo.setLocalAppInstLauncherSetting(CommonAppInstLaunchSetting(
// appInstID: instResp.getData().id.id.toInt(),
// path: '',
// installPath: event.path,
// realPath: '',
// processName: '',
// sleepTime: 0,
// advancedTracing: false,
// ));
add(GeburaRefreshLibraryListEvent());
emit(GeburaImportNewAppInstState(state, EventStatus.success,
msg: instResp.error));
}, transformer: droppable());

// on<GeburaImportSteamAppsEvent>((event, emit) async {
// if (!PlatformHelper.isWindowsApp()) {
// return;
// }
// emit(GeburaImportSteamAppsState(
// state.copyWith(
// localLibraryStateMessage: S.current.importingSteamApplications),
// EventStatus.processing));
// var processCount = 0;
// var failedCount = 0;
// final importedSteamApps = _repo.getImportedSteamAppInsts();
// for (final steamAppID in event.steamAppIDs) {
// processCount += 1;
// emit(GeburaImportSteamAppsState(
// state.copyWith(
// localLibraryStateMessage:
// '${S.current.importingSteamApplications} $processCount ( $failedCount ) / ${event.steamAppIDs.length}',
// ),
// EventStatus.processing));
// if (importedSteamApps
// .any((element) => element.steamAppID == steamAppID)) {
// continue;
// }
// await _api.doRequest(
// (client) => client.syncAppInfos,
// SyncAppInfosRequest(
// appInfoIds: [
// AppInfoID(
// internal: false, source: 'steam', sourceAppId: steamAppID)
// ],
// waitData: true,
// ),
// );
// final purchaseResp = await _api.doRequest(
// (client) => client.purchaseAppInfo,
// PurchaseAppInfoRequest(
// appInfoId: AppInfoID(
// internal: false, source: 'steam', sourceAppId: steamAppID),
// ),
// );
// if (purchaseResp.status != ApiStatus.success) {
// failedCount += 1;
// continue;
// }
// final createResp = await _api.doRequest(
// (client) => client.createApp,
// CreateAppRequest(
// app: App(
// name: (state.localInstalledSteamAppInsts ?? [])
// .firstWhere((element) => element.appId == steamAppID)
// .name,
// ),
// ),
// );
// if (createResp.status != ApiStatus.success) {
// failedCount += 1;
// continue;
// }
// final assignResp = await _api.doRequest(
// (client) => client.assignApp,
// AssignAppRequest(
// appInfoId: purchaseResp.getData().id,
// appId: createResp.getData().id,
// ),
// );
// if (assignResp.status != ApiStatus.success) {
// failedCount += 1;
// continue;
// }
// final instResp = await _api.doRequest(
// (client) => client.createAppInst,
// CreateAppInstRequest(
// appInst: AppInst(
// appId: createResp.getData().id,
// deviceId: _deviceID,
// ),
// ),
// );
// if (instResp.status != ApiStatus.success) {
// failedCount += 1;
// continue;
// }
// importedSteamApps.add(ImportedSteamAppInst(
// instID: instResp.getData().id.id.toInt(),
// appID: createResp.getData().id.id.toInt(),
// steamAppID: steamAppID,
// ));
// }
// await _repo.setImportedSteamAppInsts(importedSteamApps);
// add(GeburaRefreshLibraryEvent());
// emit(GeburaImportSteamAppsState(
// state.copyWith(
// localLibraryStateMessage: S.current.importSteamApplicationFinished(
// processCount - failedCount, failedCount),
// importedSteamAppInsts: importedSteamApps,
// ),
// EventStatus.success));
// }, transformer: droppable());

on<GeburaFetchBoundAppInfosEvent>((event, emit) async {
emit(GeburaFetchBoundAppsState(state, EventStatus.processing));
final resp = await _api.doRequest(
Expand Down
26 changes: 13 additions & 13 deletions lib/bloc/gebura/gebura_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,19 @@ final class GeburaAssignAppEvent extends GeburaEvent {
// GeburaImportSteamAppsEvent(this.steamAppIDs);
// }

final class GeburaImportNewAppInstEvent extends GeburaEvent {
final String path;
final String name;
final InternalID? appID;
final InternalID? newAppWithInfoID;

GeburaImportNewAppInstEvent(
this.path,
this.name, {
this.appID,
this.newAppWithInfoID,
});
}
// final class GeburaImportNewAppInstEvent extends GeburaEvent {
// final String path;
// final String name;
// final InternalID? appID;
// final InternalID? newAppWithInfoID;
//
// GeburaImportNewAppInstEvent(
// this.path,
// this.name, {
// this.appID,
// this.newAppWithInfoID,
// });
// }

final class GeburaFetchBoundAppInfosEvent extends GeburaEvent {
final InternalID appID;
Expand Down
22 changes: 11 additions & 11 deletions lib/bloc/gebura/gebura_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,17 @@ class GeburaFetchBoundAppsState extends GeburaState with EventStatusMixin {
final String? msg;
}

class GeburaImportNewAppInstState extends GeburaState with EventStatusMixin {
GeburaImportNewAppInstState(GeburaState state, this.statusCode, {this.msg})
: super() {
_from(state);
}

@override
final EventStatus? statusCode;
@override
final String? msg;
}
// class GeburaImportNewAppInstState extends GeburaState with EventStatusMixin {
// GeburaImportNewAppInstState(GeburaState state, this.statusCode, {this.msg})
// : super() {
// _from(state);
// }
//
// @override
// final EventStatus? statusCode;
// @override
// final String? msg;
// }

class GeburaRefreshAppInfoState extends GeburaState with EventStatusMixin {
GeburaRefreshAppInfoState(GeburaState state, this.statusCode, {this.msg})
Expand Down
Loading

0 comments on commit 779a811

Please sign in to comment.