Skip to content

Commit

Permalink
feat: upgrade proto to v0.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
MuZhou233 committed Feb 16, 2024
1 parent 193173b commit 8ee58be
Show file tree
Hide file tree
Showing 22 changed files with 133 additions and 238 deletions.
4 changes: 0 additions & 4 deletions l10n_arb/intl_zh_CN.arb
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@
"APP_TYPE": "类型",
"APP_TYPE_UNSPECIFIED": "未知",
"APP_TYPE_GAME": "游戏",
"APP_PACKAGE_SOURCE": "来源",
"APP_PACKAGE_SOURCE_UNSPECIFIED": "未知",
"APP_PACKAGE_SOURCE_MANUAL": "手动",
"APP_PACKAGE_SOURCE_SENTINEL": "扫描",
"FEED_CONFIG_STATUS": "状态",
"FEED_CONFIG_STATUS_UNSPECIFIED": "未知",
"FEED_CONFIG_STATUS_ACTIVE": "启用",
Expand Down
132 changes: 66 additions & 66 deletions lib/bloc/gebura/gebura_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,44 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
GeburaBloc(this._api, this._repo) : super(GeburaState()) {
on<GeburaInitEvent>((event, emit) async {
if (state.purchasedApps == null) {
add(GeburaPurchasedAppsLoadEvent());
add(GeburaPurchasedAppInfosLoadEvent());
add(GeburaScanLocalLibraryEvent());
}
});

on<GeburaPurchasedAppsLoadEvent>((event, emit) async {
on<GeburaPurchasedAppInfosLoadEvent>((event, emit) async {
emit(GeburaPurchasedAppsLoadState(state, EventStatus.processing));
final resp = await _api.doRequest(
(client) => client.getPurchasedApps,
GetPurchasedAppsRequest(),
(client) => client.getPurchasedAppInfos,
GetPurchasedAppInfosRequest(),
);
if (resp.status != ApiStatus.success) {
emit(GeburaPurchasedAppsLoadState(state, EventStatus.failed,
msg: resp.error));
return;
}
emit(GeburaPurchasedAppsLoadState(
state.copyWith(purchasedApps: resp.getData().apps),
state.copyWith(purchasedApps: resp.getData().appInfos),
EventStatus.success,
msg: resp.error));
}, transformer: droppable());

on<GeburaSetPurchasedAppIndexEvent>((event, emit) async {
on<GeburaSetPurchasedAppInfoIndexEvent>((event, emit) async {
final newState = state.copyWith();
newState.selectedPurchasedAppIndex = event.index;
emit(newState);
});

on<GeburaSearchAppsEvent>((event, emit) async {
on<GeburaSearchAppInfosEvent>((event, emit) async {
emit(GeburaSearchAppsState(state, EventStatus.processing));
final resp = await _api.doRequest(
(client) => client.searchApps,
SearchAppsRequest(
(client) => client.searchAppInfos,
SearchAppInfosRequest(
paging: PagingRequest(
pageSize: Int64(10),
pageNum: Int64(1),
),
keywords: event.query,
query: event.query,
),
);
if (resp.status != ApiStatus.success) {
Expand All @@ -75,16 +75,16 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
state,
EventStatus.success,
msg: resp.error,
apps: resp.getData().apps,
apps: resp.getData().appInfos,
));
}, transformer: droppable());

on<GeburaPurchaseEvent>((event, emit) async {
emit(GeburaPurchaseState(state, EventStatus.processing));
final resp = await _api.doRequest(
(client) => client.purchaseApp,
PurchaseAppRequest(
appId: AppID(
(client) => client.purchaseAppInfo,
PurchaseAppInfoRequest(
appInfoId: AppInfoID(
internal: true,
sourceAppId: event.id.id.toString(),
),
Expand All @@ -95,7 +95,7 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
return;
}
emit(GeburaPurchaseState(state, EventStatus.success, msg: resp.error));
add(GeburaPurchasedAppsLoadEvent());
add(GeburaPurchasedAppInfosLoadEvent());
}, transformer: droppable());

on<GeburaSetAppLauncherSettingEvent>((event, emit) async {
Expand All @@ -104,12 +104,12 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
emit(GeburaSetAppLauncherSettingState(state, EventStatus.success));
});

on<GeburaAddAppEvent>((event, emit) async {
on<GeburaAddAppInfoEvent>((event, emit) async {
emit(GeburaAddAppState(state, EventStatus.processing));
final resp = await _api.doRequest(
(client) => client.createApp,
CreateAppRequest(
app: event.app,
(client) => client.createAppInfo,
CreateAppInfoRequest(
appInfo: event.appInfo,
),
);
if (resp.status != ApiStatus.success) {
Expand All @@ -119,12 +119,12 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
emit(GeburaAddAppState(state, EventStatus.success, msg: resp.error));
}, transformer: droppable());

on<GeburaEditAppEvent>((event, emit) async {
on<GeburaEditAppInfoEvent>((event, emit) async {
emit(GeburaEditAppState(state, EventStatus.processing));
final resp = await _api.doRequest(
(client) => client.updateApp,
UpdateAppRequest(
app: event.app,
(client) => client.updateAppInfo,
UpdateAppInfoRequest(
appInfo: event.appInfo,
),
);
if (resp.status != ApiStatus.success) {
Expand All @@ -134,12 +134,12 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
emit(GeburaEditAppState(state, EventStatus.success, msg: resp.error));
}, transformer: droppable());

on<GeburaAddAppPackageEvent>((event, emit) async {
on<GeburaAddAppEvent>((event, emit) async {
emit(GeburaAddAppPackageState(state, EventStatus.processing));
final resp = await _api.doRequest(
(client) => client.createAppPackage,
CreateAppPackageRequest(
appPackage: event.appPackage,
(client) => client.createApp,
CreateAppRequest(
app: event.app,
),
);
if (resp.status != ApiStatus.success) {
Expand All @@ -151,12 +151,12 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
msg: resp.error));
}, transformer: droppable());

on<GeburaEditAppPackageEvent>((event, emit) async {
on<GeburaEditAppEvent>((event, emit) async {
emit(GeburaEditAppPackageState(state, EventStatus.processing));
final resp = await _api.doRequest(
(client) => client.updateAppPackage,
UpdateAppPackageRequest(
appPackage: event.appPackage,
(client) => client.updateApp,
UpdateAppRequest(
app: event.app,
),
);
if (resp.status != ApiStatus.success) {
Expand All @@ -168,13 +168,13 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
msg: resp.error));
}, transformer: droppable());

on<GeburaAssignAppPackageEvent>((event, emit) async {
on<GeburaAssignAppEvent>((event, emit) async {
emit(GeburaAssignAppPackageState(state, EventStatus.processing));
final resp = await _api.doRequest(
(client) => client.assignAppPackage,
AssignAppPackageRequest(
(client) => client.assignApp,
AssignAppRequest(
appInfoId: event.appInfoID,
appId: event.appID,
appPackageId: event.appPackageID,
),
);
if (resp.status != ApiStatus.success) {
Expand Down Expand Up @@ -284,27 +284,29 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
continue;
}
await _api.doRequest(
(client) => client.syncApps,
SyncAppsRequest(
appIds: [AppID(internal: false, source: 'steam', sourceAppId: app)],
(client) => client.syncAppInfos,
SyncAppInfosRequest(
appInfoIds: [
AppInfoID(internal: false, source: 'steam', sourceAppId: app)
],
waitData: true,
),
);
final purchaseResp = await _api.doRequest(
(client) => client.purchaseApp,
PurchaseAppRequest(
appId: AppID(internal: false, source: 'steam', sourceAppId: app),
(client) => client.purchaseAppInfo,
PurchaseAppInfoRequest(
appInfoId:
AppInfoID(internal: false, source: 'steam', sourceAppId: app),
),
);
if (purchaseResp.status != ApiStatus.success) {
failedCount += 1;
continue;
}
final createResp = await _api.doRequest(
(client) => client.createAppPackage,
CreateAppPackageRequest(
appPackage: AppPackage(
source: AppPackageSource.APP_PACKAGE_SOURCE_MANUAL,
(client) => client.createApp,
CreateAppRequest(
app: App(
name: (state.localSteamApps ?? [])
.firstWhere((element) => element.appId == app)
.name,
Expand All @@ -316,10 +318,10 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
continue;
}
final assignResp = await _api.doRequest(
(client) => client.assignAppPackage,
AssignAppPackageRequest(
appId: purchaseResp.getData().id,
appPackageId: createResp.getData().id,
(client) => client.assignApp,
AssignAppRequest(
appInfoId: purchaseResp.getData().id,
appId: createResp.getData().id,
),
);
if (assignResp.status != ApiStatus.success) {
Expand All @@ -332,7 +334,7 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
));
}
await _repo.setImportedSteamApps(importedSteamApps);
add(GeburaPurchasedAppsLoadEvent());
add(GeburaPurchasedAppInfosLoadEvent());
emit(GeburaImportSteamAppsState(
state.copyWith(
localLibraryState: S.current.importSteamApplicationFinished(
Expand All @@ -342,12 +344,12 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
EventStatus.success));
}, transformer: droppable());

on<GeburaFetchBoundAppsEvent>((event, emit) async {
on<GeburaFetchBoundAppInfosEvent>((event, emit) async {
emit(GeburaFetchBoundAppsState(state, EventStatus.processing));
final resp = await _api.doRequest(
(client) => client.getBoundApps,
GetBoundAppsRequest(
appId: event.appID,
(client) => client.getBoundAppInfos,
GetBoundAppInfosRequest(
appInfoId: event.appID,
),
);
if (resp.status != ApiStatus.success) {
Expand All @@ -356,7 +358,7 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
return;
}
final storeApps = state.storeApps ?? {};
storeApps[event.appID] = resp.getData().apps;
storeApps[event.appID] = resp.getData().appInfos;
emit(GeburaFetchBoundAppsState(
state.copyWith(storeApps: storeApps),
EventStatus.success,
Expand All @@ -369,11 +371,11 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
return _repo.getAppLauncherSetting(id.id.toInt());
}

Future<ListAppsResponse> listApps(
Future<ListAppInfosResponse> listAppInfos(
int pageSize, int pageNum, List<String> sourceFilter) async {
final resp = await _api.doRequest(
(client) => client.listApps,
ListAppsRequest(
(client) => client.listAppInfos,
ListAppInfosRequest(
paging:
PagingRequest(pageSize: Int64(pageSize), pageNum: Int64(pageNum)),
sourceFilter: sourceFilter,
Expand All @@ -382,28 +384,26 @@ class GeburaBloc extends Bloc<GeburaEvent, GeburaState> {
return resp.getData();
}

Future<ListAppPackagesResponse> listAppPackages(
int pageSize, int pageNum, List<AppPackageSource> sourceFilter) async {
Future<ListAppsResponse> listApps(int pageSize, int pageNum) async {
final resp = await _api.doRequest(
(client) => client.listAppPackages,
ListAppPackagesRequest(
(client) => client.listApps,
ListAppsRequest(
paging:
PagingRequest(pageSize: Int64(pageSize), pageNum: Int64(pageNum)),
sourceFilter: sourceFilter,
),
);
return resp.getData();
}
}

App mixApp(List<App> apps) {
var mixedApp = App();
AppInfo mixAppInfo(List<AppInfo> apps) {
var mixedApp = AppInfo();
if (apps.isEmpty) {
return mixedApp;
}
mixedApp = apps.where((element) => element.internal).isNotEmpty
? apps.firstWhere((element) => element.internal)
: App();
: AppInfo();
for (final app in apps.where((element) => !element.internal)) {
mixedApp.name = app.name.isNotEmpty ? app.name : mixedApp.name;
mixedApp.shortDescription = app.shortDescription.isNotEmpty
Expand Down
Loading

0 comments on commit 8ee58be

Please sign in to comment.