Skip to content

Commit

Permalink
Autogenerate tauri invokes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovenoboyo committed Dec 22, 2024
1 parent 61f86dd commit 867de13
Show file tree
Hide file tree
Showing 30 changed files with 861 additions and 301 deletions.
18 changes: 18 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ indexed_db_futures = "0.5.0"
lazy_static = "1.5.0"
tracing = "0.1.41"
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
tauri-invoke-proc = { path = "src-tauri/tauri-invoke-proc" }

[workspace]
resolver = "2"
Expand All @@ -64,6 +65,7 @@ members = [
"src-tauri/youtube",
"src-tauri/rodio-player",
"src/pref_gen",
"src-tauri/tauri-invoke-proc",
]

[package.metadata.leptos-i18n]
Expand Down
14 changes: 14 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::{env, path::Path};

fn main() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is not set");
let manifest_dir = Path::new(&manifest_dir);
let profile = env::var("PROFILE").expect("PROFILE environment variable is not set");

let file_path = manifest_dir.join("target").join(profile).join("build");

println!(
"cargo:rustc-env=TAURI_INVOKE_PROC_DIR={}",
file_path.to_string_lossy()
);
}
2 changes: 2 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ tracing-subscriber = { features = [
"env-filter",
], default-features = false, version = "0.3.19" }
rustls = { version = "0.23.20", features = ["ring"] }
tauri-invoke-proc = { path = "./tauri-invoke-proc" }


