Skip to content

Commit

Permalink
Merge branch 'main' into add-queries-to-show-download-modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Awakened-Redstone authored Jan 9, 2025
2 parents 1a8fb0d + c52d5e9 commit 4b08482
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
8 changes: 7 additions & 1 deletion apps/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
)]

use native_dialog::{MessageDialog, MessageType};
use std::env;
use tauri::{Listener, Manager};
use theseus::prelude::*;

Expand All @@ -29,7 +30,12 @@ async fn initialize_state(app: tauri::AppHandle) -> api::Result<()> {
theseus::EventState::init(app.clone()).await?;

#[cfg(feature = "updater")]
{
'updater: {
if env::var("MODRINTH_EXTERNAL_UPDATE_PROVIDER").is_ok() {
State::init().await?;
break 'updater;
}

use tauri_plugin_updater::UpdaterExt;

let updater = app.updater_builder().build()?;
Expand Down
22 changes: 15 additions & 7 deletions packages/app-lib/src/state/minecraft_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,16 @@ pub async fn login_finish(

minecraft_entitlements(&minecraft_token.access_token).await?;

let profile = minecraft_profile(&minecraft_token.access_token).await?;

let profile_id = profile.id.unwrap_or_default();

let credentials = Credentials {
id: profile_id,
username: profile.name,
let mut credentials = Credentials {
id: Uuid::default(),
username: String::default(),
access_token: minecraft_token.access_token,
refresh_token: oauth_token.value.refresh_token,
expires: oauth_token.date
+ Duration::seconds(oauth_token.value.expires_in as i64),
active: true,
};
credentials.get_profile().await?;

credentials.upsert(exec).await?;

Expand Down Expand Up @@ -245,11 +242,22 @@ impl Credentials {
self.expires = oauth_token.date
+ Duration::seconds(oauth_token.value.expires_in as i64);

self.get_profile().await?;

self.upsert(exec).await?;

Ok(())
}

async fn get_profile(&mut self) -> crate::Result<()> {
let profile = minecraft_profile(&self.access_token).await?;

self.id = profile.id.unwrap_or_default();
self.username = profile.name;

Ok(())
}

#[tracing::instrument]
pub async fn get_default_credential(
exec: impl sqlx::Executor<'_, Database = sqlx::Sqlite> + Copy,
Expand Down

0 comments on commit 4b08482

Please sign in to comment.