feat: complete hosted mod sync and launcher interface updates
Axolotl desktop CI / guardrails (push) Has been cancelled
Axolotl desktop CI / desktop (macos-latest) (push) Has been cancelled
Axolotl desktop CI / desktop (ubuntu-latest) (push) Has been cancelled
Axolotl desktop CI / desktop (windows-latest) (push) Has been cancelled
Axolotl desktop CI / website (push) Has been cancelled
Repository checks / typos (push) Has been cancelled
Repository checks / tombi (push) Has been cancelled
Rust checks / shear (push) Has been cancelled
Sync source to CNB / Sync Git ref (push) Has been cancelled
Axolotl desktop CI / guardrails (push) Has been cancelled
Axolotl desktop CI / desktop (macos-latest) (push) Has been cancelled
Axolotl desktop CI / desktop (ubuntu-latest) (push) Has been cancelled
Axolotl desktop CI / desktop (windows-latest) (push) Has been cancelled
Axolotl desktop CI / website (push) Has been cancelled
Repository checks / typos (push) Has been cancelled
Repository checks / tombi (push) Has been cancelled
Rust checks / shear (push) Has been cancelled
Sync source to CNB / Sync Git ref (push) Has been cancelled
Add pack sync markers, tagged mod updates, parallel progress, JWT downloads and retry recovery. Include pending onboarding, about scene, compatibility data pack and download fixes.
This commit is contained in:
1 parent
5d473ebfbc
commit
bc904065c3
63 files changed
+3516
-1059
No files matched your search
@@ -1,10 +1,79 @@
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import {
|
||||
requestSkinSiteDownloadToken,
|
||||
skinSiteStatus,
|
||||
skinSiteUser,
|
||||
} from '../composables/skin-site-session.ts'
|
||||
|
||||
let sessionUpdate: Promise<void> = Promise.resolve()
|
||||
const attemptListeners = new Set<(instanceId: string) => void>()
|
||||
|
||||
export function onHostedPackAttemptStarted(listener: (instanceId: string) => void) {
|
||||
attemptListeners.add(listener)
|
||||
return () => {
|
||||
attemptListeners.delete(listener)
|
||||
}
|
||||
}
|
||||
|
||||
function startHostedPackAttempt(instanceId: string) {
|
||||
for (const listener of attemptListeners) listener(instanceId)
|
||||
}
|
||||
|
||||
export function clearHostedSession(): Promise<void> {
|
||||
const update = sessionUpdate
|
||||
.catch(() => {})
|
||||
.then(() => invokeHosted<void>('plugin:install|hosted_set_session', { token: null }))
|
||||
sessionUpdate = update
|
||||
return update
|
||||
}
|
||||
|
||||
export async function prepareHostedSession(): Promise<void> {
|
||||
const userId = skinSiteUser.value?.uuid
|
||||
const token = await requestSkinSiteDownloadToken()
|
||||
const update = sessionUpdate
|
||||
.catch(() => {})
|
||||
.then(async () => {
|
||||
if (skinSiteStatus.value !== 'signed-in' || skinSiteUser.value?.uuid !== userId) {
|
||||
throw new Error('StarLight 登录状态已变化,请重试。')
|
||||
}
|
||||
await invokeHosted<void>('plugin:install|hosted_set_session', { token })
|
||||
})
|
||||
sessionUpdate = update
|
||||
await update
|
||||
}
|
||||
|
||||
async function invokeWithSession<T>(command: string, args?: Record<string, unknown>): Promise<T> {
|
||||
await prepareHostedSession()
|
||||
return invokeHosted<T>(command, args)
|
||||
}
|
||||
|
||||
async function invokeHosted<T>(command: string, args?: Record<string, unknown>): Promise<T> {
|
||||
try {
|
||||
return await invoke<T>(command, args)
|
||||
} catch (cause) {
|
||||
if (
|
||||
!(cause instanceof Error) &&
|
||||
typeof cause === 'object' &&
|
||||
cause !== null &&
|
||||
'message' in cause &&
|
||||
typeof cause.message === 'string'
|
||||
) {
|
||||
throw new Error(cause.message, { cause })
|
||||
}
|
||||
throw cause
|
||||
}
|
||||
}
|
||||
|
||||
export type InstanceMode = 'starlight' | 'local'
|
||||
export const getInstanceMode = (instanceId: string) =>
|
||||
invoke<InstanceMode>('plugin:install|hosted_instance_mode', { instanceId })
|
||||
export const setInstanceMode = (instanceId: string, mode: InstanceMode) =>
|
||||
invoke<void>('plugin:install|hosted_set_instance_mode', { instanceId, mode })
|
||||
invokeHosted<InstanceMode>('plugin:install|hosted_instance_mode', { instanceId })
|
||||
export const setInstanceMode = (instanceId: string, mode: InstanceMode) => {
|
||||
if (mode === 'starlight') startHostedPackAttempt(instanceId)
|
||||
return (mode === 'starlight' ? invokeWithSession<void> : invokeHosted<void>)(
|
||||
'plugin:install|hosted_set_instance_mode',
|
||||
{ instanceId, mode },
|
||||
)
|
||||
}
|
||||
|
||||
export interface HostedPublication {
|
||||
packId: string
|
||||
@@ -26,8 +95,12 @@ export interface HostedSyncResult {
|
||||
changedFiles: number
|
||||
preservedFiles: string[]
|
||||
}
|
||||
export const hostedCatalog = () => invoke<HostedPublication[]>('plugin:install|hosted_catalog')
|
||||
export const hostedDefault = () =>
|
||||
invokeWithSession<HostedPublication>('plugin:install|hosted_default')
|
||||
export const hostedCreate = () => invokeWithSession<string>('plugin:install|hosted_create')
|
||||
export const hostedBinding = (instanceId: string) =>
|
||||
invoke<HostedBinding | null>('plugin:install|hosted_binding', { instanceId })
|
||||
export const hostedSync = (instanceId: string, packId: string) =>
|
||||
invoke<HostedSyncResult>('plugin:install|hosted_sync', { instanceId, packId })
|
||||
invokeHosted<HostedBinding | null>('plugin:install|hosted_binding', { instanceId })
|
||||
export const hostedSync = (instanceId: string) => {
|
||||
startHostedPackAttempt(instanceId)
|
||||
return invokeWithSession<HostedSyncResult>('plugin:install|hosted_sync', { instanceId })
|
||||
}
|
||||
Reference in new issue
Block a user