fix: app loading speed (#6070)

This commit is contained in:
Prospector
2026-05-11 13:12:44 -07:00
committed by GitHub
parent 840b556c51
commit 6d3fdb680c
4 changed files with 64 additions and 46 deletions

View File

@@ -37,6 +37,6 @@ defineProps({
.progress-bar__fill { .progress-bar__fill {
height: 100%; height: 100%;
transition: width 0.3s; transition: width 0.3s ease-out;
} }
</style> </style>

View File

@@ -126,7 +126,7 @@ watch(
function fakeLoadingIncrease() { function fakeLoadingIncrease() {
if (loadingProgress.value < 95) { if (loadingProgress.value < 95) {
setTimeout(() => { setTimeout(() => {
loadingProgress.value += 1 loadingProgress.value += 2
fakeLoadingIncrease() fakeLoadingIncrease()
}, 5) }, 5)
} }

View File

@@ -144,18 +144,19 @@ pub(crate) async fn watch_profiles_init(
watcher: &FileWatcher, watcher: &FileWatcher,
dirs: &DirectoryInfo, dirs: &DirectoryInfo,
) { ) {
if let Ok(profiles_dir) = std::fs::read_dir(dirs.profiles_dir()) { let Ok(mut profiles_dir) = tokio::fs::read_dir(dirs.profiles_dir()).await
for profile_dir in profiles_dir { else {
if let Ok(file_name) = profile_dir.map(|x| x.file_name()) return;
&& let Some(file_name) = file_name.to_str()
{
if file_name.starts_with(".DS_Store") {
continue;
}; };
watch_profile(file_name, watcher, dirs).await; while let Ok(Some(profile_dir)) = profiles_dir.next_entry().await {
} let file_name = profile_dir.file_name();
let file_name = file_name.to_string_lossy();
if file_name.starts_with(".DS_Store") {
continue;
} }
watch_profile(&file_name, watcher, dirs).await;
} }
} }
@@ -166,18 +167,29 @@ pub(crate) async fn watch_profile(
) { ) {
let profile_path = dirs.profiles_dir().join(profile_path); let profile_path = dirs.profiles_dir().join(profile_path);
if profile_path.exists() && profile_path.is_dir() { let Ok(metadata) = tokio::fs::metadata(&profile_path).await else {
return;
};
if !metadata.is_dir() {
return;
}
let mut to_watch = Vec::new();
for sub_path in ProjectType::iterator() for sub_path in ProjectType::iterator()
.map(|x| x.get_folder()) .map(|x| x.get_folder())
.chain(["crash-reports", "saves"]) .chain(["crash-reports", "saves"])
{ {
let full_path = profile_path.join(sub_path); let full_path = profile_path.join(sub_path);
if !full_path.exists() let meta = tokio::fs::symlink_metadata(&full_path).await;
&& !full_path.is_symlink() let exists = meta.is_ok();
let is_symlink = meta.ok().is_some_and(|m| m.file_type().is_symlink());
if !exists
&& !is_symlink
&& !sub_path.contains(".") && !sub_path.contains(".")
&& let Err(e) = && let Err(e) = crate::util::io::create_dir_all(&full_path).await
crate::util::io::create_dir_all(&full_path).await
{ {
tracing::error!( tracing::error!(
"Failed to create directory for watcher {full_path:?}: {e}" "Failed to create directory for watcher {full_path:?}: {e}"
@@ -185,10 +197,13 @@ pub(crate) async fn watch_profile(
return; return;
} }
to_watch.push(full_path);
}
let mut watcher = watcher.write().await; let mut watcher = watcher.write().await;
if let Err(e) = watcher for full_path in &to_watch {
.watcher() if let Err(e) =
.watch(&full_path, RecursiveMode::Recursive) watcher.watcher().watch(full_path, RecursiveMode::Recursive)
{ {
tracing::error!( tracing::error!(
"Failed to watch directory for watcher {full_path:?}: {e}" "Failed to watch directory for watcher {full_path:?}: {e}"
@@ -197,7 +212,6 @@ pub(crate) async fn watch_profile(
} }
} }
let mut watcher = watcher.write().await;
if let Err(e) = watcher if let Err(e) = watcher
.watcher() .watcher()
.watch(&profile_path, RecursiveMode::NonRecursive) .watch(&profile_path, RecursiveMode::NonRecursive)
@@ -207,7 +221,6 @@ pub(crate) async fn watch_profile(
); );
} }
} }
}
fn crash_task(path: String) { fn crash_task(path: String) {
tokio::task::spawn(async move { tokio::task::spawn(async move {

View File

@@ -95,6 +95,12 @@ impl State {
.await?; .await?;
tokio::task::spawn(async move { tokio::task::spawn(async move {
fs_watcher::watch_profiles_init(
&state.file_watcher,
&state.directories,
)
.await;
let res = tokio::try_join!( let res = tokio::try_join!(
state.discord_rpc.clear_to_default(true), state.discord_rpc.clear_to_default(true),
Profile::refresh_all(), Profile::refresh_all(),
@@ -175,7 +181,6 @@ impl State {
tracing::info!("Initializing file watcher"); tracing::info!("Initializing file watcher");
let file_watcher = fs_watcher::init_watcher().await?; let file_watcher = fs_watcher::init_watcher().await?;
fs_watcher::watch_profiles_init(&file_watcher, &directories).await;
let process_manager = ProcessManager::new(); let process_manager = ProcessManager::new();