mirror of
https://github.com/redstrate/Auracite.git
synced 2025-04-26 22:27:45 +00:00
Bubble up errors to the Qt UI
This commit is contained in:
parent
5882bdd8f7
commit
56f3436a4c
3 changed files with 45 additions and 8 deletions
|
@ -1,3 +1,4 @@
|
|||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import QtQuick.Controls as QQC2
|
||||
import org.kde.kirigami as Kirigami
|
||||
|
@ -22,4 +23,16 @@ Kirigami.ApplicationWindow {
|
|||
onClicked: root.backend.archiveCharacter(characterNameField.text, false)
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: backend
|
||||
|
||||
function onArchiveSuccessful(): void {
|
||||
console.info("Archive done!");
|
||||
}
|
||||
|
||||
function onArchiveFailed(message: string): void {
|
||||
console.error("Failed: " + message);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,24 +9,46 @@ pub mod bridge {
|
|||
#[qobject]
|
||||
#[qml_element]
|
||||
type Backend = super::BackendRust;
|
||||
|
||||
#[qsignal]
|
||||
#[cxx_name = "archiveSuccessful"]
|
||||
fn archive_successful(self: Pin<&mut Backend>);
|
||||
|
||||
#[qsignal]
|
||||
#[cxx_name = "archiveFailed"]
|
||||
fn archive_failed(self: Pin<&mut Backend>, message: &QString);
|
||||
}
|
||||
|
||||
unsafe extern "RustQt" {
|
||||
#[qinvokable]
|
||||
#[cxx_name = "archiveCharacter"]
|
||||
fn archive_character(self: &Backend, character_name: &QString, use_dalamud: bool);
|
||||
fn archive_character(self: Pin<&mut Backend>, character_name: &QString, use_dalamud: bool);
|
||||
}
|
||||
}
|
||||
|
||||
use std::pin::Pin;
|
||||
use cxx_kde_frameworks::ki18n::i18n;
|
||||
use crate::archive_character_blocking;
|
||||
use cxx_qt_lib::QString;
|
||||
use auracite::ArchiveError;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct BackendRust {
|
||||
}
|
||||
|
||||
impl bridge::Backend {
|
||||
pub fn archive_character(&self, character_name: &QString, use_dalamud: bool) {
|
||||
archive_character_blocking(&character_name.to_string(), use_dalamud);
|
||||
pub fn archive_character(mut self: Pin<&mut Self>, character_name: &QString, use_dalamud: bool) {
|
||||
match archive_character_blocking(&character_name.to_string(), use_dalamud) {
|
||||
Ok(_) => { self.archive_successful() }
|
||||
Err(err) => {
|
||||
match err {
|
||||
// TODO: Pass the URL up
|
||||
ArchiveError::DownloadFailed(_) => { self.archive_failed(&i18n("Download failed")) }
|
||||
ArchiveError::CharacterNotFound => { self.archive_failed(&i18n("Character not found")) }
|
||||
ArchiveError::ParsingError => { self.archive_failed(&i18n("Parsing error")) }
|
||||
ArchiveError::UnknownError => { self.archive_failed(&i18n("Unknown error")) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,18 +4,20 @@ use cxx_kde_frameworks::kcoreaddons::{KAboutData, License};
|
|||
use cxx_kde_frameworks::ki18n::{i18n, i18nc, KLocalizedContext, KLocalizedString};
|
||||
use cxx_qt_lib::{QByteArray, QGuiApplication, QList, QQmlApplicationEngine, QQuickStyle, QString, QStringList, QUrl};
|
||||
use cxx_qt_lib_extras::{QCommandLineOption, QCommandLineParser};
|
||||
use auracite::archive_character;
|
||||
use auracite::{archive_character, ArchiveError};
|
||||
|
||||
pub mod bridge;
|
||||
|
||||
fn archive_character_blocking(character_name: &String, use_dalamud: bool) {
|
||||
fn archive_character_blocking(character_name: &String, use_dalamud: bool) -> Result<(), ArchiveError> {
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap();
|
||||
.map_err(|_| ArchiveError::UnknownError)?;
|
||||
|
||||
let inner = rt.block_on(archive_character(&character_name.to_string(), use_dalamud)).unwrap();
|
||||
write("/home/josh/test.zip", inner);
|
||||
let inner = rt.block_on(archive_character(&character_name.to_string(), use_dalamud))?;
|
||||
write("/home/josh/test.zip", inner)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
Loading…
Add table
Reference in a new issue