Upgrading (#354)

* fixed no download bug

* draft

* Working version

* minor improvements

* cicd fix

* merge conflicts

* fixed major merge confusion

* more conflicts, reformatting

* fixed random bugs found

* added second repair option to avoid confusion
This commit is contained in:
Wyatt Verchere
2023-07-26 20:33:03 -07:00
committed by GitHub
parent 70aaf6eef9
commit 21ae310f63
24 changed files with 817 additions and 306 deletions

View File

@@ -1,6 +1,8 @@
use crate::api::Result;
use theseus::logs::{self, Logs};
use uuid::Uuid;
use theseus::{
logs::{self, Logs},
prelude::ProfilePathId,
};
/*
A log is a struct containing the datetime string, stdout, and stderr, as follows:
@@ -27,10 +29,10 @@ pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
/// Get all Logs for a profile, sorted by datetime
#[tauri::command]
pub async fn logs_get_logs(
profile_uuid: Uuid,
profile_path: ProfilePathId,
clear_contents: Option<bool>,
) -> Result<Vec<Logs>> {
let val = logs::get_logs(profile_uuid, clear_contents).await?;
let val = logs::get_logs(profile_path, clear_contents).await?;
Ok(val)
}
@@ -38,25 +40,25 @@ pub async fn logs_get_logs(
/// Get a Log struct for a profile by profile id and datetime string
#[tauri::command]
pub async fn logs_get_logs_by_datetime(
profile_uuid: Uuid,
profile_path: ProfilePathId,
datetime_string: String,
) -> Result<Logs> {
Ok(logs::get_logs_by_datetime(profile_uuid, datetime_string).await?)
Ok(logs::get_logs_by_datetime(profile_path, datetime_string).await?)
}
/// Get the stdout for a profile by profile id and datetime string
#[tauri::command]
pub async fn logs_get_output_by_datetime(
profile_uuid: Uuid,
profile_path: ProfilePathId,
datetime_string: String,
) -> Result<String> {
let profile_path = if let Some(p) =
crate::profile::get_by_uuid(profile_uuid, None).await?
crate::profile::get(&profile_path, None).await?
{
p.profile_id()
} else {
return Err(theseus::Error::from(
theseus::ErrorKind::UnmanagedProfileError(profile_uuid.to_string()),
theseus::ErrorKind::UnmanagedProfileError(profile_path.to_string()),
)
.into());
};
@@ -66,15 +68,15 @@ pub async fn logs_get_output_by_datetime(
/// Delete all logs for a profile by profile id
#[tauri::command]
pub async fn logs_delete_logs(profile_uuid: Uuid) -> Result<()> {
Ok(logs::delete_logs(profile_uuid).await?)
pub async fn logs_delete_logs(profile_path: ProfilePathId) -> Result<()> {
Ok(logs::delete_logs(profile_path).await?)
}
/// Delete a log for a profile by profile id and datetime string
#[tauri::command]
pub async fn logs_delete_logs_by_datetime(
profile_uuid: Uuid,
profile_path: ProfilePathId,
datetime_string: String,
) -> Result<()> {
Ok(logs::delete_logs_by_datetime(profile_uuid, &datetime_string).await?)
Ok(logs::delete_logs_by_datetime(profile_path, &datetime_string).await?)
}

View File

@@ -21,6 +21,9 @@ pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
profile_add_project_from_path,
profile_toggle_disable_project,
profile_remove_project,
profile_update_managed_modrinth,
profile_repair_managed_modrinth,
profile_is_managed_modrinth,
profile_run,
profile_run_wait,
profile_run_credentials,
@@ -105,7 +108,7 @@ pub async fn profile_install(path: ProfilePathId) -> Result<()> {
pub async fn profile_update_all(
path: ProfilePathId,
) -> Result<HashMap<ProjectPathId, ProjectPathId>> {
Ok(profile::update_all(&path).await?)
Ok(profile::update_all_projects(&path).await?)
}
/// Updates a specified project
@@ -162,6 +165,28 @@ pub async fn profile_remove_project(
Ok(())
}
// Updates a managed Modrinth profile
#[tauri::command]
pub async fn profile_update_managed_modrinth(
path: ProfilePathId,
) -> Result<()> {
Ok(profile::update::update_managed_modrinth(&path).await?)
}
// Repairs a managed Modrinth profile by updating it to the current version
#[tauri::command]
pub async fn profile_repair_managed_modrinth(
path: ProfilePathId,
) -> Result<()> {
Ok(profile::update::repair_managed_modrinth(&path).await?)
}
// Gets if a profile is managed by Modrinth
#[tauri::command]
pub async fn profile_is_managed_modrinth(path: ProfilePathId) -> Result<bool> {
Ok(profile::is_managed_modrinth_pack(&path).await?)
}
// Exports a profile to a .mrpack file (export_location should end in .mrpack)
// invoke('profile_export_mrpack')
#[tauri::command]

View File

@@ -18,7 +18,7 @@ pub async fn profile_create(
loader_version: Option<String>, // the modloader version to use, set to "latest", "stable", or the ID of your chosen loader
icon: Option<PathBuf>, // the icon for the profile
) -> Result<ProfilePathId> {
let res = profile_create::profile_create(
let res = profile::create::profile_create(
name,
game_version,
modloader,

View File

@@ -17,26 +17,26 @@ pub struct Logs {
/// Get all logs that exist for a given profile
/// This is returned as an array of Log objects, sorted by datetime_string (the folder name, when the log was created)
export async function get_logs(profileUuid, clearContents) {
return await invoke('plugin:logs|logs_get_logs', { profileUuid, clearContents })
export async function get_logs(profilePath, clearContents) {
return await invoke('plugin:logs|logs_get_logs', { profilePath, clearContents })
}
/// Get a profile's log by datetime_string (the folder name, when the log was created)
export async function get_logs_by_datetime(profileUuid, datetimeString) {
return await invoke('plugin:logs|logs_get_logs_by_datetime', { profileUuid, datetimeString })
export async function get_logs_by_datetime(profilePath, datetimeString) {
return await invoke('plugin:logs|logs_get_logs_by_datetime', { profilePath, datetimeString })
}
/// Get a profile's stdout only by datetime_string (the folder name, when the log was created)
export async function get_output_by_datetime(profileUuid, datetimeString) {
return await invoke('plugin:logs|logs_get_output_by_datetime', { profileUuid, datetimeString })
export async function get_output_by_datetime(profilePath, datetimeString) {
return await invoke('plugin:logs|logs_get_output_by_datetime', { profilePath, datetimeString })
}
/// Delete a profile's log by datetime_string (the folder name, when the log was created)
export async function delete_logs_by_datetime(profileUuid, datetimeString) {
return await invoke('plugin:logs|logs_delete_logs_by_datetime', { profileUuid, datetimeString })
export async function delete_logs_by_datetime(profilePath, datetimeString) {
return await invoke('plugin:logs|logs_delete_logs_by_datetime', { profilePath, datetimeString })
}
/// Delete all logs for a given profile
export async function delete_logs(profileUuid) {
return await invoke('plugin:logs|logs_delete_logs', { profileUuid })
export async function delete_logs(profilePath) {
return await invoke('plugin:logs|logs_delete_logs', { profilePath })
}

View File

@@ -94,6 +94,21 @@ export async function remove_project(path, projectPath) {
return await invoke('plugin:profile|profile_remove_project', { path, projectPath })
}
// Update a managed Modrinth profile
export async function update_managed_modrinth(path) {
return await invoke('plugin:profile|profile_update_managed_modrinth', { path })
}
// Repair a managed Modrinth profile
export async function update_repair_modrinth(path) {
return await invoke('plugin:profile|profile_repair_managed_modrinth', { path })
}
// Gets whether a profile is managed by Modrinth
export async function is_managed_modrinth(path) {
return await invoke('plugin:profile|profile_is_managed_modrinth', { path })
}
// Export a profile to .mrpack
/// included_overrides is an array of paths to override folders to include (ie: 'mods', 'resource_packs')
// Version id is optional (ie: 1.1.5)

View File

@@ -9,6 +9,8 @@ import FloatingVue from 'floating-vue'
import { get_opening_command, initialize_state } from '@/helpers/state'
import loadCssMixin from './mixins/macCssFix.js'
import { get } from '@/helpers/settings'
import { invoke } from '@tauri-apps/api'
import { isDev } from './helpers/utils.js'
const pinia = createPinia()
@@ -20,6 +22,19 @@ app.mixin(loadCssMixin)
const mountedApp = app.mount('#app')
const raw_invoke = async (plugin, fn, args) => {
return await invoke('plugin:' + plugin + '|' + fn, args)
}
isDev()
.then((dev) => {
if (dev) {
window.raw_invoke = raw_invoke
}
})
.catch((err) => {
console.error(err)
})
initialize_state()
.then(() => {
// First, redirect to other landing page if we have that setting

View File

@@ -277,8 +277,8 @@
<label for="repair-profile">
<span class="label__title">Repair instance</span>
<span class="label__description">
Reinstalls the instance and checks for corruption. Use this if your game is not launching
due to launcher-related errors.
Reinstalls Minecraft dependencies and checks for corruption. Use this if your game is not
launching due to launcher-related errors.
</span>
</label>
<button
@@ -290,6 +290,24 @@
<HammerIcon /> Repair
</button>
</div>
<div v-if="props.instance.modrinth_update_version" class="adjacent-input">
<label for="repair-profile">
<span class="label__title">Repair modpack</span>
<span class="label__description">
Reinstalls Modrinth modpack and checks for corruption. Use this if your game is not
launching due to your instance diverging from the Modrinth modpack.
</span>
</label>
<button
id="repair-profile"
class="btn btn-highlight"
:disabled="repairing"
@click="repairModpack"
>
<HammerIcon /> Repair
</button>
</div>
<div class="adjacent-input">
<label for="delete-profile">
<span class="label__title">Delete instance</span>
@@ -329,7 +347,15 @@ import {
} from 'omorphia'
import { Multiselect } from 'vue-multiselect'
import { useRouter } from 'vue-router'
import { edit, edit_icon, get_optimal_jre_key, install, list, remove } from '@/helpers/profile.js'
import {
edit,
edit_icon,
get_optimal_jre_key,
install,
list,
remove,
update_repair_modrinth,
} from '@/helpers/profile.js'
import { computed, readonly, ref, shallowRef, watch } from 'vue'
import { get_max_memory } from '@/helpers/jre.js'
import { get } from '@/helpers/settings.js'
@@ -501,6 +527,17 @@ async function repairProfile() {
})
}
async function repairModpack() {
repairing.value = true
await update_repair_modrinth(props.instance.path).catch(handleError)
repairing.value = false
mixpanel.track('InstanceRepair', {
loader: props.instance.metadata.loader,
game_version: props.instance.metadata.game_version,
})
}
const removing = ref(false)
async function removeProfile() {
removing.value = true