Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
atlanticaccent committed Feb 14, 2025
1 parent 691ae65 commit 013ec56
Show file tree
Hide file tree
Showing 28 changed files with 877 additions and 508 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions common/src/fast_im_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,11 @@ impl<K: Clone + Hash + Eq, V: Clone> From<FastImMap<K, V>>
}
}

impl<K: Clone + Hash + Eq + PartialEq + Eq, V: Clone, O: Into<druid::im::HashMap<K, V>>> From<O>
for FastImMap<K, V>
impl<K: Clone + Hash + Eq + PartialEq + Eq, V: Clone>
From<druid::im::HashMap<K, V, ahash::RandomState>> for FastImMap<K, V>
{
fn from(other: O) -> Self {
let mut new = Self::new();
new.extend(other.into().iter().map(|(k, v)| (k.clone(), v.clone())));

new
fn from(other: druid::im::HashMap<K, V, ahash::RandomState>) -> Self {
Self(other)
}
}

Expand Down
2 changes: 1 addition & 1 deletion installer/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub enum InstallError<ENT: Entry> {
#[error("Failed to join task/thread: {0:?}")]
Join(#[from] tokio::task::JoinError),
#[error("Multiple errors")]
MultipleErrors(Vec<InstallError<ENT>>),
MultipleErrors(Vec<Self>),
#[error(transparent)]
Generic(#[from] anyhow::Error),
}
10 changes: 6 additions & 4 deletions installer/src/installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub enum Request<T, U = ()> {
Download { remote_data: U, old_path: PathBuf },
}

pub struct EnrichedEntry<T: Entry>(pub T);

type InstallerError<T> = InstallError<<T as InstallerDelegate>::Entry>;

pub trait InstallerExt: InstallerDelegate
Expand Down Expand Up @@ -146,10 +148,10 @@ where
move_or_copy(path.clone(), destination.clone()).await;

entry
.enrich(destination)
.enrich(self.context(), destination)
.await
.map_err(InstallError::EntryEnrichmentError)?;
self.completed_handler(entry);
self.completed_handler(EnrichedEntry(entry));
}
} else {
Err(InstallError::ModSearchErrorUnknown)?;
Expand All @@ -174,11 +176,11 @@ where

move_or_copy(origin, old_path.clone()).await;
entry
.enrich(old_path)
.enrich(self.context(), old_path)
.await
.map_err(InstallError::EntryEnrichmentError)?;

self.completed_handler(entry);
self.completed_handler(EnrichedEntry(entry));

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion installer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pub(crate) mod installer;
mod traits;

pub use error::InstallError;
pub use installer::{HybridPath, Request, StringOrPath};
pub use installer::{EnrichedEntry, HybridPath, Request, StringOrPath};
pub use traits::{Entry, EntryUpdate, InstallerDelegate, InstallerExt};
15 changes: 10 additions & 5 deletions installer/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@ use std::{
use futures_util::TryFutureExt as _;

pub use crate::installer::InstallerExt;
use crate::{HybridPath, InstallError, StringOrPath};
use crate::{installer::EnrichedEntry, HybridPath, InstallError, StringOrPath};

pub trait Entry: Debug + Sized + Send + 'static {
type Id: Into<StringOrPath>;
type EnrichmentError: Error + Send + Sync;
type ParseError: Error + Send + Sync;
type Context;

fn id(&self) -> Self::Id;

fn parse(
path: impl AsRef<Path> + Send,
) -> impl Future<Output = Result<Self, <Self as Entry>::ParseError>> + Send;
) -> impl Future<Output = Result<Self, Self::ParseError>> + Send;

fn destination_folder(&self, parent: &Path) -> PathBuf;

fn enrich(
&mut self,
context: &Self::Context,
path: PathBuf,
) -> impl Future<Output = Result<(), <Self as Entry>::EnrichmentError>> + Send;
) -> impl Future<Output = Result<(), Self::EnrichmentError>> + Send;
}

