This commit is contained in:
Nikita Podvirnyi 2024-08-16 14:22:31 +02:00
commit 8ae6bddcda
No known key found for this signature in database
GPG key ID: 859D416E5142AFF3
24 changed files with 801 additions and 744 deletions

2
.envrc
View file

@ -1 +1 @@
use nix
use flake

View file

@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Respect root `.version` file for game version parsing
- Added disabling of 2 new telemetry servers
### Changed
- Prioritize parsed game version over the API response
### Removed
- Removed migrate installation feature
## [1.0.1] - 05.07.2024
### Fixed

596
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -15,28 +15,28 @@ lto = true
opt-level = "s"
[build-dependencies]
glib-build-tools = "0.19"
glib-build-tools = "0.20"
[dependencies.anime-launcher-sdk]
git = "https://github.com/an-anime-team/anime-launcher-sdk"
tag = "1.16.3"
tag = "1.17.3"
features = ["all", "zzz"]
# path = "../anime-launcher-sdk" # ! for dev purposes only
[dependencies]
relm4 = { version = "0.8.1", features = ["macros", "libadwaita"] }
gtk = { package = "gtk4", version = "0.8.2", features = ["v4_12"] }
adw = { package = "libadwaita", version = "0.6.0", features = ["v1_4"] }
relm4 = { version = "0.9.0", features = ["macros", "libadwaita"] }
gtk = { package = "gtk4", version = "0.9.0", features = ["v4_12"] }
adw = { package = "libadwaita", version = "0.7.0", features = ["v1_4"] }
rfd = { version = "0.14.1", features = ["xdg-portal", "tokio"], default-features = false }
open = "5.2.0"
open = "5.3.0"
whatadistro = "0.1.0"
serde_json = "1.0"
anyhow = "1.0"
lazy_static = "1.5.0"
cached = { version = "0.52", features = ["proc_macro"] }
cached = { version = "0.53", features = ["proc_macro"] }
md-5 = { version = "0.10", features = ["asm"] }
enum-ordinalize = "4.3"
@ -46,4 +46,4 @@ tracing-subscriber = "0.3"
fluent-templates = "0.9"
unic-langid = "0.9"
human-panic = "2.0.0"
human-panic = "2.0.1"

View file

