fmt clippy prettier

This commit is contained in:
Wyatt Verchere 2024-01-30 19:47:44 -08:00
parent d2834ce720
commit 6e147cc9db
5 changed files with 42 additions and 24 deletions

View File

@ -70,7 +70,7 @@ pub struct SharedProfileResponse {
pub icon_url: Option<String>, pub icon_url: Option<String>,
pub loader: ModLoader, pub loader: ModLoader,
pub game : String, pub game: String,
pub loader_version: String, pub loader_version: String,
pub game_version: String, pub game_version: String,
@ -80,7 +80,6 @@ pub struct SharedProfileResponse {
pub users: Option<Vec<String>>, pub users: Option<Vec<String>>,
} }
// Create a new shared profile from ProfilePathId // Create a new shared profile from ProfilePathId
// This converts the LinkedData to a SharedProfile and uploads it to the Labrinth API // This converts the LinkedData to a SharedProfile and uploads it to the Labrinth API
#[tracing::instrument] #[tracing::instrument]
@ -253,7 +252,10 @@ pub fn project_file_type(ext: &str) -> Option<&str> {
pub async fn get_all() -> crate::Result<Vec<SharedProfile>> { pub async fn get_all() -> crate::Result<Vec<SharedProfile>> {
let state = crate::State::get().await?; let state = crate::State::get().await?;
let creds = state.credentials.read().await; let creds = state.credentials.read().await;
let creds = creds.0.as_ref().ok_or_else(|| crate::ErrorKind::NoCredentialsError)?; let creds = creds
.0
.as_ref()
.ok_or_else(|| crate::ErrorKind::NoCredentialsError)?;
let response = REQWEST_CLIENT let response = REQWEST_CLIENT
.get(format!("{MODRINTH_API_URL_INTERNAL}client/user")) .get(format!("{MODRINTH_API_URL_INTERNAL}client/user"))
@ -325,7 +327,13 @@ pub async fn install(
shared_profile_id: String, shared_profile_id: String,
) -> crate::Result<ProfilePathId> { ) -> crate::Result<ProfilePathId> {
let state = crate::State::get().await?; let state = crate::State::get().await?;
let shared_profile = get_all().await?.into_iter().find(|x| x.id == shared_profile_id).ok_or_else(|| crate::ErrorKind::OtherError("Profile not found".to_string()))?; let shared_profile = get_all()
.await?
.into_iter()
.find(|x| x.id == shared_profile_id)
.ok_or_else(|| {
crate::ErrorKind::OtherError("Profile not found".to_string())
})?;
let linked_data = LinkedData::SharedProfile { let linked_data = LinkedData::SharedProfile {
profile_id: shared_profile.id, profile_id: shared_profile.id,
@ -858,19 +866,22 @@ pub async fn accept_share_link(link: String) -> crate::Result<()> {
// Gets a shared profile from a share link // Gets a shared profile from a share link
// This is done without accepting it- so would not include any link information, and is only usable for basic info // This is done without accepting it- so would not include any link information, and is only usable for basic info
pub async fn get_from_link( pub async fn get_from_link(
link: String link: String,
) -> crate::Result<SharedProfileResponse> { ) -> crate::Result<SharedProfileResponse> {
let state = crate::State::get().await?; let state = crate::State::get().await?;
let creds = state.credentials.read().await; let creds = state.credentials.read().await;
let creds = creds.0.as_ref().ok_or_else(|| crate::ErrorKind::NoCredentialsError)?; let creds = creds
.0
.as_ref()
.ok_or_else(|| crate::ErrorKind::NoCredentialsError)?;
let response = REQWEST_CLIENT let response = REQWEST_CLIENT
.get( .get(format!("{MODRINTH_API_URL_INTERNAL}client/share/{link}"))
format!("{MODRINTH_API_URL_INTERNAL}client/share/{link}"),
)
.header("Authorization", &creds.session) .header("Authorization", &creds.session)
.send().await?.error_for_status()?; .send()
.await?
.error_for_status()?;
let profile = response.json::<SharedProfileResponse>().await?; let profile = response.json::<SharedProfileResponse>().await?;

View File

@ -1,5 +1,8 @@
use crate::api::Result; use crate::api::Result;
use theseus::{prelude::*, shared_profile::{SharedProfile,SharedProfileResponse}}; use theseus::{
prelude::*,
shared_profile::{SharedProfile, SharedProfileResponse},
};
pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> { pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
tauri::plugin::Builder::new("profile_share") tauri::plugin::Builder::new("profile_share")
@ -29,8 +32,7 @@ pub async fn profile_share_get_all() -> Result<Vec<SharedProfile>> {
pub async fn profile_share_install( pub async fn profile_share_install(
shared_profile_id: String, shared_profile_id: String,
) -> Result<ProfilePathId> { ) -> Result<ProfilePathId> {
let res = shared_profile::install(shared_profile_id) let res = shared_profile::install(shared_profile_id).await?;
.await?;
Ok(res) Ok(res)
} }
@ -70,13 +72,12 @@ pub async fn profile_share_accept_share_link(link: String) -> Result<()> {
// This is done without accepting it- so would not include any link information, and is only usable for basic info // This is done without accepting it- so would not include any link information, and is only usable for basic info
#[tauri::command] #[tauri::command]
pub async fn profile_share_get_link_id( pub async fn profile_share_get_link_id(
link : String link: String,
) -> Result<SharedProfileResponse> { ) -> Result<SharedProfileResponse> {
let res = shared_profile::get_from_link(link).await?; let res = shared_profile::get_from_link(link).await?;
Ok(res) Ok(res)
} }
#[tauri::command] #[tauri::command]
pub async fn profile_share_remove_users( pub async fn profile_share_remove_users(
path: ProfilePathId, path: ProfilePathId,

View File

@ -162,7 +162,7 @@ pub async fn get_opening_command() -> Result<Option<CommandPayload>> {
#[tauri::command] #[tauri::command]
pub async fn test_command(command: String) -> Result<()> { pub async fn test_command(command: String) -> Result<()> {
Ok(handle_command(command).await?) handle_command(command).await
} }
// helper function called when redirected by a weblink (ie: modrith://do-something) or when redirected by a .mrpack file (in which case its a filepath) // helper function called when redirected by a weblink (ie: modrith://do-something) or when redirected by a .mrpack file (in which case its a filepath)

View File

@ -30,7 +30,7 @@ const raw_invoke = async (plugin, fn, args) => {
} }
} }
const test_command = async (command) => { const test_command = async (command) => {
return await raw_invoke('utils', 'test_command', {command }) return await raw_invoke('utils', 'test_command', { command })
} }
isDev() isDev()

View File

@ -527,7 +527,13 @@
You are not up to date with the shared profile. Click the button to update your instance. You are not up to date with the shared profile. Click the button to update your instance.
</span> </span>
</label> </label>
<Button id="share-sync-sync" @click="inboundSyncSharedProfile" :disabled="props.instance.sync_update_version?.is_synced"> <GlobeIcon /> Sync </Button> <Button
id="share-sync-sync"
@click="inboundSyncSharedProfile"
:disabled="props.instance.sync_update_version?.is_synced"
>
<GlobeIcon /> Sync
</Button>
</div> </div>
{{ props.instance.sync_update_version }} {{ props.instance.sync_update_version }}
</Card> </Card>