Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Move the Tauri config command into its own module

Manav Rathif649e5f4107c
diff --git a/rust/apps/ensu/src-tauri/src/commands/config.rs b/rust/apps/ensu/src-tauri/src/commands/config.rs
new file mode 100644
index 0000000000..237a75b7be
--- /dev/null
+++ b/rust/apps/ensu/src-tauri/src/commands/config.rs
@@ -0,0 +1,59 @@
+use ente_ensu::config;
+use serde::Serialize;
+
+#[derive(Debug, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ModelPreset {
+ id: String,
+ title: String,
+ url: String,
+ mmproj_url: Option<String>,
+}
+
+#[derive(Debug, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct Defaults {
+ mobile_system_prompt_body: String,
+ desktop_system_prompt_body: String,
+ system_prompt_date_placeholder: String,
+ session_summary_system_prompt: String,
+ mobile_default_model: ModelPreset,
+ mobile_model_presets: Vec<ModelPreset>,
+ desktop_default_model: ModelPreset,
+ desktop_model_presets: Vec<ModelPreset>,
+}
+
+impl From<config::ModelPreset> for ModelPreset {
+ fn from(p: config::ModelPreset) -> Self {
+ Self {
+ id: p.id,
+ title: p.title,
+ url: p.url,
+ mmproj_url: p.mmproj_url,
+ }
+ }
+}
+
+impl From<config::Defaults> for Defaults {
+ fn from(d: config::Defaults) -> Self {
+ Self {
+ mobile_system_prompt_body: d.mobile_system_prompt_body,
+ desktop_system_prompt_body: d.desktop_system_prompt_body,
+ system_prompt_date_placeholder: d.system_prompt_date_placeholder,
+ session_summary_system_prompt: d.session_summary_system_prompt,
+ mobile_default_model: d.mobile_default_model.into(),
+ mobile_model_presets: d.mobile_model_presets.into_iter().map(Into::into).collect(),
+ desktop_default_model: d.desktop_default_model.into(),
+ desktop_model_presets: d
+ .desktop_model_presets
+ .into_iter()
+ .map(Into::into)
+ .collect(),
+ }
+ }
+}
+
+#[tauri::command]
+pub fn config_defaults() -> Defaults {
+ config::defaults().into()
+}
diff --git a/rust/apps/ensu/src-tauri/src/commands/llm.rs b/rust/apps/ensu/src-tauri/src/commands/llm.rs
index 620715fbe4..27fac4b4cf 100644
--- a/rust/apps/ensu/src-tauri/src/commands/llm.rs
+++ b/rust/apps/ensu/src-tauri/src/commands/llm.rs
@@ -3,7 +3,6 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};
-use ente_ensu::config;
use ente_ensu::llm;
use serde::{Deserialize, Serialize};
use tauri::async_runtime;
@@ -32,28 +31,6 @@ impl Default for ModelDownloadState {
const PANIC_JOB_ID: i64 = 0;
-#[derive(Debug, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct ModelPreset {
- id: String,
- title: String,
- url: String,
- mmproj_url: Option<String>,
-}
-
-#[derive(Debug, Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct Defaults {
- mobile_system_prompt_body: String,
- desktop_system_prompt_body: String,
- system_prompt_date_placeholder: String,
- session_summary_system_prompt: String,
- mobile_default_model: ModelPreset,
- mobile_model_presets: Vec<ModelPreset>,
- desktop_default_model: ModelPreset,
- desktop_model_presets: Vec<ModelPreset>,
-}
-
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DownloadRequest {
@@ -74,36 +51,6 @@ pub struct DownloadProgress {
file_total_bytes: Option<u64>,
}
-impl From<config::ModelPreset> for ModelPreset {
- fn from(p: config::ModelPreset) -> Self {
- Self {
- id: p.id,
- title: p.title,
- url: p.url,
- mmproj_url: p.mmproj_url,
- }
- }
-}
-
-impl From<config::Defaults> for Defaults {
- fn from(d: config::Defaults) -> Self {
- Self {
- mobile_system_prompt_body: d.mobile_system_prompt_body,
- desktop_system_prompt_body: d.desktop_system_prompt_body,
- system_prompt_date_placeholder: d.system_prompt_date_placeholder,
- session_summary_system_prompt: d.session_summary_system_prompt,
- mobile_default_model: d.mobile_default_model.into(),
- mobile_model_presets: d.mobile_model_presets.into_iter().map(Into::into).collect(),
- desktop_default_model: d.desktop_default_model.into(),
- desktop_model_presets: d
- .desktop_model_presets
- .into_iter()
- .map(Into::into)
- .collect(),
- }
- }
-}
-
fn llm_error(message: impl Into<String>) -> ApiError {
ApiError::new("llm", message)
}
@@ -268,11 +215,6 @@ impl llm::EventSink for EventSink {
}
}
-#[tauri::command]
-pub fn config_defaults() -> Defaults {
- config::defaults().into()
-}
-
#[tauri::command]
pub async fn llm_download_model_files(
window: WebviewWindow,
diff --git a/rust/apps/ensu/src-tauri/src/commands/mod.rs b/rust/apps/ensu/src-tauri/src/commands/mod.rs
index 539bb4fcdb..07315f31b8 100644
--- a/rust/apps/ensu/src-tauri/src/commands/mod.rs
+++ b/rust/apps/ensu/src-tauri/src/commands/mod.rs
@@ -1,5 +1,6 @@
pub(crate) mod chat_db;
mod common;
+pub(crate) mod config;
pub(crate) mod crypto;
pub(crate) mod fs;
pub(crate) mod llm;
diff --git a/rust/apps/ensu/src-tauri/src/main.rs b/rust/apps/ensu/src-tauri/src/main.rs
index 60b295f717..eb7ffddcdc 100644
--- a/rust/apps/ensu/src-tauri/src/main.rs
+++ b/rust/apps/ensu/src-tauri/src/main.rs
@@ -64,7 +64,7 @@ fn main() {
commands::llm::llm_generate_chat_stream,
commands::llm::llm_cancel,
commands::system::system_info,
- commands::llm::config_defaults,
+ commands::config::config_defaults,
commands::llm::llm_download_model_files,
commands::llm::llm_cancel_model_download,
commands::fs::fs_file_size,