@ -10,6 +10,12 @@
<br>
# 🚧 Project status
Due to lack of interest from my side the project stays in a legacy, maintaining-only state for a long period of time. This project will not receive huge updates unless really necessary. I still keep it up to date with latest changes in the game and work with community to solve the issues, but old-known unessential bugs will not be fixed, and new features will not be added. Instead, I'm working on other projects, and the future is in uniting all the launchers in one single [universal launcher](https://github.com/an-anime-team/anime-games-launcher). This project stays in "proof of concept" stage right now and requires major changes, which, again, require interest from my side. Keep your eye on our discord server for more details.
<br>
# ♥️ Useful links and thanks
* [macOS launcher](https://github.com/3Shain/yet-another-anime-game-launcher) which contains some additional compatibility components
@ -17,58 +23,62 @@
* [Releases page](https://github.com/an-anime-team/sleepy-launcher/releases) where you can find latest available version
* [Changelog](CHANGELOG.md) with chronology of the project
All the project's life happen in our discord server. If you have any questions or want to report an issue - please contact the dev directly there.
<br>
# ⬇️ Download
| Distribution | Format | Wiki | Source |
| - | - | - | - |
| Fedora | Flatpak | [link](https://github.com/an-anime-team/sleepy-launcher/wiki/Installation#-any-distribution-flatpak) | - |
| Arch Linux, Manjaro | AUR | [link](https://github.com/an-anime-team/sleepy-launcher/wiki/Installation#-arch-linux-aur) | [sleepy-launcher-bin](https://aur.archlinux.org/packages/sleepy-launcher-bin) |
| Fedora, OpenSUSE | RPM | [link](https://github.com/an-anime-team/sleepy-launcher/wiki/Installation#-fedora-rpm) | [SL](https://build.opensuse.org/repositories/home:Maroxy:AAT-Apps/SL) |
| Ubuntu | pacstall | - | [sleepy-launcher-bin](https://pacstall.dev/packages/sleepy-launcher-bin) |
| Gentoo | ebuild | [link](https://github.com/an-anime-team/sleepy-launcher/wiki/Installation#-gentoo-linux-ebuild) | [aagl-ebuilds](https://github.com/an-anime-team/gentoo-ebuilds) |
| NixOS | nixpkg | [link](https://github.com/an-anime-team/sleepy-launcher/wiki/Installation#-nixos-nixpkg) | [aagl-gtk-on-nix](https://github.com/ezKEa/aagl-gtk-on-nix) |
Launcher developer does not provide any packages for this programm. Instead, we almost fully rely on other people to maintain them.
To see the installation guides, please visit the wiki page [here](https://github.com/an-anime-team/sleepy-launcher/wiki/Installation)
To see the installation guides, please visit [this wiki page](https://github.com/an-anime-team/sleepy-launcher/wiki/Installation).
Lutris integration described [here](https://github.com/an-anime-team/sleepy-launcher/wiki/Installation#-lutris)
Instructions may be outdated due to lack of interest in maintaining them. You can help the project by keeping documentation up to date if you're interested in it.
## 😀 Official support
These packages are officially supported by the An Anime Team, and we try to ensure that they work for everyone.
| Format | Wiki | Source | Distributions | Maintainer |
| - | - | - | - | - |
| Flatpak | [wiki](https://github.com/an-anime-team/sleepy-launcher/wiki/Installation#-any-distribution-flatpak) | [flatpak-builds](https://github.com/an-anime-team/flatpak-builds) | Any (Fedora, Pop!_OS, SteamOS / Steam Deck, etc.) | Luna (available in discord) |
| RPM | [wiki](https://github.com/an-anime-team/sleepy-launcher/wiki/Installation#-fedora-rpm) | [AAGL](https://build.opensuse.org/repositories/home:Maroxy:AAT-Apps/AAGL) * | Fedora, OpenSUSE | Maroxy (second discord admin) |
> [!NOTE]
> RPM packages are often really outdated. It's not recommended to use them.
## 🙂 Community support
These packages are supported by active members of our community. They're widely used and we keep some level of interactions with their maintainers.
| Format | Wiki | Source | Distributions | Maintainer |
| - | - | - | - | - |
| AUR | [wiki](https://github.com/an-anime-team/sleepy-launcher/wiki/Installation#-arch-linux-aur) | [sleepy-launcher-bin](https://aur.archlinux.org/packages/sleepy-launcher-bin) | Arch Linux, Manjaro, EndeavourOS | xstra * |
| NixOS module | [wiki](https://github.com/an-anime-team/sleepy-launcher/wiki/Installation#-nixos-nixpkg) | [aagl-gtk-on-nix](https://github.com/ezKEa/aagl-gtk-on-nix) | NixOS | Luxxy * |
> [!NOTE]
> Honorary members of our discord server. We have direct contact with them.
## 😑 Third party support
These packages are supported by third party distributors. They either did not contact us, or contact exceptionally rarely. We do not verify state of these packages, and we are not related to their state at all.
| Format | Source | Distributions |
| - | - | - |
| DEB | [sleepy-launcher](https://launchpad.net/~thundergemios10/+archive/ubuntu/sleepy-launcher) | Ubuntu, Linux Mint, Pop!_OS |
| Pacstall | [sleepy-launcher-bin](https://pacstall.dev/packages/sleepy-launcher-bin) | Ubuntu |
| Ebuild | [aagl-ebuilds](https://github.com/an-anime-team/gentoo-ebuilds) * | Gentoo |
| Lutris | `lutris.net/games/zen...-zero` (stripping the link) | Any |
> [!NOTE]
> Although it's hosted in our official repo we didn't contact with its maintainer for some time already, and recent updates were made via merge requests by the community.
## Chinese version support
This should be automatically enabled if you're using zh_cn (Chinese) as your system language. If you're not using it - you can change the game edition in the launcher settings
This should be automatically enabled if you're using `zh_cn` (Chinese) as your system language. If you're not using it - you can change the game edition in the launcher settings.
<br>
The main problem, though, is that github is blocked in China, and it's used in other parts of the launcher - not just in game edition. Notably, you can't use the same components index as other people do.
# 💻 Development
To fix this, you have to make your own copy of the [components](https://github.com/an-anime-team/components) repository and change all the links there from github releases to some mirror. Later you can update the components index repo link in your launcher's `config.json` file.
| Folder | Description |
| - | - |
| src | Rust source code |
| assets | App assets folder |
| assets/locales | App localizations |
| target/release | Release build of the app |
## Clone repo
```sh
git clone --recursive https://github.com/an-anime-team/sleepy-launcher
```
## Run app
```sh
cargo run
```
## Build app
```sh
cargo build --release
```
## Updates strategy
Starting from 3.2.1 ([fcab428](https://github.com/an-anime-team/sleepy-launcher/commit/fcab428cb40b1457f41e0856f9d1e1473acbe653)) we have 2 branches: stable ([main](https://github.com/an-anime-team/sleepy-launcher/tree/main)) and dev ([next](https://github.com/an-anime-team/sleepy-launcher/tree/next)). Code changes will be pushed into dev branch and merged into stable once they're ready for new version release
<img src="repository/branches.png" />
If you have any questions - feel free to contact the dev in our discord server (or if you have no way to use discord - try sending me an email, but it's unlikely to be received).

44
flake.lock Normal file
View file

@ -0,0 +1,44 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1721226092,
"narHash": "sha256-UBvzVpo5sXSi2S/Av+t+Q+C2mhMIw/LBEZR+d6NMjws=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "c716603a63aca44f39bef1986c13402167450e0a",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-24.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-unstable": {
"locked": {
"lastModified": 1721138476,
"narHash": "sha256-+W5eZOhhemLQxelojLxETfbFbc19NWawsXBlapYpqIA=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "ad0b5eed1b6031efaed382844806550c3dcb4206",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"nixpkgs-unstable": "nixpkgs-unstable"
}
}
},
"root": "root",
"version": 7
}

36
flake.nix Normal file
View file

@ -0,0 +1,36 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs, nixpkgs-unstable }:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
pkgs-unstable = nixpkgs-unstable.legacyPackages.x86_64-linux;
in {
devShells.x86_64-linux.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
pkgs-unstable.rustup
pkgs-unstable.rustfmt
pkgs-unstable.clippy
gcc
cmake
pkg-config
libwebp
];
buildInputs = with pkgs; [
gtk4
glib
gdk-pixbuf
gobject-introspection
libadwaita
];
};
};
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

View file

@ -1,40 +0,0 @@
let
nixpkgs = builtins.fetchGit {
name = "nixos-24.05";
url = "https://github.com/nixos/nixpkgs";
ref = "refs/heads/nixos-24.05";
};
nixpkgs-unstable = builtins.fetchGit {
name = "nixos-unstable";
url = "https://github.com/nixos/nixpkgs";
ref = "refs/heads/nixos-unstable";
};
pkgs = import nixpkgs {};
pkgs-unstable = import nixpkgs-unstable {};
in pkgs.mkShell {
nativeBuildInputs = with pkgs; [
pkgs-unstable.rustup
pkgs-unstable.rustfmt
pkgs-unstable.clippy
gcc
cmake
pkg-config
xdelta
p7zip
libwebp
];
buildInputs = with pkgs; [
gtk4
glib
gdk-pixbuf
gobject-introspection
libadwaita
];
}

View file

@ -21,7 +21,7 @@ pub fn get_uri() -> String {
else {
let uri = concat!("https://sg-hyp-api.", "ho", "yo", "verse", ".com/hyp/hyp-connect/api/getAllGameBasicInfo?launcher_id=VYTpXlbWo8&language=");
uri.to_owned() + &crate::i18n::format_lang(&lang)
uri.to_owned() + &crate::i18n::format_lang(lang)
}
}
@ -73,12 +73,6 @@ pub fn download_background() -> anyhow::Result<()> {
tracing::debug!("Background picture is already downloaded. Skipping");
download_image = false;
if crate::BACKGROUND_PRIMARY_FILE.exists() {
tracing::debug!("Background picture is already patched. Skipping");
return Ok(());
}
}
}
@ -97,20 +91,20 @@ pub fn download_background() -> anyhow::Result<()> {
Command::new("dwebp")
.arg(crate::BACKGROUND_FILE.as_path())
.arg("-o")
.arg(crate::BACKGROUND_PRIMARY_FILE.as_path())
.arg(crate::PROCESSED_BACKGROUND_FILE.as_path())
.spawn()?
.wait()?;
// If it failed to re-code the file - just copy it
// Will happen with HSR because devs apparently named
// their background image ".webp" while it's JPEG
if !crate::BACKGROUND_PRIMARY_FILE.exists() {
std::fs::copy(crate::BACKGROUND_FILE.as_path(), crate::BACKGROUND_PRIMARY_FILE.as_path())?;
if !crate::PROCESSED_BACKGROUND_FILE.exists() {
std::fs::copy(crate::BACKGROUND_FILE.as_path(), crate::PROCESSED_BACKGROUND_FILE.as_path())?;
}
}
else {
std::fs::copy(crate::BACKGROUND_FILE.as_path(), crate::BACKGROUND_PRIMARY_FILE.as_path())?;
std::fs::copy(crate::BACKGROUND_FILE.as_path(), crate::PROCESSED_BACKGROUND_FILE.as_path())?;
}
Ok(())

View file

@ -1,3 +1,4 @@
use std::sync::OnceLock;
use unic_langid::{langid, LanguageIdentifier};
fluent_templates::static_loader! {
@ -32,14 +33,15 @@ pub const SUPPORTED_LANGUAGES: &[LanguageIdentifier] = &[
langid!("cs-cz")
];
pub static mut LANG: LanguageIdentifier = langid!("en-us");
/// Fallback used if the system language is not supported
static FALLBACK: LanguageIdentifier = langid!("en-us");
pub static LANG: OnceLock<LanguageIdentifier> = OnceLock::new();
/// Set launcher language
pub fn set_lang(lang: LanguageIdentifier) -> anyhow::Result<()> {
if SUPPORTED_LANGUAGES.iter().any(|item| item.language == lang.language) {
unsafe {
LANG = lang
}
LANG.set(lang).expect("Can't overwrite language!");
Ok(())
}
@ -50,8 +52,8 @@ pub fn set_lang(lang: LanguageIdentifier) -> anyhow::Result<()> {
}
/// Get launcher language
pub fn get_lang() -> LanguageIdentifier {
unsafe { LANG.clone() }
pub fn get_lang() -> &'static LanguageIdentifier {
LANG.get().expect("Language hasn't been initialized!")
}
/// Get system language or default language if system one is not supported
@ -60,7 +62,7 @@ pub fn get_lang() -> LanguageIdentifier {
/// - `LC_ALL`
/// - `LC_MESSAGES`
/// - `LANG`
pub fn get_default_lang() -> LanguageIdentifier {
pub fn get_default_lang() -> &'static LanguageIdentifier {
let current = std::env::var("LC_ALL")
.unwrap_or_else(|_| std::env::var("LC_MESSAGES")
.unwrap_or_else(|_| std::env::var("LANG")
@ -69,11 +71,11 @@ pub fn get_default_lang() -> LanguageIdentifier {
for lang in SUPPORTED_LANGUAGES {
if current.starts_with(lang.language.as_str()) {
return lang.clone();
return lang;
}
}
get_lang()
&FALLBACK
}
pub fn format_lang(lang: &LanguageIdentifier) -> String {
@ -106,8 +108,7 @@ macro_rules! tr {
{
use fluent_templates::Loader;
#[allow(unused_unsafe)]
$crate::i18n::LOCALES.lookup(unsafe { $crate::i18n::LANG.as_ref() }, $id)
$crate::i18n::LOCALES.lookup($crate::i18n::get_lang(), $id)
}
};
@ -124,8 +125,7 @@ macro_rules! tr {
args.insert($key, FluentValue::from($value));
)*
#[allow(unused_unsafe)]
$crate::i18n::LOCALES.lookup_complete(unsafe { $crate::i18n::LANG.as_ref() }, $id, Some(&args))
$crate::i18n::LOCALES.lookup_complete($crate::i18n::get_lang(), $id, Some(&args))
}
};
}

View file

@ -61,8 +61,8 @@ lazy_static::lazy_static! {
/// Path to `background` file. Standard is `$HOME/.local/share/anime-game-launcher/background`
pub static ref BACKGROUND_FILE: PathBuf = LAUNCHER_FOLDER.join("background");
/// Path to `background-primary` file. Standard is `$HOME/.local/share/anime-game-launcher/background-primary`
pub static ref BACKGROUND_PRIMARY_FILE: PathBuf = LAUNCHER_FOLDER.join("background-primary");
/// Path to the processed `background` file. Standard is `$HOME/.cache/anime-game-launcher/background`
pub static ref PROCESSED_BACKGROUND_FILE: PathBuf = CACHE_FOLDER.join("background");
/// Path to `.keep-background` file. Used to mark launcher that it shouldn't update background picture
///
@ -102,7 +102,7 @@ lazy_static::lazy_static! {
.round-bin {{
border-radius: 24px;
}}
", BACKGROUND_PRIMARY_FILE.to_string_lossy());
", PROCESSED_BACKGROUND_FILE.to_string_lossy());
}
fn main() -> anyhow::Result<()> {
@ -120,7 +120,7 @@ fn main() -> anyhow::Result<()> {
// CONFIG is initialized lazily so it will contain following changes as well
let mut config = Config::get().expect("Failed to get config");
config.launcher.language = i18n::format_lang(&i18n::get_default_lang());
config.launcher.language = i18n::format_lang(i18n::get_default_lang());
Config::update_raw(config).expect("Failed to update config");
}
@ -201,6 +201,9 @@ fn main() -> anyhow::Result<()> {
gtk::IconTheme::for_display(&gtk::gdk::Display::default().unwrap())
.add_resource_path(&format!("{APP_RESOURCE_PATH}/icons"));
// Set global css
relm4::set_global_css(&GLOBAL_CSS);
// Set application's title
gtk::glib::set_application_name("Sleepy Launcher");
gtk::glib::set_program_name(Some("Sleepy Launcher"));
@ -218,9 +221,6 @@ fn main() -> anyhow::Result<()> {
let app = RelmApp::new(APP_ID)
.with_args(gtk_args);
// Set global css
app.set_global_css(&GLOBAL_CSS);
// Show first run window
app.run::<FirstRunApp>(());
}
@ -252,9 +252,6 @@ fn main() -> anyhow::Result<()> {
let app = RelmApp::new(APP_ID)
.with_args(gtk_args);
// Set global css
app.set_global_css(&GLOBAL_CSS);
// Show main window
app.run::<App>(());
}

View file

@ -39,7 +39,7 @@ impl SimpleComponent for AboutDialog {
set_website: "https://github.com/an-anime-team/sleepy-launcher",
set_issue_url: "https://github.com/an-anime-team/sleepy-launcher/issues",
set_license_type: gtk::License::Gpl30,
set_license_type: gtk::License::Gpl30Only,
set_version: &APP_VERSION,
set_developers: &[
@ -91,17 +91,23 @@ impl SimpleComponent for AboutDialog {
set_release_notes_version: &APP_VERSION,
set_release_notes: &[
"<p>Fixed</p>",
"<p>Added</p>",
"<ul>",
"<li>Fixed infinite updates loop on minor game patches (notably 1.0.1)</li>",
"<li>Fixed prefix paths for proton builds for game drives mapping</li>",
"<li>Respect root \".version\" file for game version parsing</li>",
"<li>Added disabling of 2 new telemetry servers</li>",
"</ul>",
"<p>Changed</p>",
"<ul>",
"<li>Removed xdelta3 runtime dependency, updated dwebp package name for fedora</li>",
"<li>Prioritize parsed game version over the API response</li>",
"</ul>",
"<p>Removed</p>",
"<ul>",
"<li>Removed migrate installation feature</li>",
"</ul>"
].join("\n"),

View file

@ -162,7 +162,11 @@ impl SimpleAsyncComponent for ComponentVersion {
let progress_bar_sender = self.progress_bar.sender().clone();
#[allow(unused_must_use)]
std::thread::spawn(clone!(@strong self.download_folder as download_folder => move || {
std::thread::spawn(clone!(
#[strong(rename_to = download_folder)]
self.download_folder,
move || {
progress_bar_sender.send(ProgressBarMsg::Reset);
progress_bar_sender.send(ProgressBarMsg::SetVisible(true));
@ -188,7 +192,8 @@ impl SimpleAsyncComponent for ComponentVersion {
progress_bar_sender.send(ProgressBarMsg::UpdateFromState(DiffUpdate::InstallerUpdate(state)));
});
}));
}
));
}
}

View file

@ -12,7 +12,6 @@ pub struct DefaultPathsApp {
progress_bar: AsyncController<ProgressBar>,
show_additional: bool,
migrate_installation: bool,
show_progress: bool,
launcher: PathBuf,
@ -47,8 +46,7 @@ pub enum DefaultPathsAppMsg {
#[relm4::component(async, pub)]
impl SimpleAsyncComponent for DefaultPathsApp {
/// If `true`, then use migrate installation mode
type Init = bool;
type Init = ();
type Input = DefaultPathsAppMsg;
type Output = FirstRunAppMsg;
@ -226,11 +224,7 @@ impl SimpleAsyncComponent for DefaultPathsApp {
set_spacing: 8,
gtk::Button {
set_label: &if model.migrate_installation {
tr!("migrate")
} else {
tr!("continue")
},
set_label: &tr!("continue"),
set_css_classes: &["suggested-action", "pill"],
@ -238,17 +232,10 @@ impl SimpleAsyncComponent for DefaultPathsApp {
},
gtk::Button {
set_label: &if model.migrate_installation {
tr!("close", { "form" = "noun" })
} else {
tr!("exit")
},
set_label: &tr!("exit"),
add_css_class: "pill",
#[watch]
set_visible: !model.migrate_installation,
connect_clicked => DefaultPathsAppMsg::Exit
}
}
@ -271,7 +258,7 @@ impl SimpleAsyncComponent for DefaultPathsApp {
}
}
async fn init(init: Self::Init, root: Self::Root, _sender: AsyncComponentSender<Self>) -> AsyncComponentParts<Self> {
async fn init(_init: Self::Init, root: Self::Root, _sender: AsyncComponentSender<Self>) -> AsyncComponentParts<Self> {
let model = Self {
progress_bar: ProgressBar::builder()
.launch(ProgressBarInit {
@ -283,7 +270,6 @@ impl SimpleAsyncComponent for DefaultPathsApp {
.detach(),
show_additional: false,
migrate_installation: init,
show_progress: false,
launcher: LAUNCHER_FOLDER.to_path_buf(),
@ -294,12 +280,13 @@ impl SimpleAsyncComponent for DefaultPathsApp {
game_china: CONFIG.game.path.china.clone(),
components: CONFIG.components.path.clone(),
#[allow(clippy::or_fun_call)]
temp: CONFIG.launcher.temp.clone().unwrap_or(std::env::temp_dir())
temp: CONFIG.launcher.temp.clone()
.unwrap_or_else(std::env::temp_dir)
};
// Set progress bar width
model.progress_bar.widget().set_width_request(400);
model.progress_bar.widget()
.set_width_request(400);
let widgets = view_output!();
@ -345,48 +332,10 @@ impl SimpleAsyncComponent for DefaultPathsApp {
#[allow(unused_must_use)]
DefaultPathsAppMsg::Continue => {
let old_config = Config::get().unwrap_or_else(|_| CONFIG.clone());
match self.update_config() {
Ok(_) => {
if self.migrate_installation {
self.progress_bar.sender().send(ProgressBarMsg::SetVisible(true));
self.show_progress = true;
let folders = [
(old_config.game.wine.builds, &self.runners),
(old_config.game.dxvk.builds, &self.dxvks),
(old_config.game.wine.prefix, &self.prefix),
(old_config.game.path.global, &self.game_global),
(old_config.game.path.china, &self.game_china),
(old_config.components.path, &self.components)
];
#[allow(clippy::expect_fun_call)]
for (i, (from, to)) in folders.iter().enumerate() {
self.progress_bar.sender().send(ProgressBarMsg::UpdateCaption(Some(
from.to_str().map(|str| str.to_string()).unwrap_or_else(|| format!("{:?}", from))
)));
if &from != to && from.exists() {
move_files::move_files(from, to).expect(&format!("Failed to move folder: {:?} -> {:?}", from, to));
}
self.progress_bar.sender().send(ProgressBarMsg::UpdateProgress(i as u64 + 1, folders.len() as u64));
}
// Restart the app
std::process::Command::new(std::env::current_exe().unwrap()).spawn().unwrap();
relm4::main_application().quit();
}
else {
sender.output(Self::Output::ScrollToDownloadComponents);
}
}
Err(err) => {
sender.output(Self::Output::Toast {
@ -398,18 +347,11 @@ impl SimpleAsyncComponent for DefaultPathsApp {
}
DefaultPathsAppMsg::Exit => {
if self.migrate_installation {
// TODO: this shit should return message to general preferences component somehow to close MigrateInstallation window
todo!();
}
else {
relm4::main_application().quit();
}
}
}
}
}
impl DefaultPathsApp {
pub fn update_config(&self) -> anyhow::Result<()> {

View file

@ -127,7 +127,7 @@ impl SimpleComponent for FirstRunApp {
.forward(sender.input_sender(), std::convert::identity),
default_paths: DefaultPathsApp::builder()
.launch(false)
.launch(())
.forward(sender.input_sender(), std::convert::identity),
download_components: DownloadComponentsApp::builder()

View file

@ -21,7 +21,11 @@ pub fn download_diff(sender: ComponentSender<App>, progress_bar_input: Sender<Pr
diff = diff.with_temp_folder(temp);
}
let result = diff.install_to(game_path, clone!(@strong sender => move |state| {
let result = diff.install_to(game_path, clone!(
#[strong]
sender,
move |state| {
match &state {
DiffUpdate::InstallerUpdate(InstallerUpdate::DownloadingError(err)) => {
tracing::error!("Downloading failed: {err}");
@ -47,7 +51,8 @@ pub fn download_diff(sender: ComponentSender<App>, progress_bar_input: Sender<Pr
#[allow(unused_must_use)] {
progress_bar_input.send(ProgressBarMsg::UpdateFromState(state));
}
}));
}
));
let mut perform_on_download_needed = true;

View file

@ -52,8 +52,16 @@ pub fn download_wine(sender: ComponentSender<App>, progress_bar_input: Sender<Pr
sender.input(AppMsg::SetDownloading(true));
std::thread::spawn(clone!(@strong sender => move || {
installer.install(&config.game.wine.builds, clone!(@strong sender => move |state| {
std::thread::spawn(clone!(
#[strong]
sender,
move || {
installer.install(&config.game.wine.builds, clone!(
#[strong]
sender,
move |state| {
match &state {
InstallerUpdate::DownloadingError(err) => {
tracing::error!("Downloading failed: {err}");
@ -79,7 +87,8 @@ pub fn download_wine(sender: ComponentSender<App>, progress_bar_input: Sender<Pr
#[allow(unused_must_use)] {
progress_bar_input.send(ProgressBarMsg::UpdateFromState(DiffUpdate::InstallerUpdate(state)));
}
}));
}
));
config.game.wine.selected = Some(wine.name.clone());
@ -90,7 +99,8 @@ pub fn download_wine(sender: ComponentSender<App>, progress_bar_input: Sender<Pr
perform_on_download_needed: false,
show_status_page: true
});
}));
}
));
}
Err(err) => sender.input(AppMsg::Toast {

View file

@ -483,11 +483,16 @@ impl SimpleComponent for App {
connect_clicked[sender] => move |_| {
sender.input(AppMsg::DisableKillGameButton(true));
std::thread::spawn(clone!(@strong sender => move || {
std::thread::spawn(clone!(
#[strong]
sender,
move || {
std::thread::sleep(std::time::Duration::from_secs(3));
sender.input(AppMsg::DisableKillGameButton(false));
}));
}
));
let result = std::process::Command::new("pkill")
.arg("-f") // full text search
@ -643,7 +648,11 @@ impl SimpleComponent for App {
// TODO: reduce code somehow
group.add_action::<LauncherFolder>(RelmAction::new_stateless(clone!(@strong sender => move |_| {
group.add_action::<LauncherFolder>(RelmAction::new_stateless(clone!(
#[strong]
sender,
move |_| {
if let Err(err) = open::that(LAUNCHER_FOLDER.as_path()) {
sender.input(AppMsg::Toast {
title: tr!("launcher-folder-opening-error"),
@ -652,9 +661,14 @@ impl SimpleComponent for App {
tracing::error!("Failed to open launcher folder: {err}");
}
})));
}
)));
group.add_action::<GameFolder>(RelmAction::new_stateless(clone!(@strong sender => move |_| {
group.add_action::<GameFolder>(RelmAction::new_stateless(clone!(
#[strong]
sender,
move |_| {
let path = match Config::get() {
Ok(config) => config.game.path.for_edition(config.launcher.edition).to_path_buf(),
Err(_) => CONFIG.game.path.for_edition(CONFIG.launcher.edition).to_path_buf(),
@ -668,9 +682,14 @@ impl SimpleComponent for App {
tracing::error!("Failed to open game folder: {err}");
}
})));
}
)));
group.add_action::<ConfigFile>(RelmAction::new_stateless(clone!(@strong sender => move |_| {
group.add_action::<ConfigFile>(RelmAction::new_stateless(clone!(
#[strong]
sender,
move |_| {
if let Ok(file) = config_file() {
if let Err(err) = open::that(file) {
sender.input(AppMsg::Toast {
@ -681,9 +700,14 @@ impl SimpleComponent for App {
tracing::error!("Failed to open config file: {err}");
}
}
})));
}
)));
group.add_action::<DebugFile>(RelmAction::new_stateless(clone!(@strong sender => move |_| {
group.add_action::<DebugFile>(RelmAction::new_stateless(clone!(
#[strong]
sender,
move |_| {
if let Err(err) = open::that(crate::DEBUG_FILE.as_os_str()) {
sender.input(AppMsg::Toast {
title: tr!("debug-file-opening-error"),
@ -692,7 +716,8 @@ impl SimpleComponent for App {
tracing::error!("Failed to open debug file: {err}");
}
})));
}
)));
group.add_action::<About>(RelmAction::new_stateless(move |_| {
about_dialog_broker.send(AboutDialogMsg::Show);
@ -713,7 +738,11 @@ impl SimpleComponent for App {
// Download background picture if needed
if download_picture {
tasks.push(std::thread::spawn(clone!(@strong sender => move || {
tasks.push(std::thread::spawn(clone!(
#[strong]
sender,
move || {
if let Err(err) = crate::background::download_background() {
tracing::error!("Failed to download background picture: {err}");
@ -722,12 +751,17 @@ impl SimpleComponent for App {
description: Some(err.to_string())
});
}
})));
}
)));
}
// Update components index
tasks.push(std::thread::spawn(clone!(@strong sender => move || {
tasks.push(std::thread::spawn(clone!(
#[strong]
sender,
move || {
let components = ComponentsLoader::new(&CONFIG.components.path);
match components.is_sync(&CONFIG.components.servers) {
@ -773,11 +807,16 @@ impl SimpleComponent for App {
});
}
}
})));
}
)));
// Update initial game version status
tasks.push(std::thread::spawn(clone!(@strong sender => move || {
tasks.push(std::thread::spawn(clone!(
#[strong]
sender,
move || {
sender.input(AppMsg::SetGameDiff(match GAME.try_get_diff() {
Ok(diff) => Some(diff),
Err(err) => {
@ -793,7 +832,8 @@ impl SimpleComponent for App {
}));
tracing::info!("Updated game version status");
})));
}
)));
// Await for tasks to finish execution
for task in tasks {
@ -827,7 +867,11 @@ impl SimpleComponent for App {
self.disabled_buttons = true;
}
let updater = clone!(@strong sender => move |state| {
let updater = clone!(
#[strong]
sender,
move |state| {
if show_status_page {
match state {
StateUpdating::Game => {
@ -835,7 +879,8 @@ impl SimpleComponent for App {
}
}
}
});
}
);
let state = match LauncherState::get_from_config(updater) {
Ok(state) => Some(state),
@ -921,9 +966,14 @@ impl SimpleComponent for App {
progress_bar_input.send(ProgressBarMsg::UpdateCaption(Some(tr!("downloading"))));
std::thread::spawn(move || {
let result = game.download_to(&tmp, clone!(@strong progress_bar_input => move |curr, total| {
let result = game.download_to(&tmp, clone!(
#[strong]
progress_bar_input,
move |curr, total| {
progress_bar_input.send(ProgressBarMsg::UpdateProgress(curr, total));
}));
}
));
if let Err(err) = result {
sender.input(AppMsg::Toast {

View file

@ -52,7 +52,11 @@ pub fn repair_game(sender: ComponentSender<App>, progress_bar_input: Sender<Prog
let thread_sender = verify_sender.clone();
std::thread::spawn(clone!(@strong game_path => move || {
std::thread::spawn(clone!(
#[strong]
game_path,
move || {
for file in thread_files {
let status = if config.launcher.repairer.fast {
file.fast_verify(&game_path)
@ -62,7 +66,8 @@ pub fn repair_game(sender: ComponentSender<App>, progress_bar_input: Sender<Prog
thread_sender.send((file, status)).unwrap();
}
}));
}
));
}
// We have [config.launcher.repairer.threads] copies of this sender + the original one

View file

@ -1,52 +0,0 @@
use relm4::prelude::*;
use gtk::prelude::*;
use crate::tr;
use super::first_run::default_paths::DefaultPathsApp;
pub struct MigrateInstallationApp {
default_paths: AsyncController<DefaultPathsApp>,
}
#[relm4::component(pub)]
impl SimpleComponent for MigrateInstallationApp {
type Init = ();
type Input = ();
type Output = ();
view! {
adw::Window {
set_default_size: (780, 560),
set_modal: true,
set_hide_on_close: true,
#[watch]
set_title: Some(&tr!("migrate-installation")),
gtk::Box {
set_orientation: gtk::Orientation::Vertical,
adw::HeaderBar {
add_css_class: "flat"
},
append = model.default_paths.widget(),
}
}
}
fn init(_init: Self::Init, root: Self::Root, _sender: ComponentSender<Self>) -> ComponentParts<Self> {
tracing::info!("Initializing migration window");
let model = Self {
default_paths: DefaultPathsApp::builder()
.launch(true)
.detach()
};
let widgets = view_output!();
ComponentParts { model, widgets }
}
}

View file

@ -3,4 +3,3 @@ pub mod about;
pub mod preferences;
pub mod components;
pub mod first_run;
pub mod migrate_installation;

View file

@ -212,7 +212,8 @@ impl SimpleAsyncComponent for EnhancementsApp {
"Español",
"中国",
"日本語",
"한국어"
"한국어",
"Indonesia"
]),
set_selected: CONFIG.game.wine.language.ordinal() as u32,

View file

@ -16,14 +16,12 @@ pub mod components;
use components::*;
use crate::ui::migrate_installation::MigrateInstallationApp;
use crate::i18n::*;
use crate::*;
use super::main::PreferencesAppMsg;
pub struct GeneralApp {
migrate_installation: Controller<MigrateInstallationApp>,
components_page: AsyncController<ComponentsPage>,
game_diff: Option<VersionDiff>,
@ -40,7 +38,6 @@ pub enum GeneralAppMsg {
UpdateDownloadedWine,
UpdateDownloadedDxvk,
OpenMigrateInstallation,
RepairGame,
OpenMainPage,
@ -248,13 +245,6 @@ impl SimpleAsyncComponent for GeneralApp {
set_spacing: 8,
set_margin_top: 16,
gtk::Button {
set_label: &tr!("migrate-installation"),
set_tooltip_text: Some(&tr!("migrate-installation-description")),
connect_clicked => GeneralAppMsg::OpenMigrateInstallation
},
gtk::Button {
set_label: &tr!("repair-game"),
@ -446,10 +436,6 @@ impl SimpleAsyncComponent for GeneralApp {
tracing::info!("Initializing general settings");
let model = Self {
migrate_installation: MigrateInstallationApp::builder()
.launch(())
.detach(),
components_page: ComponentsPage::builder()
.launch(())
.forward(sender.input_sender(), std::convert::identity),
@ -486,14 +472,6 @@ impl SimpleAsyncComponent for GeneralApp {
.unwrap();
}
GeneralAppMsg::OpenMigrateInstallation => unsafe {
if let Some(window) = crate::ui::main::PREFERENCES_WINDOW.as_ref() {
self.migrate_installation.widget().set_transient_for(Some(window.widget()));
}
self.migrate_installation.widget().present();
}
GeneralAppMsg::RepairGame => {
sender.output(Self::Output::RepairGame).unwrap();
}