mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: config (#2552)
* feat: save project config * feat: implement dart key value store
This commit is contained in:
parent
d01afab96e
commit
f04d64a191
17
frontend/appflowy_flutter/lib/core/config/config.dart
Normal file
17
frontend/appflowy_flutter/lib/core/config/config.dart
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import 'package:appflowy_backend/dispatch/dispatch.dart';
|
||||||
|
import 'package:appflowy_backend/protobuf/flowy-config/entities.pb.dart';
|
||||||
|
|
||||||
|
class Config {
|
||||||
|
static Future<void> setSupabaseConfig({
|
||||||
|
required String url,
|
||||||
|
required String key,
|
||||||
|
required String secret,
|
||||||
|
}) async {
|
||||||
|
await ConfigEventSetSupabaseConfig(
|
||||||
|
SupabaseConfigPB.create()
|
||||||
|
..supabaseUrl = url
|
||||||
|
..supabaseKey = key
|
||||||
|
..jwtSecret = secret,
|
||||||
|
).send();
|
||||||
|
}
|
||||||
|
}
|
33
frontend/appflowy_flutter/lib/core/config/kv.dart
Normal file
33
frontend/appflowy_flutter/lib/core/config/kv.dart
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import 'package:appflowy_backend/dispatch/dispatch.dart';
|
||||||
|
import 'package:appflowy_backend/protobuf/flowy-config/entities.pb.dart';
|
||||||
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||||
|
import 'package:dartz/dartz.dart';
|
||||||
|
|
||||||
|
/// Key-value store
|
||||||
|
/// The data is stored in the local storage of the device.
|
||||||
|
class KeyValue {
|
||||||
|
static Future<void> set(String key, String value) async {
|
||||||
|
await ConfigEventSetKeyValue(
|
||||||
|
KeyValuePB.create()
|
||||||
|
..key = key
|
||||||
|
..value = value,
|
||||||
|
).send();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<Either<String, FlowyError>> get(String key) {
|
||||||
|
return ConfigEventGetKeyValue(
|
||||||
|
KeyPB.create()..key = key,
|
||||||
|
).send().then(
|
||||||
|
(result) => result.fold(
|
||||||
|
(pb) => left(pb.value),
|
||||||
|
(error) => right(error),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> remove(String key) async {
|
||||||
|
await ConfigEventRemoveKeyValue(
|
||||||
|
KeyPB.create()..key = key,
|
||||||
|
).send();
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:appflowy/core/notification_helper.dart';
|
import 'package:appflowy/core/notification/notification_helper.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-document2/notification.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-document2/notification.pb.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
@ -1,4 +1,4 @@
|
|||||||
import 'package:appflowy/core/grid_notification.dart';
|
import 'package:appflowy/core/notification/grid_notification.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-database2/notification.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-database2/notification.pb.dart';
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import 'package:appflowy/core/grid_notification.dart';
|
import 'package:appflowy/core/notification/grid_notification.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-database2/notification.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-database2/notification.pb.dart';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:appflowy/core/grid_notification.dart';
|
import 'package:appflowy/core/notification/grid_notification.dart';
|
||||||
import 'package:flowy_infra/notifier.dart';
|
import 'package:flowy_infra/notifier.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-database2/notification.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-database2/notification.pb.dart';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:appflowy/core/grid_notification.dart';
|
import 'package:appflowy/core/notification/grid_notification.dart';
|
||||||
import 'package:flowy_infra/notifier.dart';
|
import 'package:flowy_infra/notifier.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-database2/notification.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-database2/notification.pb.dart';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:appflowy/core/grid_notification.dart';
|
import 'package:appflowy/core/notification/grid_notification.dart';
|
||||||
import 'package:flowy_infra/notifier.dart';
|
import 'package:flowy_infra/notifier.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-error/protobuf.dart';
|
import 'package:appflowy_backend/protobuf/flowy-error/protobuf.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
|
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:appflowy/core/grid_notification.dart';
|
import 'package:appflowy/core/notification/grid_notification.dart';
|
||||||
import 'package:flowy_infra/notifier.dart';
|
import 'package:flowy_infra/notifier.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-error/protobuf.dart';
|
import 'package:appflowy_backend/protobuf/flowy-error/protobuf.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
|
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:appflowy/core/grid_notification.dart';
|
import 'package:appflowy/core/notification/grid_notification.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:flowy_infra/notifier.dart';
|
import 'package:flowy_infra/notifier.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:appflowy/core/grid_notification.dart';
|
import 'package:appflowy/core/notification/grid_notification.dart';
|
||||||
import 'package:flowy_infra/notifier.dart';
|
import 'package:flowy_infra/notifier.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'package:appflowy/core/grid_notification.dart';
|
import 'package:appflowy/core/notification/grid_notification.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-database2/sort_entities.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-database2/sort_entities.pb.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:flowy_infra/notifier.dart';
|
import 'package:flowy_infra/notifier.dart';
|
||||||
|
@ -4,7 +4,7 @@ import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
|||||||
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
|
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:appflowy/core/grid_notification.dart';
|
import 'package:appflowy/core/notification/grid_notification.dart';
|
||||||
import 'package:flowy_infra/notifier.dart';
|
import 'package:flowy_infra/notifier.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'package:appflowy/core/folder_notification.dart';
|
import 'package:appflowy/core/notification/folder_notification.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-notification/subject.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-notification/subject.pb.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-folder2/notification.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-folder2/notification.pb.dart';
|
||||||
|
@ -25,6 +25,7 @@ class InitAppWidgetTask extends LaunchTask {
|
|||||||
appearanceSetting: appearanceSetting,
|
appearanceSetting: appearanceSetting,
|
||||||
child: widget,
|
child: widget,
|
||||||
);
|
);
|
||||||
|
|
||||||
Bloc.observer = ApplicationBlocObserver();
|
Bloc.observer = ApplicationBlocObserver();
|
||||||
runApp(
|
runApp(
|
||||||
EasyLocalization(
|
EasyLocalization(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:appflowy/core/folder_notification.dart';
|
import 'package:appflowy/core/notification/folder_notification.dart';
|
||||||
import 'package:appflowy/core/user_notification.dart';
|
import 'package:appflowy/core/notification/user_notification.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-folder2/workspace.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-folder2/workspace.pb.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'package:appflowy/core/folder_notification.dart';
|
import 'package:appflowy/core/notification/folder_notification.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:appflowy_backend/log.dart';
|
import 'package:appflowy_backend/log.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-notification/subject.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-notification/subject.pb.dart';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'package:appflowy/core/document_notification.dart';
|
import 'package:appflowy/core/notification/document_notification.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-document2/protobuf.dart';
|
import 'package:appflowy_backend/protobuf/flowy-document2/protobuf.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-notification/subject.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-notification/subject.pb.dart';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'package:appflowy/core/folder_notification.dart';
|
import 'package:appflowy/core/notification/folder_notification.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-notification/subject.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-notification/subject.pb.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'package:appflowy/core/folder_notification.dart';
|
import 'package:appflowy/core/notification/folder_notification.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:flowy_infra/notifier.dart';
|
import 'package:flowy_infra/notifier.dart';
|
||||||
|
@ -22,6 +22,8 @@ import 'package:appflowy_backend/protobuf/flowy-document2/protobuf.dart';
|
|||||||
// ignore: unused_import
|
// ignore: unused_import
|
||||||
import 'package:protobuf/protobuf.dart';
|
import 'package:protobuf/protobuf.dart';
|
||||||
import 'dart:convert' show utf8;
|
import 'dart:convert' show utf8;
|
||||||
|
import '../protobuf/flowy-config/entities.pb.dart';
|
||||||
|
import '../protobuf/flowy-config/event_map.pb.dart';
|
||||||
import '../protobuf/flowy-net/event_map.pb.dart';
|
import '../protobuf/flowy-net/event_map.pb.dart';
|
||||||
import 'error.dart';
|
import 'error.dart';
|
||||||
|
|
||||||
@ -30,6 +32,7 @@ part 'dart_event/flowy-net/dart_event.dart';
|
|||||||
part 'dart_event/flowy-user/dart_event.dart';
|
part 'dart_event/flowy-user/dart_event.dart';
|
||||||
part 'dart_event/flowy-database2/dart_event.dart';
|
part 'dart_event/flowy-database2/dart_event.dart';
|
||||||
part 'dart_event/flowy-document2/dart_event.dart';
|
part 'dart_event/flowy-document2/dart_event.dart';
|
||||||
|
part 'dart_event/flowy-config/dart_event.dart';
|
||||||
|
|
||||||
enum FFIException {
|
enum FFIException {
|
||||||
RequestIsEmpty,
|
RequestIsEmpty,
|
||||||
|
16
frontend/rust-lib/Cargo.lock
generated
16
frontend/rust-lib/Cargo.lock
generated
@ -1534,6 +1534,21 @@ dependencies = [
|
|||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "flowy-config"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"appflowy-integrate",
|
||||||
|
"bytes",
|
||||||
|
"flowy-codegen",
|
||||||
|
"flowy-derive",
|
||||||
|
"flowy-error",
|
||||||
|
"flowy-sqlite",
|
||||||
|
"lib-dispatch",
|
||||||
|
"protobuf",
|
||||||
|
"strum_macros",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flowy-core"
|
name = "flowy-core"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -1541,6 +1556,7 @@ dependencies = [
|
|||||||
"appflowy-integrate",
|
"appflowy-integrate",
|
||||||
"bytes",
|
"bytes",
|
||||||
"console-subscriber",
|
"console-subscriber",
|
||||||
|
"flowy-config",
|
||||||
"flowy-database2",
|
"flowy-database2",
|
||||||
"flowy-document2",
|
"flowy-document2",
|
||||||
"flowy-error",
|
"flowy-error",
|
||||||
|
@ -14,6 +14,7 @@ members = [
|
|||||||
"flowy-error",
|
"flowy-error",
|
||||||
"flowy-database2",
|
"flowy-database2",
|
||||||
"flowy-task",
|
"flowy-task",
|
||||||
|
"flowy-config",
|
||||||
]
|
]
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
|
23
frontend/rust-lib/flowy-config/Cargo.toml
Normal file
23
frontend/rust-lib/flowy-config/Cargo.toml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
[package]
|
||||||
|
name = "flowy-config"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
flowy-sqlite = { path = "../flowy-sqlite" }
|
||||||
|
flowy-derive = { path = "../../../shared-lib/flowy-derive" }
|
||||||
|
lib-dispatch = { path = "../lib-dispatch" }
|
||||||
|
protobuf = {version = "2.28.0"}
|
||||||
|
bytes = { version = "1.4" }
|
||||||
|
flowy-error = { path = "../flowy-error" }
|
||||||
|
strum_macros = "0.21"
|
||||||
|
appflowy-integrate = {version = "0.1.0" }
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
flowy-codegen = { path = "../../../shared-lib/flowy-codegen"}
|
||||||
|
|
||||||
|
[features]
|
||||||
|
dart = ["flowy-codegen/dart"]
|
||||||
|
ts = ["flowy-codegen/ts"]
|
3
frontend/rust-lib/flowy-config/Flowy.toml
Normal file
3
frontend/rust-lib/flowy-config/Flowy.toml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Check out the FlowyConfig (located in flowy_toml.rs) for more details.
|
||||||
|
proto_input = ["src/event_map.rs", "src/entities.rs"]
|
||||||
|
event_files = ["src/event_map.rs"]
|
10
frontend/rust-lib/flowy-config/build.rs
Normal file
10
frontend/rust-lib/flowy-config/build.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
fn main() {
|
||||||
|
let crate_name = env!("CARGO_PKG_NAME");
|
||||||
|
flowy_codegen::protobuf_file::gen(crate_name);
|
||||||
|
|
||||||
|
#[cfg(feature = "dart")]
|
||||||
|
flowy_codegen::dart_event::gen(crate_name);
|
||||||
|
|
||||||
|
#[cfg(feature = "ts")]
|
||||||
|
flowy_codegen::ts_event::gen(crate_name);
|
||||||
|
}
|
45
frontend/rust-lib/flowy-config/src/entities.rs
Normal file
45
frontend/rust-lib/flowy-config/src/entities.rs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
use flowy_derive::ProtoBuf;
|
||||||
|
|
||||||
|
#[derive(Default, ProtoBuf)]
|
||||||
|
pub struct KeyValuePB {
|
||||||
|
#[pb(index = 1)]
|
||||||
|
pub key: String,
|
||||||
|
|
||||||
|
#[pb(index = 2, one_of)]
|
||||||
|
pub value: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, ProtoBuf)]
|
||||||
|
pub struct KeyPB {
|
||||||
|
#[pb(index = 1)]
|
||||||
|
pub key: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, ProtoBuf)]
|
||||||
|
pub struct SupabaseConfigPB {
|
||||||
|
#[pb(index = 1)]
|
||||||
|
supabase_url: String,
|
||||||
|
|
||||||
|
#[pb(index = 2)]
|
||||||
|
supabase_key: String,
|
||||||
|
|
||||||
|
#[pb(index = 3)]
|
||||||
|
jwt_secret: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, ProtoBuf)]
|
||||||
|
pub struct AppFlowyCollabConfigPB {
|
||||||
|
#[pb(index = 1, one_of)]
|
||||||
|
aws_config: Option<AWSDynamoDBConfigPB>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, ProtoBuf)]
|
||||||
|
pub struct AWSDynamoDBConfigPB {
|
||||||
|
#[pb(index = 1)]
|
||||||
|
pub access_key_id: String,
|
||||||
|
#[pb(index = 2)]
|
||||||
|
pub secret_access_key: String,
|
||||||
|
// Region list: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html
|
||||||
|
#[pb(index = 3)]
|
||||||
|
pub region: String,
|
||||||
|
}
|
40
frontend/rust-lib/flowy-config/src/event_handler.rs
Normal file
40
frontend/rust-lib/flowy-config/src/event_handler.rs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
use flowy_error::{FlowyError, FlowyResult};
|
||||||
|
use flowy_sqlite::kv::KV;
|
||||||
|
use lib_dispatch::prelude::{data_result_ok, AFPluginData, DataResult};
|
||||||
|
|
||||||
|
use crate::entities::{KeyPB, KeyValuePB, SupabaseConfigPB};
|
||||||
|
|
||||||
|
pub(crate) async fn set_key_value_handler(data: AFPluginData<KeyValuePB>) -> FlowyResult<()> {
|
||||||
|
let data = data.into_inner();
|
||||||
|
match data.value {
|
||||||
|
None => KV::remove(&data.key),
|
||||||
|
Some(value) => {
|
||||||
|
KV::set_str(&data.key, value);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn get_key_value_handler(
|
||||||
|
data: AFPluginData<KeyPB>,
|
||||||
|
) -> DataResult<KeyValuePB, FlowyError> {
|
||||||
|
let data = data.into_inner();
|
||||||
|
let value = KV::get_str(&data.key);
|
||||||
|
data_result_ok(KeyValuePB {
|
||||||
|
key: data.key,
|
||||||
|
value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn remove_key_value_handler(data: AFPluginData<KeyPB>) -> FlowyResult<()> {
|
||||||
|
let data = data.into_inner();
|
||||||
|
KV::remove(&data.key);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn set_supabase_config_handler(
|
||||||
|
data: AFPluginData<SupabaseConfigPB>,
|
||||||
|
) -> FlowyResult<()> {
|
||||||
|
let _config = data.into_inner();
|
||||||
|
Ok(())
|
||||||
|
}
|
31
frontend/rust-lib/flowy-config/src/event_map.rs
Normal file
31
frontend/rust-lib/flowy-config/src/event_map.rs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
use strum_macros::Display;
|
||||||
|
|
||||||
|
use flowy_derive::{Flowy_Event, ProtoBuf_Enum};
|
||||||
|
use lib_dispatch::prelude::AFPlugin;
|
||||||
|
|
||||||
|
use crate::event_handler::*;
|
||||||
|
|
||||||
|
pub fn init() -> AFPlugin {
|
||||||
|
AFPlugin::new()
|
||||||
|
.name(env!("CARGO_PKG_NAME"))
|
||||||
|
.event(ConfigEvent::SetKeyValue, set_key_value_handler)
|
||||||
|
.event(ConfigEvent::GetKeyValue, get_key_value_handler)
|
||||||
|
.event(ConfigEvent::RemoveKeyValue, remove_key_value_handler)
|
||||||
|
.event(ConfigEvent::SetSupabaseConfig, set_supabase_config_handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, Display, ProtoBuf_Enum, Flowy_Event)]
|
||||||
|
#[event_err = "FlowyError"]
|
||||||
|
pub enum ConfigEvent {
|
||||||
|
#[event(input = "KeyValuePB")]
|
||||||
|
SetKeyValue = 0,
|
||||||
|
|
||||||
|
#[event(input = "KeyPB", output = "KeyValuePB")]
|
||||||
|
GetKeyValue = 1,
|
||||||
|
|
||||||
|
#[event(input = "KeyPB")]
|
||||||
|
RemoveKeyValue = 2,
|
||||||
|
|
||||||
|
#[event(input = "SupabaseConfigPB")]
|
||||||
|
SetSupabaseConfig = 3,
|
||||||
|
}
|
4
frontend/rust-lib/flowy-config/src/lib.rs
Normal file
4
frontend/rust-lib/flowy-config/src/lib.rs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
mod entities;
|
||||||
|
mod event_handler;
|
||||||
|
pub mod event_map;
|
||||||
|
mod protobuf;
|
@ -19,6 +19,7 @@ flowy-document2 = { path = "../flowy-document2" }
|
|||||||
#flowy-revision = { path = "../flowy-revision" }
|
#flowy-revision = { path = "../flowy-revision" }
|
||||||
flowy-error = { path = "../flowy-error" }
|
flowy-error = { path = "../flowy-error" }
|
||||||
flowy-task = { path = "../flowy-task" }
|
flowy-task = { path = "../flowy-task" }
|
||||||
|
flowy-config = { path = "../flowy-config" }
|
||||||
appflowy-integrate = { version = "0.1.0" }
|
appflowy-integrate = { version = "0.1.0" }
|
||||||
|
|
||||||
tracing = { version = "0.1", features = ["log"] }
|
tracing = { version = "0.1", features = ["log"] }
|
||||||
@ -45,6 +46,7 @@ dart = [
|
|||||||
"flowy-folder2/dart",
|
"flowy-folder2/dart",
|
||||||
"flowy-database2/dart",
|
"flowy-database2/dart",
|
||||||
"flowy-document2/dart",
|
"flowy-document2/dart",
|
||||||
|
"flowy-config/dart",
|
||||||
]
|
]
|
||||||
ts = [
|
ts = [
|
||||||
"flowy-user/ts",
|
"flowy-user/ts",
|
||||||
@ -52,6 +54,7 @@ ts = [
|
|||||||
"flowy-folder2/ts",
|
"flowy-folder2/ts",
|
||||||
"flowy-database2/ts",
|
"flowy-database2/ts",
|
||||||
"flowy-document2/ts",
|
"flowy-document2/ts",
|
||||||
|
"flowy-config/ts",
|
||||||
]
|
]
|
||||||
rev-sqlite = [
|
rev-sqlite = [
|
||||||
"flowy-sqlite",
|
"flowy-sqlite",
|
||||||
|
@ -17,11 +17,13 @@ pub fn make_plugins(
|
|||||||
let network_plugin = flowy_net::event_map::init();
|
let network_plugin = flowy_net::event_map::init();
|
||||||
let database_plugin = flowy_database2::event_map::init(database_manager.clone());
|
let database_plugin = flowy_database2::event_map::init(database_manager.clone());
|
||||||
let document_plugin2 = flowy_document2::event_map::init(document_manager2.clone());
|
let document_plugin2 = flowy_document2::event_map::init(document_manager2.clone());
|
||||||
|
let config_plugin = flowy_config::event_map::init();
|
||||||
vec![
|
vec![
|
||||||
user_plugin,
|
user_plugin,
|
||||||
folder_plugin,
|
folder_plugin,
|
||||||
network_plugin,
|
network_plugin,
|
||||||
database_plugin,
|
database_plugin,
|
||||||
document_plugin2,
|
document_plugin2,
|
||||||
|
config_plugin,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ appflowy-integrate = {version = "0.1.0" }
|
|||||||
flowy-derive = { path = "../../../shared-lib/flowy-derive" }
|
flowy-derive = { path = "../../../shared-lib/flowy-derive" }
|
||||||
flowy-notification = { path = "../flowy-notification" }
|
flowy-notification = { path = "../flowy-notification" }
|
||||||
flowy-error = { path = "../flowy-error", features = ["adaptor_serde", "adaptor_database", "adaptor_dispatch", "collab"] }
|
flowy-error = { path = "../flowy-error", features = ["adaptor_serde", "adaptor_database", "adaptor_dispatch", "collab"] }
|
||||||
|
|
||||||
lib-dispatch = { path = "../lib-dispatch" }
|
lib-dispatch = { path = "../lib-dispatch" }
|
||||||
|
|
||||||
protobuf = {version = "2.28.0"}
|
protobuf = {version = "2.28.0"}
|
||||||
|
Loading…
Reference in New Issue
Block a user