Skip to content

Commit

Permalink
Restore now playing body state on startup
Browse files Browse the repository at this point in the history
Squash migrations
  • Loading branch information
ghasemi committed Aug 6, 2023
1 parent 2b4bfb5 commit d28498f
Show file tree
Hide file tree
Showing 39 changed files with 103 additions and 223 deletions.
Empty file removed migrations/.keep
Empty file.
1 change: 0 additions & 1 deletion migrations/2023-06-10-132201_collection/down.sql

This file was deleted.

11 changes: 0 additions & 11 deletions migrations/2023-06-10-132201_collection/up.sql

This file was deleted.

1 change: 0 additions & 1 deletion migrations/2023-06-18-135123_config/down.sql

This file was deleted.

9 changes: 0 additions & 9 deletions migrations/2023-06-18-135123_config/up.sql

This file was deleted.

2 changes: 0 additions & 2 deletions migrations/2023-06-20-124758_collection_id_to_row/down.sql

This file was deleted.

3 changes: 0 additions & 3 deletions migrations/2023-06-20-124758_collection_id_to_row/up.sql

This file was deleted.

4 changes: 0 additions & 4 deletions migrations/2023-06-23-095534_songs/down.sql

This file was deleted.

18 changes: 0 additions & 18 deletions migrations/2023-06-23-095534_songs/up.sql

This file was deleted.

20 changes: 0 additions & 20 deletions migrations/2023-06-24-134554_add_song_tags/down.sql

This file was deleted.

22 changes: 0 additions & 22 deletions migrations/2023-06-24-134554_add_song_tags/up.sql

This file was deleted.

2 changes: 0 additions & 2 deletions migrations/2023-06-26-153154_current_song_id/down.sql

This file was deleted.

5 changes: 0 additions & 5 deletions migrations/2023-06-26-153154_current_song_id/up.sql

This file was deleted.

2 changes: 0 additions & 2 deletions migrations/2023-07-02-084052_add_duration_to_song/down.sql

This file was deleted.

10 changes: 0 additions & 10 deletions migrations/2023-07-02-084052_add_duration_to_song/up.sql

This file was deleted.

5 changes: 0 additions & 5 deletions migrations/2023-07-12-084641_add_window_width_height/down.sql

This file was deleted.

5 changes: 0 additions & 5 deletions migrations/2023-07-12-084641_add_window_width_height/up.sql

This file was deleted.

2 changes: 0 additions & 2 deletions migrations/2023-07-12-091353_add_window_maximized/down.sql

This file was deleted.

2 changes: 0 additions & 2 deletions migrations/2023-07-12-091353_add_window_maximized/up.sql

This file was deleted.

3 changes: 0 additions & 3 deletions migrations/2023-07-15-083145_add_song_indexes/down.sql

This file was deleted.

5 changes: 0 additions & 5 deletions migrations/2023-07-15-083145_add_song_indexes/up.sql

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions migrations/2023-07-17-095420_add_current_song_position/up.sql

This file was deleted.

1 change: 0 additions & 1 deletion migrations/2023-07-19-141303_history_bodies/down.sql

This file was deleted.

8 changes: 0 additions & 8 deletions migrations/2023-07-19-141303_history_bodies/up.sql

This file was deleted.

2 changes: 0 additions & 2 deletions migrations/2023-07-20-061919_last_scroll_adjustment/down.sql

This file was deleted.

29 changes: 0 additions & 29 deletions migrations/2023-07-20-061919_last_scroll_adjustment/up.sql

This file was deleted.

Empty file.
12 changes: 0 additions & 12 deletions migrations/2023-07-24-135519_song_selected_body/up.sql

This file was deleted.

Empty file.
20 changes: 0 additions & 20 deletions migrations/2023-07-25-072251_query2/up.sql

This file was deleted.

2 changes: 0 additions & 2 deletions migrations/2023-08-02-074132_remove_collection_row/up.sql

This file was deleted.

File renamed without changes.
70 changes: 70 additions & 0 deletions migrations/2023-08-06-122201_init/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
create table bodies
(
id integer not null
constraint bodies_pk
primary key autoincrement,
query1 TEXT,
body_type TEXT not null,
scroll_adjustment REAL,
navigation_type TEXT not null,
query2 TEXT
);

