Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/app-frontend/src/helpers/cache.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { invoke } from '@tauri-apps/api/core'
import { invoke } from '@/helpers/invoke'

export async function get_project(id, cacheBehaviour) {
return await invoke('plugin:cache|get_project', { id, cacheBehaviour })
Expand Down
2 changes: 1 addition & 1 deletion apps/app-frontend/src/helpers/friends.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { User } from '@modrinth/utils'
import { invoke } from '@tauri-apps/api/core'
import { invoke } from '@/helpers/invoke'
import type { Dayjs } from 'dayjs'
import dayjs from 'dayjs'

Expand Down
2 changes: 1 addition & 1 deletion apps/app-frontend/src/helpers/install.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { invoke } from '@tauri-apps/api/core'
import { invoke } from '@/helpers/invoke'

import { install_job_listener } from './events'
import type { InstanceLink, InstanceLoader } from './types'
Expand Down
2 changes: 1 addition & 1 deletion apps/app-frontend/src/helpers/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import type { Labrinth } from '@modrinth/api-client'
import type { ContentItem, ContentOwner } from '@modrinth/ui'
import { invoke } from '@tauri-apps/api/core'
import { invoke } from '@/helpers/invoke'

import type { InstallJobSnapshot } from './install'
import type {
Expand Down
83 changes: 83 additions & 0 deletions apps/app-frontend/src/helpers/invoke.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { invoke as tauriInvoke } from '@tauri-apps/api/core'

export type OperationCause =
| 'app/startup'
| 'navigation/home'
| 'navigation/library'
| 'navigation/browse'
| 'navigation/project'
| 'navigation/instance/overview'
| 'navigation/instance/content'
| 'navigation/instance/logs'
| 'navigation/servers'
| 'navigation/server/manage'
| 'navigation/server/content'
| 'instance/refresh/user'
| 'instance/refresh/filesystem_watch'
| 'instance/update/all'
| 'instance/update/single'
| 'instance/install'
| 'cache/revalidate'
| 'auth/session_refresh'
| 'background/friends'
| 'minecraft/launch'
| 'app/update_check'
| 'unattributed'

function navigationCause(pathname: string): OperationCause {
if (pathname === '/hosting/manage' || pathname === '/hosting/manage/') {
return 'navigation/servers'
}
if (pathname.startsWith('/hosting/manage/')) {
return pathname.split('/').includes('content')
? 'navigation/server/content'
: 'navigation/server/manage'
}
if (pathname.startsWith('/browse/')) return 'navigation/browse'
if (pathname.startsWith('/project/')) return 'navigation/project'
if (pathname.startsWith('/library')) return 'navigation/library'
if (pathname.startsWith('/instance/')) {
return pathname.split('/').includes('logs')
? 'navigation/instance/logs'
: 'navigation/instance/content'
}

return 'navigation/home'
}

function commandCause(command: string): OperationCause {
if (command === 'plugin:instance|instance_update_all') return 'instance/update/all'
if (
command === 'plugin:instance|instance_update_project' ||
command === 'plugin:instance|instance_switch_project_version_with_dependencies' ||
command === 'plugin:instance|instance_update_managed_modrinth_version'
) {
return 'instance/update/single'
}
if (
command.startsWith('plugin:install|install_') ||
command === 'plugin:jre|jre_auto_install_java' ||
command === 'plugin:instance|instance_add_project_from_version' ||
command === 'plugin:instance|instance_install_project_with_dependencies' ||
command === 'plugin:instance|instance_repair_managed_modrinth'
) {
return 'instance/install'
}
if (
command === 'plugin:instance|instance_run' ||
command === 'plugin:worlds|start_join_singleplayer_world' ||
command === 'plugin:worlds|start_join_server'
) {
return 'minecraft/launch'
}
if (command === 'plugin:mr-auth|get') return 'auth/session_refresh'

return navigationCause(window.location.pathname)
}

export function invoke<T>(command: string, args: Record<string, unknown> = {}): Promise<T> {
return tauriInvoke<T>(command, {
...args,
invocationContext: { cause: commandCause(command) },
})
}
2 changes: 1 addition & 1 deletion apps/app-frontend/src/helpers/jre.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* So, for example, addDefaultInstance creates a blank instance object, where the Rust struct is serialized,
* and deserialized into a usable JS object.
*/
import { invoke } from '@tauri-apps/api/core'
import { invoke } from '@/helpers/invoke'

/*

Expand Down
2 changes: 1 addition & 1 deletion apps/app-frontend/src/helpers/metadata.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { invoke } from '@tauri-apps/api/core'
import { invoke } from '@/helpers/invoke'

/// Gets the game versions from daedalus
// Returns a VersionManifest
Expand Down
2 changes: 1 addition & 1 deletion apps/app-frontend/src/helpers/mr_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* So, for example, addDefaultInstance creates a blank instance object, where the Rust struct is serialized,
* and deserialized into a usable JS object.
*/
import { invoke } from '@tauri-apps/api/core'
import { invoke } from '@/helpers/invoke'

export type ModrinthCredentials = {
session: string
Expand Down
2 changes: 1 addition & 1 deletion apps/app-frontend/src/helpers/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* So, for example, addDefaultInstance creates a blank instance object, where the Rust struct is serialized,
* and deserialized into a usable JS object.
*/
import { invoke } from '@tauri-apps/api/core'
import { invoke } from '@/helpers/invoke'

// Gets cached category tags
export async function get_categories() {
Expand Down
2 changes: 1 addition & 1 deletion apps/app-frontend/src/helpers/worlds.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { GameVersion } from '@modrinth/ui'
import { autoToHTML } from '@sfirew/minecraft-motd-parser'
import { invoke } from '@tauri-apps/api/core'
import { invoke } from '@/helpers/invoke'
import dayjs from 'dayjs'

import { get_full_path } from '@/helpers/instance'
Expand Down
23 changes: 17 additions & 6 deletions apps/app/src/api/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,27 @@ macro_rules! impl_cache_methods {
$(
paste::paste! {
#[tauri::command]
pub async fn [<get_ $variant:snake>](id: &str, cache_behaviour: Option<CacheBehaviour>) -> Result<Option<$type>>
pub async fn [<get_ $variant:snake>](
id: &str,
cache_behaviour: Option<CacheBehaviour>,
invocation_context: theseus::InvocationContext,
) -> Result<Option<$type>>
{
Ok(theseus::cache::[<get_ $variant:snake>](id, cache_behaviour).await?)
let context = invocation_context;
Ok(theseus::cache::[<get_ $variant:snake>](&context, id, cache_behaviour).await?)
}

#[tauri::command]
pub async fn [<get_ $variant:snake _many>](
ids: Vec<String>,
cache_behaviour: Option<CacheBehaviour>,
invocation_context: theseus::InvocationContext,
) -> Result<Vec<$type>>
{
let context = invocation_context;
let ids = ids.iter().map(|x| &**x).collect::<Vec<&str>>();
let entries =
theseus::cache::[<get_ $variant:snake _many>](&*ids, cache_behaviour).await?;
theseus::cache::[<get_ $variant:snake _many>](&context, &*ids, cache_behaviour).await?;

Ok(entries)
}
Expand Down Expand Up @@ -73,9 +80,13 @@ pub async fn purge_cache_types(cache_types: Vec<CacheValueType>) -> Result<()> {
pub async fn get_project_versions(
project_id: &str,
cache_behaviour: Option<CacheBehaviour>,
invocation_context: theseus::InvocationContext,
) -> Result<Option<Vec<Version>>> {
Ok(
theseus::cache::get_project_versions(project_id, cache_behaviour)
.await?,
let context = invocation_context;
Ok(theseus::cache::get_project_versions(
&context,
project_id,
cache_behaviour,
)
.await?)
}
23 changes: 17 additions & 6 deletions apps/app/src/api/friends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ pub fn init<R: tauri::Runtime>() -> TauriPlugin<R> {
}

#[tauri::command]
pub async fn friends() -> crate::api::Result<Vec<UserFriend>> {
Ok(theseus::friends::friends().await?)
pub async fn friends(
invocation_context: theseus::InvocationContext,
) -> crate::api::Result<Vec<UserFriend>> {
let context = invocation_context;
Ok(theseus::friends::friends(&context).await?)
}

#[tauri::command]
Expand All @@ -23,11 +26,19 @@ pub async fn friend_statuses() -> crate::api::Result<Vec<UserStatus>> {
}

#[tauri::command]
pub async fn add_friend(user_id: &str) -> crate::api::Result<()> {
Ok(theseus::friends::add_friend(user_id).await?)
pub async fn add_friend(
user_id: &str,
invocation_context: theseus::InvocationContext,
) -> crate::api::Result<()> {
let context = invocation_context;
Ok(theseus::friends::add_friend(&context, user_id).await?)
}

#[tauri::command]
pub async fn remove_friend(user_id: &str) -> crate::api::Result<()> {
Ok(theseus::friends::remove_friend(user_id).await?)
pub async fn remove_friend(
user_id: &str,
invocation_context: theseus::InvocationContext,
) -> crate::api::Result<()> {
let context = invocation_context;
Ok(theseus::friends::remove_friend(&context, user_id).await?)
}
43 changes: 38 additions & 5 deletions apps/app/src/api/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,23 @@ impl InstallPostInstallEditRequest {
#[tauri::command]
pub async fn install_get_modpack_preview(
location: CreatePackLocation,
invocation_context: theseus::InvocationContext,
) -> Result<InstallModpackPreview> {
Ok(theseus::pack::install_from::get_instance_from_pack(location).await?)
let context = invocation_context;
Ok(
theseus::pack::install_from::get_instance_from_pack(&context, location)
.await?,
)
}

#[tauri::command]
pub async fn install_create_instance(
request: InstallCreateInstanceRequest,
invocation_context: theseus::InvocationContext,
) -> Result<InstallJobSnapshot> {
let context = invocation_context;
Ok(theseus::install::create_instance(
&context,
request.name.trim().to_string(),
request.game_version,
request.loader,
Expand All @@ -93,8 +101,11 @@ pub async fn install_create_instance(
pub async fn install_create_modpack_instance(
location: CreatePackLocation,
post_install_edit: Option<InstallPostInstallEditRequest>,
invocation_context: theseus::InvocationContext,
) -> Result<InstallJobSnapshot> {
let context = invocation_context;
Ok(theseus::install::create_modpack_instance(
&context,
location,
post_install_edit.map(|edit| edit.into_core()).transpose()?,
)
Expand All @@ -106,8 +117,11 @@ pub async fn install_import_instance(
launcher_type: ImportLauncherType,
base_path: PathBuf,
instance_folder: String,
invocation_context: theseus::InvocationContext,
) -> Result<InstallJobSnapshot> {
let context = invocation_context;
Ok(theseus::install::import_instance(
&context,
launcher_type,
base_path,
instance_folder,
Expand All @@ -118,25 +132,40 @@ pub async fn install_import_instance(
#[tauri::command]
pub async fn install_duplicate_instance(
source_instance_id: String,
invocation_context: theseus::InvocationContext,
) -> Result<InstallJobSnapshot> {
Ok(theseus::install::duplicate_instance(source_instance_id).await?)
let context = invocation_context;
Ok(
theseus::install::duplicate_instance(&context, source_instance_id)
.await?,
)
}

#[tauri::command]
pub async fn install_existing_instance(
instance_id: String,
force: bool,
invocation_context: theseus::InvocationContext,
) -> Result<InstallJobSnapshot> {
Ok(theseus::install::install_existing_instance(instance_id, force).await?)
let context = invocation_context;
Ok(theseus::install::install_existing_instance(
&context,
instance_id,
force,
)
.await?)
}

#[tauri::command]
pub async fn install_pack_to_existing_instance(
instance_id: String,
location: CreatePackLocation,
post_install_edit: Option<InstallPostInstallEditRequest>,
invocation_context: theseus::InvocationContext,
) -> Result<InstallJobSnapshot> {
let context = invocation_context;
Ok(theseus::install::install_pack_to_existing_instance(
&context,
instance_id,
location,
post_install_edit.map(|edit| edit.into_core()).transpose()?,
Expand All @@ -157,8 +186,12 @@ pub async fn install_job_get(job_id: Uuid) -> Result<InstallJobSnapshot> {
}

#[tauri::command]
pub async fn install_job_retry(job_id: Uuid) -> Result<InstallJobSnapshot> {
Ok(theseus::install::retry_job(job_id).await?)
pub async fn install_job_retry(
job_id: Uuid,
invocation_context: theseus::InvocationContext,
) -> Result<InstallJobSnapshot> {
let context = invocation_context;
Ok(theseus::install::retry_job(&context, job_id).await?)
}

#[tauri::command]
Expand Down
Loading
Loading