"manage sounds" button; infinitely looping audio
This commit is contained in:
parent
40c100e65b
commit
755b5769ac
36
src/main.rs
36
src/main.rs
|
@ -1,13 +1,27 @@
|
||||||
use gio::prelude::*;
|
use gio::prelude::*;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::Orientation;
|
use gtk::Orientation;
|
||||||
use rodio::Sink;
|
use rodio::{Sink, Source};
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
const SPACING: i32 = 16;
|
const SPACING: i32 = 16;
|
||||||
|
|
||||||
|
fn get_data_dir() -> PathBuf {
|
||||||
|
let mut data_dir = dirs::data_dir().expect("Couldn't find user data directory");
|
||||||
|
|
||||||
|
data_dir.push("ruin/lull");
|
||||||
|
|
||||||
|
if !data_dir.exists() {
|
||||||
|
std::fs::create_dir_all(&data_dir).expect("Couldn't create lull data directory");
|
||||||
|
}
|
||||||
|
|
||||||
|
data_dir
|
||||||
|
}
|
||||||
|
|
||||||
fn build_ui(application: >k::Application) {
|
fn build_ui(application: >k::Application) {
|
||||||
let window = gtk::ApplicationWindow::new(application);
|
let window = gtk::ApplicationWindow::new(application);
|
||||||
|
|
||||||
|
@ -23,15 +37,7 @@ fn build_ui(application: >k::Application) {
|
||||||
|
|
||||||
let device = rodio::default_output_device().unwrap();
|
let device = rodio::default_output_device().unwrap();
|
||||||
|
|
||||||
let mut data_dir = dirs::data_dir().expect("Couldn't find user data directory");
|
let paths = std::fs::read_dir(get_data_dir())
|
||||||
|
|
||||||
data_dir.push("ruin/lull");
|
|
||||||
|
|
||||||
if !data_dir.exists() {
|
|
||||||
std::fs::create_dir_all(&data_dir).expect("Couldn't create lull data directory");
|
|
||||||
}
|
|
||||||
|
|
||||||
let paths = std::fs::read_dir(&data_dir)
|
|
||||||
.expect("Couldn't read from lull data directory");
|
.expect("Couldn't read from lull data directory");
|
||||||
|
|
||||||
for path in paths {
|
for path in paths {
|
||||||
|
@ -44,6 +50,8 @@ fn build_ui(application: >k::Application) {
|
||||||
let source = rodio::Decoder::new(BufReader::new(file))
|
let source = rodio::Decoder::new(BufReader::new(file))
|
||||||
.expect("Couldn't decode audio");
|
.expect("Couldn't decode audio");
|
||||||
|
|
||||||
|
let source = source.repeat_infinite();
|
||||||
|
|
||||||
let sink = Sink::new(&device);
|
let sink = Sink::new(&device);
|
||||||
sink.append(source);
|
sink.append(source);
|
||||||
sink.pause();
|
sink.pause();
|
||||||
|
@ -72,7 +80,6 @@ fn build_ui(application: >k::Application) {
|
||||||
|
|
||||||
slider.connect_value_changed(move |scale| {
|
slider.connect_value_changed(move |scale| {
|
||||||
let volume = scale.get_value();
|
let volume = scale.get_value();
|
||||||
println!("volume: {}", volume);
|
|
||||||
|
|
||||||
if volume == 0. {
|
if volume == 0. {
|
||||||
sink.pause();
|
sink.pause();
|
||||||
|
@ -90,7 +97,12 @@ fn build_ui(application: >k::Application) {
|
||||||
let row_add = gtk::Box::new(Orientation::Horizontal, SPACING);
|
let row_add = gtk::Box::new(Orientation::Horizontal, SPACING);
|
||||||
row_add.set_homogeneous(true);
|
row_add.set_homogeneous(true);
|
||||||
|
|
||||||
let button_open_dir = gtk::Button::with_label("add more");
|
let button_open_dir = gtk::Button::with_label("manage sounds");
|
||||||
|
button_open_dir.connect_clicked(|_|{
|
||||||
|
let mut file_manager = Command::new("xdg-open");
|
||||||
|
file_manager.arg(get_data_dir());
|
||||||
|
file_manager.output().unwrap();
|
||||||
|
});
|
||||||
row_add.add(&button_open_dir);
|
row_add.add(&button_open_dir);
|
||||||
|
|
||||||
vertical.add(&row_add);
|
vertical.add(&row_add);
|
||||||
|
|
Loading…
Reference in New Issue