Skip to content

Commit

Permalink
Manually trigger specta bindings export
Browse files Browse the repository at this point in the history
  • Loading branch information
amosjyng committed May 20, 2024
1 parent 60f9aec commit a211deb
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 48 deletions.
124 changes: 122 additions & 2 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ reqwest-middleware = "0.1.6"
tokio = { version = "1.35.1", features = ["macros"] }
chrono = { version = "0.4.31", features = ["serde"] }
libsqlite3-sys = { version = "0.27.0", features = ["bundled"] }
clap = { version = "4.5.4", features = ["derive"] }

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
24 changes: 24 additions & 0 deletions src-tauri/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use clap::{Parser, Subcommand};

#[derive(Subcommand)]
pub enum Commands {
/// Run the GUI. This is the default command.
Gui {},
/// Export Specta bindings for development purposes
#[cfg(debug_assertions)]
ExportBindings {},
}

/// Zen and the Automation of Metaprogramming for the Masses
///
/// This is an experimental tool meant for automating programming-related activities,
/// although none have been implemented yet. Blog posts on progress can be found at
/// https://zamm.dev/
#[derive(Parser)]
#[command(name = "zamm")]
#[command(version)]
#[command(about = "Zen and the Automation of Metaprogramming for the Masses")]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Commands>,
}
101 changes: 55 additions & 46 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use diesel::sqlite::SqliteConnection;

use setup::api_keys::{setup_api_keys, ApiKeys};
#[cfg(all(debug_assertions, not(target_os = "windows")))]
use specta::collect_types;

#[cfg(all(debug_assertions, not(target_os = "windows")))]
use tauri_specta::ts;

use std::env;

use tokio::sync::Mutex;
mod cli;
mod commands;
mod models;
#[cfg(test)]
Expand All @@ -21,6 +10,18 @@ mod schema;
mod setup;
#[cfg(test)]
mod test_helpers;

use clap::Parser;
use diesel::sqlite::SqliteConnection;
use setup::api_keys::{setup_api_keys, ApiKeys};
#[cfg(debug_assertions)]
use specta::collect_types;
use std::env;
#[cfg(debug_assertions)]
use tauri_specta::ts;
use tokio::sync::Mutex;

use cli::{Cli, Commands};
use commands::{
chat, get_api_call, get_api_calls, get_api_keys, get_preferences, get_system_info,
play_sound, set_api_key, set_preferences,
Expand All @@ -30,40 +31,48 @@ pub struct ZammDatabase(Mutex<Option<SqliteConnection>>);
pub struct ZammApiKeys(Mutex<ApiKeys>);

fn main() {
#[cfg(all(debug_assertions, not(target_os = "windows")))]
ts::export(
collect_types![
get_api_keys,
set_api_key,
play_sound,
get_preferences,
set_preferences,
get_system_info,
chat,
get_api_call,
get_api_calls,
],
"../src-svelte/src/lib/bindings.ts",
)
.expect("Failed to export Specta bindings");
let cli = Cli::parse();

let mut possible_db = setup::get_db();
let api_keys = setup_api_keys(&mut possible_db);
match &cli.command {
#[cfg(debug_assertions)]
Some(Commands::ExportBindings {}) => {
ts::export(
collect_types![
get_api_keys,
set_api_key,
play_sound,
get_preferences,
set_preferences,
get_system_info,
chat,
get_api_call,
get_api_calls,
],
"../src-svelte/src/lib/bindings.ts",
)
.expect("Failed to export Specta bindings");
println!("Specta bindings should be exported to ../src-svelte/src/lib/bindings.ts");
}
Some(Commands::Gui {}) | None => {
let mut possible_db = setup::get_db();
let api_keys = setup_api_keys(&mut possible_db);

tauri::Builder::default()
.manage(ZammDatabase(Mutex::new(possible_db)))
.manage(ZammApiKeys(Mutex::new(api_keys)))
.invoke_handler(tauri::generate_handler![
get_api_keys,
set_api_key,
play_sound,
get_preferences,
set_preferences,
get_system_info,
chat,
get_api_call,
get_api_calls,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
tauri::Builder::default()
.manage(ZammDatabase(Mutex::new(possible_db)))
.manage(ZammApiKeys(Mutex::new(api_keys)))
.invoke_handler(tauri::generate_handler![
get_api_keys,
set_api_key,
play_sound,
get_preferences,
set_preferences,
get_system_info,
chat,
get_api_call,
get_api_calls,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
}
}

0 comments on commit a211deb

Please sign in to comment.