Integration start.
modified: Cargo.lock modified: Cargo.toml modified: src/main.rs
This commit is contained in:
parent
a792c79015
commit
84fd4b9262
1421
Cargo.lock
generated
1421
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -6,4 +6,7 @@ edition = "2021"
|
||||
[dependencies]
|
||||
rusb = "0.9.4"
|
||||
regex = "1.11.1"
|
||||
gtk = { version = "0.9.5", package = "gtk4", features = ["v4_16"] }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
async-channel = "2.3.1"
|
||||
gtk = { version = "0.9.5", package = "gtk4", features = ["v4_16"] }
|
||||
soundcloud = { git = "https://gitea.awain.net/alterwain/soundcloud_api.git" }
|
45
src/main.rs
45
src/main.rs
@ -1,5 +1,11 @@
|
||||
use gtk::{prelude::*, ApplicationWindow, Orientation, Stack, StackSidebar};
|
||||
use gtk::{glib, Application};
|
||||
use glib::clone;
|
||||
|
||||
use std::{sync::OnceLock, error::Error};
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
use soundcloud::sobjects::CloudPlaylists;
|
||||
|
||||
mod disk_util;
|
||||
mod ipod_util;
|
||||
@ -26,7 +32,28 @@ fn main() -> glib::ExitCode {
|
||||
app.run()
|
||||
}
|
||||
|
||||
fn runtime() -> &'static Runtime {
|
||||
static RUNTIME: OnceLock<Runtime> = OnceLock::new();
|
||||
RUNTIME.get_or_init(|| Runtime::new().expect("Setting up tokio runtime needs to succeed."))
|
||||
}
|
||||
|
||||
fn build_ui(app: &Application) {
|
||||
let (sender, receiver) = async_channel::bounded::<CloudPlaylists>(1);
|
||||
runtime().spawn(clone!(
|
||||
#[strong]
|
||||
sender,
|
||||
async move {
|
||||
let app_version = soundcloud::get_app().await.unwrap().unwrap();
|
||||
let client_id = soundcloud::get_client_id().await.unwrap().unwrap();
|
||||
let user_id: u64 = 774639751;
|
||||
|
||||
sender
|
||||
.send(soundcloud::get_playlists(user_id, client_id, app_version).await.unwrap())
|
||||
.await
|
||||
.expect("The channel needs to be open.");
|
||||
}
|
||||
));
|
||||
|
||||
let window = ApplicationWindow::builder()
|
||||
.application(app)
|
||||
.title("ILoader")
|
||||
@ -42,25 +69,31 @@ fn build_ui(app: &Application) {
|
||||
let label1 = gtk::Label::new(Some("Youtube Content"));
|
||||
stack.add_titled(&label1, Some("page1"), "Youtube");
|
||||
|
||||
let label2 = gtk::Label::new(Some("Soundcloud Content"));
|
||||
let grid_layout = gtk::Grid::builder()
|
||||
.row_spacing(5)
|
||||
.column_spacing(5)
|
||||
.build();
|
||||
grid_layout.attach(&label2, 0, 0, 1, 1);
|
||||
stack.add_titled(&grid_layout, Some("page2"), "Soundcloud");
|
||||
|
||||
|
||||
window.set_child(Some(&hbox));
|
||||
|
||||
let label3 = gtk::Label::new(Some("Spotify Content"));
|
||||
stack.add_titled(&label3, Some("page3"), "Spotify");
|
||||
|
||||
|
||||
let sidebar = StackSidebar::new();
|
||||
sidebar.set_stack(&stack);
|
||||
|
||||
hbox.append(&sidebar);
|
||||
hbox.append(&stack);
|
||||
|
||||
window.set_child(Some(&hbox));
|
||||
glib::spawn_future_local(async move {
|
||||
while let Ok(response) = receiver.recv().await {
|
||||
for playlist in response.collection {
|
||||
let label2 = gtk::Label::new(Some(&playlist.title));
|
||||
grid_layout.attach(&label2, 0, 0, 1, 1);
|
||||
}
|
||||
stack.add_titled(&grid_layout, Some("page2"), "Soundcloud");
|
||||
}
|
||||
});
|
||||
|
||||
window.present();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user