Add update download reason to analytics (#6023)
* Add download reason to analytics * mark modpack updates as actual updates in analytics * fmt
This commit is contained in:
@@ -184,7 +184,7 @@ export async function update_project(path: string, projectPath: string): Promise
|
|||||||
|
|
||||||
// Add a project to a profile from a version
|
// Add a project to a profile from a version
|
||||||
// Returns a path to the new project file
|
// Returns a path to the new project file
|
||||||
export type DownloadReason = 'standalone' | 'dependency' | 'modpack'
|
export type DownloadReason = 'standalone' | 'dependency' | 'modpack' | 'update'
|
||||||
|
|
||||||
export async function add_project_from_version(
|
export async function add_project_from_version(
|
||||||
path: string,
|
path: string,
|
||||||
|
|||||||
@@ -311,7 +311,7 @@ async function updateProject(mod: ContentItem) {
|
|||||||
const profile = await get(props.instance.path).catch(handleError)
|
const profile = await get(props.instance.path).catch(handleError)
|
||||||
|
|
||||||
if (profile) {
|
if (profile) {
|
||||||
await installVersionDependencies(profile, versionData).catch(handleError)
|
await installVersionDependencies(profile, versionData, 'update').catch(handleError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -347,7 +347,7 @@ async function switchProjectVersion(mod: ContentItem, version: Labrinth.Versions
|
|||||||
|
|
||||||
const profile = await get(props.instance.path).catch(handleError)
|
const profile = await get(props.instance.path).catch(handleError)
|
||||||
if (profile) {
|
if (profile) {
|
||||||
await installVersionDependencies(profile, version).catch(handleError)
|
await installVersionDependencies(profile, version, 'update').catch(handleError)
|
||||||
}
|
}
|
||||||
|
|
||||||
mod.file_path = newPath
|
mod.file_path = newPath
|
||||||
|
|||||||
@@ -430,6 +430,7 @@ export function createContentInstall(opts: {
|
|||||||
await installVersionDependencies(
|
await installVersionDependencies(
|
||||||
profile,
|
profile,
|
||||||
version,
|
version,
|
||||||
|
'dependency',
|
||||||
(depProject: Labrinth.Projects.v2.Project, depVersion?: Labrinth.Versions.v2.Version) => {
|
(depProject: Labrinth.Projects.v2.Project, depVersion?: Labrinth.Versions.v2.Version) => {
|
||||||
addInstallingItem(instance.id, depProject, depVersion)
|
addInstallingItem(instance.id, depProject, depVersion)
|
||||||
installedProjectIds.push(depProject.id)
|
installedProjectIds.push(depProject.id)
|
||||||
@@ -488,7 +489,7 @@ export function createContentInstall(opts: {
|
|||||||
await opts.router.push(`/instance/${encodeURIComponent(id)}/`)
|
await opts.router.push(`/instance/${encodeURIComponent(id)}/`)
|
||||||
|
|
||||||
const instance = await get(id)
|
const instance = await get(id)
|
||||||
await installVersionDependencies(instance, version)
|
await installVersionDependencies(instance, version, 'dependency')
|
||||||
|
|
||||||
trackEvent('InstanceCreate', {
|
trackEvent('InstanceCreate', {
|
||||||
source: 'ProjectInstallModal',
|
source: 'ProjectInstallModal',
|
||||||
@@ -589,6 +590,7 @@ export function createContentInstall(opts: {
|
|||||||
await installVersionDependencies(
|
await installVersionDependencies(
|
||||||
instance,
|
instance,
|
||||||
version,
|
version,
|
||||||
|
'dependency',
|
||||||
(
|
(
|
||||||
depProject: Labrinth.Projects.v2.Project,
|
depProject: Labrinth.Projects.v2.Project,
|
||||||
depVersion?: Labrinth.Versions.v2.Version,
|
depVersion?: Labrinth.Versions.v2.Version,
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export const isVersionCompatible = (version, project, instance) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const installVersionDependencies = async (profile, version, onDepInstalling) => {
|
export const installVersionDependencies = async (profile, version, reason, onDepInstalling) => {
|
||||||
const projectNames = new Map()
|
const projectNames = new Map()
|
||||||
const storeProjectName = (p) => {
|
const storeProjectName = (p) => {
|
||||||
if (p?.id && p.title) projectNames.set(p.id, p.title)
|
if (p?.id && p.title) projectNames.set(p.id, p.title)
|
||||||
@@ -177,7 +177,7 @@ export const installVersionDependencies = async (profile, version, onDepInstalli
|
|||||||
const batch = queuedInstalls.slice(i, i + batchSize)
|
const batch = queuedInstalls.slice(i, i + batchSize)
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
batch.map(async ({ versionId }) => {
|
batch.map(async ({ versionId }) => {
|
||||||
await add_project_from_version(profile.path, versionId, 'dependency')
|
await add_project_from_version(profile.path, versionId, reason)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ pub enum DownloadReason {
|
|||||||
Dependency,
|
Dependency,
|
||||||
/// Project was downloaded as part of a modpack.
|
/// Project was downloaded as part of a modpack.
|
||||||
Modpack,
|
Modpack,
|
||||||
|
/// Project was re-downloaded due to an update.
|
||||||
|
Update,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::str::FromStr for DownloadReason {
|
impl std::str::FromStr for DownloadReason {
|
||||||
|
|||||||
@@ -218,9 +218,8 @@ pub async fn generate_pack_from_version_id(
|
|||||||
icon_url: Option<String>,
|
icon_url: Option<String>,
|
||||||
profile_path: String,
|
profile_path: String,
|
||||||
|
|
||||||
// Existing loading bar. Unlike when existing_loading_bar is used, this one is pre-initialized with PackFileDownload
|
|
||||||
// For example, you might use this if multiple packs are being downloaded at once and you want to use the same loading bar
|
|
||||||
initialized_loading_bar: Option<LoadingBarId>,
|
initialized_loading_bar: Option<LoadingBarId>,
|
||||||
|
reason: DownloadReason,
|
||||||
) -> crate::Result<CreatePack> {
|
) -> crate::Result<CreatePack> {
|
||||||
let state = State::get().await?;
|
let state = State::get().await?;
|
||||||
let has_icon_url = icon_url.is_some();
|
let has_icon_url = icon_url.is_some();
|
||||||
@@ -301,7 +300,7 @@ pub async fn generate_pack_from_version_id(
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
let download_meta = DownloadMeta {
|
let download_meta = DownloadMeta {
|
||||||
reason: DownloadReason::Modpack,
|
reason,
|
||||||
game_version: profile.game_version.clone(),
|
game_version: profile.game_version.clone(),
|
||||||
loader: profile.loader.as_str().to_string(),
|
loader: profile.loader.as_str().to_string(),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ pub async fn install_zipped_mrpack(
|
|||||||
icon_url,
|
icon_url,
|
||||||
profile_path.clone(),
|
profile_path.clone(),
|
||||||
None,
|
None,
|
||||||
|
DownloadReason::Modpack,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
}
|
}
|
||||||
@@ -57,7 +58,12 @@ pub async fn install_zipped_mrpack(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Install pack files, and if it fails, fail safely by removing the profile
|
// Install pack files, and if it fails, fail safely by removing the profile
|
||||||
let result = install_zipped_mrpack_files(create_pack, false).await;
|
let result = install_zipped_mrpack_files(
|
||||||
|
create_pack,
|
||||||
|
false,
|
||||||
|
DownloadReason::Modpack,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(profile) => Ok(profile),
|
Ok(profile) => Ok(profile),
|
||||||
@@ -74,6 +80,7 @@ pub async fn install_zipped_mrpack(
|
|||||||
pub async fn install_zipped_mrpack_files(
|
pub async fn install_zipped_mrpack_files(
|
||||||
create_pack: CreatePack,
|
create_pack: CreatePack,
|
||||||
ignore_lock: bool,
|
ignore_lock: bool,
|
||||||
|
reason: DownloadReason,
|
||||||
) -> crate::Result<String> {
|
) -> crate::Result<String> {
|
||||||
let state = &State::get().await?;
|
let state = &State::get().await?;
|
||||||
|
|
||||||
@@ -221,7 +228,7 @@ pub async fn install_zipped_mrpack_files(
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
let download_meta = DownloadMeta {
|
let download_meta = DownloadMeta {
|
||||||
reason: DownloadReason::Modpack,
|
reason,
|
||||||
game_version: profile.game_version.clone(),
|
game_version: profile.game_version.clone(),
|
||||||
loader: profile.loader.as_str().to_string(),
|
loader: profile.loader.as_str().to_string(),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -461,7 +461,7 @@ pub async fn update_project(
|
|||||||
let mut path = Profile::add_project_version(
|
let mut path = Profile::add_project_version(
|
||||||
profile_path,
|
profile_path,
|
||||||
update_version,
|
update_version,
|
||||||
fetch::DownloadReason::Standalone,
|
fetch::DownloadReason::Update,
|
||||||
&state.pool,
|
&state.pool,
|
||||||
&state.fetch_semaphore,
|
&state.fetch_semaphore,
|
||||||
&state.io_semaphore,
|
&state.io_semaphore,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use crate::state::CacheBehaviour;
|
use crate::state::CacheBehaviour;
|
||||||
|
use crate::util::fetch::DownloadReason;
|
||||||
use crate::{
|
use crate::{
|
||||||
LoadingBarType,
|
LoadingBarType,
|
||||||
event::{
|
event::{
|
||||||
@@ -162,7 +163,8 @@ async fn replace_managed_modrinth(
|
|||||||
profile.name.clone(),
|
profile.name.clone(),
|
||||||
None,
|
None,
|
||||||
profile_path.to_string(),
|
profile_path.to_string(),
|
||||||
Some(shared_loading_bar.clone())
|
Some(shared_loading_bar.clone()),
|
||||||
|
DownloadReason::Update,
|
||||||
),
|
),
|
||||||
generate_pack_from_version_id(
|
generate_pack_from_version_id(
|
||||||
project_id.clone(),
|
project_id.clone(),
|
||||||
@@ -170,7 +172,8 @@ async fn replace_managed_modrinth(
|
|||||||
profile.name.clone(),
|
profile.name.clone(),
|
||||||
None,
|
None,
|
||||||
profile_path.to_string(),
|
profile_path.to_string(),
|
||||||
Some(shared_loading_bar)
|
Some(shared_loading_bar),
|
||||||
|
DownloadReason::Update,
|
||||||
)
|
)
|
||||||
)?
|
)?
|
||||||
} else {
|
} else {
|
||||||
@@ -182,6 +185,7 @@ async fn replace_managed_modrinth(
|
|||||||
None,
|
None,
|
||||||
profile_path.to_string(),
|
profile_path.to_string(),
|
||||||
None,
|
None,
|
||||||
|
DownloadReason::Update,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
old_pack_creator.description.existing_loading_bar = None;
|
old_pack_creator.description.existing_loading_bar = None;
|
||||||
@@ -205,6 +209,7 @@ async fn replace_managed_modrinth(
|
|||||||
pack::install_mrpack::install_zipped_mrpack_files(
|
pack::install_mrpack::install_zipped_mrpack_files(
|
||||||
new_pack_creator,
|
new_pack_creator,
|
||||||
ignore_lock,
|
ignore_lock,
|
||||||
|
DownloadReason::Update,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ pub enum DownloadReason {
|
|||||||
Standalone,
|
Standalone,
|
||||||
Dependency,
|
Dependency,
|
||||||
Modpack,
|
Modpack,
|
||||||
|
Update,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
|||||||
Reference in New Issue
Block a user