pub(crate) trait EntryExt: Entry {
Expand All @@ -48,16 +50,19 @@ pub trait EntryUpdate: Send {
}

pub trait InstallerDelegate: Clone + Send + Sync {
type Entry: Entry;
type Context;
type Entry: Entry<Context = Self::Context>;
type EntryUpdate: EntryUpdate<Entry = Self::Entry>;

fn context(&self) -> &Self::Context;

fn error_handler<E: Error + Send + Sync + 'static>(&self, error: E);

fn multiple_handler(&self, folder: HybridPath, found: Vec<Self::Entry>);

fn overwrite_handler(&self, found: StringOrPath, folder: HybridPath, entry: Self::Entry);

fn completed_handler(&self, entry: Self::Entry);
fn completed_handler(&self, entry: EnrichedEntry<Self::Entry>);

fn check_conflict(&self, entry: &Self::Entry) -> impl Future<Output = bool> + Send + 'static;
}
1 change: 1 addition & 0 deletions moss/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ mimalloc = { workspace = true }

dhat = { version = "0.3", optional = true }
uuid = "1.11.0"
tokio-stream = { version = "0.1.17", features = ["full"] }

[target.'cfg(windows)'.dependencies]
indoc = { workspace = true }
Expand Down
31 changes: 7 additions & 24 deletions moss/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ use common::{
controllers::{HoverController, REMOVE_POINTER},
fast_im_map::FastImMap,
labels::bold_text,
lenses::LensExtExt as _,
widget_ext::{WidgetExtEx as _, HOVER_STATE_CHANGE},
widgets::root_stack::RootStack,
};
use druid::{
im::{HashSet, Vector},
widget::{Flex, WidgetWrapper, ZStack},
Data, Lens, LensExt, Selector, SingleUse, Widget, WidgetExt, WidgetId,
Data, Lens, Selector, SingleUse, Widget, WidgetExt, WidgetId,
};
use druid_patch::{
tabs::tab::{InitialTab, Tabs, TabsPolicy, TabsTransition},
Expand All @@ -30,10 +29,10 @@ use webview::PROJECT;
use crate::{
app::{
browser::Browser,
controllers::{AppController, ModListController},
controllers::{AppController, AsyncController, ModListController},
installer_impl::{AsyncError, Installer},
mod_description::{ModDescription, ENABLE_DEPENDENCIES},
mod_entry::{GameVersion, ModEntry, UpdateStatus, ViewModEntry},
mod_entry::{GameVersion, ModEntry, ViewModEntry},
mod_list::ModList,
mod_repo::ModRepo,
overlays::Popup,
Expand Down Expand Up @@ -101,7 +100,6 @@ impl App {
Selector::new("app.mod_list.replace");
const RESTART: Selector = Selector::new("app.update.restart");
const SELECTOR: Selector<app_delegate::AppCommands> = Selector::new("app.update.commands");
const SELF_UPDATE: Selector<()> = Selector::new("app.update.perform");
const TOGGLE_NAV_BAR: Selector = Selector::new("app.nav_bar.collapse");
const OPEN_EXTERNALLY: Selector<String> = Selector::new("app.user_browser.open");

Expand Down Expand Up @@ -299,25 +297,6 @@ impl App {
})
},
)
.on_command(util::MASTER_VERSION_RECEIVED, |_ctx, (id, res), data| {
let remote = res.as_ref().ok().cloned();
let entry_lens = App::mod_list.then(ModList::mods).deref().index(id);

if let Some(version_checker) = entry_lens
.clone()
.then(ModEntry::version_checker.in_rc())
.get(data)
{
entry_lens
.clone()
.then(ModEntry::remote_version.in_rc())
.put(data, remote.clone());

entry_lens
.then(ModEntry::update_status.in_rc())
.put(data, Some(UpdateStatus::from((&version_checker, &remote))));
}
})
.on_notification(ENABLE_DEPENDENCIES, |_, id, data| {
ViewModEntry::enable_dependencies(id, data);
}),
Expand Down Expand Up @@ -351,6 +330,10 @@ pub impl<W: Widget<App> + 'static> W {
fn env_as_shared_data(self) -> impl Widget<App> {
self.env_scope(|env, data| env.set(crate::ENV_STATE, data))
}

fn async_controller(self, runtime: Handle) -> impl Widget<App> {
self.controller(AsyncController::new(runtime))
}
}

#[derive(Debug, Clone, Hash)]
Expand Down
2 changes: 1 addition & 1 deletion moss/src/app/app_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl Delegate<App> for AppDelegate {
}
} else if let Some(entry) = cmd.get(App::CONFIRM_DELETE_MOD) {
if remove_dir_all(&entry.path).is_ok() {
data.mod_list.mods.remove(&entry.id);
data.mod_list.mods.remove(&entry.mod_id);
data.active = None;
} else {
eprintln!("Failed to delete mod");
Expand Down
13 changes: 4 additions & 9 deletions moss/src/app/controllers/app_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use itertools::Itertools;
use crate::{
app::{
installer_impl::{InstallMessage, INSTALL},
mod_entry::UpdateStatus,
mod_entry::ModEntry,
mod_list::ModList,
settings::{self, Settings, SettingsCommand},
App,
Expand Down Expand Up @@ -72,15 +72,8 @@ impl<W: Widget<App>> Controller<App, W> for AppController {
match payload {
InstallMessage::Success(entry) => {
let mut entry = entry.clone();
if let Some(existing) = data.mod_list.mods.get(&entry.id) {
if let Some(existing) = data.mod_list.mods.get(&entry.mod_id) {
entry.enabled = existing.enabled;
if let Some(remote_version_checker) = existing.remote_version.clone() {
entry.remote_version = Some(remote_version_checker.clone());
entry.update_status = Some(UpdateStatus::from((
entry.version_checker.as_ref().unwrap(),
&Some(remote_version_checker),
)));
}
}
ctx.submit_command(ModList::INSERT_MOD.with(*entry));
ctx.request_update();
Expand Down Expand Up @@ -110,6 +103,8 @@ impl<W: Widget<App>> Controller<App, W> for AppController {
.inspect_err(|err| bang!(err));
}
}
} else if let Some(()) = cmd.get(ModEntry::VERSION_CHECK_COMPLETE) {
ctx.request_update();
}
} else if let Event::MouseDown(_) = event {
if ctx.is_disabled() {
Expand Down
Loading

0 comments on commit 013ec56

Please sign in to comment.