Skip to content

Commit

Permalink
cleaning up use
Browse files Browse the repository at this point in the history
  • Loading branch information
mfep committed Nov 7, 2023
1 parent 213e26c commit 2bb9e2e
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 180 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.flatpak-builder
/target
/.vscode
/build
/builddir
/target
115 changes: 0 additions & 115 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tokio = { version = "1.28", features = [
"rt-multi-thread",
] }
futures = "0.3.28"
rodio = "0.17.1"
rodio = { version="0.17.1", default-features=false, features = ["wav"] }
json = "0.12.4"

[build-dependencies]
Expand Down
11 changes: 5 additions & 6 deletions src/exercise_editor.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::exercise_setup::ExerciseSetup;
use gtk::prelude::{ButtonExt, GtkWindowExt, OrientableExt, WidgetExt};
use crate::exercise_setup::*;
use relm4::{
adw::{self, prelude::*},
binding::*,
gtk, ComponentParts, ComponentSender, RelmObjectExt, RelmWidgetExt, SimpleComponent,
gtk, RelmObjectExt, RelmWidgetExt,
};

#[derive(Debug)]
Expand Down Expand Up @@ -33,7 +32,7 @@ pub enum ExerciseEditorOutput {
}

#[relm4::component(pub)]
impl SimpleComponent for ExerciseEditor {
impl relm4::SimpleComponent for ExerciseEditor {
type Init = (ExerciseEditorRole, ExerciseSetup);
type Input = ExerciseEditorInput;
type Output = Option<ExerciseEditorOutput>;
Expand Down Expand Up @@ -134,10 +133,10 @@ impl SimpleComponent for ExerciseEditor {
role: init.0,
};
let widgets = view_output!();
ComponentParts { model, widgets }
relm4::ComponentParts { model, widgets }
}

fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>) {
fn update(&mut self, message: Self::Input, sender: relm4::ComponentSender<Self>) {
match message {
ExerciseEditorInput::Cancel => sender.output(None).unwrap(),
ExerciseEditorInput::Create => {
Expand Down
19 changes: 7 additions & 12 deletions src/exercise_setup.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
use std::time::Duration;

use crate::exercise_editor::*;
use crate::*;
use futures::prelude::*;
use relm4::{
gtk::{self, prelude::*, Root},
gtk::{self, prelude::*},
prelude::*,
Component, RelmWidgetExt,
RelmWidgetExt,
};

use crate::{exercise_editor::ExerciseEditor, AppModelInput};
use crate::{
exercise_editor::{ExerciseEditorOutput, ExerciseEditorRole},
settings,
};
use futures::StreamExt;
use std::time::Duration;

#[derive(Debug, Clone)]
pub struct ExerciseSetup {
Expand All @@ -35,7 +30,7 @@ impl Default for ExerciseSetup {

#[derive(Debug)]
pub enum ExerciseSetupInput {
Edit(Root),
Edit(gtk::Root),
Update(ExerciseSetup),
Load,
}
Expand Down
13 changes: 8 additions & 5 deletions src/exercise_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ mod timer;

use relm4::{
adw,
binding::Binding,
binding::*,
gtk::{self, prelude::*},
Component, ComponentParts, ComponentSender, RelmObjectExt, RelmWidgetExt, WorkerController,
prelude::*,
RelmObjectExt, RelmWidgetExt,
};
use timer::{TimerModel, TimerOutput};

Expand All @@ -28,8 +29,8 @@ pub struct ExerciseTimer {
remaining_sets: usize,
remaining_s: usize,
running: bool,
timer: Option<WorkerController<TimerModel>>,
audio_player: WorkerController<AudioPlayerModel>,
timer: Option<relm4::WorkerController<TimerModel>>,
audio_player: relm4::WorkerController<AudioPlayerModel>,
}

impl ExerciseTimer {
Expand Down Expand Up @@ -92,7 +93,9 @@ pub enum ExerciseTimerInput {
Reset,
}

fn build_timer(sender: &ComponentSender<ExerciseTimer>) -> Option<WorkerController<TimerModel>> {
fn build_timer(
sender: &ComponentSender<ExerciseTimer>,
) -> Option<relm4::WorkerController<TimerModel>> {
Some(
TimerModel::builder()
.detach_worker(())
Expand Down
9 changes: 4 additions & 5 deletions src/exercise_timer/audio_player.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use relm4::gtk::gio;
use relm4::{self, prelude::*, Worker};
use rodio::{self, Decoder, Source};
use relm4::{self, gtk::gio, prelude::*};
use rodio::{self, Source};

pub struct AudioPlayerModel {
output_stream: rodio::OutputStreamHandle,
Expand All @@ -11,7 +10,7 @@ pub struct AudioPlayerModel {
impl AudioPlayerModel {
fn play_ping(&self, times: u32) {
let cursor = std::io::Cursor::new(self.ping_bytes.clone());
let decoder = Decoder::new_wav(cursor).expect("Could not decode WAV");
let decoder = rodio::Decoder::new_wav(cursor).expect("Could not decode WAV");
let new_duration = decoder.total_duration().unwrap() * times;
let d = decoder
.repeat_infinite()
Expand All @@ -38,7 +37,7 @@ pub struct AudioPlayerModelInit {
pub volume: f64,
}

impl Worker for AudioPlayerModel {
impl relm4::Worker for AudioPlayerModel {
type Init = AudioPlayerModelInit;
type Input = AudioPlayerInput;
type Output = ();
Expand Down
3 changes: 1 addition & 2 deletions src/exercise_timer/timer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::time::Duration;

use relm4::Worker;
use std::time::Duration;

pub struct TimerModel;

Expand Down
Loading

0 comments on commit 2bb9e2e

Please sign in to comment.