Skip to content

Commit a733be6

Browse files
committed
profile import export
1 parent 85c9315 commit a733be6

17 files changed

+310
-51
lines changed

Cargo.lock

Lines changed: 26 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

YtFlowApp/App.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ namespace YtFlowApp
183183

184184
event Windows.Foundation.EventHandler<HomeProfileControl> ConnectRequested;
185185
event Windows.Foundation.EventHandler<HomeProfileControl> EditRequested;
186+
event Windows.Foundation.EventHandler<HomeProfileControl> ExportRequested;
186187
event Windows.Foundation.EventHandler<HomeProfileControl> DeleteRequested;
187188
}
188189

YtFlowApp/CoreFfi.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ namespace winrt::YtFlowApp::implementation
109109
std::lock_guard _guard(conn_mu);
110110
unwrap_ffi_result<FfiNoop>(ytflow_profile_update(id, name, locale, conn_ptr));
111111
}
112+
std::string FfiConn::ExportProfileToml(uint32_t id) &
113+
{
114+
std::lock_guard _guard(conn_mu);
115+
return unwrap_ffi_string(ytflow_profile_export_toml(id, conn_ptr));
116+
}
117+
FfiParsedTomlProfile FfiConn::ParseProfileToml(uint8_t const *toml, size_t tomlLen) &
118+
{
119+
return unwrap_ffi_buffer<FfiParsedTomlProfile>(ytflow_core::ytflow_profile_parse_toml(toml, tomlLen));
120+
}
112121
std::vector<FfiPlugin> FfiConn::GetEntryPluginsByProfile(uint32_t profileId) &
113122
{
114123
std::lock_guard _guard(conn_mu);

YtFlowApp/CoreFfi.h

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace winrt::YtFlowApp::implementation
7474
std::string desc;
7575
std::string plugin;
7676
uint16_t plugin_version{0};
77-
std::vector<uint8_t> param;
77+
nlohmann::json::binary_t param;
7878

7979
static FfiPluginVerifyResult verify(char const *plugin, uint16_t plugin_version, uint8_t const *param,
8080
size_t param_len);
@@ -130,7 +130,7 @@ namespace winrt::YtFlowApp::implementation
130130
uint32_t id{};
131131
std::string name;
132132
int32_t order_num{};
133-
std::vector<uint8_t> proxy;
133+
nlohmann::json::binary_t proxy;
134134
uint16_t proxy_version{0};
135135
};
136136
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(FfiDataProxy, id, name, order_num, proxy, proxy_version)
@@ -210,6 +210,40 @@ namespace winrt::YtFlowApp::implementation
210210
}
211211
}
212212

213+
struct FfiParsedTomlPlugin
214+
{
215+
FfiPlugin plugin;
216+
bool is_entry = false;
217+
};
218+
inline void from_json(nlohmann::json const &json, FfiParsedTomlPlugin &r)
219+
{
220+
json.get_to(r.plugin);
221+
json.at("is_entry").get_to(r.is_entry);
222+
}
223+
struct FfiParsedTomlProfile
224+
{
225+
std::optional<std::string> name;
226+
std::optional<std::string> locale;
227+
std::optional<std::string> created_at;
228+
std::vector<FfiParsedTomlPlugin> plugins;
229+
};
230+
inline void from_json(nlohmann::json const &json, FfiParsedTomlProfile &r)
231+
{
232+
if (nlohmann::json const nameDoc = json.value("name", nlohmann::json()); nameDoc != nullptr)
233+
{
234+
r.name = {nameDoc.get<std::string>()};
235+
}
236+
if (nlohmann::json const localeDoc = json.value("locale", nlohmann::json()); localeDoc != nullptr)
237+
{
238+
r.locale = {localeDoc.get<std::string>()};
239+
}
240+
if (nlohmann::json const createdAtDoc = json.value("created_at", nlohmann::json()); createdAtDoc != nullptr)
241+
{
242+
r.created_at = {createdAtDoc.get<std::string>()};
243+
}
244+
json.at("plugins").get_to(r.plugins);
245+
}
246+
213247
struct FfiConn final
214248
{
215249
FfiConn(ytflow_core::ytflow_connection *conn) noexcept : conn_ptr(conn)
@@ -223,6 +257,8 @@ namespace winrt::YtFlowApp::implementation
223257
void DeleteProfile(uint32_t id) &;
224258
uint32_t CreateProfile(const char *name, const char *locale) &;
225259
void UpdateProfile(uint32_t id, const char *name, const char *locale) &;
260+
std::string ExportProfileToml(uint32_t id) &;
261+
FfiParsedTomlProfile ParseProfileToml(uint8_t const *toml, size_t tomlLen) &;
226262
std::vector<FfiPlugin> GetPluginsByProfile(uint32_t profileId) &;
227263
std::vector<FfiPlugin> GetEntryPluginsByProfile(uint32_t profileId) &;
228264
void SetPluginAsEntry(uint32_t pluginId, uint32_t profileId) &;

YtFlowApp/CoreRpc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ namespace winrt::YtFlowApp::implementation
134134
{
135135
auto const pluginId = pluginIdParam;
136136
auto const func = funcParam;
137-
auto const params = std::move(paramsParam);
137+
auto params = std::move(paramsParam);
138138

139139
auto const writeStream{m_socket.OutputStream()};
140140
auto readStream{m_socket.InputStream()};

0 commit comments

Comments
 (0)