feat(theme): add palette system and per-element theming
This commit is contained in:
1 parent
ecc2b2bb23
commit
80210364d5
40 files changed
+2900
-1120
No files matched your search
+72
-52
@@ -121,7 +121,13 @@ pub async fn launch(
|
||||
.libraries
|
||||
.iter()
|
||||
.filter(|l| lib_allowed(l))
|
||||
.filter_map(|l| l.downloads.as_ref()?.artifact.as_ref().map(|a| lib_dir.join(&a.path)))
|
||||
.filter_map(|l| {
|
||||
l.downloads
|
||||
.as_ref()?
|
||||
.artifact
|
||||
.as_ref()
|
||||
.map(|a| lib_dir.join(&a.path))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let main_class = match config.loader {
|
||||
@@ -132,7 +138,9 @@ pub async fn launch(
|
||||
.join("loader-profiles")
|
||||
.join(format!("fabric-{}-{}.json", config.game_version, lv));
|
||||
if !profile_path.exists() {
|
||||
return Err(LaunchError::MetaNotFound(profile_path.display().to_string()));
|
||||
return Err(LaunchError::MetaNotFound(
|
||||
profile_path.display().to_string(),
|
||||
));
|
||||
}
|
||||
let profile: LoaderProfileJson =
|
||||
serde_json::from_slice(&std::fs::read(&profile_path)?)?;
|
||||
@@ -149,7 +157,9 @@ pub async fn launch(
|
||||
.join("loader-profiles")
|
||||
.join(format!("quilt-{}-{}.json", config.game_version, lv));
|
||||
if !profile_path.exists() {
|
||||
return Err(LaunchError::MetaNotFound(profile_path.display().to_string()));
|
||||
return Err(LaunchError::MetaNotFound(
|
||||
profile_path.display().to_string(),
|
||||
));
|
||||
}
|
||||
let profile: LoaderProfileJson =
|
||||
serde_json::from_slice(&std::fs::read(&profile_path)?)?;
|
||||
@@ -166,7 +176,9 @@ pub async fn launch(
|
||||
.join("loader-profiles")
|
||||
.join(format!("forge-{}-{}.json", config.game_version, lv));
|
||||
if !profile_path.exists() {
|
||||
return Err(LaunchError::MetaNotFound(profile_path.display().to_string()));
|
||||
return Err(LaunchError::MetaNotFound(
|
||||
profile_path.display().to_string(),
|
||||
));
|
||||
}
|
||||
let profile: LoaderProfileJson =
|
||||
serde_json::from_slice(&std::fs::read(&profile_path)?)?;
|
||||
@@ -190,7 +202,9 @@ pub async fn launch(
|
||||
.join("loader-profiles")
|
||||
.join(format!("neoforge-{}.json", lv));
|
||||
if !profile_path.exists() {
|
||||
return Err(LaunchError::MetaNotFound(profile_path.display().to_string()));
|
||||
return Err(LaunchError::MetaNotFound(
|
||||
profile_path.display().to_string(),
|
||||
));
|
||||
}
|
||||
let profile: LoaderProfileJson =
|
||||
serde_json::from_slice(&std::fs::read(&profile_path)?)?;
|
||||
@@ -227,6 +241,12 @@ pub async fn launch(
|
||||
let java = config
|
||||
.java_path
|
||||
.clone()
|
||||
.or_else(|| {
|
||||
crate::config::SETTINGS
|
||||
.paths
|
||||
.effective_java_path()
|
||||
.map(str::to_owned)
|
||||
})
|
||||
.unwrap_or_else(crate::net::detect_java_path);
|
||||
|
||||
let mut jvm: Vec<String> = vec![
|
||||
@@ -236,50 +256,50 @@ pub async fn launch(
|
||||
jvm.extend(config.jvm_args.clone());
|
||||
|
||||
let mut account_store = crate::auth::AccountStore::load();
|
||||
let (mc_username, mc_uuid, mc_token, mc_user_type) =
|
||||
match account_store.active_account().cloned() {
|
||||
Some(acc) => {
|
||||
let (token, new_refresh) = match acc.account_type {
|
||||
crate::auth::AccountType::Microsoft => {
|
||||
match crate::auth::refresh_and_get_token(&acc).await {
|
||||
Ok(pair) => pair,
|
||||
Err(e) => {
|
||||
return Err(LaunchError::Auth(format!(
|
||||
"Authentication failed: {e}"
|
||||
)));
|
||||
}
|
||||
let (mc_username, mc_uuid, mc_token, mc_user_type) = match account_store
|
||||
.active_account()
|
||||
.cloned()
|
||||
{
|
||||
Some(acc) => {
|
||||
let (token, new_refresh) = match acc.account_type {
|
||||
crate::auth::AccountType::Microsoft => {
|
||||
match crate::auth::refresh_and_get_token(&acc).await {
|
||||
Ok(pair) => pair,
|
||||
Err(e) => {
|
||||
return Err(LaunchError::Auth(format!("Authentication failed: {e}")));
|
||||
}
|
||||
}
|
||||
crate::auth::AccountType::Offline => ("0".to_string(), None),
|
||||
};
|
||||
if let Some(new_rt) = new_refresh {
|
||||
if let Some(stored) = account_store
|
||||
.accounts
|
||||
.iter_mut()
|
||||
.find(|a| a.uuid == acc.uuid)
|
||||
{
|
||||
stored.refresh_token = Some(new_rt);
|
||||
account_store.save();
|
||||
}
|
||||
}
|
||||
let user_type = match acc.account_type {
|
||||
crate::auth::AccountType::Microsoft => "msa",
|
||||
crate::auth::AccountType::Offline => "legacy",
|
||||
};
|
||||
(
|
||||
acc.username.clone(),
|
||||
acc.uuid.clone(),
|
||||
token,
|
||||
user_type.to_string(),
|
||||
)
|
||||
crate::auth::AccountType::Offline => ("0".to_string(), None),
|
||||
};
|
||||
if let Some(new_rt) = new_refresh {
|
||||
if let Some(stored) = account_store
|
||||
.accounts
|
||||
.iter_mut()
|
||||
.find(|a| a.uuid == acc.uuid)
|
||||
{
|
||||
stored.refresh_token = Some(new_rt);
|
||||
account_store.save();
|
||||
}
|
||||
}
|
||||
None => (
|
||||
"Player".to_string(),
|
||||
"00000000-0000-0000-0000-000000000000".to_string(),
|
||||
"0".to_string(),
|
||||
"legacy".to_string(),
|
||||
),
|
||||
};
|
||||
let user_type = match acc.account_type {
|
||||
crate::auth::AccountType::Microsoft => "msa",
|
||||
crate::auth::AccountType::Offline => "legacy",
|
||||
};
|
||||
(
|
||||
acc.username.clone(),
|
||||
acc.uuid.clone(),
|
||||
token,
|
||||
user_type.to_string(),
|
||||
)
|
||||
}
|
||||
None => (
|
||||
"Player".to_string(),
|
||||
"00000000-0000-0000-0000-000000000000".to_string(),
|
||||
"0".to_string(),
|
||||
"legacy".to_string(),
|
||||
),
|
||||
};
|
||||
|
||||
let game_args = vec![
|
||||
"--username".to_string(),
|
||||
@@ -330,8 +350,7 @@ pub async fn launch(
|
||||
|
||||
crate::running::set_state(&name, crate::running::RunState::Running);
|
||||
|
||||
let log_file_path =
|
||||
crate::instance::log_files::create_log_file(instances_dir, &name);
|
||||
let log_file_path = crate::instance::log_files::create_log_file(instances_dir, &name);
|
||||
|
||||
let name_for_task = name.clone();
|
||||
let instances_dir_owned = instances_dir.to_path_buf();
|
||||
@@ -396,15 +415,16 @@ pub async fn launch(
|
||||
if code == Some(0) {
|
||||
crate::running::remove(&name_for_task);
|
||||
} else {
|
||||
crate::running::set_state(
|
||||
&name_for_task,
|
||||
crate::running::RunState::Crashed(code),
|
||||
);
|
||||
crate::running::set_state(&name_for_task, crate::running::RunState::Crashed(code));
|
||||
}
|
||||
|
||||
let manager = crate::instance::InstanceManager::new(instances_dir_owned, meta_dir_owned);
|
||||
if let Err(e) = manager.touch_last_played(&name_for_task) {
|
||||
tracing::warn!("Failed to update last_played for '{}': {}", name_for_task, e);
|
||||
tracing::warn!(
|
||||
"Failed to update last_played for '{}': {}",
|
||||
name_for_task,
|
||||
e
|
||||
);
|
||||
}
|
||||
crate::running::push_last_played(&name_for_task, chrono::Utc::now());
|
||||
crate::running::cleanup_kill_sender(&name_for_task);
|
||||
|
||||
+26
-47
@@ -99,10 +99,7 @@ impl ModLoaderInstaller for FabricInstaller {
|
||||
}
|
||||
|
||||
async fn get_game_versions(&self, client: &HttpClient) -> Result<Vec<GameVersion>, NetError> {
|
||||
match fabric::fetch_fabric_game_versions(client).await {
|
||||
Ok(versions) => Ok(versions),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
fabric::fetch_fabric_game_versions(client).await
|
||||
}
|
||||
|
||||
async fn get_versions(
|
||||
@@ -130,13 +127,13 @@ impl ModLoaderInstaller for FabricInstaller {
|
||||
_instance_dir: &Path,
|
||||
meta_dir: &Path,
|
||||
) -> Result<(), NetError> {
|
||||
let profile =
|
||||
match fabric::fetch_fabric_profile(client, game_version, loader_version).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
let profile = match fabric::fetch_fabric_profile(client, game_version, loader_version).await
|
||||
{
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
|
||||
match fabric::download_fabric_libraries(client, &profile, meta_dir).await {
|
||||
Ok(()) => {}
|
||||
@@ -175,10 +172,7 @@ impl ModLoaderInstaller for ForgeInstaller {
|
||||
}
|
||||
|
||||
async fn get_game_versions(&self, client: &HttpClient) -> Result<Vec<GameVersion>, NetError> {
|
||||
match forge::fetch_forge_game_versions(client).await {
|
||||
Ok(versions) => Ok(versions),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
forge::fetch_forge_game_versions(client).await
|
||||
}
|
||||
|
||||
async fn get_versions(
|
||||
@@ -186,12 +180,7 @@ impl ModLoaderInstaller for ForgeInstaller {
|
||||
client: &HttpClient,
|
||||
game_version: &str,
|
||||
) -> Result<Vec<String>, NetError> {
|
||||
match forge::fetch_forge_versions(client, game_version).await {
|
||||
Ok(v) => Ok(v),
|
||||
Err(e) => {
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
forge::fetch_forge_versions(client, game_version).await
|
||||
}
|
||||
|
||||
async fn install(
|
||||
@@ -305,10 +294,7 @@ impl ModLoaderInstaller for QuiltInstaller {
|
||||
}
|
||||
|
||||
async fn get_game_versions(&self, client: &HttpClient) -> Result<Vec<GameVersion>, NetError> {
|
||||
match quilt::fetch_quilt_game_versions(client).await {
|
||||
Ok(versions) => Ok(versions),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
quilt::fetch_quilt_game_versions(client).await
|
||||
}
|
||||
|
||||
async fn get_versions(
|
||||
@@ -336,13 +322,12 @@ impl ModLoaderInstaller for QuiltInstaller {
|
||||
_instance_dir: &Path,
|
||||
meta_dir: &Path,
|
||||
) -> Result<(), NetError> {
|
||||
let profile =
|
||||
match quilt::fetch_quilt_profile(client, game_version, loader_version).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
let profile = match quilt::fetch_quilt_profile(client, game_version, loader_version).await {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
return Err(e);
|
||||
}
|
||||
};
|
||||
|
||||
match quilt::download_quilt_libraries(client, &profile, meta_dir).await {
|
||||
Ok(()) => {}
|
||||
@@ -381,10 +366,7 @@ impl ModLoaderInstaller for NeoForgeInstaller {
|
||||
}
|
||||
|
||||
async fn get_game_versions(&self, client: &HttpClient) -> Result<Vec<GameVersion>, NetError> {
|
||||
match neoforge::fetch_neoforge_game_versions(client).await {
|
||||
Ok(versions) => Ok(versions),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
neoforge::fetch_neoforge_game_versions(client).await
|
||||
}
|
||||
|
||||
async fn get_versions(
|
||||
@@ -392,12 +374,7 @@ impl ModLoaderInstaller for NeoForgeInstaller {
|
||||
client: &HttpClient,
|
||||
game_version: &str,
|
||||
) -> Result<Vec<String>, NetError> {
|
||||
match neoforge::fetch_neoforge_versions(client, game_version).await {
|
||||
Ok(v) => Ok(v),
|
||||
Err(e) => {
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
neoforge::fetch_neoforge_versions(client, game_version).await
|
||||
}
|
||||
|
||||
async fn install(
|
||||
@@ -478,10 +455,9 @@ impl ModLoaderInstaller for NeoForgeInstaller {
|
||||
tracing::warn!("Failed to save NeoForge profile: {}", e);
|
||||
}
|
||||
}
|
||||
Err(e) => tracing::warn!(
|
||||
"Failed to serialize NeoForge profile: {}",
|
||||
e
|
||||
),
|
||||
Err(e) => {
|
||||
tracing::warn!("Failed to serialize NeoForge profile: {}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => tracing::warn!("Failed to create loader-profiles dir: {}", e),
|
||||
@@ -542,7 +518,10 @@ mod tests {
|
||||
let installer = VanillaInstaller;
|
||||
let tmp = std::env::temp_dir().join("mcl_test_vanilla_install");
|
||||
let meta = std::env::temp_dir().join("mcl_test_meta");
|
||||
match installer.install(&client, "1.20.1", "vanilla", &tmp, &meta).await {
|
||||
match installer
|
||||
.install(&client, "1.20.1", "vanilla", &tmp, &meta)
|
||||
.await
|
||||
{
|
||||
Ok(()) => {}
|
||||
Err(e) => assert!(false, "install failed: {}", e),
|
||||
}
|
||||
|
||||
+24
-13
@@ -109,7 +109,6 @@ impl InstanceManager {
|
||||
loader_version: Option<&str>,
|
||||
instance_dir: &std::path::Path,
|
||||
) -> Result<InstanceConfig, InstanceError> {
|
||||
|
||||
let minecraft_dir = instance_dir.join(".minecraft");
|
||||
for subdir in &["mods", "config", "resourcepacks", "shaderpacks", "saves"] {
|
||||
match std::fs::create_dir_all(minecraft_dir.join(subdir)) {
|
||||
@@ -163,21 +162,28 @@ impl InstanceManager {
|
||||
}
|
||||
};
|
||||
|
||||
let version_meta = match crate::net::mojang::fetch_version_meta(&self.client, version_entry).await {
|
||||
Ok(m) => m,
|
||||
Err(e) => {
|
||||
return Err(InstanceError::Download(e));
|
||||
}
|
||||
};
|
||||
let version_meta =
|
||||
match crate::net::mojang::fetch_version_meta(&self.client, version_entry).await {
|
||||
Ok(m) => m,
|
||||
Err(e) => {
|
||||
return Err(InstanceError::Download(e));
|
||||
}
|
||||
};
|
||||
|
||||
match crate::net::mojang::download_client_jar(&self.client, &version_meta, &self.meta_dir).await {
|
||||
match crate::net::mojang::download_client_jar(&self.client, &version_meta, &self.meta_dir)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
return Err(InstanceError::Download(e));
|
||||
}
|
||||
}
|
||||
|
||||
let meta_json_path = self.meta_dir.join("versions").join(game_version).join("meta.json");
|
||||
let meta_json_path = self
|
||||
.meta_dir
|
||||
.join("versions")
|
||||
.join(game_version)
|
||||
.join("meta.json");
|
||||
match serde_json::to_string_pretty(&version_meta) {
|
||||
Ok(json) => {
|
||||
if let Err(e) = std::fs::write(&meta_json_path, &json) {
|
||||
@@ -189,14 +195,17 @@ impl InstanceManager {
|
||||
}
|
||||
}
|
||||
|
||||
match crate::net::mojang::download_libraries(&self.client, &version_meta, &self.meta_dir).await {
|
||||
match crate::net::mojang::download_libraries(&self.client, &version_meta, &self.meta_dir)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
return Err(InstanceError::Download(e));
|
||||
}
|
||||
}
|
||||
|
||||
match crate::net::mojang::download_assets(&self.client, &version_meta, &self.meta_dir).await {
|
||||
match crate::net::mojang::download_assets(&self.client, &version_meta, &self.meta_dir).await
|
||||
{
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
return Err(InstanceError::Download(e));
|
||||
@@ -220,7 +229,7 @@ impl InstanceManager {
|
||||
&self.client,
|
||||
game_version,
|
||||
effective_loader_version,
|
||||
&instance_dir,
|
||||
instance_dir,
|
||||
&self.meta_dir,
|
||||
)
|
||||
.await
|
||||
@@ -274,7 +283,9 @@ impl InstanceManager {
|
||||
pub fn rename(&self, old_name: &str, new_name: &str) -> Result<(), InstanceError> {
|
||||
let new_name = new_name.trim();
|
||||
if new_name.is_empty() {
|
||||
return Err(InstanceError::InvalidName("Name cannot be empty".to_string()));
|
||||
return Err(InstanceError::InvalidName(
|
||||
"Name cannot be empty".to_string(),
|
||||
));
|
||||
}
|
||||
if old_name == new_name {
|
||||
return Ok(());
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
pub mod launch;
|
||||
pub mod loader;
|
||||
pub mod log_files;
|
||||
pub mod manager;
|
||||
pub mod loader;
|
||||
pub mod models;
|
||||
pub mod mods;
|
||||
pub mod resource_packs;
|
||||
|
||||
@@ -146,15 +146,7 @@ fn read_pack_description(archive: &mut zip::ZipArchive<std::fs::File>) -> String
|
||||
}
|
||||
|
||||
fn read_pack_metadata_from_dir(dir: &Path) -> (String, String, Option<Vec<u8>>) {
|
||||
let actual_dir = if dir
|
||||
.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.is_some_and(|n| n.ends_with(".disabled"))
|
||||
{
|
||||
dir.to_path_buf()
|
||||
} else {
|
||||
dir.to_path_buf()
|
||||
};
|
||||
let actual_dir = dir.to_path_buf();
|
||||
|
||||
let description = {
|
||||
let mcmeta_path = actual_dir.join("pack.mcmeta");
|
||||
|
||||
Reference in new issue
Block a user