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,46 +167,58 @@ 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 {
for sub_path in ProjectType::iterator() return;
.map(|x| x.get_folder()) };
.chain(["crash-reports", "saves"])
{
let full_path = profile_path.join(sub_path);
if !full_path.exists() if !metadata.is_dir() {
&& !full_path.is_symlink() return;
&& !sub_path.contains(".") }
&& let Err(e) =
crate::util::io::create_dir_all(&full_path).await
{
tracing::error!(
"Failed to create directory for watcher {full_path:?}: {e}"
);
return;
}
let mut watcher = watcher.write().await; let mut to_watch = Vec::new();
if let Err(e) = watcher for sub_path in ProjectType::iterator()
.watcher() .map(|x| x.get_folder())
.watch(&full_path, RecursiveMode::Recursive) .chain(["crash-reports", "saves"])
{ {
tracing::error!( let full_path = profile_path.join(sub_path);
"Failed to watch directory for watcher {full_path:?}: {e}"
);
return;
}
}
let mut watcher = watcher.write().await; let meta = tokio::fs::symlink_metadata(&full_path).await;
if let Err(e) = watcher let exists = meta.is_ok();
.watcher() let is_symlink = meta.ok().is_some_and(|m| m.file_type().is_symlink());
.watch(&profile_path, RecursiveMode::NonRecursive)
if !exists
&& !is_symlink
&& !sub_path.contains(".")
&& let Err(e) = crate::util::io::create_dir_all(&full_path).await
{ {
tracing::error!( tracing::error!(
"Failed to watch root profile directory for watcher {profile_path:?}: {e}" "Failed to create directory for watcher {full_path:?}: {e}"
); );
return;
} }
to_watch.push(full_path);
}
let mut watcher = watcher.write().await;
for full_path in &to_watch {
if let Err(e) =
watcher.watcher().watch(full_path, RecursiveMode::Recursive)
{
tracing::error!(
"Failed to watch directory for watcher {full_path:?}: {e}"
);
return;
}
}
if let Err(e) = watcher
.watcher()
.watch(&profile_path, RecursiveMode::NonRecursive)
{
tracing::error!(
"Failed to watch root profile directory for watcher {profile_path:?}: {e}"
);
} }
} }

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();