mirror of
https://github.com/ALEZ-DEV/Babylonia-terminal.git
synced 2025-12-16 01:18:50 +00:00
can now installed fonts from GUI\
This commit is contained in:
parent
18158187a1
commit
dfde93325b
@ -11,23 +11,21 @@ enum DXVKInstallationState {
|
||||
}
|
||||
|
||||
class DXVK with ChangeNotifier {
|
||||
DXVKInstallationState protonState = DXVKInstallationState.idle;
|
||||
DXVKInstallationState dxvkState = DXVKInstallationState.idle;
|
||||
|
||||
Int64 currentProgress = Int64(0);
|
||||
Int64 maxProgress = Int64(0);
|
||||
|
||||
Future startInstallation(
|
||||
GameStateProvider gameStateProvider, String protonVersion) async {
|
||||
notifyListeners();
|
||||
|
||||
StartDXVKInstallation(protonVersion: protonVersion).sendSignalToRust();
|
||||
final progressStream = DXVKDownloadProgress.rustSignalStream;
|
||||
await for (final rustSignal in progressStream) {
|
||||
currentProgress = rustSignal.message.current;
|
||||
maxProgress = rustSignal.message.max;
|
||||
|
||||
if (protonState == DXVKInstallationState.idle) {
|
||||
protonState = DXVKInstallationState.downloading;
|
||||
if (dxvkState == DXVKInstallationState.idle) {
|
||||
dxvkState = DXVKInstallationState.downloading;
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
@ -40,7 +38,7 @@ class DXVK with ChangeNotifier {
|
||||
final notificationDecompressingStream =
|
||||
NotifyDXVKStartDecompressing.rustSignalStream;
|
||||
await for (final _ in notificationDecompressingStream) {
|
||||
protonState = DXVKInstallationState.decompressing;
|
||||
dxvkState = DXVKInstallationState.decompressing;
|
||||
notifyListeners();
|
||||
break;
|
||||
}
|
||||
|
||||
38
babylonia_terminal_launcher/lib/models/fonts.dart
Normal file
38
babylonia_terminal_launcher/lib/models/fonts.dart
Normal file
@ -0,0 +1,38 @@
|
||||
import 'package:fixnum/fixnum.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import './../messages/steps/fonts.pb.dart';
|
||||
import './../providers/providers.dart';
|
||||
|
||||
enum FontsInstallationState {
|
||||
idle,
|
||||
installing,
|
||||
}
|
||||
|
||||
class Fonts with ChangeNotifier {
|
||||
FontsInstallationState fontsState = FontsInstallationState.idle;
|
||||
|
||||
Int64 currentProgress = Int64(0);
|
||||
Int64 maxProgress = Int64(0);
|
||||
|
||||
Future startInstallation(GameStateProvider gameState) async {
|
||||
StartFontsInstallation().sendSignalToRust();
|
||||
final stream = FontsInstallationProgress.rustSignalStream;
|
||||
await for (final rustSignal in stream) {
|
||||
maxProgress = rustSignal.message.max;
|
||||
currentProgress = rustSignal.message.current;
|
||||
|
||||
if (fontsState == FontsInstallationState.idle) {
|
||||
fontsState = FontsInstallationState.installing;
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
|
||||
if (currentProgress >= maxProgress) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gameState.updateGameState();
|
||||
}
|
||||
}
|
||||
@ -18,8 +18,6 @@ class Proton with ChangeNotifier {
|
||||
|
||||
Future startInstallation(
|
||||
GameStateProvider gameStateProvider, String protonVersion) async {
|
||||
notifyListeners();
|
||||
|
||||
StartProtonInstallation(protonVersion: protonVersion).sendSignalToRust();
|
||||
final progressStream = ProtonDownloadProgress.rustSignalStream;
|
||||
await for (final rustSignal in progressStream) {
|
||||
|
||||
@ -27,6 +27,7 @@ class GameStateProvider with ChangeNotifier {
|
||||
bool hasToSetup() {
|
||||
return _gameState == States.ProtonNotInstalled ||
|
||||
_gameState == States.DXVKNotInstalled ||
|
||||
_gameState == States.FontNotInstalled ||
|
||||
_gameState == States.DependecieNotInstalled;
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import './../../widgets/selectable_yaru_expansion_panel.dart';
|
||||
import './../../widgets/simple_button.dart';
|
||||
import './../../widgets/steps/proton_steps_widget.dart';
|
||||
import './../../widgets/steps/dxvk_steps_widget.dart';
|
||||
import './../../widgets/steps/fonts_steps_widget.dart';
|
||||
|
||||
class StepsScreen extends StatelessWidget {
|
||||
StepsScreen({super.key});
|
||||
@ -23,9 +24,12 @@ class StepsScreen extends StatelessWidget {
|
||||
case States.DXVKNotInstalled:
|
||||
controller.updateSection(1);
|
||||
break;
|
||||
case States.DependecieNotInstalled:
|
||||
case States.FontNotInstalled:
|
||||
controller.updateSection(2);
|
||||
break;
|
||||
case States.DependecieNotInstalled:
|
||||
controller.updateSection(3);
|
||||
break;
|
||||
}
|
||||
|
||||
return Center(
|
||||
@ -44,11 +48,13 @@ class StepsScreen extends StatelessWidget {
|
||||
headers: const [
|
||||
Text("Proton"),
|
||||
Text("DXVK"),
|
||||
Text("Fonts"),
|
||||
Text("Dependecies"),
|
||||
],
|
||||
children: const [
|
||||
ProtonSteps(),
|
||||
DXVKSteps(),
|
||||
FontsSteps(),
|
||||
Padding(
|
||||
padding: EdgeInsets.all(40.0),
|
||||
child: Text("Dependecies"),
|
||||
|
||||
@ -26,7 +26,7 @@ class _DXVKStepsState extends State<DXVKSteps> {
|
||||
create: (_) => proton,
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
switch (Provider.of<DXVK>(context).protonState) {
|
||||
switch (Provider.of<DXVK>(context).dxvkState) {
|
||||
case DXVKInstallationState.idle:
|
||||
return const InstallDXVK();
|
||||
case DXVKInstallationState.downloading:
|
||||
|
||||
@ -0,0 +1,93 @@
|
||||
import 'package:babylonia_terminal_launcher/widgets/gtk_spinner_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:yaru/yaru.dart';
|
||||
|
||||
import './../../models/fonts.dart';
|
||||
import './../../providers/providers.dart';
|
||||
import './../../widgets/simple_button.dart';
|
||||
|
||||
class FontsSteps extends StatelessWidget {
|
||||
const FontsSteps({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: ChangeNotifierProvider(
|
||||
create: (context) => Fonts(),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
switch (Provider.of<Fonts>(context).fontsState) {
|
||||
case FontsInstallationState.idle:
|
||||
return const InstallFonts();
|
||||
case FontsInstallationState.installing:
|
||||
return const FontsInstallationProgress();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class InstallFonts extends StatefulWidget {
|
||||
const InstallFonts({super.key});
|
||||
|
||||
@override
|
||||
State<InstallFonts> createState() => _InstallFontsState();
|
||||
}
|
||||
|
||||
class _InstallFontsState extends State<InstallFonts> {
|
||||
bool canInstall = true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: SimpleButton(
|
||||
onPressed: canInstall
|
||||
? () {
|
||||
Provider.of<Fonts>(context, listen: false).startInstallation(
|
||||
Provider.of<GameStateProvider>(context, listen: false),
|
||||
);
|
||||
setState(() {
|
||||
canInstall = false;
|
||||
});
|
||||
}
|
||||
: null,
|
||||
child: const Text("Install"),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class FontsInstallationProgress extends StatelessWidget {
|
||||
const FontsInstallationProgress({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = Provider.of<Fonts>(context);
|
||||
final pourcent =
|
||||
(provider.currentProgress.toInt() / provider.maxProgress.toInt()) * 100;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const GtkSpinner(),
|
||||
Text(
|
||||
"${provider.currentProgress} / ${provider.maxProgress} fonts installed"),
|
||||
],
|
||||
),
|
||||
),
|
||||
YaruLinearProgressIndicator(
|
||||
value: pourcent / 100,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
16
babylonia_terminal_launcher/messages/steps/fonts.proto
Normal file
16
babylonia_terminal_launcher/messages/steps/fonts.proto
Normal file
@ -0,0 +1,16 @@
|
||||
syntax = "proto3";
|
||||
package fonts;
|
||||
|
||||
// [RINF:RUST-SIGNAL]
|
||||
message FontsInstallationProgress {
|
||||
uint64 current = 1;
|
||||
uint64 max = 2;
|
||||
}
|
||||
|
||||
// [RINF:DART-SIGNAL]
|
||||
message StartFontsInstallation {
|
||||
string protonVersion = 1;
|
||||
};
|
||||
|
||||
// [RINF:RUST-SIGNAL]
|
||||
message NotifiyFontsSuccessfullyInstalled {}
|
||||
@ -52,7 +52,7 @@ pub async fn listen_dxvk_installation() {
|
||||
let proton = proton_component.init_proton();
|
||||
if let Err(e) = proton {
|
||||
ReportError {
|
||||
error_message: format!("Failed to initialize DXVK : {}", e),
|
||||
error_message: format!("Failed to install DXVK : {}", e),
|
||||
}
|
||||
.send_signal_to_dart();
|
||||
continue;
|
||||
|
||||
91
babylonia_terminal_launcher/native/hub/src/fonts.rs
Normal file
91
babylonia_terminal_launcher/native/hub/src/fonts.rs
Normal file
@ -0,0 +1,91 @@
|
||||
use std::thread;
|
||||
|
||||
use babylonia_terminal_sdk::{
|
||||
components::proton_component::ProtonComponent, game_manager::GameManager, game_state::GameState,
|
||||
};
|
||||
use tokio_with_wasm::tokio;
|
||||
|
||||
use crate::messages::{
|
||||
error::ReportError,
|
||||
steps::fonts::{
|
||||
FontsInstallationProgress, NotifiyFontsSuccessfullyInstalled, StartFontsInstallation,
|
||||
},
|
||||
};
|
||||
|
||||
pub async fn listen_fonts_installation() {
|
||||
let mut receiver = StartFontsInstallation::get_dart_signal_receiver();
|
||||
while let Some(_) = receiver.recv().await {
|
||||
let proton_component = ProtonComponent::new(GameState::get_config().await.config_dir);
|
||||
let proton = proton_component.init_proton();
|
||||
if let Err(e) = proton {
|
||||
ReportError {
|
||||
error_message: format!("Failed to install DXVK : {}", e),
|
||||
}
|
||||
.send_signal_to_dart();
|
||||
continue;
|
||||
}
|
||||
|
||||
thread::spawn(move || {
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(async {
|
||||
match GameManager::install_font(
|
||||
&proton.unwrap(),
|
||||
Some(InstallationReporter::create()),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Err(e) => ReportError {
|
||||
error_message: format!("Failed to install DXVK : {}", e),
|
||||
}
|
||||
.send_signal_to_dart(),
|
||||
Ok(_) => NotifiyFontsSuccessfullyInstalled {}.send_signal_to_dart(),
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
struct InstallationReporterPrivate {
|
||||
max_progress: Option<u64>,
|
||||
}
|
||||
|
||||
struct InstallationReporter {
|
||||
private: std::sync::Mutex<Option<InstallationReporterPrivate>>,
|
||||
}
|
||||
|
||||
impl InstallationReporter {
|
||||
pub fn create() -> std::sync::Arc<Self> {
|
||||
std::sync::Arc::new(Self {
|
||||
private: std::sync::Mutex::new(None),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl downloader::progress::Reporter for InstallationReporter {
|
||||
fn setup(&self, max_progress: Option<u64>, _: &str) {
|
||||
let private = InstallationReporterPrivate { max_progress };
|
||||
|
||||
let mut guard = self.private.lock().unwrap();
|
||||
*guard = Some(private);
|
||||
}
|
||||
|
||||
fn progress(&self, current: u64) {
|
||||
if let Some(p) = self.private.lock().unwrap().as_mut() {
|
||||
FontsInstallationProgress {
|
||||
current,
|
||||
max: p.max_progress.unwrap(),
|
||||
}
|
||||
.send_signal_to_dart();
|
||||
}
|
||||
}
|
||||
|
||||
fn set_message(&self, _: &str) {}
|
||||
|
||||
fn done(&self) {
|
||||
let mut guard = self.private.lock().unwrap();
|
||||
*guard = None;
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@ use tokio_with_wasm::tokio;
|
||||
|
||||
mod config;
|
||||
mod dxvk;
|
||||
mod fonts;
|
||||
mod game_state;
|
||||
mod github;
|
||||
mod messages;
|
||||
@ -21,4 +22,5 @@ async fn main() {
|
||||
//installation
|
||||
tokio::spawn(proton::listen_proton_installation());
|
||||
tokio::spawn(dxvk::listen_dxvk_installation());
|
||||
tokio::spawn(fonts::listen_fonts_installation());
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user