Skip to content

Commit

Permalink
final fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically committed Aug 5, 2023
1 parent 60b92b7 commit b674e2f
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 37 deletions.
6 changes: 3 additions & 3 deletions theseus/src/api/mr_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub async fn authenticate_await_complete_flow(
if let Some(ref mut flow) = *write {
let creds = flow.extract_credentials(&state.fetch_semaphore).await?;

if let ModrinthCredentialsResult::Credentials { creds } = &creds {
if let ModrinthCredentialsResult::Credentials(creds) = &creds {
let mut write = state.credentials.write().await;
write.login(creds.clone()).await?;
}
Expand Down Expand Up @@ -64,7 +64,7 @@ pub async fn login_password(
)
.await?;

if let ModrinthCredentialsResult::Credentials { creds } = &creds {
if let ModrinthCredentialsResult::Credentials(creds) = &creds {
let mut write = state.credentials.write().await;
write.login(creds.clone()).await?;
}
Expand Down Expand Up @@ -95,7 +95,7 @@ pub async fn login_minecraft(
let creds =
crate::state::login_minecraft(flow, &state.fetch_semaphore).await?;

if let ModrinthCredentialsResult::Credentials { creds } = &creds {
if let ModrinthCredentialsResult::Credentials(creds) = &creds {
let mut write = state.credentials.write().await;
write.login(creds.clone()).await?;
}
Expand Down
10 changes: 8 additions & 2 deletions theseus/src/api/pack/import/curseforge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::path::PathBuf;

use serde::{Deserialize, Serialize};

use crate::state::CredentialsStore;
use crate::{
prelude::{ModLoader, ProfilePathId},
state::ProfileInstallStage,
Expand Down Expand Up @@ -90,8 +91,13 @@ pub async fn import_curseforge(
thumbnail_url: Some(thumbnail_url),
}) = minecraft_instance.installed_modpack.clone()
{
let icon_bytes =
fetch(&thumbnail_url, None, &state.fetch_semaphore).await?;
let icon_bytes = fetch(
&thumbnail_url,
None,
&state.fetch_semaphore,
&CredentialsStore(None),
)
.await?;
let filename = thumbnail_url.rsplit('/').last();
if let Some(filename) = filename {
icon = Some(
Expand Down
7 changes: 4 additions & 3 deletions theseus/src/launcher/auth.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Authentication flow based on Hydra
use crate::config::MODRINTH_API_URL;
use crate::state::CredentialsStore;
use crate::util::fetch::{fetch_advanced, fetch_json, FetchSemaphore};
use async_tungstenite as ws;
Expand All @@ -11,7 +12,7 @@ use url::Url;

lazy_static! {
static ref HYDRA_URL: Url =
Url::parse("https://staging-api.modrinth.com/v2/auth/minecraft/")
Url::parse(&format!("{MODRINTH_API_URL}auth/minecraft/"))
.expect("Hydra URL parse failed");
}

Expand Down Expand Up @@ -69,7 +70,7 @@ pub struct HydraAuthFlow<S: AsyncRead + AsyncWrite + Unpin> {
impl HydraAuthFlow<ws::tokio::ConnectStream> {
pub async fn new() -> crate::Result<Self> {
let (socket, _) = ws::tokio::connect_async(
"wss://staging-api.modrinth.com/v2/auth/minecraft/ws",
"wss://api.modrinth.com/v2/auth/minecraft/ws",
)
.await?;
Ok(Self { socket })
Expand Down Expand Up @@ -138,7 +139,7 @@ pub async fn refresh_credentials(
) -> crate::Result<()> {
let resp = fetch_json::<TokenJSON>(
Method::POST,
"https://staging-api.modrinth.com/v2/auth/minecraft/refresh",
&format!("{MODRINTH_API_URL}auth/minecraft/refresh"),
None,
Some(serde_json::json!({ "refresh_token": credentials.refresh_token })),
semaphore,
Expand Down
23 changes: 12 additions & 11 deletions theseus/src/state/mr_auth.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::config::MODRINTH_API_URL;
use crate::state::DirectoryInfo;
use crate::util::fetch::{
fetch_advanced, read_json, write, FetchSemaphore, IoSemaphore,
Expand Down Expand Up @@ -35,7 +36,7 @@ pub struct ModrinthCredentials {
#[serde(rename_all = "snake_case")]
pub enum ModrinthCredentialsResult {
TwoFactorRequired { flow: String },
Credentials { creds: ModrinthCredentials },
Credentials(ModrinthCredentials),
}

#[derive(Debug)]
Expand Down Expand Up @@ -115,7 +116,7 @@ pub struct ModrinthAuthFlow {
impl ModrinthAuthFlow {
pub async fn new(provider: &str) -> crate::Result<Self> {
let (socket, _) = async_tungstenite::tokio::connect_async(format!(
"wss://staging-api.modrinth.com/v2/auth/ws?provider={provider}"
"wss://api.modrinth.com/v2/auth/ws?provider={provider}"
))
.await?;
Ok(Self { socket })
Expand Down Expand Up @@ -186,13 +187,13 @@ async fn get_result_from_res(
} else if let Some(code) = response.get(code_key).and_then(|x| x.as_str()) {
let info = fetch_info(code, semaphore).await?;

Ok(ModrinthCredentialsResult::Credentials {
creds: ModrinthCredentials {
Ok(ModrinthCredentialsResult::Credentials(
ModrinthCredentials {
session: code.to_string(),
expires_at: Utc::now() + Duration::weeks(2),
user: info,
},
})
))
} else if let Some(error) =
response.get("description").and_then(|x| x.as_str())
{
Expand Down Expand Up @@ -221,7 +222,7 @@ pub async fn login_password(
) -> crate::Result<ModrinthCredentialsResult> {
let resp = fetch_advanced(
Method::POST,
"https://staging-api.modrinth.com/v2/auth/login",
&format!("https://{MODRINTH_API_URL}auth/login"),
None,
Some(serde_json::json!({
"username": username,
Expand Down Expand Up @@ -273,7 +274,7 @@ pub async fn login_2fa(
) -> crate::Result<ModrinthCredentials> {
let resp = fetch_advanced(
Method::POST,
"https://staging-api.modrinth.com/v2/auth/login/2fa",
&format!("{MODRINTH_API_URL}auth/login/2fa"),
None,
Some(serde_json::json!({
"code": code,
Expand Down Expand Up @@ -301,7 +302,7 @@ pub async fn create_account(
) -> crate::Result<ModrinthCredentials> {
let resp = fetch_advanced(
Method::POST,
"https://staging-api.modrinth.com/v2/auth/create",
&format!("{MODRINTH_API_URL}auth/create"),
None,
Some(serde_json::json!({
"username": username,
Expand All @@ -327,7 +328,7 @@ pub async fn login_minecraft(
) -> crate::Result<ModrinthCredentialsResult> {
let resp = fetch_advanced(
Method::POST,
"https://staging-api.modrinth.com/v2/auth/login/minecraft",
&format!("{MODRINTH_API_URL}auth/login/minecraft"),
None,
Some(serde_json::json!({
"flow": flow,
Expand All @@ -352,7 +353,7 @@ pub async fn refresh_credentials(
let token = &credentials.session;
let resp = fetch_advanced(
Method::POST,
"https://staging-api.modrinth.com/v2/session/refresh",
&format!("{MODRINTH_API_URL}session/refresh"),
None,
None,
Some(("Authorization", token)),
Expand Down Expand Up @@ -382,7 +383,7 @@ async fn fetch_info(
) -> crate::Result<ModrinthUser> {
let result = fetch_advanced(
Method::GET,
"https://staging-api.modrinth.com/v2/user",
&format!("{MODRINTH_API_URL}user"),
None,
None,
Some(("Authorization", token)),
Expand Down
4 changes: 2 additions & 2 deletions theseus/src/state/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct Settings {
#[serde(default)]
pub advanced_rendering: bool,
#[serde(default)]
pub onboarded_new: bool,
pub fully_onboarded: bool,
#[serde(default = "DirectoryInfo::get_initial_settings_dir")]
pub loaded_config_dir: Option<PathBuf>,
}
Expand Down Expand Up @@ -82,7 +82,7 @@ impl Settings {
developer_mode: false,
opt_out_analytics: false,
advanced_rendering: true,
onboarded_new: false,
fully_onboarded: false,

// By default, the config directory is the same as the settings directory
loaded_config_dir: DirectoryInfo::get_initial_settings_dir(),
Expand Down
7 changes: 6 additions & 1 deletion theseus/src/util/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,12 @@ pub async fn fetch_mirrors(
#[tracing::instrument(skip(semaphore))]
#[theseus_macros::debug_pin]
pub async fn check_internet(semaphore: &FetchSemaphore, timeout: u64) -> bool {
let result = fetch("https://api.modrinth.com", None, semaphore);
let result = fetch(
"https://api.modrinth.com",
None,
semaphore,
&CredentialsStore(None),
);
let result =
tokio::time::timeout(Duration::from_secs(timeout), result).await;
matches!(result, Ok(Ok(_)))
Expand Down
9 changes: 4 additions & 5 deletions theseus_gui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const themeStore = useTheming()
const urlModal = ref(null)
const isLoading = ref(true)
const videoPlaying = ref(false)
const offline = ref(false)
const showOnboarding = ref(false)
Expand All @@ -55,14 +54,14 @@ const onboardingVideo = ref()
defineExpose({
initialize: async () => {
isLoading.value = false
const { theme, opt_out_analytics, collapsed_navigation, advanced_rendering, onboarded_new } =
const { theme, opt_out_analytics, collapsed_navigation, advanced_rendering, fully_onboarded } =
await get()
const os = await getOS()
// video should play if the user is not on linux, and has not onboarded
videoPlaying.value = !onboarded_new && os !== 'Linux'
videoPlaying.value = !fully_onboarded && os !== 'Linux'
const dev = await isDev()
const version = await getVersion()
showOnboarding.value = !onboarded_new
showOnboarding.value = !fully_onboarded
themeStore.setThemeState(theme)
themeStore.collapsedNavigation = collapsed_navigation
Expand All @@ -72,7 +71,7 @@ defineExpose({
if (opt_out_analytics) {
mixpanel_opt_out_tracking()
}
mixpanel_track('Launched', { version, dev, onboarded_new })
mixpanel_track('Launched', { version, dev, fully_onboarded })
if (!dev) document.addEventListener('contextmenu', (event) => event.preventDefault())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const prevPage = () => {
const finishOnboarding = async () => {
mixpanel.track('OnboardingFinish')
const settings = await get()
settings.onboarded_new = true
settings.fully_onboarded = true
await set(settings)
props.finish()
}
Expand Down
10 changes: 1 addition & 9 deletions theseus_gui/src/pages/Settings.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<script setup>
import { ref, watch } from 'vue'
import {
Card,
Slider,
DropdownSelect,
Toggle,
Modal,
LogOutIcon,
LogInIcon,
} from 'omorphia'
import { Card, Slider, DropdownSelect, Toggle, Modal, LogOutIcon, LogInIcon } from 'omorphia'
import { handleError, useTheming } from '@/store/state'
import { get, set } from '@/helpers/settings'
import { get_max_memory } from '@/helpers/jre'
Expand Down

0 comments on commit b674e2f

Please sign in to comment.