Add recommended geo assets
This commit is contained in:
@@ -225,7 +225,8 @@
|
||||
"update": "Update",
|
||||
"download": "Download",
|
||||
"failureMsg": "Failed to update asset",
|
||||
"successMsg": "Successfully updated asset"
|
||||
"successMsg": "Successfully updated asset",
|
||||
"addRecommended": "Add Recommended Assets"
|
||||
}
|
||||
},
|
||||
"about": {
|
||||
|
||||
@@ -225,7 +225,8 @@
|
||||
"update": "به روز رسانی",
|
||||
"download": "دانلود",
|
||||
"failureMsg": "دارایی به روز نشد",
|
||||
"successMsg": "دارایی با موفقیت به روز شد"
|
||||
"successMsg": "دارایی با موفقیت به روز شد",
|
||||
"addRecommended": "اضافه کردن دارایی های توصیه شده"
|
||||
}
|
||||
},
|
||||
"about": {
|
||||
|
||||
@@ -225,7 +225,8 @@
|
||||
"update": "Обновлять",
|
||||
"download": "Скачать",
|
||||
"failureMsg": "Не удалось обновить объект.",
|
||||
"successMsg": "Объект успешно обновлен."
|
||||
"successMsg": "Объект успешно обновлен.",
|
||||
"addRecommended": "Добавить рекомендуемые активы"
|
||||
}
|
||||
},
|
||||
"about": {
|
||||
|
||||
@@ -225,7 +225,8 @@
|
||||
"update": "Güncelleme",
|
||||
"download": "İndirmek",
|
||||
"failureMsg": "Öğe güncellenemedi",
|
||||
"successMsg": "Öğe başarıyla güncellendi"
|
||||
"successMsg": "Öğe başarıyla güncellendi",
|
||||
"addRecommended": "Önerilen Varlıkları Ekle"
|
||||
}
|
||||
},
|
||||
"about": {
|
||||
|
||||
@@ -225,7 +225,8 @@
|
||||
"update": "更新",
|
||||
"download": "下载",
|
||||
"failureMsg": "更新资产失败",
|
||||
"successMsg": "已成功更新资产"
|
||||
"successMsg": "已成功更新资产",
|
||||
"addRecommended": "添加推荐资产"
|
||||
}
|
||||
},
|
||||
"about": {
|
||||
|
||||
@@ -12,6 +12,10 @@ class GeoAssetsDao extends DatabaseAccessor<AppDatabase>
|
||||
with _$GeoAssetsDaoMixin, InfraLogger {
|
||||
GeoAssetsDao(super.db);
|
||||
|
||||
Future<void> add(GeoAsset geoAsset) async {
|
||||
await into(geoAssetEntries).insert(geoAsset.toCompanion());
|
||||
}
|
||||
|
||||
Future<GeoAsset?> getActive(GeoAssetType type) async {
|
||||
return (geoAssetEntries.select()
|
||||
..where((tbl) => tbl.active.equals(true))
|
||||
|
||||
@@ -146,4 +146,23 @@ class GeoAssetsRepositoryImpl
|
||||
GeoAssetFailure.unexpected,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TaskEither<GeoAssetFailure, Unit> addRecommended() {
|
||||
return exceptionHandler(
|
||||
() async {
|
||||
final persistedIds = await geoAssetsDao
|
||||
.watchAll()
|
||||
.first
|
||||
.then((value) => value.map((e) => e.id));
|
||||
final missing =
|
||||
recommendedGeoAssets.where((e) => !persistedIds.contains(e.id));
|
||||
for (final geoAsset in missing) {
|
||||
await geoAssetsDao.add(geoAsset);
|
||||
}
|
||||
return right(unit);
|
||||
},
|
||||
GeoAssetFailure.unexpected,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,3 +49,21 @@ const defaultGeosite = GeoAsset(
|
||||
);
|
||||
|
||||
const defaultGeoAssets = [defaultGeoip, defaultGeosite];
|
||||
|
||||
const recommendedGeoAssets = [
|
||||
...defaultGeoAssets,
|
||||
GeoAsset(
|
||||
id: "chocolate4U-geoip",
|
||||
name: "geoip.db",
|
||||
type: GeoAssetType.geoip,
|
||||
active: false,
|
||||
providerName: "Chocolate4U/Iran-sing-box-rules",
|
||||
),
|
||||
GeoAsset(
|
||||
id: "chocolate4U-geosite",
|
||||
name: "geosite.db",
|
||||
type: GeoAssetType.geosite,
|
||||
active: false,
|
||||
providerName: "Chocolate4U/Iran-sing-box-rules",
|
||||
),
|
||||
];
|
||||
|
||||
@@ -11,4 +11,6 @@ abstract interface class GeoAssetsRepository {
|
||||
TaskEither<GeoAssetFailure, Unit> update(GeoAsset geoAsset);
|
||||
|
||||
TaskEither<GeoAssetFailure, Unit> markAsActive(GeoAsset geoAsset);
|
||||
|
||||
TaskEither<GeoAssetFailure, Unit> addRecommended();
|
||||
}
|
||||
|
||||
@@ -89,6 +89,11 @@ class GeoAssetTile extends HookConsumerWidget {
|
||||
],
|
||||
),
|
||||
selected: geoAsset.active,
|
||||
onTap: () async {
|
||||
await ref
|
||||
.read(geoAssetsNotifierProvider.notifier)
|
||||
.markAsActive(geoAsset);
|
||||
},
|
||||
trailing: PopupMenuButton(
|
||||
itemBuilder: (context) {
|
||||
return [
|
||||
|
||||
@@ -20,7 +20,28 @@ class GeoAssetsNotifier extends _$GeoAssetsNotifier with AppLogger {
|
||||
Future<void> updateGeoAsset(GeoAsset geoAsset) async {
|
||||
await ref.read(geoAssetsRepositoryProvider).update(geoAsset).getOrElse(
|
||||
(f) {
|
||||
loggy.warning("error updating profile", f);
|
||||
loggy.warning("error updating geo asset", f);
|
||||
throw f;
|
||||
},
|
||||
).run();
|
||||
}
|
||||
|
||||
Future<void> markAsActive(GeoAsset geoAsset) async {
|
||||
await ref
|
||||
.read(geoAssetsRepositoryProvider)
|
||||
.markAsActive(geoAsset)
|
||||
.getOrElse(
|
||||
(f) {
|
||||
loggy.warning("error marking geo asset as active", f);
|
||||
throw f;
|
||||
},
|
||||
).run();
|
||||
}
|
||||
|
||||
Future<void> addRecommended() async {
|
||||
await ref.read(geoAssetsRepositoryProvider).addRecommended().getOrElse(
|
||||
(f) {
|
||||
loggy.warning("error adding recommended geo assets", f);
|
||||
throw f;
|
||||
},
|
||||
).run();
|
||||
|
||||
@@ -17,6 +17,22 @@ class GeoAssetsPage extends HookConsumerWidget {
|
||||
slivers: [
|
||||
SliverAppBar(
|
||||
title: Text(t.settings.geoAssets.pageTitle),
|
||||
actions: [
|
||||
PopupMenuButton(
|
||||
itemBuilder: (context) {
|
||||
return [
|
||||
PopupMenuItem(
|
||||
child: Text(t.settings.geoAssets.addRecommended),
|
||||
onTap: () {
|
||||
ref
|
||||
.read(geoAssetsNotifierProvider.notifier)
|
||||
.addRecommended();
|
||||
},
|
||||
),
|
||||
];
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
switch (state) {
|
||||
AsyncData(value: final geoAssets) => SliverList.builder(
|
||||
|
||||
Reference in New Issue
Block a user