Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

api: return tree entries

+36 -12
+10 -5
apps/tree.c
··· 621 621 /* gets the directory's name and put it into tc.currdir */ 622 622 filename = strrchr(path+1,'/'); 623 623 size_t endpos = filename - path; 624 - printf("%s | %s | %d\n", filename, path, endpos); 625 624 if (filename && endpos < MAX_PATH - 1) 626 625 { 627 626 strmemccpy(tc.currdir, path, endpos + 1); ··· 629 628 } 630 629 else 631 630 { 632 - strcpy(tc.currdir, "/"); 633 - filename = path+1; 631 + if (strlen(tc.currdir) <= 1) 632 + { 633 + strcpy(tc.currdir, "/"); 634 + } 635 + filename = path+1; 634 636 } 635 637 } 636 638 else /* path and filename came in separate ensure an ending '/' */ ··· 956 958 #endif 957 959 958 960 default: 959 - // return GO_TO_ROOT; 961 + if (tc.browse->disable_gui == true) { 962 + return GO_TO_ROOT; 963 + } 960 964 if (default_event_handler(button) == SYS_USB_CONNECTED) 961 965 { 962 966 if(*tc.dirfilter > NUM_FILTER_MODES) 963 967 /* leave sub-browsers after usb, doing otherwise 964 968 might be confusing to the user */ 965 - exit_func = true; 969 + exit_func = true; 966 970 else 967 971 reload_dir = true; 968 972 } ··· 1133 1137 .dirfilter = SHOW_SUPPORTED, 1134 1138 .icon = Icon_NOICON, 1135 1139 .root = path, 1140 + .disable_gui = true, 1136 1141 }; 1137 1142 strcpy(tc.currdir, path); 1138 1143
+1
apps/tree.h
··· 71 71 const char *selected; /* name of selected file in the root */ 72 72 char *buf; /* buffer to store selected file */ 73 73 size_t bufsize; /* size of the buffer */ 74 + bool disable_gui; /* disable gui for this browse */ 74 75 }; 75 76 76 77 /* browser context for file or db */
+21
crates/server/src/lib.rs
··· 232 232 return; 233 233 } 234 234 235 + if path.starts_with("/tree_entries?") { 236 + let params: Vec<_> = path.split('?').collect(); 237 + let params: Vec<_> = params[1].split('&').collect(); 238 + let q = params[0].split('=').collect::<Vec<_>>()[1]; 239 + rb::browse::rockbox_browse_at(q); 240 + let mut entries = vec![]; 241 + let context = rb::browse::tree_get_context(); 242 + 243 + for i in 0..context.filesindir { 244 + let entry = rb::browse::tree_get_entry_at(i); 245 + entries.push(entry); 246 + } 247 + 248 + let response = format!( 249 + "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{}", 250 + serde_json::to_string(&entries).unwrap() 251 + ); 252 + stream.write_all(response.as_bytes()).unwrap(); 253 + return; 254 + } 255 + 235 256 let response = "HTTP/1.1 404 Not Found\r\n\r\n"; 236 257 stream.write_all(response.as_bytes()).unwrap(); 237 258 return;
+1 -1
src/main.zig
··· 51 51 return tree._tree_get_entries(); 52 52 } 53 53 54 - export fn rb_tree_get_entry_at(index: c_int) *tree.entry { 54 + export fn rb_tree_get_entry_at(index: c_int) tree.entry { 55 55 return tree._tree_get_entry_at(index); 56 56 }
+3 -6
src/rockbox/tree.zig
··· 111 111 } 112 112 113 113 pub fn _tree_get_context() tree_context { 114 - const ret = rockbox_browse_at("/home"); 115 - std.debug.print("rockbox_browse_root: {}\n", .{ret}); 116 114 const tc = tree_get_context(); 117 - const e = tree_get_entries(tc); 118 - std.debug.print("tree_get_context: {}\n{}\n", .{ tc, e }); 119 115 return tc.*; 120 116 } 121 117 ··· 124 120 return tree_get_entries(tc); 125 121 } 126 122 127 - pub fn _tree_get_entry_at(index: c_int) *entry { 123 + pub fn _tree_get_entry_at(index: c_int) entry { 128 124 const tc = tree_get_context(); 129 - return tree_get_entry_at(tc, index); 125 + const e = tree_get_entry_at(tc, index); 126 + return e.*; 130 127 }