aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src-tauri/src/main.rs
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2026-01-18 12:39:09 +0800
committerGitHub <noreply@github.com>2026-01-18 12:39:09 +0800
commitd78520b74ee7b01db633035c9c8d33ee809ba04d (patch)
tree30b888202a82a28dbd480340ab231af411037913 /src-tauri/src/main.rs
parent6d82ab2275130f3bafdb7ec664297eb700321526 (diff)
parent373fb81604451f085bf9fbccf9251acb17e400a9 (diff)
downloadDropOut-d78520b74ee7b01db633035c9c8d33ee809ba04d.tar.gz
DropOut-d78520b74ee7b01db633035c9c8d33ee809ba04d.zip
Merge pull request #57 from HsiangNianian/fix/critical-bugs
Diffstat (limited to 'src-tauri/src/main.rs')
-rw-r--r--src-tauri/src/main.rs57
1 files changed, 52 insertions, 5 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 2871b03..853c93e 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -82,13 +82,42 @@ async fn start_game(
// Check for active account
emit_log!(window, "Checking for active account...".to_string());
- let account = auth_state
+ let mut account = auth_state
.active_account
.lock()
.unwrap()
.clone()
.ok_or("No active account found. Please login first.")?;
+ // Check if Microsoft account token is expired and refresh if needed
+ if let core::auth::Account::Microsoft(ms_account) = &account {
+ if core::auth::is_token_expired(ms_account.expires_at) {
+ emit_log!(window, "Token expired, refreshing...".to_string());
+ match core::auth::refresh_full_auth(
+ &ms_account
+ .refresh_token
+ .clone()
+ .ok_or("No refresh token available")?,
+ )
+ .await
+ {
+ Ok((refreshed_account, _new_ms_refresh)) => {
+ let refreshed_account = core::auth::Account::Microsoft(refreshed_account);
+ *auth_state.active_account.lock().unwrap() = Some(refreshed_account.clone());
+ account = refreshed_account;
+ emit_log!(window, "Token refreshed successfully".to_string());
+ }
+ Err(e) => {
+ emit_log!(window, format!("Token refresh failed: {}", e));
+ return Err(format!(
+ "Your login session has expired. Please login again: {}",
+ e
+ ));
+ }
+ }
+ }
+ }
+
emit_log!(window, format!("Account found: {}", account.username()));
let config = config_state.config.lock().unwrap().clone();
@@ -1917,10 +1946,28 @@ async fn install_forge(
"Forge installer completed, creating version profile...".to_string()
);
- // Now create the version JSON
- let result = core::forge::install_forge(&game_dir, &game_version, &forge_version)
- .await
- .map_err(|e| e.to_string())?;
+ // Check if the version JSON already exists
+ let version_id = core::forge::generate_version_id(&game_version, &forge_version);
+ let json_path = game_dir.join("versions").join(&version_id).join(format!("{}.json", version_id));
+
+ let result = if json_path.exists() {
+ // Version JSON was created by the installer, load it
+ emit_log!(
+ window,
+ "Using version profile created by Forge installer".to_string()
+ );
+ core::forge::InstalledForgeVersion {
+ id: version_id,
+ minecraft_version: game_version.clone(),
+ forge_version: forge_version.clone(),
+ path: json_path,
+ }
+ } else {
+ // Installer didn't create JSON, create it manually
+ core::forge::install_forge(&game_dir, &game_version, &forge_version)
+ .await
+ .map_err(|e| e.to_string())?
+ };
emit_log!(
window,