no need for loadbackground if i could just make gameswitch use default

This commit is contained in:
RabbyDevs 2025-05-09 21:58:46 +03:00
parent 2e3c44b421
commit ef2b6fa43e

View file

@ -162,7 +162,7 @@ impl State {
mouse_area(
img
)
.on_press(Message::GameSelected(game.clone()))
.on_press(Message::GameSelected(Some(game.clone())))
.interaction(Interaction::Pointer)
.into()
} else {
@ -263,10 +263,9 @@ enum Message {
DragWindow,
LoadIcons(HashMap<PossibleGames, DynamicImage>),
LoadSplashes(HashMap<PossibleGames, DynamicImage>),
LoadBackground(()),
LoadVideo(()),
RefreshInstall(Result<(), String>),
GameSelected(PossibleGames),
GameSelected(Option<PossibleGames>),
Close,
Minimize
}
@ -290,6 +289,7 @@ async fn get_splashes() -> HashMap<PossibleGames, DynamicImage> {
}
async fn empty() {}
async fn empty_option() -> Option<PossibleGames> {None}
impl Launcher {
fn boot() -> (Self, Task<Message>) {
@ -297,7 +297,7 @@ impl Launcher {
Box::new(State::default().load().unwrap())),
Task::batch([
Task::perform(refresh_install(), Message::RefreshInstall),
Task::perform(empty(), Message::LoadBackground),
Task::perform(empty_option(), Message::GameSelected),
Task::perform(get_icons(), Message::LoadIcons),
Task::perform(get_splashes(), Message::LoadSplashes),
]))
@ -340,25 +340,6 @@ impl Launcher {
state.splash_images = splashes;
Task::none()
},
Message::LoadBackground(()) => {
let (width, height) = state.selected_game.get_game_preferred_size();
let task = window::get_latest().and_then(move |id: window::Id| {
window::resize(id, Size { width: width as f32, height: height as f32 })
});
if let Ok(background) = get_game_background(&state.selected_game, false) {
if let LauncherBackground::Video(_) = background {
state.background = Some(background);
return task.chain(Task::perform(empty(), Message::LoadVideo));
}
state.background = Some(background);
} else {
state.background = None
}
task
},
Message::LoadVideo(()) => {
if let Ok(background) = get_game_background(&state.selected_game, true) {
state.background = Some(background);
@ -377,7 +358,11 @@ impl Launcher {
Task::none()
},
Message::GameSelected(game) => {
state.selected_game = game;
if let Some(game) = game {
state.selected_game = game;
} else {
state.selected_game = PossibleGames::default();
}
let (width, height) = state.selected_game.get_game_preferred_size();
let task = window::get_latest().and_then(move |id: window::Id| {
window::resize(id, Size { width: width as f32, height: height as f32 })