mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2025-02-03 14:30:50 +03:00
Added ability to delete wine versions
This commit is contained in:
parent
8de240d5a0
commit
30c7d836bd
3 changed files with 41 additions and 16 deletions
src/ui
|
@ -77,7 +77,7 @@ impl WineRow {
|
|||
/// Download wine
|
||||
///
|
||||
/// This method doesn't update components states, so you need to call `update_state` method manually
|
||||
pub fn download<T: ToString>(&self, runners_folder: T) -> Result<Await<DownloadingResult>, std::io::Error> {
|
||||
pub fn download<T: ToString>(&self, runners_folder: T) -> std::io::Result<Await<DownloadingResult>> {
|
||||
let (sender, receiver) = glib::MainContext::channel::<InstallerUpdate>(glib::PRIORITY_DEFAULT);
|
||||
let this = self.clone();
|
||||
|
||||
|
@ -144,6 +144,10 @@ impl WineRow {
|
|||
downl_recv.recv().unwrap()
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn delete<T: ToString>(&self, runners_folder: T) -> std::io::Result<()> {
|
||||
std::fs::remove_dir_all(format!("{}/{}", runners_folder.to_string(), self.version.name))
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for WineRow {}
|
||||
|
|
|
@ -3,7 +3,6 @@ use libadwaita::{self as adw, prelude::*};
|
|||
|
||||
use gtk::glib;
|
||||
use gtk::glib::clone;
|
||||
use gtk::Align;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::cell::Cell;
|
||||
|
@ -11,11 +10,11 @@ use std::io::Error;
|
|||
|
||||
use anime_game_core::prelude::*;
|
||||
|
||||
use crate::ui::get_object;
|
||||
use crate::lib::config;
|
||||
use crate::lib::dxvk;
|
||||
use crate::lib::wine;
|
||||
|
||||
use crate::ui::*;
|
||||
use crate::ui::components::dxvk_row::DxvkRow;
|
||||
use crate::ui::components::wine_group::WineGroup;
|
||||
|
||||
|
@ -26,6 +25,9 @@ use crate::ui::components::wine_group::WineGroup;
|
|||
/// This function does not implement events
|
||||
#[derive(Clone, glib::Downgrade)]
|
||||
pub struct AppWidgets {
|
||||
pub window: adw::ApplicationWindow,
|
||||
pub toast_overlay: adw::ToastOverlay,
|
||||
|
||||
pub page: adw::PreferencesPage,
|
||||
|
||||
pub game_version: gtk::Label,
|
||||
|
@ -44,10 +46,13 @@ pub struct AppWidgets {
|
|||
}
|
||||
|
||||
impl AppWidgets {
|
||||
fn try_get() -> Result<Self, String> {
|
||||
fn try_get(window: adw::ApplicationWindow, toast_overlay: adw::ToastOverlay) -> Result<Self, String> {
|
||||
let builder = gtk::Builder::from_string(include_str!("../../../assets/ui/.dist/preferences_general.ui"));
|
||||
|
||||
let mut result = Self {
|
||||
window,
|
||||
toast_overlay,
|
||||
|
||||
page: get_object(&builder, "general_page")?,
|
||||
|
||||
game_version: get_object(&builder, "game_version")?,
|
||||
|
@ -124,7 +129,7 @@ impl AppWidgets {
|
|||
#[derive(Debug, Clone, glib::Downgrade)]
|
||||
pub enum Actions {
|
||||
DownloadDXVK(Rc<usize>),
|
||||
DownloadWine(Rc<(usize, usize)>)
|
||||
WinePerformAction(Rc<(usize, usize)>)
|
||||
}
|
||||
|
||||
impl Actions {
|
||||
|
@ -163,9 +168,9 @@ pub struct App {
|
|||
|
||||
impl App {
|
||||
/// Create new application
|
||||
pub fn new() -> Result<Self, String> {
|
||||
pub fn new(window: adw::ApplicationWindow, toast_overlay: adw::ToastOverlay) -> Result<Self, String> {
|
||||
let result = Self {
|
||||
widgets: AppWidgets::try_get()?,
|
||||
widgets: AppWidgets::try_get(window, toast_overlay)?,
|
||||
values: Default::default(),
|
||||
actions: Default::default()
|
||||
}.init_events().init_actions();
|
||||
|
@ -193,7 +198,7 @@ impl App {
|
|||
|
||||
for (i, group) in components.into_iter().enumerate() {
|
||||
for (j, component) in (&group.version_components).into_iter().enumerate() {
|
||||
component.button.connect_clicked(Actions::DownloadWine(Rc::new((i, j))).into_fn(&self));
|
||||
component.button.connect_clicked(Actions::WinePerformAction(Rc::new((i, j))).into_fn(&self));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,17 +243,27 @@ impl App {
|
|||
this.widgets.dxvk_components[*i].download();
|
||||
}
|
||||
|
||||
Actions::DownloadWine(version) => {
|
||||
Actions::WinePerformAction(version) => {
|
||||
let config = config::get().expect("Failed to load config");
|
||||
|
||||
let component = this.widgets
|
||||
.wine_components[version.0]
|
||||
.version_components[version.1].clone();
|
||||
|
||||
if let Ok(awaiter) = component.download(&config.game.wine.builds) {
|
||||
awaiter.then(move |_| {
|
||||
component.update_state(&config.game.wine.builds);
|
||||
});
|
||||
if component.is_downloaded(&config.game.wine.builds) {
|
||||
if let Err(err) = component.delete(&config.game.wine.builds) {
|
||||
this.toast_error("Failed to delete wine", err);
|
||||
}
|
||||
|
||||
component.update_state(&config.game.wine.builds);
|
||||
}
|
||||
|
||||
else {
|
||||
if let Ok(awaiter) = component.download(&config.game.wine.builds) {
|
||||
awaiter.then(move |_| {
|
||||
component.update_state(&config.game.wine.builds);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -356,5 +371,11 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToastError for App {
|
||||
fn get_toast_widgets(&self) -> (adw::ApplicationWindow, adw::ToastOverlay) {
|
||||
(self.widgets.window.clone(), self.widgets.toast_overlay.clone())
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for App {}
|
||||
unsafe impl Sync for App {}
|
||||
|
|
|
@ -38,8 +38,8 @@ impl PreferencesStack {
|
|||
let builder = gtk::Builder::from_string(include_str!("../../../assets/ui/.dist/preferences.ui"));
|
||||
|
||||
let result = Self {
|
||||
window,
|
||||
toast_overlay,
|
||||
window: window.clone(),
|
||||
toast_overlay: toast_overlay.clone(),
|
||||
|
||||
preferences: get_object(&builder, "preferences")?,
|
||||
preferences_go_back: get_object(&builder, "preferences_go_back")?,
|
||||
|
@ -49,7 +49,7 @@ impl PreferencesStack {
|
|||
|
||||
stack: get_object(&builder, "stack")?,
|
||||
|
||||
general_page: pages::GeneralPage::new()?,
|
||||
general_page: pages::GeneralPage::new(window, toast_overlay)?,
|
||||
enhanced_page: pages::EnhancedPage::new()?
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue