MCPcopy Create free account
hub / github.com/Moosync/Moosync / Controls

Function Controls

src/components/musicbar_components.rs:111–291  ·  view source on GitHub ↗
(
    #[prop(optional, default = true)] show_time: bool,
    #[prop(optional, default = true)] show_fav: bool,
)

Source from the content-addressed store, hash-verified

109#[tracing::instrument(level = "debug", skip())]
110#[component]
111pub fn Controls(
112 #[prop(optional, default = true)] show_time: bool,
113 #[prop(optional, default = true)] show_fav: bool,
114) -> impl IntoView {
115 let player_store = use_context::<RwSignal<PlayerStore>>().unwrap();
116
117 let current_song = create_read_slice(player_store, |p| p.get_current_song());
118
119 let prev_track_dis = create_read_slice(player_store, |p| p.get_queue_len() <= 1);
120 let next_track_dis = create_read_slice(player_store, |p| p.get_queue_len() <= 1);
121 let is_play = create_read_slice(player_store, |p| {
122 p.get_player_state() == PlayerState::Playing
123 });
124 let is_fav = RwSignal::new(false);
125 let (repeat_mode, toggle_repeat) =
126 create_slice(player_store, |p| p.get_repeat(), |p, _| p.toggle_repeat());
127 let is_shuffle = RwSignal::new(true);
128 let shuffle_queue = create_write_slice(player_store, |p, _| p.shuffle_queue());
129
130 let (current_time_sig, total_duration_sig) = if show_time {
131 let current_time_sig = create_read_slice(player_store, |p| {
132 format_duration(p.get_current_time(), false)
133 });
134 let total_duration_sig = create_read_slice(player_store, |p| {
135 if let Some(current_song) = p.get_current_song() {
136 format_duration(current_song.song.duration.unwrap_or(-1f64), false)
137 } else {
138 "00:00".to_string()
139 }
140 });
141
142 (current_time_sig, total_duration_sig)
143 } else {
144 (Default::default(), Default::default())
145 };
146
147 let set_current_state = create_write_slice(player_store, |player, n| player.set_state(n));
148 let next_song_setter = create_write_slice(player_store, |p, _| p.next_song());
149 let prev_song_setter = create_write_slice(player_store, |p, _| p.prev_song());
150
151 Effect::new(move || {
152 let current_song = current_song.get();
153 if let Some(current_song) = current_song {
154 spawn_local(async move {
155 tracing::debug!("Checking song in favorites");
156 let res = crate::utils::invoke::is_song_in_playlist(
157 "favorite".into(),
158 current_song.song._id.unwrap_or_default(),
159 )
160 .await;
161 match res {
162 Ok(res) => {
163 tracing::debug!("song in favorites: {}", res);
164 is_fav.set(res);
165 }
166 Err(e) => {
167 tracing::error!("Failed to check song in favs: {:?}", e);
168 is_fav.set(false);

Callers

nothing calls this directly

Calls 15

format_durationFunction · 0.85
create_playlistFunction · 0.85
add_to_playlistFunction · 0.85
get_current_songMethod · 0.80
get_queue_lenMethod · 0.80
get_player_stateMethod · 0.80
get_repeatMethod · 0.80
toggle_repeatMethod · 0.80
shuffle_queueMethod · 0.80
get_current_timeMethod · 0.80
set_stateMethod · 0.80
next_songMethod · 0.80

Tested by

no test coverage detected