Skip to content

Commit

Permalink
feat: Implement a event iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
Losses committed Jan 9, 2025
1 parent b0028b7 commit 0c8013d
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
13 changes: 13 additions & 0 deletions native/requests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "requests"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true


[dependencies]
syn = "2.0.95"
quote = "1.0.38"
proc-macro2 = "1.0.92"
103 changes: 103 additions & 0 deletions native/requests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
use proc_macro::TokenStream;
use quote::quote;

#[proc_macro]
pub fn define_request_types(_input: TokenStream) -> TokenStream {
let types = vec![
// Library
"TestLibraryInitializedRequest",
"CloseLibraryRequest",
"CancelTaskRequest",
"ScanAudioLibraryRequest",
"AnalyzeAudioLibraryRequest",
// Playback
"VolumeRequest",
"LoadRequest",
"PlayRequest",
"PauseRequest",
"NextRequest",
"PreviousRequest",
"SwitchRequest",
"SeekRequest",
"RemoveRequest",
"SetPlaybackModeRequest",
"MovePlaylistItemRequest",
"SetRealtimeFftEnabledRequest",
"SetAdaptiveSwitchingEnabledRequest",
// SFX
"SfxPlayRequest",
// Analyze
"IfAnalyzeExistsRequest",
"GetAnalyzeCountRequest",
// Media File
"FetchMediaFilesRequest",
"FetchMediaFileByIdsRequest",
"FetchParsedMediaFileRequest",
"SearchMediaFileSummaryRequest",
// Lyric
"GetLyricByTrackIdRequest",
// Collection
"FetchCollectionGroupSummaryRequest",
"FetchCollectionGroupsRequest",
"FetchCollectionByIdsRequest",
"SearchCollectionSummaryRequest",
// Cover Art
"GetCoverArtIdsByMixQueriesRequest",
"GetPrimaryColorByTrackIdRequest",
// Playlist
"FetchAllPlaylistsRequest",
"CreatePlaylistRequest",
"CreateM3u8PlaylistRequest",
"UpdatePlaylistRequest",
"RemovePlaylistRequest",
"AddItemToPlaylistRequest",
"ReorderPlaylistItemPositionRequest",
"GetPlaylistByIdRequest",
// Mix
"FetchAllMixesRequest",
"CreateMixRequest",
"UpdateMixRequest",
"RemoveMixRequest",
"AddItemToMixRequest",
"GetMixByIdRequest",
"MixQueryRequest",
"FetchMixQueriesRequest",
"OperatePlaybackWithMixQueryRequest",
// Like
"SetLikedRequest",
"GetLikedRequest",
// Query and Search
"ComplexQueryRequest",
"SearchForRequest",
// Directory
"FetchDirectoryTreeRequest",
// Scrobbler
"AuthenticateSingleServiceRequest",
"AuthenticateMultipleServiceRequest",
"LogoutSingleServiceRequest",
// Log
"ListLogRequest",
"ClearLogRequest",
"RemoveLogRequest",
// System
"SystemInfoRequest",
// License
"RegisterLicenseRequest",
"ValidateLicenseRequest",
];

let types = types.iter().map(|t| {
let ident = syn::parse_str::<syn::Ident>(t).unwrap();
quote! { #ident }
});

let expanded = quote! {
macro_rules! __private_request_iterator {
($m:tt) => {
$m!(#(#types),*);
}
}
};

TokenStream::from(expanded)
}

0 comments on commit 0c8013d

Please sign in to comment.