moosync_edk/
lib.rs

1// Moosync
2// Copyright (C) 2024, 2025  Moosync <support@moosync.app>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17pub use extism_pdk::{config, error, info, log, warn};
18use extism_pdk::{plugin_fn, FnResult, Prost};
19
20// Re-export generated types
21pub use extensions_proto;
22pub use preferences_proto;
23pub use songs_proto;
24pub use themes_proto;
25pub use ui_proto;
26pub use duration_proto;
27pub use prost_types;
28pub use extensions_proto::moosync::types::*;
29pub use preferences_proto::moosync::types::*;
30pub use songs_proto::moosync::types::*;
31pub use themes_proto::moosync::types::*;
32pub use ui_proto::moosync::types::*;
33
34pub mod api;
35pub mod handler;
36pub mod http;
37pub mod response_utils;
38
39pub use api::MoosyncResult;
40pub use handler::MoosyncError;
41
42unsafe extern "C" {
43    fn init();
44}
45
46#[tracing::instrument(level = "debug", skip())]
47#[plugin_fn]
48pub fn entry() -> FnResult<()> {
49    unsafe {
50        init();
51    }
52    Ok(())
53}
54
55#[tracing::instrument(level = "debug", skip())]
56#[plugin_fn]
57pub fn handle_extension_command(
58    Prost(cmd): Prost<ExtensionCommand>,
59) -> FnResult<Prost<ExtensionCommandResponse>> {
60    let res = handler::handle_command(cmd)?;
61    Ok(Prost(res))
62}
63
64/// Converts a standard Rust `Duration` into a protobuf `Duration`.
65pub fn duration_to_proto(d: std::time::Duration) -> duration_proto::google::protobuf::Duration {
66    duration_proto::google::protobuf::Duration {
67        seconds: d.as_secs() as i64,
68        nanos: d.subsec_nanos() as i32,
69    }
70}