[build-dependencies.tauri-build]
version = "2.0.3"
Expand Down
7 changes: 3 additions & 4 deletions src-tauri/extensions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ use socket_handler::{ExtensionCommandReceiver, MainCommandSender, SocketHandler}
use types::{
errors::{MoosyncError, Result},
extensions::{
AccountLoginArgs, ContextMenuActionArgs, EmptyResp, ExtensionAccountDetail,
ExtensionContextMenuItem, ExtensionDetail, ExtensionExtraEventArgs, ExtensionManifest,
ExtensionProviderScope, FetchedExtensionManifest, GenericExtensionHostRequest,
PackageNameArgs, ToggleExtArgs,
AccountLoginArgs, ContextMenuActionArgs, ExtensionAccountDetail, ExtensionContextMenuItem,
ExtensionDetail, ExtensionExtraEventArgs, ExtensionManifest, ExtensionProviderScope,
FetchedExtensionManifest, GenericExtensionHostRequest, PackageNameArgs, ToggleExtArgs,
},
};
use uuid::Uuid;
Expand Down
4 changes: 4 additions & 0 deletions src-tauri/macros/src/command_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
macro_rules! generate_command {
($method_name:ident, $state:ident, $ret:ty, $($v:ident: $t:ty),*) => {
#[tracing::instrument(level = "trace", skip(db))]
#[tauri_invoke_proc::parse_tauri_command]
#[tauri::command(async)]
pub fn $method_name(db: State<$state>, $($v: $t),*) -> types::errors::Result<$ret> {
tracing::debug!("calling {}", stringify!($method_name));
Expand All @@ -21,6 +22,7 @@ macro_rules! generate_command_cached {
($method_name:ident, $state:ident, $ret:ty, $($v:ident: $t:ty),*) => {
// #[flame]
#[tracing::instrument(level = "trace", skip(db, cache))]
#[tauri_invoke_proc::parse_tauri_command]
#[tauri::command(async)]
pub async fn $method_name(db: State<'_, $state>, cache: State<'_, CacheHolder>, $($v: $t),*) -> types::errors::Result<$ret> {
let mut cache_string = String::new();
Expand Down Expand Up @@ -62,6 +64,7 @@ macro_rules! generate_command_async {
($method_name:ident, $state:ident, $ret:ty, $($v:ident: $t:ty),*) => {
// #[flame]
#[tracing::instrument(level = "trace", skip(db))]
#[tauri_invoke_proc::parse_tauri_command]
#[tauri::command(async)]
pub async fn $method_name(db: State<'_, $state>, $($v: $t),*) -> types::errors::Result<$ret> {
tracing::debug!("calling async {}", stringify!($method_name));
Expand All @@ -81,6 +84,7 @@ macro_rules! generate_command_async_cached {
($method_name:ident, $state:ident, $ret:ty, $($v:ident: $t:ty),*) => {
// #[flame]
#[tracing::instrument(level = "trace", skip(db, cache))]
#[tauri_invoke_proc::parse_tauri_command]
#[tauri::command(async)]
pub async fn $method_name(db: State<'_, $state>, cache: State<'_, CacheHolder>, $($v: $t),*) -> types::errors::Result<$ret> {
let mut cache_string = String::new();
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/db/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::fs;

use database::{cache::CacheHolder, database::Database};
use macros::generate_command;
use serde_json::Value;
use std::fs;
use tauri::{App, AppHandle, Manager, State};
use tracing::{info, trace};
use types::errors::Result;
Expand All @@ -16,6 +15,7 @@ use types::{
use crate::window::handler::WindowHandler;

#[tracing::instrument(level = "trace", skip(app, db, window_handler))]
#[tauri_invoke_proc::parse_tauri_command]
#[tauri::command(async)]
pub fn export_playlist(
app: AppHandle,
Expand Down
8 changes: 4 additions & 4 deletions src-tauri/src/providers/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,16 @@ impl GenericProvider for ExtensionProvider {

async fn get_album_content(
&self,
album: QueryableAlbum,
pagination: Pagination,
_album: QueryableAlbum,
_pagination: Pagination,
) -> Result<(Vec<Song>, Pagination)> {
todo!()
}

async fn get_artist_content(
&self,
artist: QueryableArtist,
pagination: Pagination,
_artist: QueryableArtist,
_pagination: Pagination,
) -> Result<(Vec<Song>, Pagination)> {
todo!()
}
Expand Down
8 changes: 4 additions & 4 deletions src-tauri/src/providers/spotify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use regex::Regex;
use rspotify::{
clients::{BaseClient, OAuthClient},
model::{
AlbumId, AlbumType, ArtistId, FullAlbum, FullArtist, FullTrack, Id, PlaylistId,
PlaylistTracksRef, SearchType, SimplifiedAlbum, SimplifiedArtist, SimplifiedPlaylist,
SimplifiedTrack, TrackId,
AlbumId, ArtistId, FullAlbum, FullArtist, FullTrack, Id, PlaylistId, PlaylistTracksRef,
SearchType, SimplifiedAlbum, SimplifiedArtist, SimplifiedPlaylist, SimplifiedTrack,
TrackId,
},
AuthCodePkceSpotify, Token,
};
Expand Down Expand Up @@ -772,7 +772,7 @@ impl GenericProvider for SpotifyProvider {
if let Some(api_client) = &self.api_client {
if let Some(next_page_token) = &pagination.token {
// TODO: Fetch next pages
let tokens = next_page_token.split(";").collect::<Vec<_>>();
let _tokens = next_page_token.split(";").collect::<Vec<_>>();
return Ok((vec![], pagination.next_page_wtoken(None)));
}

Expand Down
8 changes: 2 additions & 6 deletions src-tauri/src/scanner/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use std::{
sync::{
atomic::AtomicBool,
mpsc::{Receiver, Sender},
Arc, Mutex,
},
thread::{self, JoinHandle},
sync::{atomic::AtomicBool, Arc, Mutex},
thread::{self},
time::Duration,
};

Expand Down
19 changes: 19 additions & 0 deletions src-tauri/tauri-invoke-proc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "tauri-invoke-proc"
version = "0.1.0"
edition = "2021"

[dependencies]
ctor = "0.2.9"
lazy_static = "1.5.0"
once_cell = "1.20.2"
proc-macro2 = "1.0.92"
quote = "1.0.37"
regex = "1.11.1"
serde = "1.0.216"
serde_json = "1.0.133"
syn = "2.0.90"
tracing = "0.1.41"

[lib]
proc-macro = true
11 changes: 11 additions & 0 deletions src-tauri/tauri-invoke-proc/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use std::env;
use std::path::Path;

fn main() {
let out_dir = env::var("OUT_DIR").expect("OUT_DIR environment variable is not set");
let output_file = Path::new(&out_dir)
.join("../../")
.join("function_details.json");

println!("cargo:rerun-if-changed={}", output_file.to_string_lossy());
}
15 changes: 15 additions & 0 deletions src-tauri/tauri-invoke-proc/src/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
pub struct FnDetails {
pub name: String,
pub args: Vec<FnArgs>,
pub ret: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]

pub struct FnArgs {
pub name: String,
pub arg_type: String,
}
Loading

0 comments on commit 867de13

Please sign in to comment.