From 08192e168787bdcfeb129234701e66867f9b11d4 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Sun, 23 Jun 2024 18:49:25 -0500 Subject: [PATCH] more progress --- Cargo.lock | 1 + apps/journal/manifest.yml | 9 ++++++- apps/journal/src/lib.rs | 1 - crates/panorama-app-sdk/src/macros.rs | 1 + crates/panorama-core/Cargo.toml | 1 + .../panorama-core/src/state/apps/manifest.rs | 25 +++++++++++++++++++ crates/panorama-core/src/state/apps/mod.rs | 17 +++---------- crates/panorama-core/src/state/mod.rs | 5 +++- crates/panorama-daemon/src/main.rs | 2 ++ ui/src-tauri/src/main.rs | 1 + 10 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 crates/panorama-core/src/state/apps/manifest.rs diff --git a/Cargo.lock b/Cargo.lock index 3c2677a..8295ee3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3492,6 +3492,7 @@ dependencies = [ "chrono", "futures", "itertools 0.13.0", + "schemars", "serde", "serde_json", "serde_yaml", diff --git a/apps/journal/manifest.yml b/apps/journal/manifest.yml index f93bb65..51f22f4 100644 --- a/apps/journal/manifest.yml +++ b/apps/journal/manifest.yml @@ -4,4 +4,11 @@ panorama_version: 0.1.0 description: Note taking app # installer_path: ../../target/wasm32-unknown-unknown/wasm-release/panorama_journal.wasm -installer_path: ../../target/wasm32-unknown-unknown/wasm-debug/panorama_journal.wasm \ No newline at end of file +installer_path: ../../target/wasm32-unknown-unknown/wasm-debug/panorama_journal.wasm + +endpoints: +- url: /date/:date + method: GET + export_name: get_date_info + +triggers: \ No newline at end of file diff --git a/apps/journal/src/lib.rs b/apps/journal/src/lib.rs index 98808bb..35337aa 100644 --- a/apps/journal/src/lib.rs +++ b/apps/journal/src/lib.rs @@ -10,6 +10,5 @@ panorama_app_sdk::init!(); #[no_mangle] pub fn install() -> i32 { println!("SHIET"); - // panorama_app_sdk::register_endpoint("/get_todays_date"); 123 } diff --git a/crates/panorama-app-sdk/src/macros.rs b/crates/panorama-app-sdk/src/macros.rs index bf55b83..82bcd97 100644 --- a/crates/panorama-app-sdk/src/macros.rs +++ b/crates/panorama-app-sdk/src/macros.rs @@ -17,6 +17,7 @@ macro_rules! init { static ALLOC: panorama_app_sdk::wee_alloc::WeeAlloc = panorama_app_sdk::wee_alloc::WeeAlloc::INIT; + #[cfg(no_std)] #[panic_handler] fn panic(_info: &core::panic::PanicInfo) -> ! { loop {} diff --git a/crates/panorama-core/Cargo.toml b/crates/panorama-core/Cargo.toml index 8a46c6d..e128a34 100644 --- a/crates/panorama-core/Cargo.toml +++ b/crates/panorama-core/Cargo.toml @@ -10,6 +10,7 @@ bimap = "0.6.3" chrono = { version = "0.4.38", features = ["serde"] } futures = "0.3.30" itertools = "0.13.0" +schemars = "0.8.21" serde = { version = "1.0.203", features = ["derive"] } serde_json = "1.0.117" serde_yaml = "0.9.34" diff --git a/crates/panorama-core/src/state/apps/manifest.rs b/crates/panorama-core/src/state/apps/manifest.rs new file mode 100644 index 0000000..67f0819 --- /dev/null +++ b/crates/panorama-core/src/state/apps/manifest.rs @@ -0,0 +1,25 @@ +use std::path::PathBuf; + +use schemars::JsonSchema; + +#[derive(Debug, Serialize, Deserialize, JsonSchema)] +pub struct AppManifest { + name: String, + version: Option, + panorama_version: Option, + description: Option, + installer_path: PathBuf, + + endpoints: Vec, + triggers: Vec, +} + +#[derive(Debug, Serialize, Deserialize, JsonSchema)] +pub struct AppManifestEndpoint { + url: String, + method: String, + export_name: String, +} + +#[derive(Debug, Serialize, Deserialize, JsonSchema)] +pub struct AppManifestTriggers {} diff --git a/crates/panorama-core/src/state/apps/mod.rs b/crates/panorama-core/src/state/apps/mod.rs index a6fa303..a3bc3b5 100644 --- a/crates/panorama-core/src/state/apps/mod.rs +++ b/crates/panorama-core/src/state/apps/mod.rs @@ -1,6 +1,7 @@ #[macro_use] pub mod macros; pub mod internal; +pub mod manifest; use std::{ collections::HashMap, @@ -12,13 +13,12 @@ use std::{ use anyhow::{anyhow, Context as _, Result}; use internal::{WasmtimeInstanceEnv, WasmtimeModule}; use itertools::Itertools; -use wasmtime::{ - AsContext, Caller, Config, Engine, Instance, Linker, Memory, Module, Store, -}; -use wasmtime_wasi::WasiCtxBuilder; +use wasmtime::{AsContext, Config, Engine, Linker, Memory, Module, Store}; use crate::AppState; +use self::manifest::AppManifest; + pub type AllAppData = HashMap; impl AppState { @@ -65,15 +65,6 @@ impl AppState { } } -#[derive(Debug, Serialize, Deserialize)] -pub struct AppManifest { - name: String, - version: Option, - panorama_version: Option, - description: Option, - installer_path: PathBuf, -} - #[derive(Debug)] pub struct AppData { name: String, diff --git a/crates/panorama-core/src/state/mod.rs b/crates/panorama-core/src/state/mod.rs index 510483a..11ae214 100644 --- a/crates/panorama-core/src/state/mod.rs +++ b/crates/panorama-core/src/state/mod.rs @@ -7,7 +7,7 @@ pub mod node; pub mod node_raw; // pub mod utils; -use std::{fs, path::Path}; +use std::{collections::HashMap, fs, path::Path}; use anyhow::{Context, Result}; use bimap::BiMap; @@ -21,6 +21,7 @@ use tantivy::{ schema::{Field, Schema, STORED, STRING, TEXT}, Index, }; +use wasmtime::Module; use crate::{ // mail::MailWorker, @@ -46,6 +47,8 @@ pub struct AppState { pub db: SqlitePool, pub tantivy_index: Index, pub tantivy_field_map: BiMap, + + pub app_wasm_modules: HashMap, } impl AppState { diff --git a/crates/panorama-daemon/src/main.rs b/crates/panorama-daemon/src/main.rs index 108fe86..6adf129 100644 --- a/crates/panorama-daemon/src/main.rs +++ b/crates/panorama-daemon/src/main.rs @@ -3,6 +3,8 @@ use anyhow::Result; #[tokio::main] async fn main() -> Result<()> { tracing_subscriber::fmt::init(); + panorama_daemon::run().await?; + Ok(()) } diff --git a/ui/src-tauri/src/main.rs b/ui/src-tauri/src/main.rs index 595c477..1f493dc 100644 --- a/ui/src-tauri/src/main.rs +++ b/ui/src-tauri/src/main.rs @@ -25,6 +25,7 @@ async fn main() { Some(Command::Daemon) => { panorama_daemon::run().await; } + None => { if !opt.no_embedded_daemon { tokio::spawn(panorama_daemon::run());