Skip to content

Commit

Permalink
More refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Not-A-Normal-Robot committed Oct 28, 2024
1 parent 6a2db78 commit 66515d7
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/cold_clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::thread;
use std::time::{Instant, Duration};
use std::sync::{mpsc, Arc, Mutex};
use slint::SharedString;
use slint::ComponentHandle;
use tokio::runtime::Runtime;
use crate::dirs::paths;

slint::include_modules!();
use crate::slint_types::ColdClearWaitWindow;

enum LoadingIPCMessage {
AdvanceTo(
Expand Down
30 changes: 28 additions & 2 deletions src/conf.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::fs;
use crate::dirs::paths;
use crate::git;
use crate::slint_types::Settings;
use serde::{Serialize, Deserialize};

slint::include_modules!();

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Config {
// Editing this struct?
Expand Down Expand Up @@ -146,4 +145,31 @@ impl Default for Config {
fn default() -> Self {
return Self::new();
}
}

impl From<Settings> for Config {
fn from(settings: Settings) -> Self {
Self {
sandboxed: settings.sandboxed,
clear_temp_dir: settings.clear_temp_dir,
import_save_on_play: settings.import_save_on_play,
repo_initialized: settings.repo_initialized,
game_repo_path: settings.game_repo_path.as_str().to_string(),
use_gui: true,
use_cold_clear: settings.use_cold_clear,
}
}
}

impl From<Config> for Settings {
fn from(cfg: Config) -> Self {
Self {
sandboxed: cfg.sandboxed,
clear_temp_dir: cfg.clear_temp_dir,
import_save_on_play: cfg.import_save_on_play,
game_repo_path: cfg.game_repo_path.clone().into(),
repo_initialized: cfg.repo_initialized,
use_cold_clear: cfg.use_cold_clear,
}
}
}
3 changes: 2 additions & 1 deletion src/error_window.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
slint::include_modules!();
use crate::slint_types::ErrorWindow;
use slint::ComponentHandle;

pub fn open(
title: Option<String>,
Expand Down
6 changes: 2 additions & 4 deletions src/git.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::dirs;
use crate::slint_types::GitCloneWaitWindow;
use std::fs;
use std::io;
use std::process::{Command, ExitStatus, Stdio};
use slint::{SharedString};

slint::include_modules!();
use slint::{SharedString, ComponentHandle};

pub fn tags(repo_path: &str) -> Vec<String> {
let mut cmd = Command::new("git");
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod git;
mod main_window;
mod error_window;
mod setup;

mod slint_types;
fn main() -> Result<(), slint::PlatformError> {
print_intro();

Expand Down
14 changes: 3 additions & 11 deletions src/main_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use crate::conf::Config;
use crate::game;
use crate::git;
use crate::error_window;
use slint::{ModelRc, VecModel, SharedString};

slint::include_modules!();
use crate::slint_types::{Settings, MainWindow};
use slint::{ModelRc, VecModel, SharedString, ModelExt, ComponentHandle};

pub fn open(cfg: &Config) -> Result<MainWindow, slint::PlatformError> {
let main_window = MainWindow::new()?;
Expand Down Expand Up @@ -64,14 +63,7 @@ pub fn open(cfg: &Config) -> Result<MainWindow, slint::PlatformError> {
);
}
});
main_window.set_settings(Settings {
sandboxed: cfg.sandboxed,
clear_temp_dir: cfg.clear_temp_dir,
import_save_on_play: cfg.import_save_on_play,
game_repo_path: cfg.game_repo_path.clone().into(),
repo_initialized: cfg.repo_initialized,
use_cold_clear: cfg.use_cold_clear,
});
main_window.set_settings(cfg.clone().into());
main_window.set_is_wayland_used(is_wayland_session());
main_window.set_versions(
ModelRc::new(
Expand Down
6 changes: 3 additions & 3 deletions src/setup.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::error_window;
use crate::slint_types::SetupWindow;
use crate::git;
use crate::conf;
use crate::dirs;
use rfd::FileDialog;
use std::cell::RefCell;
use crate::dirs;
use std::rc::Rc;

slint::include_modules!();
use slint::ComponentHandle;

pub fn run_setup() -> Result<(), slint::PlatformError> {
// Wrap `setup_finished` and `setup_window` in Rc<RefCell> for shared access.
Expand Down
1 change: 1 addition & 0 deletions src/slint_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
slint::include_modules!();

0 comments on commit 66515d7

Please sign in to comment.