create table collections
(
id integer not null
constraint collections_pk
primary key autoincrement,
path TEXT not null,
modified sqlite_uint64
);

create unique index collections_path_uindex
on collections (path);

create table songs
(
id integer not null
constraint songs_pk
primary key autoincrement,
path TEXT not null,
collection_id integer not null
constraint songs_collections_id_fk
references collections
on update cascade on delete cascade,
title TEXT,
artist TEXT,
album TEXT,
datetime sqlite_uint64,
genre TEXT,
track_number integer,
album_artist TEXT,
duration sqlite_uint64 not null
);

create table config
(
current_song_position sqlite_uint64 not null
constraint config_pk
primary key,
current_song_id integer
constraint config_songs_id_fk
references songs
on update cascade on delete set null,
window_width integer default 0 not null,
window_height integer default 0 not null,
maximized integer default 0 not null,
now_playing_body_realized integer default 0 not null
);

insert into config(current_song_position)
VALUES (0);

create index songs_artist_index
on songs (artist);

create index songs_collection_id_index
on songs (collection_id);

create unique index songs_path_uindex
on songs (path);
12 changes: 11 additions & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
use diesel::prelude::*;
use diesel::update;
use crate::db::get_connection;
use crate::schema::config::dsl::config;
use crate::schema::config::now_playing_body_realized;

#[derive(Queryable, Selectable, Debug)]
#[diesel(table_name = crate::schema::config)]
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
pub struct Config {
pub current_song_position: i64,
pub current_song_id: Option<i32>,
pub window_width: i32,
pub window_height: i32,
pub maximized: i32,
pub current_song_position: i64,
pub now_playing_body_realized: i32,
}

pub fn update_now_playing_body_realized(realized: bool) {
update(config).set(now_playing_body_realized.eq(if realized { 1 } else { 0 })).execute(&mut get_connection())
.unwrap();
}
15 changes: 9 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ fn main() -> Result<ExitCode> {
let back_button = Button::builder().icon_name(BACK_ICON).tooltip_text("Home").visible(history_bodies.len() > 1)
.build();
header_bar.pack_start(&back_button);
let now_playing = now_playing::create(song_selected_body.clone(), &window_title, &scrolled_window,
history.clone(), &back_button, &header_body, &body);
body.append(&now_playing);
let (now_playing_body, wrapper, now_playing) = now_playing::create(song_selected_body.clone(), &window_title,
&scrolled_window, history.clone(), &back_button, &header_body, &body);
body.append(&wrapper);
*song_selected_body.borrow_mut() = bodies.filter(navigation_type.eq(SongSelected)).limit(1)
.get_result::<BodyTable>(&mut get_connection()).ok().map(|body_table| {
let body = Body::from_body_table(&body_table, &window_title, &scrolled_window, history.clone(),
&now_playing, &back_button, &window);
&wrapper, &back_button, &window);
body.scroll_adjustment.set(body_table.scroll_adjustment);
Rc::new(body)
});
Expand All @@ -96,12 +96,12 @@ fn main() -> Result<ExitCode> {
}
});
for body_table in history_bodies {
Body::from_body_table(&body_table, &window_title, &scrolled_window, history.clone(), &now_playing,
Body::from_body_table(&body_table, &window_title, &scrolled_window, history.clone(), &wrapper,
&back_button, &window,
).put_to_history(body_table.scroll_adjustment, history.clone());
}
if empty_history {
Rc::new(Body::artists(&window_title, &scrolled_window, history.clone(), &now_playing,
Rc::new(Body::artists(&window_title, &scrolled_window, history.clone(), &wrapper,
&Some(back_button.clone()))
).set(&window_title, &scrolled_window, history.clone(), &None);
} else if let Some((body, _)) = history.borrow().last() {
Expand All @@ -110,6 +110,9 @@ fn main() -> Result<ExitCode> {
scrolled_window.set_child(Some((**widget).as_ref()));
scrolled_window.adjust(&body_scroll_adjustment);
}
if config.now_playing_body_realized == 1 {
now_playing.borrow().realize_body(&window_title, &back_button, &header_body, &now_playing_body);
}
window.connect_close_request({
let history = history.clone();
let scrolled_window = scrolled_window.clone();
Expand Down
Loading

0 comments on commit d28498f

Please sign in to comment.