Sync source to CNB / Sync Git ref (push) Has been cancelled
新增同步 helpers(synced-options / synced-packs / game-options),在 instance helper 中补充同步类型与 API。新增实例设置「同步」标签页(SyncSettings)及 SyncSource / SyncedPacks / servers / command-history 四个弹窗,并把 CheckCircleButton、TeleportOverflowMenu 从 ui 包导出。同步相关的 en-US / zh-CN 文案已补齐(各 62 条)。game-settings-modal 留待下一轮。
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
import type { ContentItem } from '@modrinth/ui'
|
|
import { queryOptions } from '@tanstack/vue-query'
|
|
import { invoke } from '@tauri-apps/api/core'
|
|
|
|
import { adaptContentItems, isSyncedOptionAvailable } from './instance'
|
|
|
|
export type SyncedPackType = 'resourcepack' | 'datapack'
|
|
export type SyncedPackAction = 'enable' | 'disable'
|
|
|
|
export type DesyncServerMode = 'keep_in_other_instances' | 'remove_from_other_instances'
|
|
|
|
export function isSyncedPackTypeAvailable(projectType: ContentItem['project_type']): boolean {
|
|
return (
|
|
['resourcepack', 'datapack'].includes(projectType) &&
|
|
isSyncedOptionAvailable(projectType === 'resourcepack' ? 'resource_packs' : 'data_packs')
|
|
)
|
|
}
|
|
|
|
export interface PackSyncPreview {
|
|
pack: ContentItem
|
|
instances: {
|
|
instance_id: string
|
|
name: string
|
|
game_version: string
|
|
compatible: boolean
|
|
participating: boolean
|
|
}[]
|
|
}
|
|
|
|
export const syncedPackKeys = {
|
|
all: ['synced-packs'] as const,
|
|
list: (type: SyncedPackType) => ['synced-packs', 'list', type] as const,
|
|
}
|
|
|
|
export function syncedPackQueryOptions(type: SyncedPackType) {
|
|
return queryOptions({
|
|
queryKey: syncedPackKeys.list(type),
|
|
queryFn: () => list_synced_packs(type),
|
|
enabled: isSyncedPackTypeAvailable(type),
|
|
})
|
|
}
|
|
|
|
export async function list_synced_packs(projectType: SyncedPackType): Promise<ContentItem[]> {
|
|
const items = await invoke<ContentItem[]>('plugin:instance|instance_list_synced_packs', {
|
|
projectType,
|
|
})
|
|
return adaptContentItems(items).map((item) => ({ ...item, external: !item.project }))
|
|
}
|
|
|
|
export function get_pack_sync_preview(
|
|
instanceId: string,
|
|
projectPath: string,
|
|
): Promise<PackSyncPreview> {
|
|
return invoke('plugin:instance|instance_get_pack_sync_preview', { instanceId, projectPath })
|
|
}
|
|
|
|
export function sync_pack(instanceId: string, projectPath: string): Promise<void> {
|
|
return invoke('plugin:instance|instance_sync_pack', { instanceId, projectPath })
|
|
}
|
|
|
|
export function desync_pack(
|
|
instanceId: string,
|
|
packId: string,
|
|
mode: DesyncServerMode,
|
|
): Promise<void> {
|
|
return invoke('plugin:instance|instance_desync_pack', { instanceId, packId, mode })
|
|
}
|
|
|
|
export function upload_synced_pack(
|
|
path: string,
|
|
projectType: SyncedPackType,
|
|
gameVersions: string[],
|
|
): Promise<void> {
|
|
return invoke('plugin:instance|instance_upload_synced_pack', { path, projectType, gameVersions })
|
|
}
|
|
|
|
export function set_synced_pack_enabled(packId: string, enabled: boolean): Promise<void> {
|
|
return invoke('plugin:instance|instance_set_synced_pack_enabled', { packId, enabled })
|
|
}
|
|
|
|
export function remove_synced_pack(packId: string): Promise<void> {
|
|
return invoke('plugin:instance|instance_remove_synced_pack', { packId })
|
|
}
|