mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-11-22 04:46:08 +03:00
Several changes
- added "Open launcher folder" button to settings - removed `glib::Downgrade` trait from all the `App`s' `Value`s - removed `tasks` mod; removed `tokio` dependency; rewritten `OpenPreferencesPage` to work with threads instead of futures - added `opt-level = 3` to release profile
This commit is contained in:
parent
0baa3593ac
commit
b5fe109be6
8 changed files with 37 additions and 28 deletions
|
@ -10,6 +10,7 @@ build = "build.rs"
|
|||
[profile.release]
|
||||
strip = true
|
||||
lto = true
|
||||
opt-level = 3
|
||||
|
||||
[build-dependencies]
|
||||
gtk4 = "0.4"
|
||||
|
@ -24,7 +25,6 @@ serde = { version = "1.0", features = ["derive"] }
|
|||
serde_json = "1.0"
|
||||
|
||||
dirs = "4.0.0"
|
||||
tokio = { version = "1.20", features = ["rt", "rt-multi-thread", "macros"] }
|
||||
wait_not_await = "0.2.1"
|
||||
regex = "1.6.0"
|
||||
lazy_static = "1.4.0"
|
||||
|
|
|
@ -32,6 +32,10 @@ Adw.PreferencesPage page {
|
|||
spacing: 8;
|
||||
margin-top: 16;
|
||||
|
||||
Gtk.Button launcher_folder {
|
||||
label: "Open launcher folder";
|
||||
}
|
||||
|
||||
Gtk.Button repair_game {
|
||||
label: "Repair game";
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
pub mod consts;
|
||||
pub mod config;
|
||||
pub mod tasks;
|
||||
pub mod game;
|
||||
pub mod dxvk;
|
||||
pub mod wine;
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
use std::future::Future;
|
||||
|
||||
pub fn run<T>(future: T) where
|
||||
T: Future + Send + 'static,
|
||||
<T as Future>::Output: Send
|
||||
{
|
||||
tokio::task::spawn(future);
|
||||
}
|
|
@ -16,8 +16,7 @@ pub const APP_ID: &str = "com.gitlab.an-anime-team.an-anime-game-launcher-gtk";
|
|||
pub const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
pub const APP_DEBUG: bool = cfg!(debug_assertions);
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
fn main() {
|
||||
gtk::init().expect("GTK initialization failed");
|
||||
adw::init();
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ use super::components::progress_bar::*;
|
|||
|
||||
use crate::lib::config;
|
||||
use crate::lib::game;
|
||||
use crate::lib::tasks;
|
||||
use crate::lib::launcher::states::LauncherState;
|
||||
use crate::lib::wine::{
|
||||
Version as WineVersion,
|
||||
|
@ -155,9 +154,9 @@ impl Actions {
|
|||
/// In this example we store a counter here to know what should we increment or decrement
|
||||
///
|
||||
/// This must implement `Default` trait
|
||||
#[derive(Debug, Default, glib::Downgrade)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Values {
|
||||
state: Rc<LauncherState>
|
||||
state: LauncherState
|
||||
}
|
||||
|
||||
/// The main application structure
|
||||
|
@ -238,7 +237,9 @@ impl App {
|
|||
Actions::OpenPreferencesPage => {
|
||||
this.widgets.leaflet.set_visible_child_name("preferences_page");
|
||||
|
||||
tasks::run(clone!(@strong this => async move {
|
||||
let this = this.clone();
|
||||
|
||||
std::thread::spawn(move || {
|
||||
if let Err(err) = this.widgets.preferences_stack.update() {
|
||||
glib::MainContext::default().invoke(move || {
|
||||
this.update(Actions::PreferencesGoBack).unwrap();
|
||||
|
@ -246,7 +247,7 @@ impl App {
|
|||
this.toast("Failed to update preferences", err);
|
||||
});
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
Actions::PreferencesGoBack => {
|
||||
|
@ -257,7 +258,7 @@ impl App {
|
|||
|
||||
Actions::PerformButtonEvent => {
|
||||
let values = this.values.take();
|
||||
let state = (*values.state).clone();
|
||||
let state = values.state.clone();
|
||||
|
||||
this.values.set(values);
|
||||
|
||||
|
@ -801,7 +802,7 @@ impl App {
|
|||
|
||||
let mut values = self.values.take();
|
||||
|
||||
values.state = Rc::new(state);
|
||||
values.state = state;
|
||||
|
||||
self.values.set(values);
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ pub enum Actions {
|
|||
/// This must implement `Default` trait
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Values {
|
||||
pub rows: HashMap<String, adw::ActionRow>
|
||||
rows: HashMap<String, adw::ActionRow>
|
||||
}
|
||||
|
||||
/// The main application structure
|
||||
|
|
|
@ -7,9 +7,11 @@ use gtk::glib::clone;
|
|||
use std::rc::Rc;
|
||||
use std::cell::Cell;
|
||||
use std::io::Error;
|
||||
use std::process::Command;
|
||||
|
||||
use anime_game_core::prelude::*;
|
||||
|
||||
use crate::lib::consts;
|
||||
use crate::lib::config;
|
||||
use crate::lib::dxvk;
|
||||
use crate::lib::wine;
|
||||
|
@ -33,6 +35,7 @@ pub struct AppWidgets {
|
|||
pub voiceovers_row: adw::ExpanderRow,
|
||||
pub voieover_components: Rc<Vec<VoiceoverRow>>,
|
||||
|
||||
pub launcher_folder: gtk::Button,
|
||||
pub repair_game: gtk::Button,
|
||||
|
||||
pub game_version: gtk::Label,
|
||||
|
@ -64,6 +67,7 @@ impl AppWidgets {
|
|||
voiceovers_row: get_object(&builder, "voiceovers_row")?,
|
||||
voieover_components: Default::default(),
|
||||
|
||||
launcher_folder: get_object(&builder, "launcher_folder")?,
|
||||
repair_game: get_object(&builder, "repair_game")?,
|
||||
|
||||
game_version: get_object(&builder, "game_version")?,
|
||||
|
@ -163,8 +167,9 @@ impl AppWidgets {
|
|||
/// It may be helpful if you want to add the same event for several widgets, or call an action inside of another action
|
||||
#[derive(Debug, Clone, glib::Downgrade)]
|
||||
pub enum Actions {
|
||||
VoiceoverPerformAction(Rc<usize>),
|
||||
OpenLauncherFolder,
|
||||
RepairGame,
|
||||
VoiceoverPerformAction(Rc<usize>),
|
||||
DxvkPerformAction(Rc<usize>),
|
||||
WinePerformAction(Rc<(usize, usize)>),
|
||||
UpdateDxvkComboRow,
|
||||
|
@ -187,10 +192,10 @@ impl Actions {
|
|||
/// In this example we store a counter here to know what should we increment or decrement
|
||||
///
|
||||
/// This must implement `Default` trait
|
||||
#[derive(Debug, Default, glib::Downgrade)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Values {
|
||||
downloaded_wine_versions: Rc<Option<Vec<wine::Version>>>,
|
||||
downloaded_dxvk_versions: Rc<Option<Vec<dxvk::Version>>>
|
||||
downloaded_wine_versions: Option<Vec<wine::Version>>,
|
||||
downloaded_dxvk_versions: Option<Vec<dxvk::Version>>
|
||||
}
|
||||
|
||||
/// The main application structure
|
||||
|
@ -231,6 +236,7 @@ impl App {
|
|||
|
||||
/// Add default events and values to the widgets
|
||||
fn init_events(self) -> Self {
|
||||
self.widgets.launcher_folder.connect_clicked(Actions::OpenLauncherFolder.into_fn(&self));
|
||||
self.widgets.repair_game.connect_clicked(Actions::RepairGame.into_fn(&self));
|
||||
|
||||
// Voiceover download/delete button event
|
||||
|
@ -332,6 +338,14 @@ impl App {
|
|||
println!("[general page] [update] action: {:?}", &action);
|
||||
|
||||
match action {
|
||||
Actions::OpenLauncherFolder => {
|
||||
if let Some(launcher_folder) = consts::launcher_dir(){
|
||||
if let Err(err) = Command::new("xdg-open").arg(launcher_folder).spawn() {
|
||||
this.toast("Failed to open launcher folder", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Actions::RepairGame => {
|
||||
let option = (&*this.app).take();
|
||||
this.app.set(option.clone());
|
||||
|
@ -472,7 +486,7 @@ impl App {
|
|||
|
||||
let mut values = this.values.take();
|
||||
|
||||
values.downloaded_dxvk_versions = Rc::new(Some(raw_list));
|
||||
values.downloaded_dxvk_versions = Some(raw_list);
|
||||
|
||||
this.values.set(values);
|
||||
|
||||
|
@ -491,7 +505,7 @@ impl App {
|
|||
Actions::SelectDxvkVersion(i) => {
|
||||
let values = this.values.take();
|
||||
|
||||
if let Some(dxvk_versions) = &*values.downloaded_dxvk_versions {
|
||||
if let Some(dxvk_versions) = &values.downloaded_dxvk_versions {
|
||||
let version = dxvk_versions[*i].clone();
|
||||
|
||||
if config.game.dxvk.selected != Some(version.name.clone()) {
|
||||
|
@ -535,7 +549,7 @@ impl App {
|
|||
|
||||
let mut values = this.values.take();
|
||||
|
||||
values.downloaded_wine_versions = Rc::new(Some(list));
|
||||
values.downloaded_wine_versions = Some(list);
|
||||
|
||||
this.values.set(values);
|
||||
|
||||
|
@ -554,7 +568,7 @@ impl App {
|
|||
Actions::SelectWineVersion(i) => {
|
||||
let values = this.values.take();
|
||||
|
||||
if let Some(wine_versions) = &*values.downloaded_wine_versions {
|
||||
if let Some(wine_versions) = &values.downloaded_wine_versions {
|
||||
match *i {
|
||||
0 => config.game.wine.selected = None,
|
||||
i => config.game.wine.selected = Some(wine_versions[i - 1].name.clone())
|
||||
|
|
Loading…
Reference in a new issue