Skip to content

Commit

Permalink
Add error dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ALEZ-DEV committed May 27, 2024
1 parent a330bf9 commit 7c83f0d
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 6 deletions.
6 changes: 5 additions & 1 deletion babylonia_terminal_launcher/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ import 'package:yaru/yaru.dart';
import './screens/screens.dart';
import './screens/setup_screen.dart';
import './providers/providers.dart';
import './models/error_reporter.dart';

class BabyloniaLauncher extends StatelessWidget {
const BabyloniaLauncher(
BabyloniaLauncher(
{super.key,
required this.settingsProvider,
required this.gameStateProvider});
final SettingsProvider settingsProvider;
final GameStateProvider gameStateProvider;
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

@override
Widget build(BuildContext context) {
ErrorReporter.listenAllRustError(navigatorKey);
return MultiProvider(
providers: [
ChangeNotifierProvider(
Expand All @@ -27,6 +30,7 @@ class BabyloniaLauncher extends StatelessWidget {
],
child: YaruTheme(
builder: (context, yaru, child) => MaterialApp(
navigatorKey: navigatorKey,
title: "Babylonia Terminal",
debugShowCheckedModeBanner: false,
theme: yaru.theme,
Expand Down
56 changes: 56 additions & 0 deletions babylonia_terminal_launcher/lib/models/error_reporter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_highlight/flutter_highlight.dart';
import 'package:flutter_highlight/themes/vs.dart';
import 'package:flutter_highlight/themes/vs2015.dart';
import 'package:yaru/icons.dart';
import 'package:yaru/widgets.dart';

import './../messages/error.pb.dart';

class ErrorReporter {
static Future listenAllRustError(
GlobalKey<NavigatorState> navigatorState) async {
final stream = ReportError.rustSignalStream;
await for (final rustSignal in stream) {
final context = navigatorState.currentState!.overlay!.context;
await showDialog<void>(
context: context,
builder: (context) => AlertDialog(
titlePadding: EdgeInsets.zero,
title: YaruDialogTitleBar(
title: const Text('Error'),
isClosable: true,
leading: Center(
child: YaruIconButton(
icon: const Icon(YaruIcons.copy),
tooltip: 'Copy',
onPressed: () async {
Clipboard.setData(
ClipboardData(text: rustSignal.message.errorMessage),
);
},
),
),
),
contentPadding: EdgeInsets.zero,
content: SizedBox(
height: 400,
width: 700,
child: HighlightView(
rustSignal.message.errorMessage,
language: '',
theme: Theme.of(context).brightness == Brightness.dark
? vs2015Theme
: vsTheme,
padding: const EdgeInsets.all(12),
textStyle: const TextStyle(
fontSize: 16,
),
),
),
),
);
}
}
}
7 changes: 7 additions & 0 deletions babylonia_terminal_launcher/messages/error.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";
package error;

// [RINF:RUST-SIGNAL]
message ReportError {
string errorMessage = 1;
}
13 changes: 10 additions & 3 deletions babylonia_terminal_launcher/native/hub/src/game_state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use babylonia_terminal_sdk::game_state::GameState;

use crate::messages::game_state::{AskGameState, GameState as GameStateMessage, States};
use crate::messages::{
error::ReportError,
game_state::{AskGameState, GameState as GameStateMessage, States},
};

impl GameStateMessage {
fn from_sdk_state_to_msg_state(state: GameState) -> Self {
Expand All @@ -24,8 +27,12 @@ pub async fn listen_game_state() {
let mut receiver = AskGameState::get_dart_signal_receiver();
while let Some(_) = receiver.recv().await {
let result_state = GameState::get_current_state().await;
if let Ok(state) = result_state {
GameStateMessage::from_sdk_state_to_msg_state(state).send_signal_to_dart();
match result_state {
Ok(state) => GameStateMessage::from_sdk_state_to_msg_state(state).send_signal_to_dart(),
Err(e) => ReportError {
error_message: format!("When updating the game state : {}", e),
}
.send_signal_to_dart(),
}
}
}
12 changes: 10 additions & 2 deletions babylonia_terminal_launcher/native/hub/src/github.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use std::fmt::format;

use babylonia_terminal_sdk::{
components::proton_component::{PROTON_DEV, PROTON_REPO},
utils::github_requester::{GithubRelease, GithubRequester},
};

use crate::messages::github::{AskProtonVersions, ProtonVersions};
use crate::messages::{
error::ReportError,
github::{AskProtonVersions, ProtonVersions},
};

#[warn(dead_code)]
struct GithubInfo;
Expand All @@ -24,7 +29,10 @@ pub async fn listen_proton_version() {
versions: r.iter().map(|v| v.tag_name.to_owned()).collect(),
}
.send_signal_to_dart(),
Err(_) => todo!(),
Err(e) => ReportError {
error_message: format!("When fetching proton versions : {}", e),
}
.send_signal_to_dart(),
}
}
}
1 change: 1 addition & 0 deletions babylonia_terminal_launcher/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies:
protobuf: ^3.1.0
shared_preferences: ^2.2.3
http: ^1.2.1
flutter_highlight: ^0.7.0

dependency_overrides:
media_kit:
Expand Down

0 comments on commit 7c83f0d

Please sign in to comment.