Several changes

- made preparations for environment settings
- now launcher hides when you launch the game
- now `Config::try_get_wine_executable` can return `Some("wine")`
- removed old wine and dxvk versions;
  added new Wine-GE-Proton and GE-Proton builds
This commit is contained in:
Observer KRypt0n_ 2022-08-01 14:13:26 +02:00
parent c378f8e379
commit 21ee39ad17
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
14 changed files with 324 additions and 332 deletions

View file

@ -34,19 +34,19 @@
"name": "dxvk-1.9.2",
"version": "1.9.2",
"uri": "https://github.com/doitsujin/dxvk/releases/download/v1.9.2/dxvk-1.9.2.tar.gz",
"recommended": true
"recommended": false
},
{
"name": "dxvk-1.9.1",
"version": "1.9.1",
"uri": "https://github.com/doitsujin/dxvk/releases/download/v1.9.1/dxvk-1.9.1.tar.gz",
"recommended": true
"recommended": false
},
{
"name": "dxvk-1.9",
"version": "1.9",
"uri": "https://github.com/doitsujin/dxvk/releases/download/v1.9/dxvk-1.9.tar.gz",
"recommended": true
"recommended": false
},
{
"name": "dxvk-1.8.1",
@ -71,30 +71,6 @@
"version": "1.7.2",
"uri": "https://github.com/doitsujin/dxvk/releases/download/v1.7.2/dxvk-1.7.2.tar.gz",
"recommended": false
},
{
"name": "dxvk-1.7.1",
"version": "1.7.1",
"uri": "https://github.com/doitsujin/dxvk/releases/download/v1.7.1/dxvk-1.7.1.tar.gz",
"recommended": false
},
{
"name": "dxvk-1.7",
"version": "1.7",
"uri": "https://github.com/doitsujin/dxvk/releases/download/v1.7/dxvk-1.7.tar.gz",
"recommended": false
},
{
"name": "dxvk-1.6.1",
"version": "1.6.1",
"uri": "https://github.com/doitsujin/dxvk/releases/download/v1.6.1/dxvk-1.6.1.tar.gz",
"recommended": false
},
{
"name": "dxvk-1.6",
"version": "1.6",
"uri": "https://github.com/doitsujin/dxvk/releases/download/v1.6/dxvk-1.6.tar.gz",
"recommended": false
}
],
"async": [
@ -132,19 +108,19 @@
"name": "dxvk-async-1.9.2",
"version": "1.9.2",
"uri": "https://github.com/Sporif/dxvk-async/releases/download/1.9.4/dxvk-async-1.9.4.tar.gz",
"recommended": true
"recommended": false
},
{
"name": "dxvk-async-1.9.1",
"version": "1.9.1",
"uri": "https://github.com/Sporif/dxvk-async/releases/download/1.9.1/dxvk-async-1.9.1.tar.gz",
"recommended": true
"recommended": false
},
{
"name": "dxvk-async-1.9",
"version": "1.9",
"uri": "https://github.com/Sporif/dxvk-async/releases/download/1.9/dxvk-async-1.9.tar.gz",
"recommended": true
"recommended": false
},
{
"name": "dxvk-async-1.8.1",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

View file

@ -3,7 +3,4 @@
<gresource prefix="/org/app/assets/images">
<file alias="icon.png">images/icon.png</file>
</gresource>
<gresource prefix="/org/app/assets/icons">
<file alias="64x64">icons/64x64.ico</file>
</gresource>
</gresources>

View file

@ -5,8 +5,6 @@ Adw.ApplicationWindow window {
default-width: 900;
default-height: 600;
icon-name: "resource:///org/app/assets/icons/64x64";
content: Adw.ToastOverlay toast_overlay {
Adw.Leaflet leaflet {
can-navigate-back: true;
@ -34,7 +32,7 @@ Adw.ApplicationWindow window {
Adw.StatusPage status_page {
icon-name: "image-loading-symbolic";
title: "Loading data";
vexpand: true;
}
@ -92,7 +90,6 @@ Adw.ApplicationWindow window {
spacing: 20;
Gtk.ProgressBar progress_bar {
text: "Downloading: 37% (3.7 of 10 GB)";
show-text: true;
width-request: 360;

View file

@ -1,9 +1,7 @@
using Gtk 4.0;
using Adw 1;
Adw.PreferencesPage enhanced_page {
title: "Enhancements";
Adw.PreferencesPage page {
Adw.PreferencesGroup {
title: "Wine";

View file

@ -0,0 +1,81 @@
using Gtk 4.0;
using Adw 1;
Adw.PreferencesPage page {
Adw.PreferencesGroup {
title: "New variable";
Gtk.Box {
orientation: horizontal;
spacing: 8;
Gtk.Entry {
placeholder-text: "Name";
}
Gtk.Entry {
placeholder-text: "Value";
hexpand: true;
}
}
Gtk.Button {
label: "Add";
margin-top: 8;
halign: start;
}
}
Adw.PreferencesGroup {
title: "Variables";
Adw.ActionRow {
title: "DXVK_HUD";
subtitle: "1";
Gtk.Button {
icon-name: "user-trash-symbolic";
valign: center;
styles ["flat"]
}
}
Adw.ActionRow {
title: "DXVK_HUD";
subtitle: "1";
Gtk.Button {
icon-name: "user-trash-symbolic";
valign: center;
styles ["flat"]
}
}
Adw.ActionRow {
title: "DXVK_HUD";
subtitle: "1";
Gtk.Button {
icon-name: "user-trash-symbolic";
valign: center;
styles ["flat"]
}
}
Adw.ActionRow {
title: "DXVK_HUD";
subtitle: "1";
Gtk.Button {
icon-name: "user-trash-symbolic";
valign: center;
styles ["flat"]
}
}
}
}

View file

@ -1,7 +1,7 @@
using Gtk 4.0;
using Adw 1;
Adw.PreferencesPage general_page {
Adw.PreferencesPage page {
Adw.PreferencesGroup {
title: "General";

View file

@ -3,6 +3,32 @@
"title": "Wine-GE-Proton",
"subtitle": null,
"versions": [
{
"family": "Wine-GE-Proton",
"name": "lutris-GE-Proton7-24-x86_64",
"title": "Wine-GE-Proton 7-24",
"uri": "https://github.com/GloriousEggroll/wine-ge-custom/releases/download/GE-Proton7-24/wine-lutris-GE-Proton7-24-x86_64.tar.xz",
"files": {
"wine": "bin/wine64",
"wineserver": "bin/wineserver",
"wineboot": "bin/wineboot",
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": true
},
{
"family": "Wine-GE-Proton",
"name": "lutris-GE-Proton7-23-x86_64",
"title": "Wine-GE-Proton 7-23",
"uri": "https://github.com/GloriousEggroll/wine-ge-custom/releases/download/GE-Proton7-23/wine-lutris-GE-Proton7-23-x86_64.tar.xz",
"files": {
"wine": "bin/wine64",
"wineserver": "bin/wineserver",
"wineboot": "bin/wineboot",
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": true
},
{
"family": "Wine-GE-Proton",
"name": "lutris-GE-Proton7-22-x86_64",
@ -66,7 +92,7 @@
"wineboot": "bin/wineboot",
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": true
"recommended": false
},
{
"family": "Wine-GE-Proton",
@ -79,7 +105,7 @@
"wineboot": "bin/wineboot",
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": true
"recommended": false
},
{
"family": "Wine-GE-Proton",
@ -119,123 +145,6 @@
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "Wine-GE-Proton",
"name": "lutris-GE-Proton7-9-x86_64",
"title": "Wine-GE-Proton 7-9",
"uri": "https://github.com/GloriousEggroll/wine-ge-custom/releases/download/GE-Proton7-9/wine-lutris-GE-Proton7-9-x86_64.tar.xz",
"files": {
"wine": "bin/wine64",
"wineserver": "bin/wineserver",
"wineboot": "bin/wineboot",
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "Wine-GE-Proton",
"name": "lutris-GE-Proton7-8-x86_64",
"title": "Wine-GE-Proton 7-8",
"uri": "https://github.com/GloriousEggroll/wine-ge-custom/releases/download/GE-Proton7-8/wine-lutris-GE-Proton7-8-x86_64.tar.xz",
"files": {
"wine": "bin/wine64",
"wineserver": "bin/wineserver",
"wineboot": "bin/wineboot",
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "Wine-GE-Proton",
"name": "lutris-GE-Proton7-7-x86_64",
"title": "Wine-GE-Proton 7-7",
"uri": "https://github.com/GloriousEggroll/wine-ge-custom/releases/download/GE-Proton7-7/wine-lutris-GE-Proton7-7-x86_64.tar.xz",
"files": {
"wine": "bin/wine64",
"wineserver": "bin/wineserver",
"wineboot": "bin/wineboot",
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "Wine-GE-Proton",
"name": "lutris-GE-Proton7-6-x86_64",
"title": "Wine-GE-Proton 7-6",
"uri": "https://github.com/GloriousEggroll/wine-ge-custom/releases/download/GE-Proton7-6/wine-lutris-GE-Proton7-6-x86_64.tar.xz",
"files": {
"wine": "bin/wine64",
"wineserver": "bin/wineserver",
"wineboot": "bin/wineboot",
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "Wine-GE-Proton",
"name": "lutris-GE-Proton7-5-x86_64",
"title": "Wine-GE-Proton 7-5",
"uri": "https://github.com/GloriousEggroll/wine-ge-custom/releases/download/GE-Proton7-5/wine-lutris-GE-Proton7-5-x86_64.tar.xz",
"files": {
"wine": "bin/wine64",
"wineserver": "bin/wineserver",
"wineboot": "bin/wineboot",
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "Wine-GE-Proton",
"name": "lutris-GE-Proton7-4-x86_64",
"title": "Wine-GE-Proton 7-4",
"uri": "https://github.com/GloriousEggroll/wine-ge-custom/releases/download/GE-Proton7-4/wine-lutris-GE-Proton7-4-x86_64.tar.xz",
"files": {
"wine": "bin/wine64",
"wineserver": "bin/wineserver",
"wineboot": "bin/wineboot",
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "Wine-GE-Proton",
"name": "lutris-GE-Proton7-3-x86_64",
"title": "Wine-GE-Proton 7-3",
"uri": "https://github.com/GloriousEggroll/wine-ge-custom/releases/download/GE-Proton7-3/wine-lutris-GE-Proton7-3-x86_64.tar.xz",
"files": {
"wine": "bin/wine64",
"wineserver": "bin/wineserver",
"wineboot": "bin/wineboot",
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "Wine-GE-Proton",
"name": "lutris-GE-Proton7-2-x86_64",
"title": "Wine-GE-Proton 7-2",
"uri": "https://github.com/GloriousEggroll/wine-ge-custom/releases/download/GE-Proton7-2/wine-lutris-GE-Proton7-2-x86_64.tar.xz",
"files": {
"wine": "bin/wine64",
"wineserver": "bin/wineserver",
"wineboot": "bin/wineboot",
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "Wine-GE-Proton",
"name": "lutris-GE-Proton7-1-x86_64",
"title": "Wine-GE-Proton 7-1",
"uri": "https://github.com/GloriousEggroll/wine-ge-custom/releases/download/GE-Proton7-1/wine-lutris-GE-Proton7-1-x86_64.tar.xz",
"files": {
"wine": "bin/wine64",
"wineserver": "bin/wineserver",
"wineboot": "bin/wineboot",
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
}
]
},
@ -243,6 +152,32 @@
"title": "GE-Proton",
"subtitle": "This version includes its own DXVK builds and you can use DXVK_ASYNC variable",
"versions": [
{
"family": "GE-Proton",
"name": "GE-Proton7-28",
"title": "GE-Proton 7-28",
"uri": "https://github.com/GloriousEggroll/proton-ge-custom/releases/download/GE-Proton7-28/GE-Proton7-28.tar.gz",
"files": {
"wine": "files/bin/wine64",
"wineserver": "files/bin/wineserver",
"wineboot": "files/bin/wineboot",
"winecfg": "files/lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": true
},
{
"family": "GE-Proton",
"name": "GE-Proton7-27",
"title": "GE-Proton 7-27",
"uri": "https://github.com/GloriousEggroll/proton-ge-custom/releases/download/GE-Proton7-27/GE-Proton7-27.tar.gz",
"files": {
"wine": "files/bin/wine64",
"wineserver": "files/bin/wineserver",
"wineboot": "files/bin/wineboot",
"winecfg": "files/lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": true
},
{
"family": "GE-Proton",
"name": "GE-Proton7-26",
@ -332,7 +267,7 @@
"wineboot": "files/bin/wineboot",
"winecfg": "files/lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": true
"recommended": false
},
{
"family": "GE-Proton",
@ -345,7 +280,7 @@
"wineboot": "files/bin/wineboot",
"winecfg": "files/lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": true
"recommended": false
},
{
"family": "GE-Proton",
@ -372,123 +307,6 @@
"winecfg": "files/lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "GE-Proton",
"name": "GE-Proton7-9",
"title": "GE-Proton 7-9",
"uri": "https://github.com/GloriousEggroll/proton-ge-custom/releases/download/GE-Proton7-9/GE-Proton7-9.tar.gz",
"files": {
"wine": "files/bin/wine64",
"wineserver": "files/bin/wineserver",
"wineboot": "files/bin/wineboot",
"winecfg": "files/lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "GE-Proton",
"name": "GE-Proton7-8",
"title": "GE-Proton 7-8",
"uri": "https://github.com/GloriousEggroll/proton-ge-custom/releases/download/GE-Proton7-8/GE-Proton7-8.tar.gz",
"files": {
"wine": "files/bin/wine64",
"wineserver": "files/bin/wineserver",
"wineboot": "files/bin/wineboot",
"winecfg": "files/lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "GE-Proton",
"name": "GE-Proton7-7",
"title": "GE-Proton 7-7",
"uri": "https://github.com/GloriousEggroll/proton-ge-custom/releases/download/GE-Proton7-7/GE-Proton7-7.tar.gz",
"files": {
"wine": "files/bin/wine64",
"wineserver": "files/bin/wineserver",
"wineboot": "files/bin/wineboot",
"winecfg": "files/lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "GE-Proton",
"name": "GE-Proton7-6",
"title": "GE-Proton 7-6",
"uri": "https://github.com/GloriousEggroll/proton-ge-custom/releases/download/GE-Proton7-6/GE-Proton7-6.tar.gz",
"files": {
"wine": "files/bin/wine64",
"wineserver": "files/bin/wineserver",
"wineboot": "files/bin/wineboot",
"winecfg": "files/lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "GE-Proton",
"name": "GE-Proton7-5",
"title": "GE-Proton 7-5",
"uri": "https://github.com/GloriousEggroll/proton-ge-custom/releases/download/GE-Proton7-5/GE-Proton7-5.tar.gz",
"files": {
"wine": "files/bin/wine64",
"wineserver": "files/bin/wineserver",
"wineboot": "files/bin/wineboot",
"winecfg": "files/lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "GE-Proton",
"name": "GE-Proton7-4",
"title": "GE-Proton 7-4",
"uri": "https://github.com/GloriousEggroll/proton-ge-custom/releases/download/GE-Proton7-4/GE-Proton7-4.tar.gz",
"files": {
"wine": "files/bin/wine64",
"wineserver": "files/bin/wineserver",
"wineboot": "files/bin/wineboot",
"winecfg": "files/lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "GE-Proton",
"name": "GE-Proton7-3",
"title": "GE-Proton 7-3",
"uri": "https://github.com/GloriousEggroll/proton-ge-custom/releases/download/GE-Proton7-3/GE-Proton7-3.tar.gz",
"files": {
"wine": "files/bin/wine64",
"wineserver": "files/bin/wineserver",
"wineboot": "files/bin/wineboot",
"winecfg": "files/lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "GE-Proton",
"name": "GE-Proton7-2",
"title": "GE-Proton 7-2",
"uri": "https://github.com/GloriousEggroll/proton-ge-custom/releases/download/GE-Proton7-2/GE-Proton7-2.tar.gz",
"files": {
"wine": "dist/bin/wine64",
"wineserver": "dist/bin/wineserver",
"wineboot": "files/bin/wineboot",
"winecfg": "dist/lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "GE-Proton",
"name": "GE-Proton7-1",
"title": "GE-Proton 7-1",
"uri": "https://github.com/GloriousEggroll/proton-ge-custom/releases/download/GE-Proton7-1/GE-Proton7-1.tar.gz",
"files": {
"wine": "dist/bin/wine64",
"wineserver": "dist/bin/wineserver",
"wineboot": "files/bin/wineboot",
"winecfg": "dist/lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
}
]
},
@ -709,45 +527,6 @@
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "Lutris",
"name": "lutris-6.13-3-x86_64",
"title": "Lutris 6.13-3",
"uri": "https://github.com/lutris/wine/releases/download/lutris-6.13-3/wine-lutris-6.13-3-x86_64.tar.xz",
"files": {
"wine": "bin/wine64",
"wineserver": "bin/wineserver",
"wineboot": "bin/wineboot",
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "Lutris",
"name": "lutris-6.13-2-x86_64",
"title": "Lutris 6.13-2",
"uri": "https://github.com/lutris/wine/releases/download/lutris-6.13-2/wine-lutris-6.13-2-x86_64.tar.xz",
"files": {
"wine": "bin/wine64",
"wineserver": "bin/wineserver",
"wineboot": "bin/wineboot",
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
},
{
"family": "Lutris",
"name": "lutris-6.13-x86_64",
"title": "Lutris 6.13",
"uri": "https://github.com/lutris/wine/releases/download/lutris-6.13/wine-lutris-6.13-x86_64.tar.xz",
"files": {
"wine": "bin/wine64",
"wineserver": "bin/wineserver",
"wineboot": "bin/wineboot",
"winecfg": "lib64/wine/x86_64-windows/winecfg.exe"
},
"recommended": false
}
]
}

View file

@ -1,7 +1,9 @@
use std::collections::HashMap;
use std::{fs::File, io::Read};
use std::fs::File;
use std::io::Read;
use std::path::Path;
use std::io::{Error, ErrorKind, Write};
use std::process::{Command, Stdio};
use serde::{Serialize, Deserialize};
@ -122,6 +124,10 @@ pub struct Config {
impl Config {
/// Try to get a path to the wine executable based on `game.wine.builds` and `game.wine.selected`
///
/// Returns `Some("wine")` if:
/// 1) `game.wine.selected = None`
/// 2) wine installed and available in system
pub fn try_get_wine_executable(&self) -> Option<String> {
match &self.game.wine.selected {
Some(selected) => {
@ -142,7 +148,10 @@ impl Config {
// ????
None
},
None => None
None => match Command::new("wine").stdout(Stdio::null()).stderr(Stdio::null()).output() {
Ok(output) => if output.status.success() { Some(String::from("wine")) } else { None },
Err(_) => None
}
}
}

View file

@ -7,6 +7,7 @@ use gtk4::glib::clone;
use std::rc::Rc;
use std::cell::Cell;
use std::io::Error;
use std::process::{Command, Stdio};
use anime_game_core::prelude::*;
use wait_not_await::Await;
@ -256,10 +257,35 @@ impl App {
Ok(mut config) => {
match state {
LauncherState::Launch => {
// Display toast message if the game is failed to run
if let Err(err) = game::run(false) {
this.toast_error("Failed to run game", err);
}
let this = this.clone();
this.widgets.window.hide();
std::thread::spawn(move || {
// Display toast message if the game is failed to run
if let Err(err) = game::run(false) {
this.widgets.window.show();
this.toast_error("Failed to run game", err);
}
else {
loop {
std::thread::sleep(std::time::Duration::from_secs(3));
match Command::new("ps").arg("-A").stdout(Stdio::piped()).output() {
Ok(output) => {
if !String::from_utf8_lossy(&output.stdout).contains("GenshinImpact.e") {
break;
}
},
Err(_) => break
}
}
this.widgets.window.show();
}
});
},
LauncherState::PatchAvailable(patch) => {
@ -546,6 +572,7 @@ impl App {
self.widgets.launch_game.add_css_class("suggested-action");
self.widgets.launch_game.remove_css_class("warning");
self.widgets.launch_game.remove_css_class("destructive-action");
match &state {
LauncherState::Launch => {
@ -559,6 +586,9 @@ impl App {
Patch::Preparation { .. } => {
self.widgets.launch_game.set_label("Patch not available");
self.widgets.launch_game.set_sensitive(false);
self.widgets.launch_game.remove_css_class("suggested-action");
self.widgets.launch_game.add_css_class("destructive-action");
}
Patch::Testing { .. } => {

View file

@ -34,7 +34,7 @@ impl AppWidgets {
let builder = gtk::Builder::from_string(include_str!("../../../assets/ui/.dist/preferences/enhancements.ui"));
let result = Self {
page: get_object(&builder, "enhanced_page")?,
page: get_object(&builder, "page")?,
sync_combo: get_object(&builder, "sync_combo")?,
wine_lang: get_object(&builder, "wine_lang")?,

View file

@ -0,0 +1,119 @@
use gtk4 as gtk;
use libadwaita::{self as adw, prelude::*};
use gtk4::glib;
use gtk4::glib::clone;
use std::rc::Rc;
use std::cell::Cell;
use std::io::Error;
use crate::ui::get_object;
use crate::lib::config;
/// This structure is used to describe widgets used in application
///
/// `AppWidgets::try_get` function loads UI file from `.assets/ui/.dist` folder and returns structure with references to its widgets
///
/// This function does not implement events
#[derive(Clone, glib::Downgrade)]
pub struct AppWidgets {
pub page: adw::PreferencesPage
}
impl AppWidgets {
fn try_get() -> Result<Self, String> {
let builder = gtk::Builder::from_string(include_str!("../../../assets/ui/.dist/preferences/environment.ui"));
let result = Self {
page: get_object(&builder, "page")?
};
Ok(result)
}
}
/// This enum is used to describe an action inside of this application
///
/// 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)]
pub enum Actions {
None
}
/// This enum is used to store some of this application data
///
/// 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)]
pub struct Values;
/// The main application structure
///
/// `Default` macro automatically calls `AppWidgets::default`, i.e. loads UI file and reference its widgets
///
/// `Rc<Cell<Values>>` means this:
/// - `Rc` addeds ability to reference the same value from various clones of the structure.
/// This will guarantee us that inner `Cell<Values>` is the same for all the `App::clone()` values
/// - `Cell` addeds inner mutability to its value, so we can mutate it even without mutable reference.
///
/// So we have a shared reference to some value that can be changed without mutable reference.
/// That's what we need and what we use in `App::update` method
#[derive(Clone, glib::Downgrade)]
pub struct App {
widgets: AppWidgets,
values: Rc<Cell<Values>>
}
impl App {
/// Create new application
pub fn new() -> Result<Self, String> {
let result = Self {
widgets: AppWidgets::try_get()?,
values: Default::default()
}.init_events();
Ok(result)
}
/// Add default events and values to the widgets
fn init_events(self) -> Self {
// ..
self
}
/// Update widgets state by calling some action
pub fn update(&self, action: Actions) {
let values = self.values.take();
match action {
Actions::None => ()
}
self.values.set(values);
}
pub fn title() -> String {
String::from("Environment (WIP)")
}
pub fn get_page(&self) -> adw::PreferencesPage {
self.widgets.page.clone()
}
/// This method is being called by the `PreferencesStack::update`
pub fn prepare(&self, status_page: &adw::StatusPage) -> Result<(), Error> {
let config = config::get()?;
status_page.set_description(Some("Loading environment..."));
// ..
Ok(())
}
}
unsafe impl Send for App {}
unsafe impl Sync for App {}

View file

@ -57,7 +57,7 @@ impl AppWidgets {
let builder = gtk::Builder::from_string(include_str!("../../../assets/ui/.dist/preferences/general.ui"));
let mut result = Self {
page: get_object(&builder, "general_page")?,
page: get_object(&builder, "page")?,
voiceovers_row: get_object(&builder, "voiceovers_row")?,
voieover_components: Default::default(),

View file

@ -10,12 +10,14 @@ use std::io::Error;
use crate::ui::*;
use crate::ui::traits::prelude::*;
mod general_page;
mod enhancements_page;
mod general;
mod enhancements;
mod environment;
pub mod pages {
pub use super::general_page::App as GeneralPage;
pub use super::enhancements_page::App as EnhancementsPage;
pub use super::general::App as GeneralPage;
pub use super::enhancements::App as EnhancementsPage;
pub use super::environment::App as EnvironmentPage;
}
#[derive(Clone, glib::Downgrade)]
@ -31,7 +33,8 @@ pub struct PreferencesStack {
pub stack: gtk::Stack,
pub general_page: pages::GeneralPage,
pub enhancements_page: pages::EnhancementsPage
pub enhancements_page: pages::EnhancementsPage,
pub environment_page: pages::EnvironmentPage
}
impl PreferencesStack {
@ -50,11 +53,13 @@ impl PreferencesStack {
stack: get_object(&builder, "stack")?,
general_page: pages::GeneralPage::new()?,
enhancements_page: pages::EnhancementsPage::new()?
enhancements_page: pages::EnhancementsPage::new()?,
environment_page: pages::EnvironmentPage::new()?
};
result.stack.add_titled(&result.general_page.get_page(), None, &pages::GeneralPage::title());
result.stack.add_titled(&result.enhancements_page.get_page(), None, &pages::EnhancementsPage::title());
result.stack.add_titled(&result.environment_page.get_page(), None, &pages::EnvironmentPage::title());
Ok(result)
}
@ -75,6 +80,7 @@ impl PreferencesStack {
self.general_page.prepare(&self.status_page)?;
self.enhancements_page.prepare(&self.status_page)?;
self.environment_page.prepare(&self.status_page)?;
self.status_page.hide();
self.flap.show();